# HG changeset patch # User Aziz K?ksal # Date 1190371667 -7200 # Node ID 0a4619735ce910d63e26897cc428ce5188936862 # Parent ac9cd48151b684e67ac74f897436f83aa0f1a696 Applied fixes to Lexer, Parser and other classes. Added asserts to cmd.Generate.syntaxToDoc(). Added if-statements to Declaration, Expression and Statement classes to check for null variables. Fixed octal number scanner in Lexer.scanNumber(). Fixes in Parser: skip comma in parseBaseClasses(); changed || to &&; added 'qword' to list of asm type prefixes. diff -r ac9cd48151b6 -r 0a4619735ce9 trunk/src/cmd/Generate.d --- a/trunk/src/cmd/Generate.d Wed Sep 19 23:12:20 2007 +0300 +++ b/trunk/src/cmd/Generate.d Fri Sep 21 12:47:47 2007 +0200 @@ -297,7 +297,13 @@ { foreach (node; nodes) { - assert(node !is null); + assert(delegate bool(){ + foreach (child; node.children) + if (child is null) + return false; + return true; + }() == true, Format("Node '{0}' has a null child", node.classinfo.name) + ); auto begin = node.begin; if (begin) { @@ -306,10 +312,18 @@ beginNodes[begin] ~= node; endNodes[end] ~= node; } + if (node.children.length) populateAAs(node.children); } } + assert(delegate bool(){ + foreach (child; root.children) + if (child is null) + return false; + return true; + }() == true, Format("Root node has a null child") + ); populateAAs(root.children); char[] getTag(NodeCategory nc) diff -r ac9cd48151b6 -r 0a4619735ce9 trunk/src/dil/Declarations.d --- a/trunk/src/dil/Declarations.d Wed Sep 19 23:12:20 2007 +0300 +++ b/trunk/src/dil/Declarations.d Fri Sep 21 12:47:47 2007 +0200 @@ -195,7 +195,8 @@ this.children = [tparams]; if (bases.length) this.children ~= bases; - this.children ~= decls; + if (decls) + this.children ~= decls; this.name = name; this.tparams = tparams; @@ -218,7 +219,8 @@ this.children = [tparams]; if (bases.length) this.children ~= bases; - this.children ~= decls; + if (decls) + this.children ~= decls; this.name = name; this.tparams = tparams; @@ -238,7 +240,8 @@ mixin(set_kind); if (tparams) this.children = [tparams]; - this.children ~= decls; + if (decls) + this.children ~= decls; this.name = name; this.tparams = tparams; @@ -257,7 +260,8 @@ mixin(set_kind); if (tparams) this.children = [tparams]; - this.children ~= decls; + if (decls) + this.children ~= decls; this.name = name; this.tparams = tparams; @@ -273,7 +277,9 @@ { super(true); mixin(set_kind); + assert(parameters !is null && funcBody !is null); this.children = [cast(Node)parameters, funcBody]; + this.parameters = parameters; this.funcBody = funcBody; } @@ -286,7 +292,9 @@ { super(true); mixin(set_kind); + assert(funcBody !is null); this.children = [funcBody]; + this.funcBody = funcBody; } } @@ -299,6 +307,7 @@ super(true); mixin(set_kind); this.children = [funcBody]; + this.funcBody = funcBody; } } @@ -311,6 +320,7 @@ super(true); mixin(set_kind); this.children = [funcBody]; + this.funcBody = funcBody; } } @@ -331,6 +341,7 @@ if (tparams) this.children ~= tparams; this.children ~= [cast(Node)params, funcBody]; + this.returnType = returnType; this.funcName = funcName; this.tparams = tparams; @@ -353,6 +364,7 @@ foreach(value; values) if (value) this.children ~= value; + this.type = type; this.idents = idents; this.values = values; @@ -366,7 +378,9 @@ { super(true); mixin(set_kind); + assert(funcBody !is null); this.children = [funcBody]; + this.funcBody = funcBody; } } @@ -378,7 +392,9 @@ { super(true); mixin(set_kind); + assert(funcBody !is null); this.children = [funcBody]; + this.funcBody = funcBody; } } @@ -397,6 +413,7 @@ this.children = [decls]; if (elseDecls) this.children ~= elseDecls; + this.spec = spec; this.cond = cond; this.decls = decls; @@ -418,6 +435,7 @@ this.children = [decls]; if (elseDecls) this.children ~= elseDecls; + this.spec = spec; this.cond = cond; this.decls = decls; @@ -433,7 +451,13 @@ { super(true); mixin(set_kind); - this.children = [cast(Node)condition, ifDecls, elseDecls]; + assert(condition !is null); + this.children = [condition]; + if (ifDecls) + this.children ~= ifDecls; + if (elseDecls) + this.children ~= elseDecls; + this.condition = condition; this.ifDecls = ifDecls; this.elseDecls = elseDecls; @@ -447,6 +471,7 @@ { super(true); mixin(set_kind); + assert(condition !is null); this.children = [condition]; if (message) this.children ~= message; @@ -466,7 +491,9 @@ mixin(set_kind); if (tparams) this.children = [tparams]; + assert(decls !is null); this.children ~= decls; + this.name = name; this.tparams = tparams; this.decls = decls; @@ -481,7 +508,9 @@ { super(true); mixin(set_kind); + assert(parameters !is null && funcBody !is null); this.children = [cast(Node)parameters, funcBody]; + this.parameters = parameters; this.funcBody = funcBody; } @@ -495,7 +524,9 @@ { super(true); mixin(set_kind); + assert(parameters !is null && funcBody !is null); this.children = [cast(Node)parameters, funcBody]; + this.parameters = parameters; this.funcBody = funcBody; } @@ -509,7 +540,9 @@ { super(true); mixin(set_kind); - this.children = [decls]; + assert(decls !is null); + this.children ~= decls; + this.attribute = attribute; this.decls = decls; } @@ -545,10 +578,11 @@ Expression[] args; this(Token* ident, Expression[] args, Declaration decls) { + if (args.length) + this.children ~= args; // Add args before calling super(). super(TOK.Pragma, decls); mixin(set_kind); - if (args.length) - this.children ~= args; + this.ident = ident; this.args = args; } @@ -563,6 +597,7 @@ { super(false); mixin(set_kind); + assert(templateIdents.length != 0); this.children = templateIdents; this.templateIdents = templateIdents; this.mixinIdent = mixinIdent; @@ -571,6 +606,7 @@ { super(false); mixin(set_kind); + assert(argument !is null); this.children = [argument]; this.argument = argument; } diff -r ac9cd48151b6 -r 0a4619735ce9 trunk/src/dil/Expressions.d --- a/trunk/src/dil/Expressions.d Wed Sep 19 23:12:20 2007 +0300 +++ b/trunk/src/dil/Expressions.d Fri Sep 21 12:47:47 2007 +0200 @@ -557,7 +557,11 @@ { super(e); mixin(set_kind); - this.children ~= [left, right]; + if (left) + this.children ~= left; + if (right) + this.children ~= right; + this.left = left; this.right = right; } diff -r ac9cd48151b6 -r 0a4619735ce9 trunk/src/dil/Lexer.d --- a/trunk/src/dil/Lexer.d Wed Sep 19 23:12:20 2007 +0300 +++ b/trunk/src/dil/Lexer.d Fri Sep 21 12:47:47 2007 +0200 @@ -1335,24 +1335,33 @@ case 'x','X': goto LscanHex; case 'b','B': - goto LscanBin; + goto LscanBinary; case 'L': if (p[1] == 'i') - goto LscanReal; - break; + goto LscanReal; // 0Li + break; // 0L case '.': if (p[1] == '.') - break; + break; // 0.. + // 0. case 'i','f','F', // Imaginary and float literal suffixes. 'e', 'E': // Float exponent. goto LscanReal; default: - if (*p == '_' || isoctal(*p)) - goto LscanOct; + if (*p == '_') + goto LscanOctal; // 0_ + else if (isdigit(*p)) + { + if (*p == '8' || *p == '9') + goto Loctal_hasDecimalDigits; // 08 or 09 + else + goto Loctal_enter_loop; // 0[0-7] + } } // Number 0 assert(p[-1] == '0'); + assert(*p != '_' && !isdigit(*p)); assert(ulong_ == 0); isDecimal = true; goto Lfinalize; @@ -1440,7 +1449,7 @@ goto Lfinalize; - LscanBin: + LscanBinary: assert(digits == 0); assert(*p == 'b'); while (1) @@ -1471,33 +1480,31 @@ assert( !(*p == '0' || *p == '1' || *p == '_') ); goto Lfinalize; - LscanOct: - assert(*p == '_' || isoctal(*p)); - if (*p != '_') - goto Lenter_loop_oct; + LscanOctal: + assert(*p == '_'); while (1) { if (*++p == '_') continue; if (!isoctal(*p)) break; - Lenter_loop_oct: + Loctal_enter_loop: if (ulong_ < ulong.max/2 || (ulong_ == ulong.max/2 && *p <= '1')) { ulong_ *= 8; ulong_ += *p - '0'; - ++p; continue; } // Overflow: skip following digits. overflow = true; - while (isdigit(*++p)) {} + while (isoctal(*++p)) {} break; } bool hasDecimalDigits; if (isdigit(*p)) { + Loctal_hasDecimalDigits: hasDecimalDigits = true; while (isdigit(*++p)) {} } diff -r ac9cd48151b6 -r 0a4619735ce9 trunk/src/dil/Parser.d --- a/trunk/src/dil/Parser.d Wed Sep 19 23:12:20 2007 +0300 +++ b/trunk/src/dil/Parser.d Fri Sep 21 12:47:47 2007 +0200 @@ -1025,6 +1025,7 @@ bases ~= new BaseClass(prot, type); if (token.type != T.Comma) break; + nT(); } return bases; } @@ -2248,7 +2249,7 @@ finBody = new FinallyBody(parseNoScopeStatement()); } - if (catchBodies.length == 0 || finBody is null) + if (catchBodies.length == 0 && finBody is null) { // TODO: issue error msg. } @@ -2782,7 +2783,7 @@ switch (token.identifier) { case "near", "far", /*"byte", "short", "int",*/ - "word", "dword"/*, "float", "double", "real"*/: + "word", "dword", "qword"/*, "float", "double", "real"*/: LAsmTypePrefix: nT(); if (token.type == T.Identifier && token.identifier == "ptr") diff -r ac9cd48151b6 -r 0a4619735ce9 trunk/src/dil/Statements.d --- a/trunk/src/dil/Statements.d Wed Sep 19 23:12:20 2007 +0300 +++ b/trunk/src/dil/Statements.d Fri Sep 21 12:47:47 2007 +0200 @@ -319,6 +319,7 @@ this(Expression expr, Statement withBody) { mixin(set_kind); + assert(expr !is null && withBody !is null); this.children = [cast(Node)expr, withBody]; this.expr = expr; this.withBody = withBody; @@ -329,10 +330,13 @@ { Expression expr; Statement syncBody; - this(Expression expr, Statement withBody) + this(Expression expr, Statement syncBody) { mixin(set_kind); - this.children = [cast(Node)expr, syncBody]; + if (expr) + this.children ~= expr; + assert(syncBody !is null); + this.children ~= syncBody; this.expr = expr; this.syncBody = syncBody; } @@ -346,6 +350,7 @@ this(Statement tryBody, CatchBody[] catchBodies, FinallyBody finallyBody) { mixin(set_kind); + assert(tryBody !is null); this.children = [tryBody]; if (catchBodies.length) this.children ~= catchBodies; @@ -364,7 +369,10 @@ this(Parameter param, Statement catchBody) { mixin(set_kind); - this.children = [cast(Node)param, catchBody]; + if (param) + this.children ~= param; + assert(catchBody !is null); + this.children ~= catchBody; this.param = param; this.catchBody = catchBody; } @@ -376,6 +384,7 @@ this(Statement finallyBody) { mixin(set_kind); + assert(finallyBody !is null); this.children = [finallyBody]; this.finallyBody = finallyBody; } @@ -388,6 +397,7 @@ this(Token* condition, Statement scopeBody) { mixin(set_kind); + assert(scopeBody !is null); this.children = [scopeBody]; this.condition = condition; this.scopeBody = scopeBody;