diff dmd/StaticIfCondition.d @ 0:10317f0c89a5

Initial commit
author korDen
date Sat, 24 Oct 2009 08:42:06 +0400
parents
children 1628b221808d
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dmd/StaticIfCondition.d	Sat Oct 24 08:42:06 2009 +0400
@@ -0,0 +1,70 @@
+module dmd.StaticIfCondition;
+
+import dmd.Expression;
+import dmd.ScopeDsymbol;
+import dmd.OutBuffer;
+import dmd.Loc;
+import dmd.Scope;
+import dmd.Condition;
+import dmd.HdrGenState;
+import dmd.WANT;
+import dmd.Util;
+
+class StaticIfCondition : Condition
+{
+	Expression exp;
+
+	this(Loc loc, Expression exp)
+	{
+		super(loc);
+		this.exp = exp;
+	}
+
+	Condition syntaxCopy()
+	{
+		assert(false);
+	}
+
+	bool include(Scope sc, ScopeDsymbol s)
+	{
+	static if (false) {
+		printf("StaticIfCondition.include(sc = %p, s = %p)\n", sc, s);
+		if (s)
+		{
+			printf("\ts = '%s', kind = %s\n", s.toChars(), s.kind());
+		}
+	}
+		if (inc == 0)
+		{
+			if (!sc)
+			{
+				error(loc, "static if conditional cannot be at global scope");
+				inc = 2;
+				return 0;
+			}
+
+			sc = sc.push(sc.scopesym);
+			sc.sd = s;			// s gets any addMember()
+			sc.flags |= SCOPE.SCOPEstaticif;
+			Expression e = exp.semantic(sc);
+			sc.pop();
+			e = e.optimize(WANTvalue | WANTinterpret);
+			if (e.isBool(true))
+				inc = 1;
+			else if (e.isBool(false))
+				inc = 2;
+			else
+			{
+				e.error("expression %s is not constant or does not evaluate to a bool", e.toChars());
+				inc = 2;
+			}
+		}
+		return (inc == 1);
+	}
+
+	void toCBuffer(OutBuffer buf, HdrGenState* hgs)
+	{
+		assert(false);
+	}
+}
+