diff trunk/src/dil/Statements.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 0a4619735ce9
children b60450804b6e
line wrap: on
line diff
--- a/trunk/src/dil/Statements.d	Sat Dec 01 21:42:24 2007 +0100
+++ b/trunk/src/dil/Statements.d	Mon Dec 03 22:44:27 2007 +0100
@@ -26,7 +26,7 @@
 
   void opCatAssign(Statement s)
   {
-    this.children ~= s;
+    addChild(s);
   }
 }
 
@@ -60,12 +60,9 @@
 
   void finishConstruction()
   {
-    if (funcBody)
-      this.children ~= funcBody;
-    if (inBody)
-      this.children ~= inBody;
-    if (outBody)
-      this.children ~= outBody;
+    addOptChild(funcBody);
+    addOptChild(inBody);
+    addOptChild(outBody);
   }
 }
 
@@ -75,7 +72,7 @@
   this(Statement s)
   {
     mixin(set_kind);
-    this.children = [s];
+    addChild(s);
     this.s = s;
   }
 }
@@ -87,7 +84,7 @@
   this(Token* label, Statement s)
   {
     mixin(set_kind);
-    this.children = [s];
+    addChild(s);
     this.label = label;
     this.s = s;
   }
@@ -99,7 +96,7 @@
   this(Expression expression)
   {
     mixin(set_kind);
-    this.children = [expression];
+    addChild(expression);
     this.expression = expression;
   }
 }
@@ -110,7 +107,7 @@
   this(Declaration declaration)
   {
     mixin(set_kind);
-    this.children = [declaration];
+    addChild(declaration);
     this.declaration = declaration;
   }
 }
@@ -125,12 +122,12 @@
   {
     mixin(set_kind);
     if (variable)
-      this.children ~= variable;
+      addChild(variable);
     else
-      this.children ~= condition;
-    this.children ~= ifBody;
-    if (elseBody)
-      this.children ~= elseBody;
+      addChild(condition);
+    addChild(ifBody);
+    addOptChild(elseBody);
+
     this.variable = variable;
     this.condition = condition;
     this.ifBody = ifBody;
@@ -145,7 +142,9 @@
   this(Expression condition, Statement whileBody)
   {
     mixin(set_kind);
-    this.children = [cast(Node)condition, whileBody];
+    addChild(condition);
+    addChild(whileBody);
+
     this.condition = condition;
     this.whileBody = whileBody;
   }
@@ -158,7 +157,9 @@
   this(Expression condition, Statement doBody)
   {
     mixin(set_kind);
-    this.children = [cast(Node)condition, doBody];
+    addChild(condition);
+    addChild(doBody);
+
     this.condition = condition;
     this.doBody = doBody;
   }
@@ -173,13 +174,11 @@
   this(Statement init, Expression condition, Expression increment, Statement forBody)
   {
     mixin(set_kind);
-    if (init)
-      this.children ~= init;
-    if (condition)
-      this.children ~= condition;
-    if (increment)
-      this.children ~= increment;
-    this.children ~= forBody;
+    addOptChild(init);
+    addOptChild(condition);
+    addOptChild(increment);
+    addChild(forBody);
+
     this.init = init;
     this.condition = condition;
     this.increment = increment;
@@ -197,7 +196,8 @@
   this(TOK tok, Parameters params, Expression aggregate, Statement forBody)
   {
     mixin(set_kind);
-    this.children = [cast(Node)params, aggregate, forBody];
+    addChildren([cast(Node)params, aggregate, forBody]);
+
     this.tok = tok;
     this.params = params;
     this.aggregate = aggregate;
@@ -217,7 +217,8 @@
   this(TOK tok, Parameters params, Expression lower, Expression upper, Statement forBody)
   {
     mixin(set_kind);
-    this.children = [cast(Node)params, lower, upper, forBody];
+    addChildren([cast(Node)params, lower, upper, forBody]);
+
     this.tok = tok;
     this.params = params;
     this.lower = lower;
@@ -235,7 +236,9 @@
   this(Expression condition, Statement switchBody)
   {
     mixin(set_kind);
-    this.children = [cast(Node)condition, switchBody];
+    addChild(condition);
+    addChild(switchBody);
+
     this.condition = condition;
     this.switchBody = switchBody;
   }
@@ -249,7 +252,9 @@
   this(Expression[] values, Statement caseBody)
   {
     mixin(set_kind);
-    this.children = cast(Node[])values ~ [caseBody];
+    addChildren(values);
+    addChild(caseBody);
+
     this.values = values;
     this.caseBody = caseBody;
   }
@@ -261,7 +266,8 @@
   this(Statement defaultBody)
   {
     mixin(set_kind);
-    this.children = [defaultBody];
+    addChild(defaultBody);
+
     this.defaultBody = defaultBody;
   }
 }
@@ -292,8 +298,7 @@
   this(Expression expr)
   {
     mixin(set_kind);
-    if (expr)
-      this.children = [expr];
+    addOptChild(expr);
     this.expr = expr;
   }
 }
@@ -305,8 +310,7 @@
   this(Token* ident, Expression caseExpr)
   {
     mixin(set_kind);
-    if (caseExpr)
-      this.children = [caseExpr];
+    addOptChild(caseExpr);
     this.ident = ident;
     this.caseExpr = caseExpr;
   }
@@ -319,8 +323,9 @@
   this(Expression expr, Statement withBody)
   {
     mixin(set_kind);
-    assert(expr !is null && withBody !is null);
-    this.children = [cast(Node)expr, withBody];
+    addChild(expr);
+    addChild(withBody);
+
     this.expr = expr;
     this.withBody = withBody;
   }
@@ -333,10 +338,9 @@
   this(Expression expr, Statement syncBody)
   {
     mixin(set_kind);
-    if (expr)
-      this.children ~= expr;
-    assert(syncBody !is null);
-    this.children ~= syncBody;
+    addOptChild(expr);
+    addChild(syncBody);
+
     this.expr = expr;
     this.syncBody = syncBody;
   }
@@ -350,12 +354,10 @@
   this(Statement tryBody, CatchBody[] catchBodies, FinallyBody finallyBody)
   {
     mixin(set_kind);
-    assert(tryBody !is null);
-    this.children = [tryBody];
-    if (catchBodies.length)
-      this.children ~= catchBodies;
-    if (finallyBody)
-      this.children ~= finallyBody;
+    addChild(tryBody);
+    addOptChildren(catchBodies);
+    addOptChild(finallyBody);
+
     this.tryBody = tryBody;
     this.catchBodies = catchBodies;
     this.finallyBody = finallyBody;
@@ -369,10 +371,8 @@
   this(Parameter param, Statement catchBody)
   {
     mixin(set_kind);
-    if (param)
-      this.children ~= param;
-    assert(catchBody !is null);
-    this.children ~= catchBody;
+    addOptChild(param);
+    addChild(catchBody);
     this.param = param;
     this.catchBody = catchBody;
   }
@@ -384,8 +384,7 @@
   this(Statement finallyBody)
   {
     mixin(set_kind);
-    assert(finallyBody !is null);
-    this.children = [finallyBody];
+    addChild(finallyBody);
     this.finallyBody = finallyBody;
   }
 }
@@ -397,8 +396,7 @@
   this(Token* condition, Statement scopeBody)
   {
     mixin(set_kind);
-    assert(scopeBody !is null);
-    this.children = [scopeBody];
+    addChild(scopeBody);
     this.condition = condition;
     this.scopeBody = scopeBody;
   }
@@ -410,7 +408,7 @@
   this(Expression expr)
   {
     mixin(set_kind);
-    this.children = [expr];
+    addChild(expr);
     this.expr = expr;
   }
 }
@@ -421,8 +419,7 @@
   this(Statement volatileBody)
   {
     mixin(set_kind);
-    if (volatileBody)
-      this.children = [volatileBody];
+    addOptChild(volatileBody);
     this.volatileBody = volatileBody;
   }
 }
