changeset 588:870652a9af23

Constant fold structliteral.member again.
author Christian Kamm <kamm incasoftware de>
date Fri, 12 Sep 2008 12:39:06 +0200
parents 23538d0f0d5b
children 7690d7065fa8
files dmd/expression.h dmd/interpret.c dmd/optimize.c
diffstat 3 files changed, 47 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/dmd/expression.h	Thu Sep 11 21:10:15 2008 +0200
+++ b/dmd/expression.h	Fri Sep 12 12:39:06 2008 +0200
@@ -825,6 +825,11 @@
     void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
     void dump(int indent);
     elem *toElem(IRState *irs);
+
+    //LLVMDC: since we don't convert abc.def -> *(&abc + ABC.def.offsetof)
+    // these are needed
+    Expression *optimize(int result);
+    Expression *interpret(InterState *istate);
 };
 
 struct DotTemplateInstanceExp : UnaExp
--- a/dmd/interpret.c	Thu Sep 11 21:10:15 2008 +0200
+++ b/dmd/interpret.c	Fri Sep 12 12:39:06 2008 +0200
@@ -2157,6 +2157,27 @@
     return e;
 }
 
+Expression *DotVarExp::interpret(InterState *istate)
+{   Expression *e = EXP_CANT_INTERPRET;
+
+    Expression *ex = e1->interpret(istate);
+
+    // Constant fold structliteral.member
+    if (ex != EXP_CANT_INTERPRET && ex->op == TOKstructliteral)
+    {	StructLiteralExp *se = (StructLiteralExp *)ex;
+
+	VarDeclaration* v;
+	if (v = var->isVarDeclaration())
+	{
+	    e = se->getField(type, v->offset);
+	    if (!e)
+		e = EXP_CANT_INTERPRET;
+	}
+    }
+
+    return e;
+}
+
 /******************************* Special Functions ***************************/
 
 Expression *interpret_aaLen(InterState *istate, Expressions *arguments)
--- a/dmd/optimize.c	Thu Sep 11 21:10:15 2008 +0200
+++ b/dmd/optimize.c	Fri Sep 12 12:39:06 2008 +0200
@@ -276,6 +276,27 @@
     return this;
 }
 
+Expression *DotVarExp::optimize(int result)
+{
+    e1 = e1->optimize(result);
+
+    // Constant fold structliteral.member
+    if (e1->op == TOKstructliteral)
+    {	StructLiteralExp *se = (StructLiteralExp *)e1;
+
+	VarDeclaration* v;
+	if (v = var->isVarDeclaration())
+	{
+	    Expression *e = se->getField(type, v->offset);
+	    if (!e)
+		e = EXP_CANT_INTERPRET;
+	    return e;
+	}
+    }
+
+    return this;
+}
+
 Expression *CallExp::optimize(int result)
 {   Expression *e = this;