-
Notifications
You must be signed in to change notification settings - Fork 0
/
fields.go
91 lines (72 loc) · 1.35 KB
/
fields.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
package symbols
import (
"sync"
"sync/atomic"
)
type FieldKey struct {
Name string
Class string
}
func NewFieldKey(name, class string) FieldKey {
return FieldKey{
Name: name,
Class: class,
}
}
var FieldsCount int64
type Field struct {
Name string
Class *Class
Used *Functions
Id int64
}
func NewField(name string, class *Class) *Field {
atomic.AddInt64(&FieldsCount, 1)
return &Field{
Name: name,
Class: class,
Used: NewFunctions(),
Id: FieldsCount,
}
}
func (f *Field) ID() int64 {
return f.Id
}
func (f *Field) String() string {
return f.Class.Name + "::" + f.Name
}
type Fields struct {
m sync.Mutex
Fields map[FieldKey]*Field
}
func NewFields() *Fields {
return &Fields{
Fields: map[FieldKey]*Field{},
}
}
func (c *Fields) Len() int {
return len(c.Fields)
}
func (c *Fields) Add(field *Field) {
c.m.Lock()
c.Fields[NewFieldKey(field.Name, field.Class.Name)] = field
c.m.Unlock()
}
func (c *Fields) Get(key FieldKey) (*Field, bool) {
c.m.Lock()
field, ok := c.Fields[key]
c.m.Unlock()
return field, ok
}
func (c *Fields) AddMethodAccess(key FieldKey, class *Class, method *Function) {
field, found := c.Get(key)
if !found {
c.Add(NewField(key.Name, class))
field, _ = c.Get(key)
}
if method.Class != nil {
method.Class.AddDeps(field.Class)
}
method.UsedFields.Add(field)
field.Used.Add(method)
}