diff dmd/CompileStatement.d @ 17:ddae60498573

Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
author Robert Clipsham <robert@octarineparrot.com>
date Mon, 05 Apr 2010 03:24:08 +0100
parents 10317f0c89a5
children 460959608115
line wrap: on
line diff
--- a/dmd/CompileStatement.d	Sun Apr 04 22:41:11 2010 +0100
+++ b/dmd/CompileStatement.d	Mon Apr 05 03:24:08 2010 +0100
@@ -7,34 +7,71 @@
 import dmd.OutBuffer;
 import dmd.HdrGenState;
 import dmd.ArrayTypes;
+import dmd.TOK;
+import dmd.WANT;
+import dmd.ParseStatementFlags;
+import dmd.Parser;
+import dmd.CompoundStatement;
+import dmd.StringExp;
 
 class CompileStatement : Statement
 {
-    Expression exp;
+	Expression exp;
 
-    this(Loc loc, Expression exp)
+	this(Loc loc, Expression exp)
 	{
-		assert(false);
 		super(loc);
+		this.exp = exp;
 	}
 
-    Statement syntaxCopy()
+	Statement syntaxCopy()
 	{
-		assert(false);
+		Expression e = exp.syntaxCopy();
+		CompileStatement es = new CompileStatement(loc, e);
+		return es;
+	}
+
+	void toCBuffer(OutBuffer buf, HdrGenState* hgs)
+	{
+		buf.writestring("mixin(");
+		exp.toCBuffer(buf, hgs);
+		buf.writestring(");");
+		if (!hgs.FLinit.init)
+			buf.writenl();
 	}
 
-    void toCBuffer(OutBuffer buf, HdrGenState* hgs)
+	Statements flatten(Scope sc)
 	{
-		assert(false);
+		//printf("CompileStatement::flatten() %s\n", exp->toChars());
+		exp = exp.semantic(sc);
+		exp = resolveProperties(sc, exp);
+		exp = exp.optimize(WANT.WANTvalue | WANT.WANTinterpret);
+		if (exp.op != TOK.TOKstring)
+		{	error("argument to mixin must be a string, not (%s)", exp.toChars());
+			return null;
+		}
+		StringExp se = cast(StringExp)exp;
+		se = se.toUTF8(sc);
+		Parser p = new Parser(sc.module_, cast(ubyte *)se.string_, se.len, 0);
+		p.loc = loc;
+		p.nextToken();
+
+		Statements a = new Statements();
+		while (p.token.value != TOK.TOKeof)
+		{
+			Statement s = p.parseStatement(ParseStatementFlags.PSsemi | ParseStatementFlags.PScurlyscope);
+			a.push(cast(void*)s);
+		}
+		return a;
 	}
 
-    Statements flatten(Scope sc)
+	Statement semantic(Scope sc)
 	{
-		assert(false);
+		//printf("CompileStatement::semantic() %s\n", exp->toChars());
+		Statements a = flatten(sc);
+		if (!a)
+			return null;
+		Statement s = new CompoundStatement(loc, a);
+		return s.semantic(sc);
 	}
-
-    Statement semantic(Scope sc)
-	{
-		assert(false);
-	}
-}
\ No newline at end of file
+}