comparison trunk/src/dil/semantic/Pass1.d @ 649:3ebe76ad680e

Using SemanticPass1 in main.d do start semantic analysis. visit() methods in class Visitor are not abstract anymore, because it's a pain having to override all abstract methods in subclasses. Removed semantic() method from Module. Implemented SemanticPass1.start().
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Tue, 15 Jan 2008 11:11:03 +0100
parents 4ae7b13aaac8
children 0acc43b86bf2
comparison
equal deleted inserted replaced
648:4ae7b13aaac8 649:3ebe76ad680e
23 import dil.Messages; 23 import dil.Messages;
24 import common; 24 import common;
25 25
26 class SemanticPass1 : Visitor 26 class SemanticPass1 : Visitor
27 { 27 {
28 Scope scop; 28 Scope scop; /// The current scope.
29 Module modul; 29 Module modul; /// The module to be semantically checked.
30 30
31 this(Module modul) 31 this(Module modul)
32 { 32 {
33 this.modul = modul; 33 this.modul = modul;
34 } 34 }
35 35
36 /// Start semantic analysis. 36 /// Start semantic analysis.
37 void start() 37 void start()
38 { 38 {
39 assert(modul.root !is null); 39 assert(modul.root !is null);
40 // Create module scope.
41 scop = new Scope();
42 scop.symbol = modul; // Set this module as the scope's symbol.
43 scop.infoMan = modul.infoMan;
40 visitN(modul.root); 44 visitN(modul.root);
41 } 45 }
42 46
43 void enterScope(ScopeSymbol s) 47 void enterScope(ScopeSymbol s)
44 { 48 {
78 Declaration visit(ModuleDeclaration) 82 Declaration visit(ModuleDeclaration)
79 { return null; } 83 { return null; }
80 Declaration visit(ImportDeclaration) 84 Declaration visit(ImportDeclaration)
81 { return null; } 85 { return null; }
82 86
83 // Declaration visit(AliasDeclaration ad) 87 Declaration visit(AliasDeclaration ad)
84 // { 88 {
85 /+ 89 /+
86 decl.semantic(scop); // call semantic() or do SA in if statements? 90 decl.semantic(scop); // call semantic() or do SA in if statements?
87 if (auto fd = TryCast!(FunctionDeclaration)(decl)) 91 if (auto fd = TryCast!(FunctionDeclaration)(decl))
88 { 92 {
89 // TODO: do SA here? 93 // TODO: do SA here?
91 else if (auto vd = TryCast!(VariableDeclaration)(decl)) 95 else if (auto vd = TryCast!(VariableDeclaration)(decl))
92 { 96 {
93 // TODO: do SA here? 97 // TODO: do SA here?
94 } 98 }
95 +/ 99 +/
96 // return ad; 100 return ad;
97 // } 101 }
98 102
99 Declaration visit(TypedefDeclaration td) 103 Declaration visit(TypedefDeclaration td)
100 { 104 {
101 /+ 105 /+
102 decl.semantic(scop); // call semantic() or do SA in if statements? 106 decl.semantic(scop); // call semantic() or do SA in if statements?
269 { return null; } 273 { return null; }
270 Declaration visit(NewDeclaration) 274 Declaration visit(NewDeclaration)
271 { return null; } 275 { return null; }
272 Declaration visit(DeleteDeclaration) 276 Declaration visit(DeleteDeclaration)
273 { return null; } 277 { return null; }
274 Declaration visit(AttributeDeclaration) 278
275 { return null; } 279 Declaration visit(ProtectionDeclaration d)
276 Declaration visit(ProtectionDeclaration) 280 { visitD(d.decls); return d; }
277 { return null; } 281 Declaration visit(StorageClassDeclaration d)
278 Declaration visit(StorageClassDeclaration) 282 { visitD(d.decls); return d; }
279 { return null; } 283 Declaration visit(LinkageDeclaration d)
280 Declaration visit(LinkageDeclaration) 284 { visitD(d.decls); return d; }
281 { return null; } 285 Declaration visit(AlignDeclaration d)
282 Declaration visit(AlignDeclaration) 286 { visitD(d.decls); return d; }
283 { return null; }
284 287
285 Declaration visit(PragmaDeclaration d) 288 Declaration visit(PragmaDeclaration d)
286 { 289 {
287 pragmaSemantic(scop, d.begin, d.ident, d.args); 290 pragmaSemantic(scop, d.begin, d.ident, d.args);
288 visitD(d.decls); 291 visitD(d.decls);