diff dmd/DeclarationExp.d @ 63:cab4c37afb89

A bunch of implementations
author korDen
date Mon, 23 Aug 2010 16:52:24 +0400
parents 10317f0c89a5
children 2e2a5c3f943a
line wrap: on
line diff
--- a/dmd/DeclarationExp.d	Mon Aug 23 03:21:32 2010 +0400
+++ b/dmd/DeclarationExp.d	Mon Aug 23 16:52:24 2010 +0400
@@ -19,6 +19,7 @@
 import dmd.Global;
 import dmd.TOK;
 import dmd.VoidInitializer;
+import dmd.GlobalExpressions;
 import dmd.Type;
 import dmd.codegen.Util;
 
@@ -119,9 +120,54 @@
 		return this;
 	}
 
-	Expression interpret(InterState* istate)
+	Expression interpret(InterState istate)
 	{
-		assert(false);
+version (LOG) {
+		printf("DeclarationExp.interpret() %s\n", toChars());
+}
+		Expression e;
+		VarDeclaration v = declaration.isVarDeclaration();
+		if (v)
+		{
+			Dsymbol s = v.toAlias();
+			if (s == v && !v.isStatic() && v.init)
+			{
+				ExpInitializer ie = v.init.isExpInitializer();
+				if (ie)
+					e = ie.exp.interpret(istate);
+				else if (v.init.isVoidInitializer())
+					e = null;
+			}
+///version (DMDV2) {
+			else if (s == v && (v.isConst() || v.isInvariant()) && v.init)
+///} else {
+///			else if (s == v && v.isConst() && v.init)
+///}
+			{   
+				e = v.init.toExpression();
+				if (!e)
+					e = EXP_CANT_INTERPRET;
+				else if (!e.type)
+					e.type = v.type;
+			}
+		}
+		else if (declaration.isAttribDeclaration() ||
+			 declaration.isTemplateMixin() ||
+			 declaration.isTupleDeclaration())
+		{	
+			// These can be made to work, too lazy now
+			error("Declaration %s is not yet implemented in CTFE", toChars());
+
+			e = EXP_CANT_INTERPRET;
+		}
+		else
+		{	// Others should not contain executable code, so are trivial to evaluate
+			e = null;
+		}
+version (LOG) {
+		printf("-DeclarationExp.interpret(%.*s): %p\n", toChars(), e);
+}
+		return e;
 	}
 
 	bool checkSideEffect(int flag)