diff dmd/DoStatement.d @ 0:10317f0c89a5

Initial commit
author korDen
date Sat, 24 Oct 2009 08:42:06 +0400
parents
children cab4c37afb89
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dmd/DoStatement.d	Sat Oct 24 08:42:06 2009 +0400
@@ -0,0 +1,141 @@
+module dmd.DoStatement;
+
+import dmd.Statement;
+import dmd.Expression;
+import dmd.Loc;
+import dmd.Scope;
+import dmd.InterState;
+import dmd.HdrGenState;
+import dmd.OutBuffer;
+import dmd.InlineScanState;
+import dmd.IRState;
+import dmd.BE;
+import dmd.WANT;
+
+import dmd.backend.block;
+import dmd.backend.Blockx;
+import dmd.backend.Util;
+import dmd.backend.BC;
+
+class DoStatement : Statement
+{
+    Statement body_;
+    Expression condition;
+
+    this(Loc loc, Statement b, Expression c)
+	{
+		super(loc);
+		body_ = b;
+		condition = c;
+	}
+	
+    Statement syntaxCopy()
+	{
+		DoStatement s = new DoStatement(loc, body_ ? body_.syntaxCopy() : null, condition.syntaxCopy());
+		return s;
+	}
+
+    Statement semantic(Scope sc)
+	{
+		sc.noctor++;
+		if (body_)
+			body_ = body_.semanticScope(sc, this, this);
+		sc.noctor--;
+		condition = condition.semantic(sc);
+		condition = resolveProperties(sc, condition);
+		condition = condition.optimize(WANTvalue);
+
+		condition = condition.checkToBoolean();
+
+		return this;
+	}
+
+    bool hasBreak()
+	{
+		return true;
+	}
+
+    bool hasContinue()
+	{
+		return true;
+	}
+
+    bool usesEH()
+	{
+		return body_ ? body_.usesEH() : false;
+	}
+
+    BE blockExit()
+	{
+		BE result;
+
+		if (body_)
+		{	
+			result = body_.blockExit();
+			if (result == BE.BEbreak)
+				return BE.BEfallthru;
+			if (result & BE.BEcontinue)
+				result |= BE.BEfallthru;
+		}
+		else
+			result = BE.BEfallthru;
+
+		if (result & BE.BEfallthru)
+		{	
+			if (condition.canThrow())
+				result |= BE.BEthrow;
+			if (!(result & BE.BEbreak) && condition.isBool(true))
+				result &= ~BE.BEfallthru;
+		}
+		result &= ~(BE.BEbreak | BE.BEcontinue);
+
+		return result;
+	}
+
+    bool comeFrom()
+	{
+		assert(false);
+	}
+
+    Expression interpret(InterState* istate)
+	{
+		assert(false);
+	}
+
+    void toCBuffer(OutBuffer buf, HdrGenState* hgs)
+	{
+		assert(false);
+	}
+
+    Statement inlineScan(InlineScanState* iss)
+	{
+		body_ = body_ ? body_.inlineScan(iss) : null;
+		condition = condition.inlineScan(iss);
+		return this;
+	}
+
+    void toIR(IRState* irs)
+	{
+		Blockx *blx = irs.blx;
+
+		IRState mystate = IRState(irs,this);
+		mystate.breakBlock = block_calloc(blx);
+		mystate.contBlock = block_calloc(blx);
+
+		block* bpre = blx.curblock;
+		block_next(blx, BCgoto, null);
+		list_append(&bpre.Bsucc, blx.curblock);
+
+		list_append(&mystate.contBlock.Bsucc, blx.curblock);
+		list_append(&mystate.contBlock.Bsucc, mystate.breakBlock);
+
+		if (body_)
+			body_.toIR(&mystate);
+		list_append(&blx.curblock.Bsucc, mystate.contBlock);
+
+		block_next(blx, BCgoto, mystate.contBlock);
+		incUsage(irs, condition.loc);
+		block_appendexp(mystate.contBlock, condition.toElem(&mystate));
+		block_next(blx, BCiftrue, mystate.breakBlock);
+	}
+}
\ No newline at end of file