# HG changeset patch # User Aziz K?ksal # Date 1203192880 -3600 # Node ID 0af3b145a405e59e7275935cf7a0be961a8ff8e9 # Parent bc812843603c6f64e71b6214c635fc1e1daa787f Revised TemplateParameterList parsing functions. diff -r bc812843603c -r 0af3b145a405 trunk/src/cmd/DDoc.d --- a/trunk/src/cmd/DDoc.d Sat Feb 16 20:18:42 2008 +0100 +++ b/trunk/src/cmd/DDoc.d Sat Feb 16 21:14:40 2008 +0100 @@ -160,7 +160,6 @@ return Token.textSpan(left, right); } - bool isTemplatized; /// True if an aggregate declaration is templatized. TemplateParameters tparams; /// The template parameters of the declaration. DDocComment cmnt; /// Current comment. @@ -416,10 +415,9 @@ void writeTemplateParams() { - if (!isTemplatized) + if (!tparams) return; - write("(", (tparams ? escape(textSpan(tparams.begin, tparams.end)) : ""), ")"); - isTemplatized = false; + write(escape(textSpan(tparams.begin, tparams.end))); tparams = null; } @@ -581,12 +579,10 @@ D visit(TemplateDeclaration d) { - this.isTemplatized = true; this.tparams = d.tparams; if (d.begin.kind != TOK.Template) { // This is a templatized class/interface/struct/union/function. super.visit(d.decls); - this.isTemplatized = false; this.tparams = null; return d; } diff -r bc812843603c -r 0af3b145a405 trunk/src/dil/ast/Declarations.d --- a/trunk/src/dil/ast/Declarations.d Sat Feb 16 20:18:42 2008 +0100 +++ b/trunk/src/dil/ast/Declarations.d Sat Feb 16 21:14:40 2008 +0100 @@ -205,7 +205,7 @@ { super.hasBody = true; mixin(set_kind); - addOptChild(tparams); + addChild(tparams); addChild(decls); this.name = name; @@ -237,7 +237,7 @@ { super(name, /+tparams, +/decls); mixin(set_kind); -// addOptChild(tparams); +// addChild(tparams); addOptChildren(bases); addOptChild(decls); @@ -254,7 +254,7 @@ { super(name, /+tparams, +/decls); mixin(set_kind); -// addOptChild(tparams); +// addChild(tparams); addOptChildren(bases); addOptChild(decls); @@ -273,7 +273,7 @@ { super(name, /+tparams, +/decls); mixin(set_kind); -// addOptChild(tparams); +// addChild(tparams); addOptChild(decls); } @@ -291,7 +291,7 @@ { super(name, /+tparams, +/decls); mixin(set_kind); -// addOptChild(tparams); +// addChild(tparams); addOptChild(decls); } @@ -367,7 +367,7 @@ super.hasBody = funcBody.funcBody !is null; mixin(set_kind); addChild(returnType); -// addOptChild(tparams); +// addChild(tparams); addChild(params); addChild(funcBody); diff -r bc812843603c -r 0af3b145a405 trunk/src/dil/ast/DefaultVisitor.d --- a/trunk/src/dil/ast/DefaultVisitor.d Sat Feb 16 20:18:42 2008 +0100 +++ b/trunk/src/dil/ast/DefaultVisitor.d Sat Feb 16 21:14:40 2008 +0100 @@ -47,13 +47,13 @@ d.value && visitE(d.value); static if (is(D == ClassDeclaration) || is( D == InterfaceDeclaration)) { -// d.tparams && visitN(d.tparams); +// visitN(d.tparams); foreach (base; d.bases) visitT(base); d.decls && visitD(d.decls); } static if (is(D == StructDeclaration) || is(D == UnionDeclaration)) -// d.tparams && visitN(d.tparams), +// visitN(d.tparams), d.decls && visitD(d.decls); static if (is(D == ConstructorDeclaration)) visitN(d.params), visitS(d.funcBody); @@ -65,7 +65,7 @@ visitS(d.funcBody); static if (is(D == FunctionDeclaration)) visitT(d.returnType), -// d.tparams && visitN(d.tparams), +// visitN(d.tparams), visitN(d.params), visitS(d.funcBody); static if (is(D == VariablesDeclaration)) @@ -85,7 +85,7 @@ visitE(d.condition), d.message && visitE(d.message); static if (is(D == TemplateDeclaration)) - d.tparams && visitN(d.tparams), + visitN(d.tparams), visitD(d.decls); static if (is(D == NewDeclaration) || is(D == DeleteDeclaration)) visitN(d.params), diff -r bc812843603c -r 0af3b145a405 trunk/src/dil/parser/Parser.d --- a/trunk/src/dil/parser/Parser.d Sat Feb 16 20:18:42 2008 +0100 +++ b/trunk/src/dil/parser/Parser.d Sat Feb 16 21:14:40 2008 +0100 @@ -484,12 +484,9 @@ assert(token.kind == T.LParen); // It's a function declaration TemplateParameters tparams; - bool isTemplate; if (tokenAfterParenIs(T.LParen)) - { // ( TemplateParameterList ) ( ParameterList ) + // ( TemplateParameterList ) ( ParameterList ) tparams = parseTemplateParameterList(); - isTemplate = true; - } auto params = parseParameterList(); version(D2) @@ -513,7 +510,7 @@ fd.setStorageClass(stc); fd.setLinkageType(linkType); fd.setProtection(protection); - if (isTemplate) + if (tparams) { auto d = putInsideTemplateDeclaration(begin, ident, fd, tparams); d.setStorageClass(stc); @@ -1059,8 +1056,7 @@ className = requireIdentifier(MSG.ExpectedClassName); - bool isTemplate = token.kind == T.LParen; - if (isTemplate) + if (token.kind == T.LParen) tparams = parseTemplateParameterList(); if (token.kind == T.Colon) @@ -1074,7 +1070,7 @@ error(token, MSG.ExpectedClassBody, token.srcText); Declaration d = new ClassDeclaration(className, /+tparams, +/bases, decls); - if (isTemplate) + if (tparams) d = putInsideTemplateDeclaration(begin, className, d, tparams); return d; } @@ -1125,8 +1121,7 @@ name = requireIdentifier(MSG.ExpectedInterfaceName); - bool isTemplate = token.kind == T.LParen; - if (isTemplate) + if (token.kind == T.LParen) tparams = parseTemplateParameterList(); if (token.kind == T.Colon) @@ -1140,7 +1135,7 @@ error(token, MSG.ExpectedInterfaceBody, token.srcText); Declaration d = new InterfaceDeclaration(name, /+tparams, +/bases, decls); - if (isTemplate) + if (tparams) d = putInsideTemplateDeclaration(begin, name, d, tparams); return d; } @@ -1157,8 +1152,7 @@ name = optionalIdentifier(); - bool isTemplate = name && token.kind == T.LParen; - if (isTemplate) + if (name && token.kind == T.LParen) tparams = parseTemplateParameterList(); if (name && skipped(T.Semicolon)) @@ -1167,8 +1161,8 @@ decls = parseDeclarationDefinitionsBody(); else error(token, begin.kind == T.Struct ? - MSG.ExpectedStructBody : - MSG.ExpectedUnionBody, token.srcText); + MSG.ExpectedStructBody : + MSG.ExpectedUnionBody, token.srcText); Declaration d; if (begin.kind == T.Struct) @@ -1180,7 +1174,7 @@ else d = new UnionDeclaration(name, /+tparams, +/decls); - if (isTemplate) + if (tparams) d = putInsideTemplateDeclaration(begin, name, d, tparams); return d; } @@ -3935,12 +3929,13 @@ TemplateParameters parseTemplateParameterList() { - TemplateParameters tparams; + auto begin = token; + auto tparams = new TemplateParameters; require(T.LParen); if (token.kind != T.RParen) - tparams = parseTemplateParameterList_(); + parseTemplateParameterList_(tparams); require(T.RParen); - return tparams; + return set(tparams, begin); } version(D2) @@ -3949,20 +3944,18 @@ { assert(token.kind == T.Comma); nT(); - TemplateParameters tparams; + auto begin = token; + auto tparams = new TemplateParameters; if (token.kind != T.RParen) - tparams = parseTemplateParameterList_(); + parseTemplateParameterList_(tparams); else error(token, MSG.ExpectedTemplateParameters); - return tparams; + return set(tparams, begin); } } // version(D2) - TemplateParameters parseTemplateParameterList_() + void parseTemplateParameterList_(TemplateParameters tparams) { - auto begin = token; - auto tparams = new TemplateParameters; - do { auto paramBegin = token; @@ -4047,8 +4040,6 @@ tparams ~= set(tp, paramBegin); } while (skipped(T.Comma)) - set(tparams, begin); - return tparams; } void expected(TOK tok)