comparison src/dil/semantic/Pass1.d @ 810:525ee3f848d9

Added modules cmd.Compile and dil.ModuleManager. Added options -I, -release and -unittest to the compile command. Tidied main.d up a bit. Renamed start() methods of SemanticPass1 and 2 to run(). Moved function findModuleFilePath() to class ModuleManager. Added msg CouldntLoadModule. Corrected two others. Added member semanticPass to class Module. Implemented visit(ImportDeclaration) in SemanticPass1.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Tue, 11 Mar 2008 02:48:01 +0100
parents bcb74c9b895c
children 1d06b4aed7cf
comparison
equal deleted inserted replaced
809:7e84472f4e91 810:525ee3f848d9
24 import dil.Messages; 24 import dil.Messages;
25 import dil.Enums; 25 import dil.Enums;
26 import dil.CompilerInfo; 26 import dil.CompilerInfo;
27 import common; 27 import common;
28 28
29 import tango.io.FileConst;
30 alias FileConst.PathSeparatorChar dirSep;
31
29 /// The first pass is the declaration pass. 32 /// The first pass is the declaration pass.
30 /// 33 ///
31 /// The basic task of this class is to traverse the parse tree, 34 /// The basic task of this class is to traverse the parse tree,
32 /// find all kinds of declarations and add them 35 /// find all kinds of declarations and add them
33 /// to the symbol tables of their respective scopes. 36 /// to the symbol tables of their respective scopes.
34 class SemanticPass1 : Visitor 37 class SemanticPass1 : Visitor
35 { 38 {
36 Scope scop; /// The current scope. 39 Scope scop; /// The current scope.
37 Module modul; /// The module to be semantically checked. 40 Module modul; /// The module to be semantically checked.
38 CompilationContext context; /// The compilation context. 41 CompilationContext context; /// The compilation context.
42 Module delegate(string) importModule; /// Called when importing a module.
39 43
40 // Attributes: 44 // Attributes:
41 LinkageType linkageType; /// Current linkage type. 45 LinkageType linkageType; /// Current linkage type.
42 Protection protection; /// Current protection attribute. 46 Protection protection; /// Current protection attribute.
43 StorageClass storageClass; /// Current storage classes. 47 StorageClass storageClass; /// Current storage classes.
53 this.context = new CompilationContext(context); 57 this.context = new CompilationContext(context);
54 this.alignSize = context.structAlign; 58 this.alignSize = context.structAlign;
55 } 59 }
56 60
57 /// Starts processing the module. 61 /// Starts processing the module.
58 void start() 62 void run()
59 { 63 {
60 assert(modul.root !is null); 64 assert(modul.root !is null);
61 // Create module scope. 65 // Create module scope.
62 scop = new Scope(null, modul); 66 scop = new Scope(null, modul);
67 modul.semanticPass = 1;
63 visit(modul.root); 68 visit(modul.root);
64 } 69 }
65 70
66 /// Enters a new scope. 71 /// Enters a new scope.
67 void enterScope(ScopeSymbol s) 72 void enterScope(ScopeSymbol s)
185 } 190 }
186 191
187 D visit(IllegalDeclaration) 192 D visit(IllegalDeclaration)
188 { assert(0, "semantic pass on invalid AST"); return null; } 193 { assert(0, "semantic pass on invalid AST"); return null; }
189 194
190 D visit(EmptyDeclaration ed) 195 // D visit(EmptyDeclaration ed)
191 { return ed; } 196 // { return ed; }
192 197
193 D visit(ModuleDeclaration) 198 // D visit(ModuleDeclaration)
194 { return null; } 199 // { return null; }
195 200
196 D visit(ImportDeclaration d) 201 D visit(ImportDeclaration d)
197 { 202 {
203 if (importModule is null)
204 return d;
205 foreach (moduleFQNPath; d.getModuleFQNs(dirSep))
206 {
207 auto importedModule = importModule(moduleFQNPath);
208 if (importedModule is null)
209 error(d.begin, MSG.CouldntLoadModule, moduleFQNPath ~ ".d");
210 modul.modules ~= importedModule;
211 }
198 return d; 212 return d;
199 } 213 }
200 214
201 D visit(AliasDeclaration ad) 215 D visit(AliasDeclaration ad)
202 { 216 {