diff dmd/ThrowStatement.d @ 0:10317f0c89a5

Initial commit
author korDen
date Sat, 24 Oct 2009 08:42:06 +0400
parents
children a8b50ff7f201
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dmd/ThrowStatement.d	Sat Oct 24 08:42:06 2009 +0400
@@ -0,0 +1,85 @@
+module dmd.ThrowStatement;
+
+import dmd.Statement;
+import dmd.Expression;
+import dmd.Loc;
+import dmd.IRState;
+import dmd.InlineScanState;
+import dmd.HdrGenState;
+import dmd.OutBuffer;
+import dmd.Scope;
+import dmd.Expression;
+import dmd.FuncDeclaration;
+import dmd.BE;
+
+import dmd.backend.Util;
+import dmd.backend.Blockx;
+import dmd.backend.elem;
+import dmd.backend.RTLSYM;
+import dmd.backend.OPER;
+import dmd.backend.TYM;
+
+class ThrowStatement : Statement
+{
+    Expression exp;
+
+    this(Loc loc, Expression exp)
+	{
+		super(loc);
+		this.exp = exp;
+	}
+	
+    Statement syntaxCopy()
+	{
+		assert(false);
+	}
+	
+    Statement semantic(Scope sc)
+	{
+		//printf("ThrowStatement::semantic()\n");
+
+		FuncDeclaration fd = sc.parent.isFuncDeclaration();
+		fd.hasReturnExp |= 2;
+
+		if (sc.incontract)
+			error("Throw statements cannot be in contracts");
+		exp = exp.semantic(sc);
+		exp = resolveProperties(sc, exp);
+		if (!exp.type.toBasetype().isClassHandle())
+			error("can only throw class objects, not type %s", exp.type.toChars());
+		return this;
+	}
+	
+    void toCBuffer(OutBuffer buf, HdrGenState* hgs)
+	{
+		assert(false);
+	}
+	
+    BE blockExit()
+	{
+		return BE.BEthrow;  // obviously
+	}
+
+    Statement inlineScan(InlineScanState* iss)
+	{
+		if (exp)
+			exp = exp.inlineScan(iss);
+		return this;
+	}
+
+    void toIR(IRState* irs)
+	{
+		// throw(exp)
+
+		Blockx *blx = irs.blx;
+
+		incUsage(irs, loc);
+		elem *e = exp.toElem(irs);
+	static if (false) {
+		e = el_bin(OPcall, TYvoid, el_var(rtlsym[RTLSYM_LTHROW]),e);
+	} else {
+		e = el_bin(OPcall, TYvoid, el_var(rtlsym[RTLSYM_THROW]),e);
+	}
+		block_appendexp(blx.curblock, e);
+	}
+}
\ No newline at end of file