Mercurial > projects > dil
comparison src/dil/semantic/Symbols.d @ 806:bcb74c9b895c
Moved out files in the trunk folder to the root.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Sun, 09 Mar 2008 00:12:19 +0100 |
parents | trunk/src/dil/semantic/Symbols.d@c24be8d4f6ab |
children | 1d06b4aed7cf |
comparison
equal
deleted
inserted
replaced
805:a3fab8b74a7d | 806:bcb74c9b895c |
---|---|
1 /++ | |
2 Author: Aziz Köksal | |
3 License: GPL3 | |
4 +/ | |
5 module dil.semantic.Symbols; | |
6 | |
7 import dil.ast.Expression; | |
8 import dil.semantic.Symbol; | |
9 import dil.semantic.SymbolTable; | |
10 import dil.semantic.Types; | |
11 import dil.ast.Node; | |
12 import dil.lexer.IdTable; | |
13 import dil.Enums; | |
14 import common; | |
15 | |
16 /// A symbol that has its own scope with a symbol table. | |
17 class ScopeSymbol : Symbol | |
18 { | |
19 SymbolTable symbolTable; /// The symbol table. | |
20 Symbol[] members; /// The member symbols (in lexical order.) | |
21 | |
22 this(SYM sid, Identifier* name, Node node) | |
23 { | |
24 super(sid, name, node); | |
25 } | |
26 | |
27 /// Look up name in the table. | |
28 Symbol lookup(Identifier* name) | |
29 { | |
30 return symbolTable.lookup(name); | |
31 } | |
32 | |
33 /// Look up name in the table. | |
34 Symbol lookup(string name) | |
35 { | |
36 auto id = IdTable.lookup(name); | |
37 return id ? symbolTable.lookup(id) : null; | |
38 } | |
39 | |
40 /// Insert a symbol into the table. | |
41 void insert(Symbol s, Identifier* name) | |
42 { | |
43 symbolTable.insert(s, name); | |
44 members ~= s; | |
45 } | |
46 } | |
47 | |
48 /// Aggregates have function and field members. | |
49 abstract class Aggregate : ScopeSymbol | |
50 { | |
51 Function[] funcs; | |
52 Variable[] fields; | |
53 | |
54 this(SYM sid, Identifier* name, Node node) | |
55 { | |
56 super(sid, name, node); | |
57 } | |
58 | |
59 override void insert(Symbol s, Identifier* ident) | |
60 { | |
61 if (s.isVariable) | |
62 // Append variable to fields. | |
63 fields ~= cast(Variable)cast(void*)s; | |
64 else if (s.isFunction) | |
65 // Append function to funcs. | |
66 funcs ~= cast(Function)cast(void*)s; | |
67 super.insert(s, ident); | |
68 } | |
69 } | |
70 | |
71 /// A class symbol. | |
72 class Class : Aggregate | |
73 { | |
74 this(Identifier* name, Node classNode) | |
75 { | |
76 super(SYM.Class, name, classNode); | |
77 } | |
78 } | |
79 | |
80 /// An interface symbol. | |
81 class Interface : Aggregate | |
82 { | |
83 this(Identifier* name, Node interfaceNode) | |
84 { | |
85 super(SYM.Interface, name, interfaceNode); | |
86 } | |
87 } | |
88 | |
89 /// A union symbol. | |
90 class Union : Aggregate | |
91 { | |
92 this(Identifier* name, Node unionNode) | |
93 { | |
94 super(SYM.Union, name, unionNode); | |
95 } | |
96 } | |
97 | |
98 /// A struct symbol. | |
99 class Struct : Aggregate | |
100 { | |
101 this(Identifier* name, Node structNode) | |
102 { | |
103 super(SYM.Struct, name, structNode); | |
104 } | |
105 } | |
106 | |
107 /// An enum symbol. | |
108 class Enum : ScopeSymbol | |
109 { | |
110 TypeEnum type; | |
111 this(Identifier* name, Node enumNode) | |
112 { | |
113 super(SYM.Enum, name, enumNode); | |
114 } | |
115 | |
116 void setType(TypeEnum type) | |
117 { | |
118 this.type = type; | |
119 } | |
120 } | |
121 | |
122 /// A template symbol. | |
123 class Template : ScopeSymbol | |
124 { | |
125 this(Identifier* name, Node templateNode) | |
126 { | |
127 super(SYM.Template, name, templateNode); | |
128 } | |
129 } | |
130 | |
131 /// A function symbol. | |
132 class Function : ScopeSymbol | |
133 { | |
134 Protection prot; /// The protection. | |
135 StorageClass stc; /// The storage classes. | |
136 LinkageType linkType; /// The linkage type. | |
137 | |
138 Type returnType; | |
139 Variable[] params; | |
140 | |
141 this(Identifier* name, Node functionNode) | |
142 { | |
143 super(SYM.Function, name, functionNode); | |
144 } | |
145 } | |
146 | |
147 /// A variable symbol. | |
148 class Variable : Symbol | |
149 { | |
150 Protection prot; /// The protection. | |
151 StorageClass stc; /// The storage classes. | |
152 LinkageType linkType; /// The linkage type. | |
153 | |
154 Type type; /// The type of this variable. | |
155 Expression value; /// The value of this variable. | |
156 | |
157 this(Identifier* name, | |
158 Protection prot, StorageClass stc, LinkageType linkType, | |
159 Node variableNode) | |
160 { | |
161 super(SYM.Variable, name, variableNode); | |
162 | |
163 this.prot = prot; | |
164 this.stc = stc; | |
165 this.linkType = linkType; | |
166 } | |
167 } | |
168 | |
169 /// An enum member symbol. | |
170 class EnumMember : Variable | |
171 { | |
172 this(Identifier* name, | |
173 Protection prot, StorageClass stc, LinkageType linkType, | |
174 Node enumMemberNode) | |
175 { | |
176 super(name, prot, stc, linkType, enumMemberNode); | |
177 this.sid = SYM.EnumMember; | |
178 } | |
179 } | |
180 | |
181 /// An alias symbol. | |
182 class Alias : Symbol | |
183 { | |
184 this(Identifier* name, Node aliasNode) | |
185 { | |
186 super(SYM.Alias, name, aliasNode); | |
187 } | |
188 } | |
189 | |
190 /// A list of symbols that share the same identifier. | |
191 /// | |
192 /// These can be functions, templates and aggregates with template parameter lists. | |
193 class OverloadSet : Symbol | |
194 { | |
195 Symbol[] symbols; | |
196 | |
197 this(Identifier* name, Node node) | |
198 { | |
199 super(SYM.OverloadSet, name, node); | |
200 } | |
201 | |
202 void add(Symbol s) | |
203 { | |
204 symbols ~= s; | |
205 } | |
206 } |