changeset 195:37c2ffd649c4

- Parsing template parameter list for class, interface, struct and union declarations.
author aziz
date Sun, 15 Jul 2007 19:00:05 +0000
parents b3604b237292
children ea3f66901fa4
files trunk/src/Declarations.d trunk/src/Parser.d
diffstat 2 files changed, 23 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/trunk/src/Declarations.d	Sun Jul 15 18:49:04 2007 +0000
+++ b/trunk/src/Declarations.d	Sun Jul 15 19:00:05 2007 +0000
@@ -92,12 +92,14 @@
 class ClassDeclaration : Declaration
 {
   string name;
+  TemplateParameter[] tparams;
   BaseClass[] bases;
   Declaration[] decls;
-  this(string name, BaseClass[] bases, Declaration[] decls, bool hasBody)
+  this(string name, TemplateParameter[] tparams, BaseClass[] bases, Declaration[] decls, bool hasBody)
   {
     super(hasBody);
     this.name = name;
+    this.tparams = tparams;
     this.bases = bases;
     this.decls = decls;
   }
@@ -106,12 +108,14 @@
 class InterfaceDeclaration : Declaration
 {
   string name;
+  TemplateParameter[] tparams;
   BaseClass[] bases;
   Declaration[] decls;
-  this(string name, BaseClass[] bases, Declaration[] decls, bool hasBody)
+  this(string name, TemplateParameter[] tparams, BaseClass[] bases, Declaration[] decls, bool hasBody)
   {
     super(hasBody);
     this.name = name;
+    this.tparams = tparams;
     this.bases = bases;
     this.decls = decls;
   }
@@ -120,11 +124,13 @@
 class StructDeclaration : Declaration
 {
   string name;
+  TemplateParameter[] tparams;
   Declaration[] decls;
-  this(string name, Declaration[] decls, bool hasBody)
+  this(string name, TemplateParameter[] tparams, Declaration[] decls, bool hasBody)
   {
     super(hasBody);
     this.name = name;
+    this.tparams = tparams;
     this.decls = decls;
   }
 }
@@ -132,11 +138,13 @@
 class UnionDeclaration : Declaration
 {
   string name;
+  TemplateParameter[] tparams;
   Declaration[] decls;
-  this(string name, Declaration[] decls, bool hasBody)
+  this(string name, TemplateParameter[] tparams, Declaration[] decls, bool hasBody)
   {
     super(hasBody);
     this.name = name;
+    this.tparams = tparams;
     this.decls = decls;
   }
 }
--- a/trunk/src/Parser.d	Sun Jul 15 18:49:04 2007 +0000
+++ b/trunk/src/Parser.d	Sun Jul 15 19:00:05 2007 +0000
@@ -581,6 +581,7 @@
     assert(token.type == T.Class);
 
     string className;
+    TemplateParameter[] tparams;
     BaseClass[] bases;
     Declaration[] decls;
     bool hasBody;
@@ -590,8 +591,7 @@
 
     if (token.type == T.LParen)
     {
-      // TODO: parse template parameters
-      // parseTemplateParameters();
+      tparams = parseTemplateParameterList();
     }
 
     if (token.type == T.Colon)
@@ -600,7 +600,7 @@
     if (token.type == T.Semicolon)
     {
       //if (bases.length != 0)
-        // error: bases classes are not allowed in forward declarations.
+        // TODO: Error: bases classes are not allowed in forward declarations.
       nT();
     }
     else if (token.type == T.LBrace)
@@ -614,9 +614,7 @@
     else
       expected(T.LBrace); // TODO: better error msg
 
-    // TODO: error if decls.length == 0
-
-    return new ClassDeclaration(className, bases, decls, hasBody);
+    return new ClassDeclaration(className, tparams, bases, decls, hasBody);
   }
 
   BaseClass[] parseBaseClasses(bool colonLeadsOff = true)
@@ -661,6 +659,7 @@
     assert(token.type == T.Interface);
 
     string name;
+    TemplateParameter[] tparams;
     BaseClass[] bases;
     Declaration[] decls;
     bool hasBody;
@@ -670,7 +669,7 @@
 
     if (token.type == T.LParen)
     {
-      // TODO: parse template parameters
+      tparams = parseTemplateParameterList();
     }
 
     if (token.type == T.Colon)
@@ -694,7 +693,7 @@
 
     // TODO: error if decls.length == 0
 
-    return new InterfaceDeclaration(name, bases, decls, hasBody);
+    return new InterfaceDeclaration(name, tparams, bases, decls, hasBody);
   }
 
   Declaration parseAggregateDeclaration()
@@ -704,6 +703,7 @@
     TOK tok = token.type;
 
     string name;
+    TemplateParameter[] tparams;
     Declaration[] decls;
     bool hasBody;
 
@@ -715,7 +715,7 @@
       nT();
       if (token.type == T.LParen)
       {
-        // TODO: parse template parameters
+        tparams = parseTemplateParameterList();
       }
     }
 
@@ -738,9 +738,9 @@
     // TODO: error if decls.length == 0
 
     if (tok == T.Struct)
-      return new StructDeclaration(name, decls, hasBody);
+      return new StructDeclaration(name, tparams, decls, hasBody);
     else
-      return new UnionDeclaration(name, decls, hasBody);
+      return new UnionDeclaration(name, tparams, decls, hasBody);
   }
 
   Declaration parseConstructorDeclaration()