# HG changeset patch # User Aziz K?ksal # Date 1200391863 -3600 # Node ID 3ebe76ad680eca7f4f945d80d54b6371fa3bb483 # Parent 4ae7b13aaac8c57de10f78cf2024a25891355aea 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(). diff -r 4ae7b13aaac8 -r 3ebe76ad680e trunk/src/dil/ast/Visitor.d --- a/trunk/src/dil/ast/Visitor.d Mon Jan 14 22:34:09 2008 +0100 +++ b/trunk/src/dil/ast/Visitor.d Tue Jan 15 11:11:03 2008 +0100 @@ -13,18 +13,16 @@ dil.ast.Parameters; /++ - Generate abstract visit methods. + Generate visit methods. E.g.: - Declaration visit(ClassDeclaration); - Expression visit(CommaExpression); + Declaration visit(ClassDeclaration){return null;}; + Expression visit(CommaExpression){return null;}; +/ -char[] generateAbstractVisitMethods() +char[] generateVisitMethods() { char[] text; foreach (className; classNames) - { - text ~= "returnType!(\""~className~"\") visit("~className~");\n"; - } + text ~= "returnType!(\""~className~"\") visit("~className~"){return null;}\n"; return text; } // pragma(msg, generateAbstractVisitMethods()); @@ -84,8 +82,7 @@ abstract class Visitor { - abstract - mixin(generateAbstractVisitMethods()); + mixin(generateVisitMethods()); static mixin(generateDispatchFunctions()); diff -r 4ae7b13aaac8 -r 3ebe76ad680e trunk/src/dil/semantic/Module.d --- a/trunk/src/dil/semantic/Module.d Mon Jan 14 22:34:09 2008 +0100 +++ b/trunk/src/dil/semantic/Module.d Tue Jan 15 11:11:03 2008 +0100 @@ -85,18 +85,6 @@ } } - /// Starts the semantic analysis of this module. - void semantic() - { - if (this.hasErrors) - return; - // Create module scope. - auto scop = new Scope(); - scop.symbol = this; // Set this module as the scope's symbol. - scop.infoMan = this.infoMan; -// this.root.semantic(scop); - } - /// Returns true if there are errors in the source file. bool hasErrors() { diff -r 4ae7b13aaac8 -r 3ebe76ad680e trunk/src/dil/semantic/Pass1.d --- a/trunk/src/dil/semantic/Pass1.d Mon Jan 14 22:34:09 2008 +0100 +++ b/trunk/src/dil/semantic/Pass1.d Tue Jan 15 11:11:03 2008 +0100 @@ -25,8 +25,8 @@ class SemanticPass1 : Visitor { - Scope scop; - Module modul; + Scope scop; /// The current scope. + Module modul; /// The module to be semantically checked. this(Module modul) { @@ -37,6 +37,10 @@ void start() { assert(modul.root !is null); + // Create module scope. + scop = new Scope(); + scop.symbol = modul; // Set this module as the scope's symbol. + scop.infoMan = modul.infoMan; visitN(modul.root); } @@ -80,8 +84,8 @@ Declaration visit(ImportDeclaration) { return null; } -// Declaration visit(AliasDeclaration ad) -// { + Declaration visit(AliasDeclaration ad) + { /+ decl.semantic(scop); // call semantic() or do SA in if statements? if (auto fd = TryCast!(FunctionDeclaration)(decl)) @@ -93,8 +97,8 @@ // TODO: do SA here? } +/ -// return ad; -// } + return ad; + } Declaration visit(TypedefDeclaration td) { @@ -271,16 +275,15 @@ { return null; } Declaration visit(DeleteDeclaration) { return null; } - Declaration visit(AttributeDeclaration) - { return null; } - Declaration visit(ProtectionDeclaration) - { return null; } - Declaration visit(StorageClassDeclaration) - { return null; } - Declaration visit(LinkageDeclaration) - { return null; } - Declaration visit(AlignDeclaration) - { return null; } + + Declaration visit(ProtectionDeclaration d) + { visitD(d.decls); return d; } + Declaration visit(StorageClassDeclaration d) + { visitD(d.decls); return d; } + Declaration visit(LinkageDeclaration d) + { visitD(d.decls); return d; } + Declaration visit(AlignDeclaration d) + { visitD(d.decls); return d; } Declaration visit(PragmaDeclaration d) { diff -r 4ae7b13aaac8 -r 3ebe76ad680e trunk/src/main.d --- a/trunk/src/main.d Mon Jan 14 22:34:09 2008 +0100 +++ b/trunk/src/main.d Tue Jan 15 11:11:03 2008 +0100 @@ -53,8 +53,11 @@ auto mod = new Module(filePath, infoMan); // Parse the file. mod.parse(); + if (mod.hasErrors) + continue; // Start semantic analysis. - mod.semantic(); + auto pass1 = new SemanticPass1(mod); + pass1.start(); void printSymbolTable(ScopeSymbol scopeSym) {