-
Notifications
You must be signed in to change notification settings - Fork 14
/
reg_types.go
48 lines (40 loc) · 1008 Bytes
/
reg_types.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
package goql
import (
"sync"
"github.com/fzerorubigd/goql/astdata"
)
type typeProvider struct {
cache map[string][]interface{}
lock *sync.Mutex
}
func (t *typeProvider) Provide(in interface{}) []interface{} {
t.lock.Lock()
defer t.lock.Unlock()
p := in.(*astdata.Package)
if d, ok := t.cache[p.Path()]; ok {
return d
}
fs := p.Types()
res := make([]interface{}, len(fs))
for i := range fs {
res[i] = fs[i]
}
t.cache[p.Path()] = res
return res
}
func registerTypes() {
RegisterTable("types", &typeProvider{
cache: make(map[string][]interface{}),
lock: &sync.Mutex{},
})
RegisterField("types", "name", genericName{})
RegisterField("types", "pkg_name", genericPackageName{})
RegisterField("types", "pkg_path", genericPackagePath{})
RegisterField("types", "file", genericFileName{})
RegisterField("types", "exported", genericIsExported{})
RegisterField("types", "docs", genericDoc{})
RegisterField("types", "def", genericDefinition{})
}
func init() {
registerTypes()
}