changeset 704:ff4643a4a97c

Wrote code for SemanticPass2.visit(MixinDeclaration).
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Mon, 28 Jan 2008 18:48:02 +0100
parents bf10602159c1
children d75aad38d1b2
files trunk/src/dil/ast/Declarations.d trunk/src/dil/parser/Parser.d trunk/src/dil/semantic/Pass2.d
diffstat 3 files changed, 37 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- 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;
+  }
 }
--- 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);
--- 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;
   }