-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcall.go
More file actions
65 lines (56 loc) · 1.32 KB
/
call.go
File metadata and controls
65 lines (56 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package golang
import (
"fmt"
"go/token"
"github.com/code-visible/golang/parsedtypes"
"github.com/code-visible/golang/utils"
)
const (
CallTypeBuiltin = "builtin"
CallTypeStd = "std"
CallTypeInternal = "internal"
CallTypeExternal = "external"
CallTypePackage = "package"
)
type Call struct {
ID string `json:"id"`
Pos string `json:"pos"`
Caller string `json:"caller"`
Callee string `json:"callee"`
File string `json:"file"`
Typ string `json:"typ"`
Signature string `json:"signature"`
Dep string `json:"dep"`
pos token.Pos
caller string
scope string
selector string
typ *parsedtypes.Type
file *File
}
func NewCall(pos token.Pos, scope string, selector string, typ *parsedtypes.Type, file *File) *Call {
return &Call{
pos: pos,
scope: scope,
selector: selector,
typ: typ,
file: file,
}
}
func (c *Call) SetupID() {
c.ID = utils.Hash(c.LookupName())
}
func (c *Call) LookupName() string {
return fmt.Sprintf("%s:%s-%s", c.file.LookupName(), c.caller, c.Signature)
}
func (c *Call) Complete() {
if c.typ != nil {
c.Signature = fmt.Sprintf("(%s).%s()", c.typ, c.selector)
return
}
if c.scope != "" {
c.Signature = fmt.Sprintf("%s.%s()", c.scope, c.selector)
return
}
c.Signature = fmt.Sprintf("%s()", c.selector)
}