diff dmd/DeclarationStatement.d @ 0:10317f0c89a5

Initial commit
author korDen
date Sat, 24 Oct 2009 08:42:06 +0400
parents
children 2e2a5c3f943a
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dmd/DeclarationStatement.d	Sat Oct 24 08:42:06 2009 +0400
@@ -0,0 +1,92 @@
+module dmd.DeclarationStatement;
+
+import dmd.Loc;
+import dmd.ExpStatement;
+import dmd.Dsymbol;
+import dmd.Expression;
+import dmd.Statement;
+import dmd.OutBuffer;
+import dmd.HdrGenState;
+import dmd.Scope;
+import dmd.DeclarationExp;
+import dmd.TOK;
+import dmd.VarDeclaration;
+
+class DeclarationStatement : ExpStatement
+{
+    // Doing declarations as an expression, rather than a statement,
+    // makes inlining functions much easier.
+
+    this(Loc loc, Dsymbol declaration)
+	{
+		super(loc, new DeclarationExp(loc, declaration));
+	}
+	
+    this(Loc loc, Expression exp)
+	{
+		super(loc, exp);
+	}
+	
+    Statement syntaxCopy()
+	{
+		DeclarationStatement ds = new DeclarationStatement(loc, exp.syntaxCopy());
+		return ds;
+	}
+	
+    void toCBuffer(OutBuffer buf, HdrGenState* hgs)
+	{
+		exp.toCBuffer(buf, hgs);
+	}
+	
+    void scopeCode(Scope sc, Statement* sentry, Statement* sexception, Statement* sfinally)
+	{
+		//printf("DeclarationStatement.scopeCode()\n");
+		//print();
+
+		*sentry = null;
+		*sexception = null;
+		*sfinally = null;
+
+		if (exp)
+		{
+			if (exp.op == TOK.TOKdeclaration)
+			{
+				DeclarationExp de = cast(DeclarationExp)exp;
+				VarDeclaration v = de.declaration.isVarDeclaration();
+				if (v)
+				{	
+					Expression e;
+
+					e = v.callAutoDtor(sc);
+					if (e)
+					{
+						//printf("dtor is: "); e.print();
+static if (false) {
+						if (v.type.toBasetype().ty == Tstruct)
+						{	
+							/* Need a 'gate' to turn on/off destruction,
+							 * in case v gets moved elsewhere.
+							 */
+							Identifier id = Lexer.uniqueId("__runDtor");
+							ExpInitializer ie = new ExpInitializer(loc, new IntegerExp(1));
+							VarDeclaration rd = new VarDeclaration(loc, Type.tint32, id, ie);
+							*sentry = new DeclarationStatement(loc, rd);
+							v.rundtor = rd;
+
+							/* Rewrite e as:
+							 *  rundtor && e
+							 */
+							Expression ve = new VarExp(loc, v.rundtor);
+							e = new AndAndExp(loc, ve, e);
+							e.type = Type.tbool;
+						}
+}
+						*sfinally = new ExpStatement(loc, e);
+					}
+				}
+			}
+		}
+	}
+
+    DeclarationStatement isDeclarationStatement() { return this; }
+}
\ No newline at end of file