# HG changeset patch # User Aziz K?ksal # Date 1203189522 -3600 # Node ID bc812843603c6f64e71b6214c635fc1e1daa787f # Parent 4579e8505d5e69d325683ddb55d9f30436425de4 Template functions are wrapped inside TemplateDeclarations now. diff -r 4579e8505d5e -r bc812843603c trunk/src/cmd/DDoc.d --- a/trunk/src/cmd/DDoc.d Sat Feb 16 03:28:39 2008 +0100 +++ b/trunk/src/cmd/DDoc.d Sat Feb 16 20:18:42 2008 +0100 @@ -113,7 +113,8 @@ { auto src = new SourceText(filePath); src.load(infoMan); - return sanitizeText(src.data); + auto text = src.data[0..$-1]; // Exclude '\0'. + return sanitizeText(text); } /// Traverses the syntax tree and writes DDoc macros to a string buffer. @@ -583,8 +584,12 @@ this.isTemplatized = true; this.tparams = d.tparams; if (d.begin.kind != TOK.Template) - // This is a templatized class/interface/struct/union. - return super.visit(d.decls); + { // This is a templatized class/interface/struct/union/function. + super.visit(d.decls); + this.isTemplatized = false; + this.tparams = null; + return d; + } if (!ddoc(d)) return d; DECL({ @@ -667,8 +672,6 @@ if (!ddoc(d)) return d; auto type = textSpan(d.returnType.baseType.begin, d.returnType.end); - this.isTemplatized = d.isTemplatized(); - this.tparams = d.tparams; DECL({ write(escape(type), " "); SYMBOL(d.name.str); diff -r 4579e8505d5e -r bc812843603c trunk/src/dil/ast/Declarations.d --- a/trunk/src/dil/ast/Declarations.d Sat Feb 16 03:28:39 2008 +0100 +++ b/trunk/src/dil/ast/Declarations.d Sat Feb 16 20:18:42 2008 +0100 @@ -357,23 +357,23 @@ { TypeNode returnType; Identifier* name; - TemplateParameters tparams; +// TemplateParameters tparams; Parameters params; FuncBodyStatement funcBody; LinkageType linkageType; - this(TypeNode returnType, Identifier* name, TemplateParameters tparams, + this(TypeNode returnType, Identifier* name,/+ TemplateParameters tparams,+/ Parameters params, FuncBodyStatement funcBody) { super.hasBody = funcBody.funcBody !is null; mixin(set_kind); addChild(returnType); - addOptChild(tparams); +// addOptChild(tparams); addChild(params); addChild(funcBody); this.returnType = returnType; this.name = name; - this.tparams = tparams; +// this.tparams = tparams; this.params = params; this.funcBody = funcBody; } diff -r 4579e8505d5e -r bc812843603c trunk/src/dil/ast/DefaultVisitor.d --- a/trunk/src/dil/ast/DefaultVisitor.d Sat Feb 16 03:28:39 2008 +0100 +++ b/trunk/src/dil/ast/DefaultVisitor.d Sat Feb 16 20:18:42 2008 +0100 @@ -65,7 +65,7 @@ visitS(d.funcBody); static if (is(D == FunctionDeclaration)) visitT(d.returnType), - d.tparams && visitN(d.tparams), +// d.tparams && visitN(d.tparams), visitN(d.params), visitS(d.funcBody); static if (is(D == VariablesDeclaration)) diff -r 4579e8505d5e -r bc812843603c trunk/src/dil/parser/Parser.d --- a/trunk/src/dil/parser/Parser.d Sat Feb 16 03:28:39 2008 +0100 +++ b/trunk/src/dil/parser/Parser.d Sat Feb 16 20:18:42 2008 +0100 @@ -484,10 +484,11 @@ 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(); @@ -508,11 +509,18 @@ } // ReturnType FunctionName ( ParameterList ) auto funcBody = parseFunctionBody(); - auto d = new FunctionDeclaration(type, ident, tparams, params, funcBody); - d.setStorageClass(stc); - d.setLinkageType(linkType); - d.setProtection(protection); - return set(d, begin); + auto fd = new FunctionDeclaration(type, ident,/+ tparams,+/ params, funcBody); + fd.setStorageClass(stc); + fd.setLinkageType(linkType); + fd.setProtection(protection); + if (isTemplate) + { + auto d = putInsideTemplateDeclaration(begin, ident, fd, tparams); + d.setStorageClass(stc); + d.setProtection(protection); + return set(d, begin); + } + return set(fd, begin); } else { @@ -1020,16 +1028,22 @@ return new EnumDeclaration(enumName, baseType, members, hasBody); } - /// Puts a declaration inside a template declaration. - Declaration putInsideTemplateDeclaration(Token* begin, Identifier* name, - Declaration aggregateDecl, - TemplateParameters tparams) + /// Wraps a declaration inside a template declaration. + /// Params: + /// begin = begin token of decl. + /// name = name of decl. + /// decl = the declaration to be wrapped. + /// tparams = the template parameters. + TemplateDeclaration putInsideTemplateDeclaration(Token* begin, + Identifier* name, + Declaration decl, + TemplateParameters tparams) { - set(aggregateDecl, begin); - auto decls = new CompoundDeclaration; - decls ~= aggregateDecl; - set(decls, begin); - return new TemplateDeclaration(name, tparams, decls); + set(decl, begin); + auto cd = new CompoundDeclaration; + cd ~= decl; + set(cd, begin); + return new TemplateDeclaration(name, tparams, cd); } Declaration parseClassDeclaration() diff -r 4579e8505d5e -r bc812843603c trunk/src/main.d --- a/trunk/src/main.d Sat Feb 16 03:28:39 2008 +0100 +++ b/trunk/src/main.d Sat Feb 16 20:18:42 2008 +0100 @@ -86,7 +86,7 @@ printSymbolTable(mod, ""); } - printErrors(infoMan); + infoMan.hasInfo && printErrors(infoMan); break; case "ddoc", "d": if (args.length < 4) @@ -113,8 +113,7 @@ infoMan = new InfoManager(); // Execute command. cmd.DDoc.execute(filePaths, destination, macroPaths, incUndoc, verbose, infoMan); - if (infoMan.hasInfo) - printErrors(infoMan); + infoMan.hasInfo && printErrors(infoMan); break; case "gen", "generate": char[] fileName; @@ -136,8 +135,7 @@ if (!(options & (DocOption.XML | DocOption.HTML))) options |= DocOption.XML; // Default to XML. cmd.Generate.execute(fileName, options, infoMan); - if (infoMan.hasInfo) - printErrors(infoMan); + infoMan.hasInfo && printErrors(infoMan); break; case "importgraph", "igraph": string filePath; @@ -238,7 +236,7 @@ Stdout(token.srcText)(separator); } - printErrors(infoMan); + infoMan.hasInfo && printErrors(infoMan); break; case "trans", "translate": if (args.length < 3)