changeset 340:1accb3013bd2

- Changed class TemplateParameter to an abstract class. - Added classes TemplateAlias-, Type-, Value- and TupleParameter.
author aziz
date Wed, 22 Aug 2007 19:50:01 +0000
parents 9954367bcd4b
children 3ac651ea83fb
files trunk/src/dil/Parser.d trunk/src/dil/SyntaxTree.d trunk/src/dil/Types.d
diffstat 3 files changed, 76 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/trunk/src/dil/Parser.d	Wed Aug 22 15:56:02 2007 +0000
+++ b/trunk/src/dil/Parser.d	Wed Aug 22 19:50:01 2007 +0000
@@ -3971,26 +3971,16 @@
     auto tparams = new TemplateParameters;
 
     require(T.LParen);
-    if (token.type == T.RParen)
-      return tparams;
-
+    if (token.type != T.RParen)
     while (1)
     {
       auto paramBegin = token;
-      TP tp;
+      TemplateParameter tp;
       Token* ident;
-      Type valueType;
       Type specType, defType;
-      Expression specValue, defValue;
-
-      switch (token.type)
+
+      void parseSpecAndOrDefaultType()
       {
-      case T.Alias:
-        // TemplateAliasParameter:
-        //         alias Identifier
-        tp = TP.Alias;
-        nT(); // Skip alias keyword.
-        ident = requireId();
         // : SpecializationType
         if (token.type == T.Colon)
         {
@@ -4003,6 +3993,17 @@
           nT();
           defType = parseType();
         }
+      }
+
+      switch (token.type)
+      {
+      case T.Alias:
+        // TemplateAliasParameter:
+        //         alias Identifier
+        nT(); // Skip alias keyword.
+        ident = requireId();
+        parseSpecAndOrDefaultType();
+        tp = new TemplateAliasParameter(ident, specType, defType);
         break;
       case T.Identifier:
         ident = token;
@@ -4011,29 +4012,18 @@
         case T.Ellipses:
           // TemplateTupleParameter:
           //         Identifier ...
-          tp = TP.Tuple;
           nT(); // Skip Identifier.
           nT(); // Skip Ellipses.
           // if (token.type == T.Comma)
           //  error(); // TODO: issue error msg for variadic param not being last.
+          tp = new TemplateTupleParameter(ident);
           break;
         case T.Comma, T.RParen, T.Colon, T.Assign:
           // TemplateTypeParameter:
           //         Identifier
-          tp = TP.Type;
           nT(); // Skip Identifier.
-          // : SpecializationType
-          if (token.type == T.Colon)
-          {
-            nT();
-            specType = parseType();
-          }
-          // = DefaultType
-          if (token.type == T.Assign)
-          {
-            nT();
-            defType = parseType();
-          }
+          parseSpecAndOrDefaultType();
+          tp = new TemplateAliasParameter(ident, specType, defType);
           break;
         default:
           // TemplateValueParameter:
@@ -4046,8 +4036,8 @@
       LTemplateValueParameter:
         // TemplateValueParameter:
         //         Declarator
-        tp = TP.Value;
-        valueType = parseDeclarator(ident);
+        Expression specValue, defValue;
+        auto valueType = parseDeclarator(ident);
         // : SpecializationValue
         if (token.type == T.Colon)
         {
@@ -4060,9 +4050,11 @@
           nT();
           defValue = parseCondExpression();
         }
+        tp = new TemplateValueParameter(valueType, ident, specValue, defValue);
       }
 
-      tparams ~= set(new TemplateParameter(tp, valueType, ident, specType, defType, specValue, defValue), paramBegin);
+      // Push template parameter.
+      tparams ~= set(tp, paramBegin);
 
       if (token.type != T.Comma)
         break;
--- a/trunk/src/dil/SyntaxTree.d	Wed Aug 22 15:56:02 2007 +0000
+++ b/trunk/src/dil/SyntaxTree.d	Wed Aug 22 19:50:01 2007 +0000
@@ -202,7 +202,10 @@
   Parameter,
   Parameters,
   BaseClass,
-  TemplateParameter,
+  TemplateAliasParameter,
+  TemplateTypeParameter,
+  TemplateValueParameter,
+  TemplateTupleParameter,
   TemplateParameters,
   TemplateArguments,
 }
--- a/trunk/src/dil/Types.d	Wed Aug 22 15:56:02 2007 +0000
+++ b/trunk/src/dil/Types.d	Wed Aug 22 19:50:01 2007 +0000
@@ -142,45 +142,78 @@
   }
 }
 
-enum TP
+abstract class TemplateParameter : Node
 {
-  Type,
-  Value,
-  Alias,
-  Tuple
+  this()
+  {
+    super(NodeCategory.Other);
+  }
 }
 
-class TemplateParameter : Node
+class TemplateAliasParameter : TemplateParameter
 {
-  TP tp;
-  Type valueType;
   Token* ident;
   Type specType, defType;
-  Expression specValue, defValue;
-  this(TP tp, Type valueType, Token* ident, Type specType, Type defType, Expression specValue, Expression defValue)
+  this(Token* ident, Type specType, Type defType)
   {
-    super(NodeCategory.Other);
     mixin(set_kind);
-    if (valueType)
-      this.children ~= valueType;
     if (specType)
       this.children ~= specType;
     if (defType)
       this.children ~= defType;
+    this.ident = ident;
+    this.specType = specType;
+    this.defType = defType;
+  }
+}
+
+class TemplateTypeParameter : TemplateParameter
+{
+  Token* ident;
+  Type specType, defType;
+  this(Token* ident, Type specType, Type defType)
+  {
+    mixin(set_kind);
+    if (specType)
+      this.children ~= specType;
+    if (defType)
+      this.children ~= defType;
+    this.ident = ident;
+    this.specType = specType;
+    this.defType = defType;
+  }
+}
+
+class TemplateValueParameter : TemplateParameter
+{
+  Type valueType;
+  Token* ident;
+  Expression specValue, defValue;
+  this(Type valueType, Token* ident, Expression specValue, Expression defValue)
+  {
+    mixin(set_kind);
+    this.children ~= valueType;
     if (specValue)
       this.children ~= specValue;
     if (defValue)
       this.children ~= defValue;
-    this.tp = tp;
     this.valueType = valueType;
     this.ident = ident;
-    this.specType = specType;
-    this.defType = defType;
     this.specValue = specValue;
     this.defValue = defValue;
   }
 }
 
+class TemplateTupleParameter : TemplateParameter
+{
+  Token* ident;
+  this(Token* ident)
+  {
+    mixin(set_kind);
+    this.ident = ident;
+  }
+}
+
 class TemplateParameters : Node
 {
   this()