mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-01-11 18:33:14 +01:00
Constant fold structliteral.member again.
This commit is contained in:
@@ -825,6 +825,11 @@ struct DotVarExp : UnaExp
|
||||
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
|
||||
|
||||
@@ -2157,6 +2157,27 @@ Expression *PtrExp::interpret(InterState *istate)
|
||||
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)
|
||||
|
||||
@@ -276,6 +276,27 @@ Expression *PtrExp::optimize(int result)
|
||||
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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user