OSDN Git Service

libgo: Update to weekly.2012-01-15.
[pf3gnuchains/gcc-fork.git] / libgo / go / exp / types / universe.go
1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 // FILE UNDER CONSTRUCTION. ANY AND ALL PARTS MAY CHANGE.
6 // This file implements the universe and unsafe package scopes.
7
8 package types
9
10 import "go/ast"
11
12 var (
13         scope    *ast.Scope // current scope to use for initialization
14         Universe *ast.Scope
15         Unsafe   *ast.Object // package unsafe
16 )
17
18 func define(kind ast.ObjKind, name string) *ast.Object {
19         obj := ast.NewObj(kind, name)
20         if scope.Insert(obj) != nil {
21                 panic("types internal error: double declaration")
22         }
23         obj.Decl = scope
24         return obj
25 }
26
27 func defType(name string) *Name {
28         obj := define(ast.Typ, name)
29         typ := &Name{Underlying: &Basic{}, Obj: obj}
30         obj.Type = typ
31         return typ
32 }
33
34 func defConst(name string) {
35         obj := define(ast.Con, name)
36         _ = obj // TODO(gri) fill in other properties
37 }
38
39 func defFun(name string) {
40         obj := define(ast.Fun, name)
41         _ = obj // TODO(gri) fill in other properties
42 }
43
44 var (
45         Bool,
46         Int,
47         Float64,
48         Complex128,
49         String *Name
50 )
51
52 func init() {
53         scope = ast.NewScope(nil)
54         Universe = scope
55
56         Bool = defType("bool")
57         defType("byte") // TODO(gri) should be an alias for uint8
58         defType("rune") // TODO(gri) should be an alias for int
59         defType("complex64")
60         Complex128 = defType("complex128")
61         defType("error")
62         defType("float32")
63         Float64 = defType("float64")
64         defType("int8")
65         defType("int16")
66         defType("int32")
67         defType("int64")
68         String = defType("string")
69         defType("uint8")
70         defType("uint16")
71         defType("uint32")
72         defType("uint64")
73         Int = defType("int")
74         defType("uint")
75         defType("uintptr")
76
77         defConst("true")
78         defConst("false")
79         defConst("iota")
80         defConst("nil")
81
82         defFun("append")
83         defFun("cap")
84         defFun("close")
85         defFun("complex")
86         defFun("copy")
87         defFun("delete")
88         defFun("imag")
89         defFun("len")
90         defFun("make")
91         defFun("new")
92         defFun("panic")
93         defFun("print")
94         defFun("println")
95         defFun("real")
96         defFun("recover")
97
98         scope = ast.NewScope(nil)
99         Unsafe = ast.NewObj(ast.Pkg, "unsafe")
100         Unsafe.Data = scope
101
102         defType("Pointer")
103
104         defFun("Alignof")
105         defFun("New")
106         defFun("NewArray")
107         defFun("Offsetof")
108         defFun("Reflect")
109         defFun("Sizeof")
110         defFun("Typeof")
111         defFun("Unreflect")
112 }