changeset 277:38a68e534a3b

- Made classes Declaration, Expression and Statement abstract. - Added declarations to enum NodeKind. - Added mixin(set_kind) statement to every constructor that inherits from Declaration.
author aziz
date Mon, 06 Aug 2007 15:15:01 +0000
parents d6b2f7616ca5
children e5a6b56c7716
files trunk/src/Declarations.d trunk/src/Expressions.d trunk/src/Statements.d trunk/src/SyntaxTree.d
diffstat 4 files changed, 69 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/trunk/src/Declarations.d	Mon Aug 06 15:01:02 2007 +0000
+++ b/trunk/src/Declarations.d	Mon Aug 06 15:15:01 2007 +0000
@@ -9,7 +9,7 @@
 import Statements;
 import Token;
 
-class Declaration : Node
+abstract class Declaration : Node
 {
   bool hasBody;
   this(bool hasBody)
@@ -24,6 +24,7 @@
   this()
   {
     super(false);
+    mixin(set_kind);
   }
 }
 
@@ -33,6 +34,7 @@
   this(TOK tok)
   {
     super(false);
+    mixin(set_kind);
     this.tok = tok;
   }
 }
@@ -45,6 +47,7 @@
   this(ModuleName moduleName)
   {
     super(false);
+    mixin(set_kind);
     this.moduleName = moduleName;
   }
 }
@@ -58,6 +61,7 @@
   this(ModuleName[] moduleNames, Token*[] moduleAliases, Token*[] bindNames, Token*[] bindAliases)
   {
     super(false);
+    mixin(set_kind);
     this.moduleNames = moduleNames;
     this.moduleAliases = moduleAliases;
     this.bindNames = bindNames;
@@ -71,6 +75,7 @@
   this(Declaration decl)
   {
     super(false);
+    mixin(set_kind);
     this.decl = decl;
   }
 }
@@ -81,6 +86,7 @@
   this(Declaration decl)
   {
     super(false);
+    mixin(set_kind);
     this.decl = decl;
   }
 }
