-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcheckident.go
More file actions
46 lines (42 loc) · 1.24 KB
/
Copy pathcheckident.go
File metadata and controls
46 lines (42 loc) · 1.24 KB
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
package eval
import (
"reflect"
"go/ast"
)
func checkIdent(ident *ast.Ident, env Env) (_ *Ident, errs []error) {
aexpr := &Ident{Ident: ident}
switch aexpr.Name {
case "nil":
aexpr.constValue = constValueOf(UntypedNil{})
aexpr.knownType = []reflect.Type{ConstNil}
case "true":
aexpr.constValue = constValueOf(true)
aexpr.knownType = []reflect.Type{ConstBool}
case "false":
aexpr.constValue = constValueOf(false)
aexpr.knownType = []reflect.Type{ConstBool}
default:
for searchEnv := env; searchEnv != nil; searchEnv = searchEnv.PopScope() {
if v := searchEnv.Var(aexpr.Name); v.IsValid() {
aexpr.knownType = knownType{v.Elem().Type()}
aexpr.source = envVar
return aexpr, errs
} else if v := searchEnv.Func(aexpr.Name); v.IsValid() {
aexpr.knownType = knownType{v.Type()}
aexpr.source = envFunc
return aexpr, errs
} else if v := searchEnv.Const(aexpr.Name); v.IsValid() {
if n, ok := v.Interface().(*ConstNumber); ok {
aexpr.knownType = knownType{n.Type}
} else {
aexpr.knownType = knownType{v.Type()}
}
aexpr.constValue = constValue(v)
aexpr.source = envConst
return aexpr, errs
}
}
return aexpr, append(errs, ErrUndefined{aexpr})
}
return aexpr, errs
}