diff dmd/ExpStatement.d @ 0:10317f0c89a5

Initial commit
author korDen
date Sat, 24 Oct 2009 08:42:06 +0400
parents
children 5c9b78899f5d
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dmd/ExpStatement.d	Sat Oct 24 08:42:06 2009 +0400
@@ -0,0 +1,125 @@
+module dmd.ExpStatement;
+
+import dmd.Loc;
+import dmd.Statement;
+import dmd.AssertExp;
+import dmd.Expression;
+import dmd.OutBuffer;
+import dmd.HdrGenState;
+import dmd.Scope;
+import dmd.InterState;
+import dmd.InlineCostState;
+import dmd.InlineDoState;
+import dmd.InlineScanState;
+import dmd.IRState;
+import dmd.BE;
+import dmd.TOK;
+import dmd.DeclarationStatement;
+
+import dmd.backend.Blockx;
+import dmd.backend.Util;
+
+class ExpStatement : Statement
+{
+    Expression exp;
+
+    this(Loc loc, Expression exp)
+	{
+		super(loc);
+		this.exp = exp;
+	}
+	
+    Statement syntaxCopy()
+	{
+		Expression e = exp ? exp.syntaxCopy() : null;
+		ExpStatement es = new ExpStatement(loc, e);
+		return es;
+	}
+	
+    void toCBuffer(OutBuffer buf, HdrGenState* hgs)
+	{
+		if (exp)
+			exp.toCBuffer(buf, hgs);
+		buf.writeByte(';');
+		if (!hgs.FLinit.init)
+			buf.writenl();
+	}
+	
+    Statement semantic(Scope sc)
+	{
+		if (exp)
+		{
+			//printf("ExpStatement::semantic() %s\n", exp->toChars());
+			exp = exp.semantic(sc);
+			exp = resolveProperties(sc, exp);
+			exp.checkSideEffect(0);
+			exp = exp.optimize(0);
+			if (exp.op == TOK.TOKdeclaration && !isDeclarationStatement())
+			{   
+				Statement s = new DeclarationStatement(loc, exp);
+				return s;
+			}
+			//exp = exp.optimize(isDeclarationStatement() ? WANT.WANTvalue : 0);
+		}
+		return this;
+	}
+
+    Expression interpret(InterState* istate)
+	{
+		assert(false);
+	}
+
+    BE blockExit()
+	{
+		BE result = BE.BEfallthru;
+
+		if (exp)
+		{
+			if (exp.op == TOK.TOKhalt)
+				return BE.BEhalt;
+			if (exp.op == TOK.TOKassert)
+			{   	
+				AssertExp a = cast(AssertExp)exp;
+
+				if (a.e1.isBool(false))	// if it's an assert(0)
+					return BE.BEhalt;
+			}
+			if (exp.canThrow())
+				result |= BE.BEthrow;
+		}
+		return result;
+	}
+
+    int inlineCost(InlineCostState* ics)
+	{
+		return exp ? exp.inlineCost(ics) : 0;
+	}
+
+    Expression doInline(InlineDoState ids)
+	{
+	version (LOG) {
+		if (exp) printf("ExpStatement.doInline() '%s'\n", exp.toChars());
+	}
+		return exp ? exp.doInline(ids) : null;
+	}
+
+    Statement inlineScan(InlineScanState* iss)
+	{
+	version (LOG) {
+		printf("ExpStatement.inlineScan(%s)\n", toChars());
+	}
+		if (exp)
+			exp = exp.inlineScan(iss);
+		return this;
+	}
+
+    void toIR(IRState* irs)
+	{
+		Blockx* blx = irs.blx;
+
+		//printf("ExpStatement.toIR(), exp = %s\n", exp ? exp.toChars() : "");
+		incUsage(irs, loc);
+		if (exp) 
+			block_appendexp(blx.curblock, exp.toElem(irs));
+	}
+}
\ No newline at end of file