# HG changeset patch # User Aziz K?ksal # Date 1197048155 -3600 # Node ID 9a7ca8c56e5953e0645ad08cabafefde4af60562 # Parent d13502b6fa5f2751cdaba4a531fe250cae1c57ed Refactored a few things in the Parser. Removed unnecessary 'bool hasBody' parameter from some declarations. Added shebang to list of tokens in Lexer unittest. Added some semantic methods. diff -r d13502b6fa5f -r 9a7ca8c56e59 trunk/src/dil/Declarations.d --- a/trunk/src/dil/Declarations.d Thu Dec 06 22:59:38 2007 +0100 +++ b/trunk/src/dil/Declarations.d Fri Dec 07 18:22:35 2007 +0100 @@ -58,6 +58,15 @@ { addChildren(ds.children); } + + void semantic(Scope scop) + { + foreach (node; this.children) + { + assert(node.category == NodeCategory.Declaration); + (cast(Declaration)cast(void*)node).semantic(scop); + } + } } class EmptyDeclaration : Declaration @@ -66,6 +75,9 @@ { mixin(set_kind); } + + void semantic(Scope) + {} } class IllegalDeclaration : Declaration @@ -76,6 +88,9 @@ mixin(set_kind); this.token = token; } + + void semantic(Scope) + {} } /// FQN = fully qualified name @@ -215,9 +230,9 @@ TemplateParameters tparams; BaseClass[] bases; Declarations decls; - this(Token* name, TemplateParameters tparams, BaseClass[] bases, Declarations decls, bool hasBody) + this(Token* name, TemplateParameters tparams, BaseClass[] bases, Declarations decls) { - super.hasBody = hasBody; + super.hasBody = decls !is null; mixin(set_kind); addOptChild(tparams); addOptChildren(bases); @@ -236,9 +251,9 @@ TemplateParameters tparams; BaseClass[] bases; Declarations decls; - this(Token* name, TemplateParameters tparams, BaseClass[] bases, Declarations decls, bool hasBody) + this(Token* name, TemplateParameters tparams, BaseClass[] bases, Declarations decls) { - super.hasBody = hasBody; + super.hasBody = decls !is null; mixin(set_kind); addOptChild(tparams); addOptChildren(bases); @@ -256,9 +271,9 @@ Token* name; TemplateParameters tparams; Declarations decls; - this(Token* name, TemplateParameters tparams, Declarations decls, bool hasBody) + this(Token* name, TemplateParameters tparams, Declarations decls) { - super.hasBody = hasBody; + super.hasBody = decls !is null; mixin(set_kind); addOptChild(tparams); addOptChild(decls); @@ -274,9 +289,9 @@ Token* name; TemplateParameters tparams; Declarations decls; - this(Token* name, TemplateParameters tparams, Declarations decls, bool hasBody) + this(Token* name, TemplateParameters tparams, Declarations decls) { - super.hasBody = hasBody; + super.hasBody = decls !is null; mixin(set_kind); addOptChild(tparams); addOptChild(decls); @@ -561,24 +576,10 @@ void semantic(Scope scop) { - /+ - void traverse(Node[] nodes) - { - foreach (node; nodes) - { - if (node.kind == NodeKind.ProtectionDeclaration) - break; - if (node.category == NodeCategory.Declaration) - { - auto decl = cast(Declaration)cast(void*)node; - decl.prot = this.prot; - if (node.children) - traverse(node.children); - } - } - } - traverse([this.decls]); - +/ +// auto saved_prot = scop.protection; +// scop.protection = this.prot; +// decls.semantic(scop); +// scop.protection = saved_prot; } } diff -r d13502b6fa5f -r 9a7ca8c56e59 trunk/src/dil/Lexer.d --- a/trunk/src/dil/Lexer.d Thu Dec 06 22:59:38 2007 +0100 +++ b/trunk/src/dil/Lexer.d Fri Dec 07 18:22:35 2007 +0100 @@ -2683,6 +2683,7 @@ TOK type; } static Pair[] pairs = [ + {"#!äöüß", TOK.Shebang}, {"\n", TOK.Newline}, {"//çay", TOK.Comment}, {"\n", TOK.Newline}, {"&", TOK.AndBinary}, {"/*çağ*/", TOK.Comment}, {"&&", TOK.AndLogical}, @@ -2725,7 +2726,8 @@ // Join all token texts into a single string. foreach (i, pair; pairs) - if (pair.type == TOK.Comment && pair.tokenText[1] == '/') // Line comment. + if (pair.type == TOK.Comment && pair.tokenText[1] == '/' || // Line comment. + pair.type == TOK.Shebang) { assert(pairs[i+1].type == TOK.Newline); // Must be followed by a newline. src ~= pair.tokenText; diff -r d13502b6fa5f -r 9a7ca8c56e59 trunk/src/dil/LexerFuncs.d --- a/trunk/src/dil/LexerFuncs.d Thu Dec 06 22:59:38 2007 +0100 +++ b/trunk/src/dil/LexerFuncs.d Fri Dec 07 18:22:35 2007 +0100 @@ -59,7 +59,7 @@ default: if (isUnicodeNewline(p)) { - ++p; ++p; ++p; + p += 3; return '\n'; } } diff -r d13502b6fa5f -r 9a7ca8c56e59 trunk/src/dil/Parser.d --- a/trunk/src/dil/Parser.d Thu Dec 06 22:59:38 2007 +0100 +++ b/trunk/src/dil/Parser.d Fri Dec 07 18:22:35 2007 +0100 @@ -1007,15 +1007,12 @@ TemplateParameters tparams; BaseClass[] bases; Declarations decls; - bool hasBody; nT(); // Skip class keyword. className = requireId(); if (token.type == T.LParen) - { tparams = parseTemplateParameterList(); - } if (token.type == T.Colon) bases = parseBaseClasses(); @@ -1027,14 +1024,11 @@ nT(); } else if (token.type == T.LBrace) - { - hasBody = true; decls = parseDeclarationDefinitionsBlock(); - } else expected(T.LBrace); // TODO: better error msg - return new ClassDeclaration(className, tparams, bases, decls, hasBody); + return new ClassDeclaration(className, tparams, bases, decls); } BaseClass[] parseBaseClasses(bool colonLeadsOff = true) @@ -1083,15 +1077,12 @@ TemplateParameters tparams; BaseClass[] bases; Declarations decls; - bool hasBody; nT(); // Skip interface keyword. name = requireId(); if (token.type == T.LParen) - { tparams = parseTemplateParameterList(); - } if (token.type == T.Colon) bases = parseBaseClasses(); @@ -1103,14 +1094,11 @@ nT(); } else if (token.type == T.LBrace) - { - hasBody = true; decls = parseDeclarationDefinitionsBlock(); - } else expected(T.LBrace); // TODO: better error msg - return new InterfaceDeclaration(name, tparams, bases, decls, hasBody); + return new InterfaceDeclaration(name, tparams, bases, decls); } Declaration parseAggregateDeclaration() @@ -1122,7 +1110,6 @@ Token* name; TemplateParameters tparams; Declarations decls; - bool hasBody; nT(); // Skip struct or union keyword. // name is optional. @@ -1131,9 +1118,7 @@ name = token; nT(); if (token.type == T.LParen) - { tparams = parseTemplateParameterList(); - } } if (token.type == T.Semicolon) @@ -1143,17 +1128,14 @@ nT(); } else if (token.type == T.LBrace) - { - hasBody = true; decls = parseDeclarationDefinitionsBlock(); - } else expected(T.LBrace); // TODO: better error msg if (tok == T.Struct) - return new StructDeclaration(name, tparams, decls, hasBody); + return new StructDeclaration(name, tparams, decls); else - return new UnionDeclaration(name, tparams, decls, hasBody); + return new UnionDeclaration(name, tparams, decls); } Declaration parseConstructorDeclaration()