comparison dmd/interpret.c @ 913:29c0d1194033

Fix #198 and #199 by making CTFE on static struct initializers work. Renamed SymbolDeclaration to StaticStructInitDeclaration to make its usage clearer.
author Christian Kamm <kamm incasoftware de>
date Sun, 01 Feb 2009 20:20:56 +0100
parents 330f999ade44
children b30fe7e1dbb9
comparison
equal deleted inserted replaced
912:16264a3973bf 913:29c0d1194033
985 985
986 Expression *getVarExp(Loc loc, InterState *istate, Declaration *d) 986 Expression *getVarExp(Loc loc, InterState *istate, Declaration *d)
987 { 987 {
988 Expression *e = EXP_CANT_INTERPRET; 988 Expression *e = EXP_CANT_INTERPRET;
989 VarDeclaration *v = d->isVarDeclaration(); 989 VarDeclaration *v = d->isVarDeclaration();
990 SymbolDeclaration *s = d->isSymbolDeclaration(); 990 StaticStructInitDeclaration *s = d->isStaticStructInitDeclaration();
991 if (v) 991 if (v)
992 { 992 {
993 #if DMDV2 993 #if DMDV2
994 if ((v->isConst() || v->isInvariant()) && v->init && !v->value) 994 if ((v->isConst() || v->isInvariant()) && v->init && !v->value)
995 #else 995 #else
1009 if (!e) 1009 if (!e)
1010 e = EXP_CANT_INTERPRET; 1010 e = EXP_CANT_INTERPRET;
1011 } 1011 }
1012 else if (s) 1012 else if (s)
1013 { 1013 {
1014 if (s->dsym->toInitializer() == s->sym) 1014 Expressions *exps = new Expressions();
1015 { Expressions *exps = new Expressions(); 1015 e = new StructLiteralExp(0, s->dsym, exps);
1016 e = new StructLiteralExp(0, s->dsym, exps); 1016 e = e->semantic(NULL);
1017 e = e->semantic(NULL);
1018 }
1019 } 1017 }
1020 return e; 1018 return e;
1021 } 1019 }
1022 1020
1023 Expression *VarExp::interpret(InterState *istate) 1021 Expression *VarExp::interpret(InterState *istate)
1464 /* Chase down rebinding of out and ref 1462 /* Chase down rebinding of out and ref
1465 */ 1463 */
1466 if (v->value && v->value->op == TOKvar) 1464 if (v->value && v->value->op == TOKvar)
1467 { 1465 {
1468 VarExp *ve2 = (VarExp *)v->value; 1466 VarExp *ve2 = (VarExp *)v->value;
1469 if (ve2->var->isSymbolDeclaration()) 1467 if (ve2->var->isStaticStructInitDeclaration())
1470 { 1468 {
1471 /* This can happen if v is a struct initialized to 1469 /* This can happen if v is a struct initialized to
1472 * 0 using an __initZ SymbolDeclaration from 1470 * 0 using an StaticStructInitDeclaration from
1473 * TypeStruct::defaultInit() 1471 * TypeStruct::defaultInit()
1474 */ 1472 */
1475 } 1473 }
1476 else 1474 else
1477 v = ve2->var->isVarDeclaration(); 1475 v = ve2->var->isVarDeclaration();