Mercurial > projects > dil
comparison trunk/src/dil/semantic/Pass2.d @ 804:9e6c6bb73e5f
Implemented visit methods for some type nodes.
Added method SemanticPass2.search().
Added methods arrayOf() and arrayOf(Type) to class Type.
Refactored ModuleScopeType.
Added error msg UndefinedIdentifier.
Added release.py.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Sat, 08 Mar 2008 22:02:20 +0100 |
parents | c24be8d4f6ab |
children |
comparison
equal
deleted
inserted
replaced
803:cb8040538772 | 804:9e6c6bb73e5f |
---|---|
82 private alias Declaration D; | 82 private alias Declaration D; |
83 private alias Expression E; /// ditto | 83 private alias Expression E; /// ditto |
84 private alias Statement S; /// ditto | 84 private alias Statement S; /// ditto |
85 private alias TypeNode T; /// ditto | 85 private alias TypeNode T; /// ditto |
86 | 86 |
87 /// The scope symbol to use in identifier or template instance expressions. | 87 /// The current scope symbol to use for looking up identifiers. |
88 /// E.g.: object.method(); // After 'object' has been visited, dotIdScope is | 88 /// E.g.: |
89 /// // set, and 'method' will be looked up there. | 89 /// --- |
90 //ScopeSymbol dotIdScope; | 90 /// object.method(); // *) object is looked up in the current scope. |
91 /// // *) idScope is set if object is a ScopeSymbol. | |
92 /// // *) method will be looked up in idScope. | |
93 /// dil.ast.Node.Node node; // A fully qualified type. | |
94 /// --- | |
95 ScopeSymbol idScope; | |
96 | |
97 /// Searches for a symbol. | |
98 Symbol search(Token* idTok) | |
99 { | |
100 assert(idTok.kind == TOK.Identifier); | |
101 auto id = idTok.ident; | |
102 Symbol symbol; | |
103 | |
104 if (idScope is null) | |
105 for (auto sc = scop; sc; sc = sc.parent) | |
106 { | |
107 symbol = sc.lookup(id); | |
108 if (symbol) | |
109 return symbol; | |
110 } | |
111 else | |
112 symbol = idScope.lookup(id); | |
113 | |
114 if (symbol is null) | |
115 error(idTok, MSG.UndefinedIdentifier, id.str); | |
116 else if (auto scopSymbol = cast(ScopeSymbol)symbol) | |
117 idScope = scopSymbol; | |
118 | |
119 return symbol; | |
120 } | |
91 | 121 |
92 override | 122 override |
93 { | 123 { |
94 D visit(CompoundDeclaration d) | 124 D visit(CompoundDeclaration d) |
95 { | 125 { |
160 // TODO: implement template mixin. | 190 // TODO: implement template mixin. |
161 } | 191 } |
162 return md.decls; | 192 return md.decls; |
163 } | 193 } |
164 | 194 |
195 // Type nodes: | |
196 | |
165 T visit(TypeofType t) | 197 T visit(TypeofType t) |
166 { | 198 { |
167 t.e = visitE(t.e); | 199 t.e = visitE(t.e); |
168 t.type = t.e.type; | 200 t.type = t.e.type; |
169 return t; | 201 return t; |
170 } | 202 } |
171 | 203 |
172 T visit(ArrayType t) | 204 T visit(ArrayType t) |
173 { | 205 { |
206 auto baseType = visitT(t.next).type; | |
207 if (t.isAssociative) | |
208 t.type = baseType.arrayOf(visitT(t.assocType).type); | |
209 else if (t.isDynamic) | |
210 t.type = baseType.arrayOf(); | |
211 else if (t.isStatic) | |
212 {} | |
213 else | |
214 assert(t.isSlice); | |
174 return t; | 215 return t; |
175 } | 216 } |
176 | 217 |
177 T visit(PointerType t) | 218 T visit(PointerType t) |
178 { | 219 { |
179 t.type = visitT(t.next).type.ptrTo(); | 220 t.type = visitT(t.next).type.ptrTo(); |
221 return t; | |
222 } | |
223 | |
224 T visit(QualifiedType t) | |
225 { | |
226 if (t.lhs.Is!(QualifiedType) is null) | |
227 idScope = null; // Reset at left-most type. | |
228 visitT(t.lhs); | |
229 visitT(t.rhs); | |
230 t.type = t.rhs.type; | |
231 return t; | |
232 } | |
233 | |
234 T visit(IdentifierType t) | |
235 { | |
236 auto idToken = t.begin; | |
237 auto symbol = search(idToken); | |
238 // TODO: save symbol or its type in t. | |
239 return t; | |
240 } | |
241 | |
242 T visit(TemplateInstanceType t) | |
243 { | |
244 auto idToken = t.begin; | |
245 auto symbol = search(idToken); | |
246 // TODO: save symbol or its type in t. | |
247 return t; | |
248 } | |
249 | |
250 T visit(ModuleScopeType t) | |
251 { | |
252 idScope = modul; | |
180 return t; | 253 return t; |
181 } | 254 } |
182 | 255 |
183 T visit(IntegralType t) | 256 T visit(IntegralType t) |
184 { | 257 { |
195 assert(t.tok in tok2Type); | 268 assert(t.tok in tok2Type); |
196 t.type = tok2Type[t.tok]; | 269 t.type = tok2Type[t.tok]; |
197 return t; | 270 return t; |
198 } | 271 } |
199 | 272 |
273 // Expression nodes: | |
274 | |
200 E visit(ParenExpression e) | 275 E visit(ParenExpression e) |
201 { | 276 { |
202 if (!e.type) | 277 if (!e.type) |
203 { | 278 { |
204 e.next = visitE(e.next); | 279 e.next = visitE(e.next); |