-
Notifications
You must be signed in to change notification settings - Fork 14
/
reg_consts.go
48 lines (40 loc) · 1 KB
/
reg_consts.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 constProvider struct {
cache map[string][]interface{}
lock *sync.Mutex
}
func (v *constProvider) Provide(in interface{}) []interface{} {
v.lock.Lock()
defer v.lock.Unlock()
p := in.(*astdata.Package)
if d, ok := v.cache[p.Path()]; ok {
return d
}
va := p.Constants()
res := make([]interface{}, len(va))
for i := range va {
res[i] = va[i]
}
v.cache[p.Path()] = res
return res
}
func registerConstant() {
RegisterTable("consts", &constProvider{
cache: make(map[string][]interface{}),
lock: &sync.Mutex{},
})
RegisterField("consts", "name", genericName{})
RegisterField("consts", "pkg_name", genericPackageName{})
RegisterField("consts", "pkg_path", genericPackagePath{})
RegisterField("consts", "file", genericFileName{})
RegisterField("consts", "exported", genericIsExported{})
RegisterField("consts", "docs", genericDoc{})
RegisterField("consts", "def", genericDefinition{})
}
func init() {
registerConstant()
}