Mercurial > projects > dang
comparison sema/ScopeBuilder.d @ 145:a14ac9e5c858
Changes Scope to use char[]'s insted of Identifiers for lookup.
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Mon, 21 Jul 2008 17:56:33 +0200 |
parents | 6e6355fb5f0f |
children | 393a1f47a6d2 |
comparison
equal
deleted
inserted
replaced
144:6e6355fb5f0f | 145:a14ac9e5c858 |
---|---|
41 inFunctionBodyStack.pop(); | 41 inFunctionBodyStack.pop(); |
42 | 42 |
43 d.sym = current.symbol.createMember( | 43 d.sym = current.symbol.createMember( |
44 d.identifier.get, | 44 d.identifier.get, |
45 d.type, | 45 d.type, |
46 d.env.find(d.identifier)); | 46 d.env.find(d.identifier.get)); |
47 } | 47 } |
48 | 48 |
49 override void visitVarDecl(VarDecl d) | 49 override void visitVarDecl(VarDecl d) |
50 { | 50 { |
51 visitExp(d.varType); | 51 visitExp(d.varType); |
55 visitExp(d.init); | 55 visitExp(d.init); |
56 | 56 |
57 DType t = typeOf(d.varType, d.env); | 57 DType t = typeOf(d.varType, d.env); |
58 d.sym = current.symbol.createAlias( | 58 d.sym = current.symbol.createAlias( |
59 d.identifier.get, | 59 d.identifier.get, |
60 d.env.find(d.varType).sym, | 60 d.env.find(d.varType.get).sym, |
61 d.env.find(d.identifier)); | 61 d.env.find(d.identifier.get)); |
62 d.sym.type = t; | 62 d.sym.type = t; |
63 } | 63 } |
64 | 64 |
65 override void visitStructDecl(StructDecl s) | 65 override void visitStructDecl(StructDecl s) |
66 { | 66 { |
96 { | 96 { |
97 if(auto i = cast(PointerIdentifier)id) | 97 if(auto i = cast(PointerIdentifier)id) |
98 return (typeOf(i.pointerOf, sc)).getPointerTo(); | 98 return (typeOf(i.pointerOf, sc)).getPointerTo(); |
99 else if(auto i = cast(StaticArrayIdentifier)id) | 99 else if(auto i = cast(StaticArrayIdentifier)id) |
100 return typeOf(i.arrayOf, sc).getAsStaticArray(i.size); | 100 return typeOf(i.arrayOf, sc).getAsStaticArray(i.size); |
101 return sc.findType(id); | 101 return sc.findType(id.get); |
102 } | 102 } |
103 | 103 |
104 Module[] modules; | 104 Module[] modules; |
105 Module current; | 105 Module current; |
106 SmallArray!(bool) inFunctionBodyStack; | 106 SmallArray!(bool) inFunctionBodyStack; |
118 } | 118 } |
119 } | 119 } |
120 | 120 |
121 override void visitStructDecl(StructDecl s) | 121 override void visitStructDecl(StructDecl s) |
122 { | 122 { |
123 auto st = s.env.findType(s.identifier).asStruct; | 123 auto st = s.env.findType(s.identifier.get).asStruct; |
124 s.sym = current.symbol.createMember( | 124 s.sym = current.symbol.createMember( |
125 s.identifier.get, | 125 s.identifier.get, |
126 st, | 126 st, |
127 s.env.find(s.identifier)); | 127 s.env.find(s.identifier.get)); |
128 | 128 |
129 foreach (decl; s.decls) | 129 foreach (decl; s.decls) |
130 { | 130 { |
131 DType type; | 131 DType type; |
132 char[] name; | 132 char[] name; |
144 } | 144 } |
145 } | 145 } |
146 | 146 |
147 override void visitClassDecl(ClassDecl s) | 147 override void visitClassDecl(ClassDecl s) |
148 { | 148 { |
149 auto st = s.env.findType(s.identifier).asClass; | 149 auto st = s.env.findType(s.identifier.get).asClass; |
150 s.sym = current.symbol.createMember( | 150 s.sym = current.symbol.createMember( |
151 s.identifier.get, | 151 s.identifier.get, |
152 st, | 152 st, |
153 s.env.find(s.identifier)); | 153 s.env.find(s.identifier.get)); |
154 | 154 |
155 foreach (decl; s.decls) | 155 foreach (decl; s.decls) |
156 { | 156 { |
157 DType type; | 157 DType type; |
158 char[] name; | 158 char[] name; |
170 } | 170 } |
171 } | 171 } |
172 | 172 |
173 override void visitInterfaceDecl(InterfaceDecl s) | 173 override void visitInterfaceDecl(InterfaceDecl s) |
174 { | 174 { |
175 auto st = s.env.findType(s.identifier).asInterface; | 175 auto st = s.env.findType(s.identifier.get).asInterface; |
176 s.sym = current.symbol.createMember( | 176 s.sym = current.symbol.createMember( |
177 s.identifier.get, | 177 s.identifier.get, |
178 st, | 178 st, |
179 s.env.find(s.identifier)); | 179 s.env.find(s.identifier.get)); |
180 | 180 |
181 foreach (decl; s.decls) | 181 foreach (decl; s.decls) |
182 { | 182 { |
183 DType type; | 183 DType type; |
184 char[] name; | 184 char[] name; |
201 { | 201 { |
202 if(auto i = cast(PointerIdentifier)id) | 202 if(auto i = cast(PointerIdentifier)id) |
203 return (typeOf(i.pointerOf, sc)).getPointerTo(); | 203 return (typeOf(i.pointerOf, sc)).getPointerTo(); |
204 else if(auto i = cast(StaticArrayIdentifier)id) | 204 else if(auto i = cast(StaticArrayIdentifier)id) |
205 return typeOf(i.arrayOf, sc).getAsStaticArray(i.size); | 205 return typeOf(i.arrayOf, sc).getAsStaticArray(i.size); |
206 return sc.findType(id); | 206 return sc.findType(id.get); |
207 } | 207 } |
208 | 208 |
209 Module current; | 209 Module current; |
210 } | 210 } |
211 | 211 |
245 auto decl = new DummyDecl(); | 245 auto decl = new DummyDecl(); |
246 auto sym = m.symbol.createMember(n, t, decl); | 246 auto sym = m.symbol.createMember(n, t, decl); |
247 sym.decl = decl; | 247 sym.decl = decl; |
248 decl.sym = sym; | 248 decl.sym = sym; |
249 decl.env = sc; | 249 decl.env = sc; |
250 sc.put(id, decl); | 250 sc.put(id.get, decl); |
251 } | 251 } |
252 | 252 |
253 override void visitModule(Module m) | 253 override void visitModule(Module m) |
254 { | 254 { |
255 auto root = new Scope; | 255 auto root = new Scope; |
309 super.visitExp(e); | 309 super.visitExp(e); |
310 } | 310 } |
311 | 311 |
312 override void visitFuncDecl(FuncDecl d) | 312 override void visitFuncDecl(FuncDecl d) |
313 { | 313 { |
314 current().put(d.identifier, d); | 314 current().put(d.identifier.get, d); |
315 d.env = current(); | 315 d.env = current(); |
316 auto sc = push(); | 316 auto sc = push(); |
317 | 317 |
318 visitExp(d.returnType); | 318 visitExp(d.returnType); |
319 visitExp(d.identifier); | 319 visitExp(d.identifier); |
337 push(); | 337 push(); |
338 --need_push; | 338 --need_push; |
339 } | 339 } |
340 | 340 |
341 auto sc = current(); | 341 auto sc = current(); |
342 sc.put(d.identifier, d); | 342 sc.put(d.identifier.get, d); |
343 d.env = sc; | 343 d.env = sc; |
344 visitExp(d.varType); | 344 visitExp(d.varType); |
345 visitExp(d.identifier); | 345 visitExp(d.identifier); |
346 } | 346 } |
347 | 347 |
348 override void visitStructDecl(StructDecl s) | 348 override void visitStructDecl(StructDecl s) |
349 { | 349 { |
350 auto sc = current(); | 350 auto sc = current(); |
351 sc.put(s.identifier, s); | 351 sc.put(s.identifier.get, s); |
352 s.env = sc; | 352 s.env = sc; |
353 auto type = new DStruct(s.identifier); | 353 auto type = new DStruct(s.identifier); |
354 | 354 |
355 sc.types[s.identifier.get] = type; | 355 sc.types[s.identifier.get] = type; |
356 | 356 |
360 } | 360 } |
361 | 361 |
362 override void visitClassDecl(ClassDecl s) | 362 override void visitClassDecl(ClassDecl s) |
363 { | 363 { |
364 auto sc = current(); | 364 auto sc = current(); |
365 sc.put(s.identifier, s); | 365 sc.put(s.identifier.get, s); |
366 s.env = sc; | 366 s.env = sc; |
367 auto type = new DClass(s.identifier); | 367 auto type = new DClass(s.identifier); |
368 | 368 |
369 sc.types[s.identifier.get] = type; | 369 sc.types[s.identifier.get] = type; |
370 | 370 |
374 } | 374 } |
375 | 375 |
376 override void visitInterfaceDecl(InterfaceDecl s) | 376 override void visitInterfaceDecl(InterfaceDecl s) |
377 { | 377 { |
378 auto sc = current(); | 378 auto sc = current(); |
379 sc.put(s.identifier, s); | 379 sc.put(s.identifier.get, s); |
380 s.env = sc; | 380 s.env = sc; |
381 auto type = new DInterface(s.identifier); | 381 auto type = new DInterface(s.identifier); |
382 | 382 |
383 sc.types[s.identifier.get] = type; | 383 sc.types[s.identifier.get] = type; |
384 | 384 |