-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapi.go
104 lines (87 loc) · 2.15 KB
/
api.go
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package compat
import (
"go/types"
)
// API
type API struct {
// Packages included directly in the API.
Packages []*Package
// Reachable is the set of all objects that are reachable from the API.
Reachable []*Object
}
// NewAPI creates an empty API.
func NewAPI() *API {
return &API{}
}
func (a *API) LookupSymbol(sym *Symbol) *Object {
for _, obj := range a.Reachable {
if &obj.Symbol == sym {
return obj
}
}
return nil
}
type Package struct {
Path string `json:"path"`
Objects map[string]*Object `json:"objects"`
}
func NewPackage(path string) *Package {
return &Package{
Path: path,
Objects: make(map[string]*Object),
}
}
type DeclarationType string
const (
TypeDeclaration DeclarationType = "type"
AliasDeclaration = "alias"
VarDeclaration = "var"
ConstDeclaration = "const"
FuncDeclaration = "func"
)
type Type string
const (
StructType Type = "struct"
BasicType = "basic"
SliceType = "slice"
ArrayType = "array"
FuncType = "func"
ChanType = "chan"
MapType = "map"
PointerType = "pointer"
InterfaceType = "interface"
)
type Symbol struct {
Package string `json:"package"`
Name string `json:"name"`
}
type Object struct {
Symbol Symbol `json:"symbol"`
Type DeclarationType `json:"type"`
Definition *Definition `json:"definition,omitempty"`
Methods []*Func `json:"methods,omitempty"`
}
type Definition struct {
Type Type `json:"type"`
Symbol *Symbol `json:"symbol,omitempty"`
Elem *Definition `json:"elem,omitempty"`
Key *Definition `json:"key,omitempty"`
Len int64 `json:"len,omitempty"`
ChanDir types.ChanDir `json:"chandir,omitempty"`
Fields []*Field `json:"fields,omitempty"`
Functions []*Func `json:"functions,omitempty"`
Signature *Signature `json:"signature,omitempty"`
}
type Field struct {
Name string
Type *Definition
}
type Func struct {
Signature
Name string
}
type Signature struct {
Params []*Definition
Results []*Definition
Variadic bool
}