@@ -94,6 +100,7 @@
   this(Token* name, Type baseType, Token*[] members, Expression[] values, bool hasBody)
   {
     super(hasBody);
+    mixin(set_kind);
     this.name = name;
     this.baseType = baseType;
     this.members = members;
@@ -110,6 +117,7 @@
   this(Token* name, TemplateParameters tparams, BaseClass[] bases, Declaration[] decls, bool hasBody)
   {
     super(hasBody);
+    mixin(set_kind);
     this.name = name;
     this.tparams = tparams;
     this.bases = bases;
@@ -126,6 +134,7 @@
   this(Token* name, TemplateParameters tparams, BaseClass[] bases, Declaration[] decls, bool hasBody)
   {
     super(hasBody);
+    mixin(set_kind);
     this.name = name;
     this.tparams = tparams;
     this.bases = bases;
@@ -141,6 +150,7 @@
   this(Token* name, TemplateParameters tparams, Declaration[] decls, bool hasBody)
   {
     super(hasBody);
+    mixin(set_kind);
     this.name = name;
     this.tparams = tparams;
     this.decls = decls;
@@ -155,6 +165,7 @@
   this(Token* name, TemplateParameters tparams, Declaration[] decls, bool hasBody)
   {
     super(hasBody);
+    mixin(set_kind);
     this.name = name;
     this.tparams = tparams;
     this.decls = decls;
@@ -168,6 +179,7 @@
   this(Parameters parameters, FunctionBody funcBody)
   {
     super(true);
+    mixin(set_kind);
     this.parameters = parameters;
     this.funcBody = funcBody;
   }
@@ -179,6 +191,7 @@
   this(FunctionBody funcBody)
   {
     super(true);
+    mixin(set_kind);
     this.funcBody = funcBody;
   }
 }
@@ -189,6 +202,7 @@
   this(FunctionBody funcBody)
   {
     super(true);
+    mixin(set_kind);
     this.funcBody = funcBody;
   }
 }
@@ -199,6 +213,7 @@
   this(FunctionBody funcBody)
   {
     super(true);
+    mixin(set_kind);
     this.funcBody = funcBody;
   }
 }
@@ -212,6 +227,7 @@
   this(Token* funcName, Type funcType, TemplateParameters tparams, FunctionBody funcBody)
   {
     super(funcBody.funcBody !is null);
+    mixin(set_kind);
     this.funcName = funcName;
     this.funcType = funcType;
     this.funcBody = funcBody;
@@ -225,6 +241,7 @@
   this(Token*[] idents, Expression[] values)
   {
     super(false);
+    mixin(set_kind);
     this.idents = idents;
     this.values = values;
   }
@@ -236,6 +253,7 @@
   this(FunctionBody funcBody)
   {
     super(true);
+    mixin(set_kind);
     this.funcBody = funcBody;
   }
 }
@@ -246,6 +264,7 @@
   this(FunctionBody funcBody)
   {
     super(true);
+    mixin(set_kind);
     this.funcBody = funcBody;
   }
 }
@@ -259,6 +278,7 @@
   this(Token* spec, Token* cond, Declaration[] decls, Declaration[] elseDecls)
   {
     super(decls.length != 0);
+    mixin(set_kind);
     this.spec = spec;
     this.cond = cond;
     this.decls = decls;
@@ -275,6 +295,7 @@
   this(Token* spec, Token* cond, Declaration[] decls, Declaration[] elseDecls)
   {
     super(decls.length != 0);
+    mixin(set_kind);
     this.spec = spec;
     this.cond = cond;
     this.decls = decls;
@@ -289,6 +310,7 @@
   this(Expression condition, Declaration[] ifDecls, Declaration[] elseDecls)
   {
     super(true);
+    mixin(set_kind);
     this.condition = condition;
     this.ifDecls = ifDecls;
     this.elseDecls = elseDecls;
@@ -301,6 +323,7 @@
   this(Expression condition, Expression message)
   {
     super(true);
+    mixin(set_kind);
     this.condition = condition;
     this.message = message;
   }
@@ -314,6 +337,7 @@
   this(Token* templateName, TemplateParameters templateParams, Declaration[] decls)
   {
     super(true);
+    mixin(set_kind);
     this.templateName = templateName;
     this.templateParams = templateParams;
     this.decls = decls;
@@ -327,6 +351,7 @@
   this(Parameters parameters, FunctionBody funcBody)
   {
     super(true);
+    mixin(set_kind);
     this.parameters = parameters;
     this.funcBody = funcBody;
   }
@@ -339,6 +364,7 @@
   this(Parameters parameters, FunctionBody funcBody)
   {
     super(true);
+    mixin(set_kind);
     this.parameters = parameters;
     this.funcBody = funcBody;
   }
@@ -351,6 +377,7 @@
   this(TOK attribute, Declaration[] decls)
   {
     super(true);
+    mixin(set_kind);
     this.attribute = attribute;
     this.decls = decls;
   }
@@ -362,6 +389,7 @@
   this(Linkage linkage, Declaration[] decls)
   {
     super(TOK.Extern, decls);
+    mixin(set_kind);
     this.linkage = linkage;
   }
 }
@@ -372,6 +400,7 @@
   this(int size, Declaration[] decls)
   {
     super(TOK.Align, decls);
+    mixin(set_kind);
     this.size = size;
   }
 }
@@ -383,6 +412,7 @@
   this(Token* ident, Expression[] args, Declaration[] decls)
   {
     super(TOK.Pragma, decls);
+    mixin(set_kind);
     this.ident = ident;
     this.args = args;
   }
@@ -396,12 +426,14 @@
   this(Expression[] templateIdent, Token* mixinIdent)
   {
     super(false);
+    mixin(set_kind);
     this.templateIdent = templateIdent;
     this.mixinIdent = mixinIdent;
   }
   this(Expression assignExpr)
   {
     super(false);
+    mixin(set_kind);
     this.assignExpr = assignExpr;
   }
 }
--- a/trunk/src/Expressions.d	Mon Aug 06 15:01:02 2007 +0000
+++ b/trunk/src/Expressions.d	Mon Aug 06 15:15:01 2007 +0000
@@ -9,7 +9,7 @@
 import Declarations;
 import Statements;
 
-class Expression : Node
+abstract class Expression : Node
 {
   this()
   {
--- a/trunk/src/Statements.d	Mon Aug 06 15:01:02 2007 +0000
+++ b/trunk/src/Statements.d	Mon Aug 06 15:15:01 2007 +0000
@@ -9,7 +9,7 @@
 import Types;
 import Token;
 
-class Statement : Node
+abstract class Statement : Node
 {
   this()
   {
--- a/trunk/src/SyntaxTree.d	Mon Aug 06 15:01:02 2007 +0000
+++ b/trunk/src/SyntaxTree.d	Mon Aug 06 15:15:01 2007 +0000
@@ -16,7 +16,7 @@
 
 enum NodeKind
 {
-  Expression,
+  // Expressions:
   EmptyExpression,
   BinaryExpression,
   CondExpression,
@@ -98,6 +98,39 @@
   VoidInitializer,
   ArrayInitializer,
   StructInitializer,
+
+  // Declarations:
+  EmptyDeclaration,
+  IllegalDeclaration,
+  ModuleDeclaration,
+  ImportDeclaration,
+  AliasDeclaration,
+  TypedefDeclaration,
+  EnumDeclaration,
+  ClassDeclaration,
+  InterfaceDeclaration,
+  StructDeclaration,
+  UnionDeclaration,
+  ConstructorDeclaration,
+  StaticConstructorDeclaration,
+  DestructorDeclaration,
+  StaticDestructorDeclaration,
+  FunctionDeclaration,
+  VariableDeclaration,
+  InvariantDeclaration,
+  UnittestDeclaration,
+  DebugDeclaration,
+  VersionDeclaration,
+  StaticIfDeclaration,
+  StaticAssertDeclaration,
+  TemplateDeclaration,
+  NewDeclaration,
+  DeleteDeclaration,
+  AttributeDeclaration,
+  ExternDeclaration,
+  AlignDeclaration,
+  PragmaDeclaration,
+  MixinDeclaration,
 }
 
 /// This string is mixed in into the constructor of a class that inherits from Node.