-
Notifications
You must be signed in to change notification settings - Fork 14
/
reg_functions.go
78 lines (64 loc) · 1.71 KB
/
reg_functions.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
package goql
import (
"sync"
"github.com/fzerorubigd/goql/astdata"
)
type functionProvider struct {
cache map[string][]interface{}
lock *sync.Mutex
}
func (f *functionProvider) Provide(in interface{}) []interface{} {
f.lock.Lock()
defer f.lock.Unlock()
p := in.(*astdata.Package)
if d, ok := f.cache[p.Path()]; ok {
return d
}
fn := p.Functions()
res := make([]interface{}, len(fn))
for i := range fn {
res[i] = fn[i]
}
f.cache[p.Path()] = res
return res
}
type isMethodColumn struct{}
func (isMethodColumn) Value(in interface{}) String {
fn := in.(*astdata.Function)
if fn.ReceiverType() == "" {
return String{Null: true}
}
return String{String: fn.ReceiverType()}
}
type isPointerMethod struct{}
func (isPointerMethod) Value(in interface{}) Bool {
fn := in.(*astdata.Function)
if fn.ReceiverType() == "" {
return Bool{Null: true}
}
return Bool{Bool: fn.RecieverPointer()}
}
type bodyCol struct{}
func (bodyCol) Value(in interface{}) String {
fn := in.(*astdata.Function)
return String{String: fn.Body()}
}
func registerFunc() {
RegisterTable("funcs", &functionProvider{
cache: make(map[string][]interface{}),
lock: &sync.Mutex{},
})
RegisterField("funcs", "name", genericName{})
RegisterField("funcs", "pkg_name", genericPackageName{})
RegisterField("funcs", "pkg_path", genericPackagePath{})
RegisterField("funcs", "file", genericFileName{})
RegisterField("funcs", "receiver", isMethodColumn{})
RegisterField("funcs", "pointer_receiver", isPointerMethod{})
RegisterField("funcs", "exported", genericIsExported{})
RegisterField("funcs", "docs", genericDoc{})
RegisterField("funcs", "body", bodyCol{})
RegisterField("funcs", "def", genericDefinition{})
}
func init() {
registerFunc()
}