-
Notifications
You must be signed in to change notification settings - Fork 0
/
universe.go
71 lines (58 loc) · 1.65 KB
/
universe.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
package parser
import "github.com/rogpeppe/godef/go/ast"
var Universe = ast.NewScope(nil)
func declObj(kind ast.ObjKind, name string) {
// don't use Insert because it forbids adding to Universe
Universe.Objects[name] = ast.NewObj(kind, name)
}
func init() {
declObj(ast.Typ, "bool")
declObj(ast.Typ, "complex64")
declObj(ast.Typ, "complex128")
declObj(ast.Typ, "int")
declObj(ast.Typ, "int8")
declObj(ast.Typ, "int16")
declObj(ast.Typ, "int32")
declObj(ast.Typ, "int64")
declObj(ast.Typ, "uint")
declObj(ast.Typ, "uintptr")
declObj(ast.Typ, "uint8")
declObj(ast.Typ, "uint16")
declObj(ast.Typ, "uint32")
declObj(ast.Typ, "uint64")
declObj(ast.Typ, "float")
declObj(ast.Typ, "float32")
declObj(ast.Typ, "float64")
declObj(ast.Typ, "string")
declObj(ast.Typ, "error")
// predeclared constants
// TODO(gri) provide constant value
declObj(ast.Con, "false")
declObj(ast.Con, "true")
declObj(ast.Con, "iota")
declObj(ast.Con, "nil")
// predeclared functions
// TODO(gri) provide "type"
declObj(ast.Fun, "append")
declObj(ast.Fun, "cap")
declObj(ast.Fun, "close")
declObj(ast.Fun, "complex")
declObj(ast.Fun, "copy")
declObj(ast.Fun, "delete")
declObj(ast.Fun, "imag")
declObj(ast.Fun, "len")
declObj(ast.Fun, "make")
declObj(ast.Fun, "new")
declObj(ast.Fun, "panic")
declObj(ast.Fun, "panicln")
declObj(ast.Fun, "print")
declObj(ast.Fun, "println")
declObj(ast.Fun, "real")
declObj(ast.Fun, "recover")
// byte is an alias for uint8, so cheat
// by storing the same object for both name
// entries
Universe.Objects["byte"] = Universe.Objects["uint8"]
// The same applies to rune.
Universe.Objects["rune"] = Universe.Objects["uint32"]
}