@@ -12,19 +12,18 @@ var (
12
12
)
13
13
14
14
type Nature struct {
15
- Type reflect.Type
16
- Nil bool
17
- SubType SubType
18
- Func * builtin.Function
19
- Method bool
20
- MethodIndex int
21
- FieldIndex []int
15
+ Type reflect.Type // Type of the value. If nil, then value is unknown.
16
+ Func * builtin.Function // Used to pass function type from callee to CallNode.
17
+ ArrayOf * Nature // Elem nature of array type (usually Type is []any, but ArrayOf can be any nature).
18
+ Fields map [string ]Nature // Fields of map type.
19
+ Strict bool // If map is types.StrictMap.
20
+ Nil bool // If value is nil.
21
+ Method bool // If value retrieved from method. Usually used to determine amount of in arguments.
22
+ MethodIndex int // Index of method in type.
23
+ FieldIndex []int // Index of field in type.
22
24
}
23
25
24
26
func (n Nature ) String () string {
25
- if n .SubType != nil {
26
- return n .SubType .String ()
27
- }
28
27
if n .Type != nil {
29
28
return n .Type .String ()
30
29
}
@@ -57,8 +56,8 @@ func (n Nature) Elem() Nature {
57
56
case reflect .Map , reflect .Ptr :
58
57
return Nature {Type : n .Type .Elem ()}
59
58
case reflect .Array , reflect .Slice :
60
- if array , ok := n . SubType .( Array ); ok {
61
- return array . Elem
59
+ if n . ArrayOf != nil {
60
+ return * n . ArrayOf
62
61
}
63
62
return Nature {Type : n .Type .Elem ()}
64
63
}
@@ -180,14 +179,14 @@ func (n Nature) Get(name string) (Nature, bool) {
180
179
}, true
181
180
}
182
181
case reflect .Map :
183
- if f , ok := n .SubType . Get ( name ) ; ok {
182
+ if f , ok := n .Fields [ name ] ; ok {
184
183
return f , true
185
184
}
186
185
}
187
186
return unknown , false
188
187
}
189
188
190
- func (n Nature ) List () map [string ]Nature {
189
+ func (n Nature ) All () map [string ]Nature {
191
190
table := make (map [string ]Nature )
192
191
193
192
if n .Type == nil {
@@ -215,23 +214,11 @@ func (n Nature) List() map[string]Nature {
215
214
}
216
215
217
216
case reflect .Map :
218
- if st , ok := n .SubType .(Map ); ok {
219
- for key , nt := range st .Fields {
220
- if _ , ok := table [key ]; ok {
221
- continue
222
- }
223
- table [key ] = nt
224
- }
225
- }
226
- v := reflect .ValueOf (n .SubType )
227
- if v .Kind () != reflect .Map {
228
- break
229
- }
230
- for _ , key := range v .MapKeys () {
231
- value := v .MapIndex (key )
232
- if key .Kind () == reflect .String && value .IsValid () && value .CanInterface () {
233
- table [key .String ()] = Nature {Type : reflect .TypeOf (value .Interface ())}
217
+ for key , nt := range n .Fields {
218
+ if _ , ok := table [key ]; ok {
219
+ continue
234
220
}
221
+ table [key ] = nt
235
222
}
236
223
}
237
224
0 commit comments