@@ -433,7 +430,7 @@
   this(Statements statements)
   {
     mixin(set_kind);
-    this.children = [statements];
+    addChild(statements);
     this.statements = statements;
   }
 }
@@ -445,8 +442,7 @@
   this(Token* ident, Expression[] operands)
   {
     mixin(set_kind);
-    if (operands.length)
-      this.children = operands;
+    addOptChildren(operands);
     this.ident = ident;
     this.operands = operands;
   }
@@ -479,9 +475,9 @@
   this(Token* ident, Expression[] args, Statement pragmaBody)
   {
     mixin(set_kind);
-    if (args.length)
-      this.children = args;
-    this.children ~= pragmaBody;
+    addOptChildren(args);
+    addChild(pragmaBody);
+
     this.ident = ident;
     this.args = args;
     this.pragmaBody = pragmaBody;
@@ -495,7 +491,7 @@
   this(Expression[] templateIdents, Token* mixinIdent)
   {
     mixin(set_kind);
-    this.children = templateIdents;
+    addChildren(templateIdents);
     this.templateIdents = templateIdents;
     this.mixinIdent = mixinIdent;
   }
@@ -508,9 +504,9 @@
   this(Expression condition, Statement ifBody, Statement elseBody)
   {
     mixin(set_kind);
-    this.children = [cast(Node)condition, ifBody];
-    if (elseBody)
-      this.children ~= elseBody;
+    addChild(condition);
+    addChild(ifBody);
+    addOptChild(elseBody);
     this.condition = condition;
     this.ifBody = ifBody;
     this.elseBody = elseBody;
@@ -523,9 +519,8 @@
   this(Expression condition, Expression message)
   {
     mixin(set_kind);
-    this.children = [condition];
-    if (message)
-      this.children ~= message;
+    addChild(condition);
+    addOptChild(message);
     this.condition = condition;
     this.message = message;
   }
@@ -538,9 +533,8 @@
   this(Token* cond, Statement debugBody, Statement elseBody)
   {
     mixin(set_kind);
-    this.children = [debugBody];
-    if (elseBody)
-      this.children ~= elseBody;
+    addChild(debugBody);
+    addOptChild(elseBody);
     this.cond = cond;
     this.debugBody = debugBody;
     this.elseBody = elseBody;
@@ -554,9 +548,8 @@
   this(Token* cond, Statement versionBody, Statement elseBody)
   {
     mixin(set_kind);
-    this.children = [versionBody];
-    if (elseBody)
-      this.children ~= [elseBody];
+    addChild(versionBody);
+    addOptChild(elseBody);
     this.cond = cond;
     this.versionBody = versionBody;
     this.elseBody = elseBody;
@@ -570,8 +563,7 @@
   this(TOK tok, Statement statement)
   {
     mixin(set_kind);
-    assert(statement !is null);
-    this.children = [statement];
+    addChild(statement);
     this.tok = tok;
     this.statement = statement;
   }
@@ -584,8 +576,7 @@
   {
     super(TOK.Extern, statement);
     mixin(set_kind);
-    if (linkage)
-      this.children ~= linkage;
+    addOptChild(linkage);
     this.linkage = linkage;
   }
 }