blob: 46cff31bce84e8e833483d5e7cbbd96d61bf9c20 (
plain)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// FILE UNDER CONSTRUCTION. ANY AND ALL PARTS MAY CHANGE.
// This file implements the universe and unsafe package scopes.
package types
import "go/ast"
var (
scope *ast.Scope // current scope to use for initialization
Universe *ast.Scope
Unsafe *ast.Object // package unsafe
)
func define(kind ast.ObjKind, name string) *ast.Object {
obj := ast.NewObj(kind, name)
if scope.Insert(obj) != nil {
panic("types internal error: double declaration")
}
obj.Decl = scope
return obj
}
func defType(name string) *Name {
obj := define(ast.Typ, name)
typ := &Name{Underlying: &Basic{}, Obj: obj}
obj.Type = typ
return typ
}
func defConst(name string) {
obj := define(ast.Con, name)
_ = obj // TODO(gri) fill in other properties
}
func defFun(name string) {
obj := define(ast.Fun, name)
_ = obj // TODO(gri) fill in other properties
}
var (
Bool,
Int,
Float64,
Complex128,
String *Name
)
func init() {
scope = ast.NewScope(nil)
Universe = scope
Bool = defType("bool")
defType("byte") // TODO(gri) should be an alias for uint8
defType("rune") // TODO(gri) should be an alias for int
defType("complex64")
Complex128 = defType("complex128")
defType("error")
defType("float32")
Float64 = defType("float64")
defType("int8")
defType("int16")
defType("int32")
defType("int64")
String = defType("string")
defType("uint8")
defType("uint16")
defType("uint32")
defType("uint64")
Int = defType("int")
defType("uint")
defType("uintptr")
defConst("true")
defConst("false")
defConst("iota")
defConst("nil")
defFun("append")
defFun("cap")
defFun("close")
defFun("complex")
defFun("copy")
defFun("delete")
defFun("imag")
defFun("len")
defFun("make")
defFun("new")
defFun("panic")
defFun("print")
defFun("println")
defFun("real")
defFun("recover")
scope = ast.NewScope(nil)
Unsafe = ast.NewObj(ast.Pkg, "unsafe")
Unsafe.Data = scope
defType("Pointer")
defFun("Alignof")
defFun("New")
defFun("NewArray")
defFun("Offsetof")
defFun("Reflect")
defFun("Sizeof")
defFun("Typeof")
defFun("Unreflect")
}
|