From 8726eefefaf5796a2a4fa228860f2a5a93e60cdd Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Tue, 3 Feb 2009 18:00:17 +0100 Subject: [PATCH] Apply StaticStructInit changes from [913] to dmd2/ --- dmd2/declaration.c | 11 ++++++++++- dmd2/declaration.h | 9 ++++----- dmd2/dsymbol.h | 4 ++-- dmd2/interpret.c | 14 ++++++-------- dmd2/mtype.c | 6 ++---- 5 files changed, 24 insertions(+), 20 deletions(-) diff --git a/dmd2/declaration.c b/dmd2/declaration.c index 05a20c1f..fa2dcb64 100644 --- a/dmd2/declaration.c +++ b/dmd2/declaration.c @@ -1647,4 +1647,13 @@ Dsymbol *ThisDeclaration::syntaxCopy(Dsymbol *s) return NULL; } - + +/********************** StaticStructInitDeclaration ***************************/ + +StaticStructInitDeclaration::StaticStructInitDeclaration(Loc loc, StructDeclaration *dsym) + : Declaration(new Identifier("", TOKidentifier)) +{ + this->loc = loc; + this->dsym = dsym; + storage_class |= STCconst; +} diff --git a/dmd2/declaration.h b/dmd2/declaration.h index 356ad230..cb203a2d 100644 --- a/dmd2/declaration.h +++ b/dmd2/declaration.h @@ -284,19 +284,18 @@ struct VarDeclaration : Declaration /**************************************************************/ -// This is a shell around a back end symbol +// LDC uses this to denote static struct initializers -struct SymbolDeclaration : Declaration +struct StaticStructInitDeclaration : Declaration { - Symbol *sym; StructDeclaration *dsym; - SymbolDeclaration(Loc loc, Symbol *s, StructDeclaration *dsym); + StaticStructInitDeclaration(Loc loc, StructDeclaration *dsym); Symbol *toSymbol(); // Eliminate need for dynamic_cast - SymbolDeclaration *isSymbolDeclaration() { return (SymbolDeclaration *)this; } + StaticStructInitDeclaration *isStaticStructInitDeclaration() { return (StaticStructInitDeclaration *)this; } }; struct ClassInfoDeclaration : VarDeclaration diff --git a/dmd2/dsymbol.h b/dmd2/dsymbol.h index 7959af72..96d8fd7a 100644 --- a/dmd2/dsymbol.h +++ b/dmd2/dsymbol.h @@ -65,7 +65,7 @@ struct EnumMember; struct ScopeDsymbol; struct WithScopeSymbol; struct ArrayScopeSymbol; -struct SymbolDeclaration; +struct StaticStructInitDeclaration; struct Expression; struct DeleteDeclaration; struct HdrGenState; @@ -219,7 +219,7 @@ struct Dsymbol : Object #ifdef _DH virtual DeleteDeclaration *isDeleteDeclaration() { return NULL; } #endif - virtual SymbolDeclaration *isSymbolDeclaration() { return NULL; } + virtual StaticStructInitDeclaration *isStaticStructInitDeclaration() { return NULL; } virtual AttribDeclaration *isAttribDeclaration() { return NULL; } virtual OverloadSet *isOverloadSet() { return NULL; } virtual TypeInfoDeclaration* isTypeInfoDeclaration() { return NULL; } diff --git a/dmd2/interpret.c b/dmd2/interpret.c index 68f9a6c4..f3c8ce3f 100644 --- a/dmd2/interpret.c +++ b/dmd2/interpret.c @@ -987,7 +987,7 @@ Expression *getVarExp(Loc loc, InterState *istate, Declaration *d) { Expression *e = EXP_CANT_INTERPRET; VarDeclaration *v = d->isVarDeclaration(); - SymbolDeclaration *s = d->isSymbolDeclaration(); + StaticStructInitDeclaration *s = d->isStaticStructInitDeclaration(); if (v) { #if DMDV2 @@ -1011,11 +1011,9 @@ Expression *getVarExp(Loc loc, InterState *istate, Declaration *d) } else if (s) { - if (s->dsym->toInitializer() == s->sym) - { Expressions *exps = new Expressions(); - e = new StructLiteralExp(0, s->dsym, exps); - e = e->semantic(NULL); - } + Expressions *exps = new Expressions(); + e = new StructLiteralExp(0, s->dsym, exps); + e = e->semantic(NULL); } return e; } @@ -1466,10 +1464,10 @@ Expression *BinExp::interpretAssignCommon(InterState *istate, fp_t fp, int post) if (v->value && v->value->op == TOKvar) { VarExp *ve2 = (VarExp *)v->value; - if (ve2->var->isSymbolDeclaration()) + if (ve2->var->isStaticStructInitDeclaration()) { /* This can happen if v is a struct initialized to - * 0 using an __initZ SymbolDeclaration from + * 0 using an StaticStructInitDeclaration from * TypeStruct::defaultInit() */ } diff --git a/dmd2/mtype.c b/dmd2/mtype.c index 8b872465..fb5f7bf1 100644 --- a/dmd2/mtype.c +++ b/dmd2/mtype.c @@ -5249,14 +5249,12 @@ unsigned TypeStruct::memalign(unsigned salign) } Expression *TypeStruct::defaultInit(Loc loc) -{ Symbol *s; - Declaration *d; +{ Declaration *d; #if LOGDEFAULTINIT printf("TypeStruct::defaultInit() '%s'\n", toChars()); #endif - s = sym->toInitializer(); - d = new SymbolDeclaration(sym->loc, s, sym); + d = new StaticStructInitDeclaration(sym->loc, sym); assert(d); d->type = this; return new VarExp(sym->loc, d);