Mercurial > projects > dil
diff trunk/src/dil/Expressions.d @ 489:a7291d3ee9d7
Refactored classes that inherit from Node.
Added methods addChild(), addOptChild(), addChildren(), addOptChildren()
to class Node. Refactored subclasses to use the new methods instead of
appending directly to the array Node.children.
Moved enums StorageClass and Protection to new module dil.Enums.
Added members stc, prot, isStatic() and isPulic() to Declaration.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Mon, 03 Dec 2007 22:44:27 +0100 |
parents | cfb3805768b6 |
children | 47be6bfe39cd |
line wrap: on
line diff
--- a/trunk/src/dil/Expressions.d Sat Dec 01 21:42:24 2007 +0100 +++ b/trunk/src/dil/Expressions.d Mon Dec 03 22:44:27 2007 +0100 @@ -31,7 +31,7 @@ Token* tok; this(Expression left, Expression right, Token* tok) { - this.children = [left, right]; + addChildren([left, right]); this.left = left; this.right = right; this.tok = tok; @@ -45,7 +45,7 @@ { super(left, right, tok); mixin(set_kind); - this.children ~= [condition]; + addChild(condition); this.condition = condition; } } @@ -339,7 +339,7 @@ Expression e; this(Expression e) { - this.children ~= e; + addChild(e); this.e = e; } } @@ -455,7 +455,7 @@ { super(e); mixin(set_kind); - this.children ~= [dotList]; + addChild(dotList); this.dotList = dotList; } } @@ -467,7 +467,7 @@ { super(e); mixin(set_kind); - this.children ~= args; + addOptChildren(args); this.args = args; } } @@ -481,11 +481,9 @@ { /*super(e);*/ mixin(set_kind); - if (newArgs.length) - this.children ~= newArgs; - this.children ~= type; - if (ctorArgs.length) - this.children ~= ctorArgs; + addOptChildren(newArgs); + addChild(type); + addOptChildren(ctorArgs); this.newArgs = newArgs; this.type = type; this.ctorArgs = ctorArgs; @@ -502,13 +500,10 @@ { /*super(e);*/ mixin(set_kind); - if (newArgs.length) - this.children ~= newArgs; - if (bases.length) - this.children ~= bases; - if (ctorArgs.length) - this.children ~= ctorArgs; - this.children ~= decls; + addOptChildren(newArgs); + addOptChildren(bases); + addOptChildren(ctorArgs); + addChild(decls); this.newArgs = newArgs; this.bases = bases; @@ -531,7 +526,7 @@ Type type; this(Expression e, Type type) { - this.children = [type]; + addChild(type); // Add type before super(). super(e); mixin(set_kind); this.type = type; @@ -545,7 +540,7 @@ { super(e); mixin(set_kind); - this.children ~= args; + addChildren(args); this.args = args; } } @@ -557,10 +552,9 @@ { super(e); mixin(set_kind); + assert(left ? (right !is null) : right is null); if (left) - this.children ~= left; - if (right) - this.children ~= right; + addChildren([left, right]); this.left = left; this.right = right; @@ -619,7 +613,7 @@ this(Expression[] items) { mixin(set_kind); - this.children = items; + addChildren(items); this.items = items; } } @@ -631,8 +625,7 @@ this(Token* ident, TemplateArguments targs) { mixin(set_kind); - if (targs) - this.children = [targs]; + addOptChild(targs); this.ident = ident; this.targs = targs; } @@ -738,7 +731,7 @@ this(Expression[] values) { mixin(set_kind); - this.children = values; + addOptChildren(values); this.values = values; } } @@ -751,7 +744,7 @@ assert(keys.length == values.length); mixin(set_kind); foreach (i, key; keys) - this.children ~= [key, values[i]]; + addChildren([key, values[i]]); this.keys = keys; this.values = values; } @@ -763,9 +756,8 @@ this(Expression expr, Expression msg) { mixin(set_kind); - this.children = [expr]; - if (msg) - this.children ~= msg; + addChild(expr); + addOptChild(msg); this.expr = expr; this.msg = msg; } @@ -777,7 +769,7 @@ this(Expression expr) { mixin(set_kind); - this.children = [expr]; + addChild(expr); this.expr = expr; } } @@ -788,7 +780,7 @@ this(Expression expr) { mixin(set_kind); - this.children = [expr]; + addChild(expr); this.expr = expr; } } @@ -799,7 +791,7 @@ this(Type type) { mixin(set_kind); - this.children = [type]; + addChild(type); this.type = type; } } @@ -811,7 +803,7 @@ this(Type type, Token* ident) { mixin(set_kind); - this.children = [type]; + addChild(type); this.type = type; this.ident = ident; } @@ -823,7 +815,7 @@ this(Type type) { mixin(set_kind); - this.children = [type]; + addChild(type); this.type = type; } } @@ -838,11 +830,10 @@ this(Type type, Token* ident, Token* opTok, Token* specTok, Type specType, typeof(tparams) tparams) { mixin(set_kind); - this.children = [type]; - if (specType) - this.children ~= specType; - if (tparams) - this.children ~= tparams; + addChild(type); + addOptChild(specType); + version(D2) + addOptChild(tparams); this.type = type; this.ident = ident; this.opTok = opTok; @@ -861,11 +852,9 @@ this() { mixin(set_kind); - if (returnType) - this.children ~= returnType; - if (parameters) - this.children ~= parameters; - this.children ~= funcBody; + addOptChild(returnType); + addOptChild(parameters); + addChild(funcBody); } this(Type returnType, Parameters parameters, FunctionBody funcBody) @@ -892,8 +881,7 @@ this(typeof(ident) ident, typeof(targs) targs) { mixin(set_kind); - if (targs) - this.children = [targs]; + addOptChild(targs); this.ident = ident; this.targs = targs; } @@ -918,10 +906,8 @@ mixin(set_kind); foreach (i, key; keys) { - if (key) - this.children ~= key; - if (values[i]) - this.children ~= values[i]; + addOptChild(key); // The key is optional in ArrayInitializers. + addChild(values[i]); } this.keys = keys; this.values = values; @@ -935,7 +921,7 @@ this(Token*[] idents, Expression[] values) { mixin(set_kind); - this.children = values; + addOptChildren(values); this.idents = idents; this.values = values; } @@ -983,7 +969,7 @@ this(Expression e) { mixin(set_kind); - this.children = [e]; + addChild(e); this.e = e; } }