# HG changeset patch # User aziz # Date 1184526005 0 # Node ID 37c2ffd649c483fade117ee1f64299ba20157ac9 # Parent b3604b23729225747c38ca057cd7328356d3054f - Parsing template parameter list for class, interface, struct and union declarations. diff -r b3604b237292 -r 37c2ffd649c4 trunk/src/Declarations.d --- 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; } } diff -r b3604b237292 -r 37c2ffd649c4 trunk/src/Parser.d --- 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()