# HG changeset patch # User Christian Kamm # Date 1221215946 -7200 # Node ID 870652a9af23cf5f39306825f4ca4f0fa6736aff # Parent 23538d0f0d5bb85d9e4b94ebb8270c52b29c46bb Constant fold structliteral.member again. diff -r 23538d0f0d5b -r 870652a9af23 dmd/expression.h --- 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 diff -r 23538d0f0d5b -r 870652a9af23 dmd/interpret.c --- 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) diff -r 23538d0f0d5b -r 870652a9af23 dmd/optimize.c --- 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;