-
Notifications
You must be signed in to change notification settings - Fork 8
/
types_value_bind.go
65 lines (59 loc) · 1.32 KB
/
types_value_bind.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
package gotype
func newTypeValueBind(typ, val Type, info *info) Type {
switch typ.Kind() {
case Struct:
if v, ok := val.(*typeValuePairs); ok {
nt := &typeStruct{}
fl := typ.NumField()
for i := 0; i != fl; i++ {
f := typ.Field(i)
name := f.Name()
b := f
if val, ok := v.li.Search(name); ok {
b = newTypeValueBind(f, val, info)
}
nt.fields = append(nt.fields, b)
}
return nt
}
case Declaration:
name := typ.Name()
t := newTypeValueBind(typ.Declaration(), val, info)
if typ.Origin() != nil {
t = newTypeOrigin(t, typ.Origin(), info, typ.Doc(), typ.Comment())
}
return newDeclaration(name, t)
}
return newValueBind(typ, val.Value)
}
func newValueBind(typ Type, valfunc func() string) *typeValueBind {
if tv, ok := typ.(*typeValueBind); ok {
return newValueBind(tv.Type, tv.Value)
}
return &typeValueBind{
Type: typ,
valfunc: valfunc,
}
}
func newEvalBind(val Type, index int64, info *infoFile) Type {
ori := val.Origin()
val = newValueBind(val, func() string {
v, err := constantEval(ori, int64(index), info)
if err != nil {
return ""
}
return v.ExactString()
})
return val
}
type typeValueBind struct {
Type
valfunc func() string
val string
}
func (t *typeValueBind) Value() string {
if t.val == "" {
t.val = t.valfunc()
}
return t.val
}