Mercurial > projects > dil
changeset 726:7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Sat, 02 Feb 2008 19:58:09 +0100 |
parents | 84291c0a9e13 |
children | c204b6a9e0ef |
files | trunk/src/dil/ast/Declarations.d trunk/src/dil/ast/DefaultVisitor.d trunk/src/dil/parser/Parser.d trunk/src/dil/semantic/Pass1.d |
diffstat | 4 files changed, 60 insertions(+), 48 deletions(-) [+] |
line wrap: on
line diff
--- a/trunk/src/dil/ast/Declarations.d Sat Feb 02 14:24:29 2008 +0100 +++ b/trunk/src/dil/ast/Declarations.d Sat Feb 02 19:58:09 2008 +0100 @@ -219,13 +219,13 @@ abstract class AggregateDeclaration : Declaration { Identifier* name; - TemplateParameters tparams; +// TemplateParameters tparams; CompoundDeclaration decls; - this(Identifier* name, TemplateParameters tparams, CompoundDeclaration decls) + this(Identifier* name, /+TemplateParameters tparams, +/CompoundDeclaration decls) { super.hasBody = decls !is null; this.name = name; - this.tparams = tparams; +// this.tparams = tparams; this.decls = decls; } } @@ -233,11 +233,11 @@ class ClassDeclaration : AggregateDeclaration { BaseClassType[] bases; - this(Identifier* name, TemplateParameters tparams, BaseClassType[] bases, CompoundDeclaration decls) + this(Identifier* name, /+TemplateParameters tparams, +/BaseClassType[] bases, CompoundDeclaration decls) { - super(name, tparams, decls); + super(name, /+tparams, +/decls); mixin(set_kind); - addOptChild(tparams); +// addOptChild(tparams); addOptChildren(bases); addOptChild(decls); @@ -250,11 +250,11 @@ class InterfaceDeclaration : AggregateDeclaration { BaseClassType[] bases; - this(Identifier* name, TemplateParameters tparams, BaseClassType[] bases, CompoundDeclaration decls) + this(Identifier* name, /+TemplateParameters tparams, +/BaseClassType[] bases, CompoundDeclaration decls) { - super(name, tparams, decls); + super(name, /+tparams, +/decls); mixin(set_kind); - addOptChild(tparams); +// addOptChild(tparams); addOptChildren(bases); addOptChild(decls); @@ -269,11 +269,11 @@ class StructDeclaration : AggregateDeclaration { uint alignSize; - this(Identifier* name, TemplateParameters tparams, CompoundDeclaration decls) + this(Identifier* name, /+TemplateParameters tparams, +/CompoundDeclaration decls) { - super(name, tparams, decls); + super(name, /+tparams, +/decls); mixin(set_kind); - addOptChild(tparams); +// addOptChild(tparams); addOptChild(decls); } @@ -287,11 +287,11 @@ class UnionDeclaration : AggregateDeclaration { - this(Identifier* name, TemplateParameters tparams, CompoundDeclaration decls) + this(Identifier* name, /+TemplateParameters tparams, +/CompoundDeclaration decls) { - super(name, tparams, decls); + super(name, /+tparams, +/decls); mixin(set_kind); - addOptChild(tparams); +// addOptChild(tparams); addOptChild(decls); }
--- a/trunk/src/dil/ast/DefaultVisitor.d Sat Feb 02 14:24:29 2008 +0100 +++ b/trunk/src/dil/ast/DefaultVisitor.d Sat Feb 02 19:58:09 2008 +0100 @@ -47,13 +47,13 @@ d.value && visitE(d.value); static if (is(D == ClassDeclaration) || is( D == InterfaceDeclaration)) { - d.tparams && visitN(d.tparams); +// 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), +// d.tparams && visitN(d.tparams), d.decls && visitD(d.decls); static if (is(D == ConstructorDeclaration)) visitN(d.params), visitS(d.funcBody);
--- a/trunk/src/dil/parser/Parser.d Sat Feb 02 14:24:29 2008 +0100 +++ b/trunk/src/dil/parser/Parser.d Sat Feb 02 19:58:09 2008 +0100 @@ -1020,9 +1020,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) + { + set(aggregateDecl, begin); + auto decls = new CompoundDeclaration; + decls ~= aggregateDecl; + set(decls, begin); + return new TemplateDeclaration(name, tparams, decls); + } + Declaration parseClassDeclaration() { assert(token.kind == T.Class); + auto begin = token; nT(); // Skip class keyword. Identifier* className; @@ -1032,7 +1045,8 @@ className = requireIdentifier(MSG.ExpectedClassName); - if (token.kind == T.LParen) + bool isTemplate = token.kind == T.LParen; + if (isTemplate) tparams = parseTemplateParameterList(); if (token.kind == T.Colon) @@ -1045,7 +1059,10 @@ else error(token, MSG.ExpectedClassBody, token.srcText); - return new ClassDeclaration(className, tparams, bases, decls); + Declaration d = new ClassDeclaration(className, /+tparams, +/bases, decls); + if (isTemplate) + d = putInsideTemplateDeclaration(begin, className, d, tparams); + return d; } BaseClassType[] parseBaseClasses(bool colonLeadsOff = true) @@ -1084,6 +1101,7 @@ Declaration parseInterfaceDeclaration() { assert(token.kind == T.Interface); + auto begin = token; nT(); // Skip interface keyword. Identifier* name; @@ -1093,7 +1111,8 @@ name = requireIdentifier(MSG.ExpectedInterfaceName); - if (token.kind == T.LParen) + bool isTemplate = token.kind == T.LParen; + if (isTemplate) tparams = parseTemplateParameterList(); if (token.kind == T.Colon) @@ -1106,13 +1125,16 @@ else error(token, MSG.ExpectedInterfaceBody, token.srcText); - return new InterfaceDeclaration(name, tparams, bases, decls); + Declaration d = new InterfaceDeclaration(name, /+tparams, +/bases, decls); + if (isTemplate) + d = putInsideTemplateDeclaration(begin, name, d, tparams); + return d; } Declaration parseStructOrUnionDeclaration() { assert(token.kind == T.Struct || token.kind == T.Union); - TOK tok = token.kind; + auto begin = token; nT(); // Skip struct or union keyword. Identifier* name; @@ -1121,7 +1143,8 @@ name = optionalIdentifier(); - if (name && token.kind == T.LParen) + bool isTemplate = name && token.kind == T.LParen; + if (isTemplate) tparams = parseTemplateParameterList(); if (name && skipped(T.Semicolon)) @@ -1129,18 +1152,23 @@ else if (token.kind == T.LBrace) decls = parseDeclarationDefinitionsBody(); else - error(token, tok == T.Struct ? + error(token, begin.kind == T.Struct ? MSG.ExpectedStructBody : MSG.ExpectedUnionBody, token.srcText); - if (tok == T.Struct) + Declaration d; + if (begin.kind == T.Struct) { - auto sd = new StructDeclaration(name, tparams, decls); + auto sd = new StructDeclaration(name, /+tparams, +/decls); sd.setAlignSize(this.alignSize); - return sd; + d = sd; } else - return new UnionDeclaration(name, tparams, decls); + d = new UnionDeclaration(name, /+tparams, +/decls); + + if (isTemplate) + d = putInsideTemplateDeclaration(begin, name, d, tparams); + return d; } Declaration parseConstructorDeclaration()
--- a/trunk/src/dil/semantic/Pass1.d Sat Feb 02 14:24:29 2008 +0100 +++ b/trunk/src/dil/semantic/Pass1.d Sat Feb 02 19:58:09 2008 +0100 @@ -229,10 +229,7 @@ return d; d.symbol = new Class(d.name, d); // Insert into current scope. - if (d.tparams) - insertOverload(d.symbol, d.name); - else - insert(d.symbol, d.name); + insert(d.symbol, d.name); enterScope(d.symbol); // Continue semantic analysis. d.decls && visitD(d.decls); @@ -246,10 +243,7 @@ return d; d.symbol = new dil.semantic.Symbols.Interface(d.name, d); // Insert into current scope. - if (d.tparams) - insertOverload(d.symbol, d.name); - else - insert(d.symbol, d.name); + insert(d.symbol, d.name); enterScope(d.symbol); // Continue semantic analysis. d.decls && visitD(d.decls); @@ -264,12 +258,7 @@ d.symbol = new Struct(d.name, d); // Insert into current scope. if (d.name) - { - if (d.tparams) - insertOverload(d.symbol, d.name); - else - insert(d.symbol, d.name); - } + insert(d.symbol, d.name); enterScope(d.symbol); // Continue semantic analysis. d.decls && visitD(d.decls); @@ -284,12 +273,7 @@ d.symbol = new Union(d.name, d); // Insert into current scope. if (d.name) - { - if (d.tparams) - insertOverload(d.symbol, d.name); - else - insert(d.symbol, d.name); - } + insert(d.symbol, d.name); enterScope(d.symbol); // Continue semantic analysis. d.decls && visitD(d.decls);