Mercurial > projects > dil
changeset 299:559d5d62e0c1
- Added checks for null before adding member to Node.children.
- Added finishConstruction() to FunctionBody.
author | aziz |
---|---|
date | Thu, 09 Aug 2007 21:39:03 +0000 |
parents | dc8bed242db5 |
children | 6cf3a5069109 |
files | trunk/src/Declarations.d trunk/src/Expressions.d trunk/src/Parser.d trunk/src/Statements.d trunk/src/Types.d trunk/src/main.d |
diffstat | 6 files changed, 52 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/trunk/src/Declarations.d Thu Aug 09 19:49:03 2007 +0000 +++ b/trunk/src/Declarations.d Thu Aug 09 21:39:03 2007 +0000 @@ -121,7 +121,12 @@ { super(hasBody); mixin(set_kind); - this.children = [tparams] ~ cast(Node[])bases ~ decls; + if (tparams) + this.children = [tparams]; + if (bases.length) + this.children ~= bases; + if (decls.length) + this.children ~= decls; this.name = name; this.tparams = tparams; this.bases = bases; @@ -240,7 +245,10 @@ { super(funcBody.funcBody !is null); mixin(set_kind); - this.children = [cast(Node)returnType, tparams, params, funcBody]; + this.children = [returnType]; + if (tparams) + this.children ~= tparams; + this.children ~= [cast(Node)params, funcBody]; this.returnType = returnType; this.funcName = funcName; this.tparams = tparams; @@ -258,7 +266,11 @@ { super(false); mixin(set_kind); - this.children = [type] ~ cast(Node[])values; + if (type) + this.children = [type]; + foreach(value; values) + if (value) + this.children ~= value; this.type = type; this.idents = idents; this.values = values;
--- a/trunk/src/Expressions.d Thu Aug 09 19:49:03 2007 +0000 +++ b/trunk/src/Expressions.d Thu Aug 09 21:39:03 2007 +0000 @@ -726,7 +726,9 @@ this(Expression expr, Expression msg) { mixin(set_kind); - this.children = [expr, msg]; + this.children = [expr]; + if (msg) + this.children ~= msg; this.expr = expr; this.msg = msg; } @@ -873,7 +875,12 @@ assert(keys.length == values.length); mixin(set_kind); foreach (i, key; keys) - this.children ~= [key, values[i]]; + { + if (key) + this.children ~= key; + if (values[i]) + this.children ~= values[i]; + } this.keys = keys; this.values = values; }
--- a/trunk/src/Parser.d Thu Aug 09 19:49:03 2007 +0000 +++ b/trunk/src/Parser.d Thu Aug 09 21:39:03 2007 +0000 @@ -529,6 +529,7 @@ break; // exit while loop } set(func, begin); + func.finishConstruction(); return func; } @@ -3579,6 +3580,7 @@ // NewArguments Type ( ArgumentList ) // NewArguments Type auto type = parseType(); +// FIXME: TID.DotList doesn't cover all valid types. if (type.tid == TID.DotList && token.type == T.LParen) { ctorArguments = parseArguments(T.RParen);
--- a/trunk/src/Statements.d Thu Aug 09 19:49:03 2007 +0000 +++ b/trunk/src/Statements.d Thu Aug 09 21:39:03 2007 +0000 @@ -23,6 +23,7 @@ { mixin(set_kind); } + void opCatAssign(Statement s) { this.children ~= s; @@ -54,12 +55,17 @@ this() { super(NodeCategory.Other); - this.children = [funcBody]; + mixin(set_kind); + } + + void finishConstruction() + { + if (funcBody) + this.children ~= funcBody; if (inBody) this.children ~= inBody; if (outBody) this.children ~= outBody; - mixin(set_kind); } } @@ -286,7 +292,8 @@ this(Expression expr) { mixin(set_kind); - this.children = [expr]; + if (expr) + this.children = [expr]; this.expr = expr; } } @@ -298,7 +305,8 @@ this(Token* ident, Expression caseExpr) { mixin(set_kind); - this.children = [caseExpr]; + if (caseExpr) + this.children = [caseExpr]; this.ident = ident; this.caseExpr = caseExpr; }
--- a/trunk/src/Types.d Thu Aug 09 19:49:03 2007 +0000 +++ b/trunk/src/Types.d Thu Aug 09 21:39:03 2007 +0000 @@ -51,7 +51,8 @@ { super(NodeCategory.Other); mixin(set_kind); - this.children = [type]; + if (type) // type can be null when param in foreach statement + this.children = [type]; if (assignExpr) this.children ~= assignExpr;
--- a/trunk/src/main.d Thu Aug 09 19:49:03 2007 +0000 +++ b/trunk/src/main.d Thu Aug 09 21:39:03 2007 +0000 @@ -23,13 +23,24 @@ } return result; } - +import Declarations, SyntaxTree; void main(char[][] args) { auto srctext = cast(char[]) std.file.read(args[1]); auto parser = new Parser(srctext, args[1]); parser.start(); auto decls = parser.parseModule(); + +void print(Node[] decls, char[] indent) +{ + foreach(decl; decls) + { + assert(decl !is null); + writefln(indent, decl.classinfo.name, ":", decl.children.length); + print(decl.children, indent ~ " "); + } +} +print(decls, ""); foreach (error; parser.errors) { writefln(`%s(%d)P: %s`, parser.lx.fileName, error.loc, error.getMsg);