# HG changeset patch # User Aziz K?ksal # Date 1201542482 -3600 # Node ID ff4643a4a97c2e4893fb124f366e54ceea2f4bf0 # Parent bf10602159c179ff0baf049c37a768643c35c8bf Wrote code for SemanticPass2.visit(MixinDeclaration). diff -r bf10602159c1 -r ff4643a4a97c trunk/src/dil/ast/Declarations.d --- a/trunk/src/dil/ast/Declarations.d Sun Jan 27 20:51:19 2008 +0100 +++ b/trunk/src/dil/ast/Declarations.d Mon Jan 28 18:48:02 2008 +0100 @@ -616,9 +616,12 @@ class MixinDeclaration : Declaration { + /// IdExpression := IdentifierExpression | TemplateInstanceExpression + /// MixinTemplate := IdExpression ("." IdExpression)* Expression templateExpr; - Identifier* mixinIdent; - Expression argument; // mixin ( AssignExpression ) + Identifier* mixinIdent; /// Optional mixin identifier. + Expression argument; /// "mixin" "(" AssignExpression ")" + Declaration decls; /// Initialized in the semantic phase. this(Expression templateExpr, Identifier* mixinIdent) { @@ -636,4 +639,9 @@ this.argument = argument; } + + bool isMixinExpression() + { + return argument !is null; + } } diff -r bf10602159c1 -r ff4643a4a97c trunk/src/dil/parser/Parser.d --- a/trunk/src/dil/parser/Parser.d Sun Jan 27 20:51:19 2008 +0100 +++ b/trunk/src/dil/parser/Parser.d Mon Jan 28 18:48:02 2008 +0100 @@ -1376,14 +1376,14 @@ return type; } - /* + /++ TemplateMixin: mixin ( AssignExpression ) ; mixin TemplateIdentifier ; mixin TemplateIdentifier MixinIdentifier ; mixin TemplateIdentifier !( TemplateArguments ) ; mixin TemplateIdentifier !( TemplateArguments ) MixinIdentifier ; - */ + +/ Class parseMixin(Class)() { assert(token.kind == T.Mixin); diff -r bf10602159c1 -r ff4643a4a97c trunk/src/dil/semantic/Pass2.d --- a/trunk/src/dil/semantic/Pass2.d Sun Jan 27 20:51:19 2008 +0100 +++ b/trunk/src/dil/semantic/Pass2.d Mon Jan 28 18:48:02 2008 +0100 @@ -77,30 +77,33 @@ D visit(MixinDeclaration md) { - /+ - if (type) - return this.expr; - // TODO: - auto expr = this.expr.semantic(scop); - expr = expr.evaluate(); - if (expr is null) - return this; - auto strExpr = TryCast!(StringExpression)(expr); - if (strExpr is null) - error(scop, MSG.MixinArgumentMustBeString); + if (md.decls) + return md.decls; + if (md.isMixinExpression) + { + md.argument = visitE(md.argument); + auto expr = Interpreter.interpret(md.argument, modul.infoMan, scop); + if (expr is Interpreter.NAR) + return md; + auto stringExpr = expr.Is!(StringExpression); + if (stringExpr is null) + { + error(md.begin, MSG.MixinArgumentMustBeString); + return md; + } + else + { // Parse the declarations in the string. + auto loc = md.begin.getErrorLocation(); + auto filePath = loc.filePath; + auto parser = new Parser(stringExpr.getString(), filePath, modul.infoMan); + md.decls = parser.start(); + } + } else { - auto loc = this.begin.getErrorLocation(); - auto filePath = loc.filePath; - auto parser = new_ExpressionParser(strExpr.getString(), filePath, scop.infoMan); - expr = parser.parse(); - expr = expr.semantic(scop); + // TODO: implement template mixin. } - this.expr = expr; - this.type = expr.type; - return expr; - +/ - return md; + return md.decls; } T visit(TypeofType t) @@ -228,7 +231,7 @@ E visit(RealExpression e) { - if (e.type) + if (!e.type) e.type = Types.Double; return e; }