Skip to content

Commit 332918b

Browse files
committed
rename Optional to TypeData
1 parent 9356f33 commit 332918b

File tree

5 files changed

+37
-37
lines changed

5 files changed

+37
-37
lines changed

checker/checker.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -264,18 +264,18 @@ func (v *Checker) ident(node ast.Node, name string, strict, builtins bool) Natur
264264
if builtins {
265265
if fn, ok := v.config.Functions[name]; ok {
266266
nt := v.config.NtCache.FromType(fn.Type())
267-
if nt.Optional == nil {
268-
nt.Optional = new(Optional)
267+
if nt.TypeData == nil {
268+
nt.TypeData = new(TypeData)
269269
}
270-
nt.Optional.Func = fn
270+
nt.TypeData.Func = fn
271271
return nt
272272
}
273273
if fn, ok := v.config.Builtins[name]; ok {
274274
nt := v.config.NtCache.FromType(fn.Type())
275-
if nt.Optional == nil {
276-
nt.Optional = new(Optional)
275+
if nt.TypeData == nil {
276+
nt.TypeData = new(TypeData)
277277
}
278-
nt.Optional.Func = fn
278+
nt.TypeData.Func = fn
279279
return nt
280280
}
281281
}
@@ -552,7 +552,7 @@ func (v *Checker) memberNode(node *ast.MemberNode) Nature {
552552
if !prop.AssignableTo(base.Key(&v.config.NtCache)) && !prop.IsUnknown(&v.config.NtCache) {
553553
return v.error(node.Property, "cannot use %s to get an element from %s", prop.String(), base.String())
554554
}
555-
if prop, ok := node.Property.(*ast.StringNode); ok && base.Optional != nil {
555+
if prop, ok := node.Property.(*ast.StringNode); ok && base.TypeData != nil {
556556
if field, ok := base.Fields[prop.Value]; ok {
557557
return field
558558
} else if base.Strict {
@@ -644,8 +644,8 @@ func (v *Checker) callNode(node *ast.CallNode) Nature {
644644
return Nature{}
645645
}
646646

647-
if nt.Optional != nil && nt.Optional.Func != nil {
648-
return v.checkFunction(nt.Optional.Func, node, node.Arguments)
647+
if nt.TypeData != nil && nt.TypeData.Func != nil {
648+
return v.checkFunction(nt.TypeData.Func, node, node.Arguments)
649649
}
650650

651651
fnName := "function"

checker/info.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func MethodIndex(c *Cache, env Nature, node ast.Node) (bool, int, string) {
3232
switch n := node.(type) {
3333
case *ast.IdentifierNode:
3434
if env.Kind == reflect.Struct {
35-
if m, ok := env.Get(c, n.Value); ok && m.Optional != nil {
35+
if m, ok := env.Get(c, n.Value); ok && m.TypeData != nil {
3636
return m.Method, m.MethodIndex, n.Value
3737
}
3838
}

checker/nature/nature.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type Nature struct {
3737
Type reflect.Type // Type of the value. If nil, then value is unknown.
3838
Kind reflect.Kind // Kind of the value.
3939

40-
*Optional
40+
*TypeData
4141

4242
// Ref is a reference used for multiple, disjoint purposes. When the Nature
4343
// is for a:
@@ -50,7 +50,7 @@ type Nature struct {
5050
Method bool // If value retrieved from method. Usually used to determine amount of in arguments.
5151
}
5252

53-
type Optional struct {
53+
type TypeData struct {
5454
pkgPath string
5555
methodset *methodset // optional to avoid the map in *Cache
5656

@@ -100,15 +100,15 @@ func (c *Cache) FromType(t reflect.Type) Nature {
100100
if t == nil {
101101
return Nature{}
102102
}
103-
var opt *Optional
103+
var opt *TypeData
104104
k := t.Kind()
105105
switch k {
106106
case reflect.Struct:
107107
return c.getStruct(t)
108108
case reflect.Func:
109-
opt = new(Optional)
109+
opt = new(TypeData)
110110
}
111-
return Nature{Type: t, Kind: k, Optional: opt}
111+
return Nature{Type: t, Kind: k, TypeData: opt}
112112
}
113113

114114
func (c *Cache) getStruct(t reflect.Type) Nature {
@@ -122,7 +122,7 @@ func (c *Cache) getStruct(t reflect.Type) Nature {
122122
nt := Nature{
123123
Type: t,
124124
Kind: reflect.Struct,
125-
Optional: &Optional{
125+
TypeData: &TypeData{
126126
structData: &structData{
127127
rType: t,
128128
numField: t.NumField(),
@@ -215,7 +215,7 @@ func (n *Nature) Elem(c *Cache) Nature {
215215
case reflect.Ptr:
216216
return c.FromType(n.Type.Elem())
217217
case reflect.Map:
218-
if n.Optional != nil && n.DefaultMapValue != nil {
218+
if n.TypeData != nil && n.DefaultMapValue != nil {
219219
return *n.DefaultMapValue
220220
}
221221
return c.FromType(n.Type.Elem())
@@ -243,12 +243,12 @@ func (n *Nature) AssignableTo(nt Nature) bool {
243243
}
244244

245245
func (n *Nature) getMethodset(c *Cache) *methodset {
246-
if n.Optional != nil && n.Optional.methodset != nil {
247-
return n.Optional.methodset
246+
if n.TypeData != nil && n.TypeData.methodset != nil {
247+
return n.TypeData.methodset
248248
}
249249
s := c.getMethodset(n.Type, n.Kind)
250-
if n.Optional != nil {
251-
n.Optional.methodset = s // cache locally if possible
250+
if n.TypeData != nil {
251+
n.TypeData.methodset = s // cache locally if possible
252252
}
253253
return s
254254
}
@@ -341,7 +341,7 @@ func (n *Nature) FieldByName(c *Cache, name string) (Nature, bool) {
341341
return Nature{}, false
342342
}
343343
var sd *structData
344-
if n.Optional != nil && n.structData != nil {
344+
if n.TypeData != nil && n.structData != nil {
345345
sd = n.structData
346346
} else {
347347
sd = c.getStruct(n.Type).structData
@@ -356,13 +356,13 @@ func (n *Nature) PkgPath() string {
356356
if n.Type == nil {
357357
return ""
358358
}
359-
if n.Optional != nil && n.Optional.pkgPathSet {
360-
return n.Optional.pkgPath
359+
if n.TypeData != nil && n.TypeData.pkgPathSet {
360+
return n.TypeData.pkgPath
361361
}
362362
p := n.Type.PkgPath()
363-
if n.Optional != nil {
364-
n.Optional.pkgPathSet = true
365-
n.Optional.pkgPath = p
363+
if n.TypeData != nil {
364+
n.TypeData.pkgPathSet = true
365+
n.TypeData.pkgPath = p
366366
}
367367
return p
368368
}
@@ -375,7 +375,7 @@ func (n *Nature) IsFastMap() bool {
375375
}
376376

377377
func (n *Nature) Get(c *Cache, name string) (Nature, bool) {
378-
if n.Kind == reflect.Map && n.Optional != nil {
378+
if n.Kind == reflect.Map && n.TypeData != nil {
379379
f, ok := n.Fields[name]
380380
return f, ok
381381
}
@@ -414,8 +414,8 @@ func (n *Nature) All(c *Cache) map[string]Nature {
414414
for i := 0; i < n.NumMethods(c); i++ {
415415
method := n.Type.Method(i)
416416
nt := c.FromType(method.Type)
417-
if nt.Optional == nil {
418-
nt.Optional = new(Optional)
417+
if nt.TypeData == nil {
418+
nt.TypeData = new(TypeData)
419419
}
420420
nt.Method = true
421421
nt.MethodIndex = method.Index
@@ -434,7 +434,7 @@ func (n *Nature) All(c *Cache) map[string]Nature {
434434
}
435435

436436
case reflect.Map:
437-
if n.Optional != nil {
437+
if n.TypeData != nil {
438438
for key, nt := range n.Fields {
439439
if _, ok := table[key]; ok {
440440
continue

conf/env.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ func EnvWithCache(c *Cache, env any) Nature {
4040

4141
case reflect.Map:
4242
n := c.FromType(v.Type())
43-
if n.Optional == nil {
44-
n.Optional = new(Optional)
43+
if n.TypeData == nil {
44+
n.TypeData = new(TypeData)
4545
}
4646
n.Strict = true
4747
n.Fields = make(map[string]Nature, v.Len())

types/types.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ const Extra = "[[__extra_keys__]]"
101101

102102
func (m Map) Nature() Nature {
103103
nt := NatureOf(map[string]any{})
104-
if nt.Optional == nil {
105-
nt.Optional = new(Optional)
104+
if nt.TypeData == nil {
105+
nt.TypeData = new(TypeData)
106106
}
107107
nt.Fields = make(map[string]Nature, len(m))
108108
nt.Strict = true
@@ -157,8 +157,8 @@ type array struct {
157157
func (a array) Nature() Nature {
158158
of := a.of.Nature()
159159
nt := NatureOf([]any{})
160-
if nt.Optional == nil {
161-
nt.Optional = new(Optional)
160+
if nt.TypeData == nil {
161+
nt.TypeData = new(TypeData)
162162
}
163163
nt.Fields = make(map[string]Nature, 1)
164164
nt.Ref = &of

0 commit comments

Comments
 (0)