diff dmd/CompileExp.d @ 19:01cadcfa4842

Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
author Robert Clipsham <robert@octarineparrot.com>
date Tue, 06 Apr 2010 02:21:04 +0100
parents 10317f0c89a5
children 460959608115
line wrap: on
line diff
--- a/dmd/CompileExp.d	Mon Apr 05 19:16:14 2010 +0100
+++ b/dmd/CompileExp.d	Tue Apr 06 02:21:04 2010 +0100
@@ -7,23 +7,51 @@
 import dmd.Scope;
 import dmd.HdrGenState;
 import dmd.TOK;
+import dmd.PREC;
+import dmd.WANT;
+import dmd.StringExp;
+import dmd.Type;
+import dmd.Parser;
 
-class CompileExp : UnaExp
-{
-	this(Loc loc, Expression e)
-	{
-		assert(false);
-		super(loc, TOK.init, 0, null);
-	}
-
-	Expression semantic(Scope sc)
-	{
-		assert(false);
-	}
-
-	void toCBuffer(OutBuffer buf, HdrGenState* hgs)
-	{
-		assert(false);
-	}
-}
-
+import dmd.expression.Util;
+
+class CompileExp : UnaExp
+{
+	this(Loc loc, Expression e)
+	{
+		super(loc, TOK.TOKmixin, this.sizeof, e);
+	}
+
+	Expression semantic(Scope sc)
+	{
+		version (LOGSEMANTIC) {
+			printf("CompileExp.semantic('%s')\n", toChars());
+		}
+		UnaExp.semantic(sc);
+		e1 = resolveProperties(sc, e1);
+		e1 = e1.optimize(WANT.WANTvalue | WANT.WANTinterpret);
+		if (e1.op != TOK.TOKstring)
+		{	error("argument to mixin must be a string, not (%s)", e1.toChars());
+			type = Type.terror;
+			return this;
+		}
+		StringExp se = cast(StringExp)e1;
+		se = se.toUTF8(sc);
+		Parser p = new Parser(sc.module_, cast(ubyte*)se.string_, se.len, 0);
+		p.loc = loc;
+		p.nextToken();
+		//printf("p.loc.linnum = %d\n", p.loc.linnum);
+		Expression e = p.parseExpression();
+		if (p.token.value != TOK.TOKeof)
+			error("incomplete mixin expression (%s)", se.toChars());
+		return e.semantic(sc);
+	}
+
+	void toCBuffer(OutBuffer buf, HdrGenState* hgs)
+	{
+		buf.writestring("mixin(");
+		expToCBuffer(buf, hgs, e1, PREC.PREC_assign);
+		buf.writeByte(')');
+	}
+}
+