Mercurial > projects > ldc
diff dmd2/attrib.c @ 1577:e4f7b5d9c68a
DMD 2.032 Merge.
author | Robert Clipsham <robert@octarineparrot.com> |
---|---|
date | Tue, 08 Sep 2009 10:07:56 +0100 |
parents | 54b3c1394d62 |
children |
line wrap: on
line diff
--- a/dmd2/attrib.c Tue Aug 25 21:35:43 2009 +0200 +++ b/dmd2/attrib.c Tue Sep 08 10:07:56 2009 +0100 @@ -77,6 +77,41 @@ return m; } +void AttribDeclaration::setScopeNewSc(Scope *sc, + unsigned stc, enum LINK linkage, enum PROT protection, int explicitProtection, + unsigned structalign) +{ + if (decl) + { + Scope *newsc = sc; + if (stc != sc->stc || + linkage != sc->linkage || + protection != sc->protection || + explicitProtection != sc->explicitProtection || + structalign != sc->structalign) + { + // create new one for changes + newsc = new Scope(*sc); + newsc->flags &= ~SCOPEfree; + newsc->stc = stc; + newsc->linkage = linkage; + newsc->protection = protection; + newsc->explicitProtection = explicitProtection; + newsc->structalign = structalign; + } + for (unsigned i = 0; i < decl->dim; i++) + { Dsymbol *s = (Dsymbol *)decl->data[i]; + + s->setScope(newsc); // yes, the only difference from semanticNewSc() + } + if (newsc != sc) + { + sc->offset = newsc->offset; + newsc->pop(); + } + } +} + void AttribDeclaration::semanticNewSc(Scope *sc, unsigned stc, enum LINK linkage, enum PROT protection, int explicitProtection, unsigned structalign) @@ -340,11 +375,33 @@ return scd; } +void StorageClassDeclaration::setScope(Scope *sc) +{ + if (decl) + { + unsigned scstc = sc->stc; + + /* These sets of storage classes are mutually exclusive, + * so choose the innermost or most recent one. + */ + if (stc & (STCauto | STCscope | STCstatic | STCextern | STCmanifest)) + scstc &= ~(STCauto | STCscope | STCstatic | STCextern | STCmanifest); + if (stc & (STCauto | STCscope | STCstatic | STCtls | STCmanifest | STCgshared)) + scstc &= ~(STCauto | STCscope | STCstatic | STCtls | STCmanifest | STCgshared); + if (stc & (STCconst | STCimmutable | STCmanifest)) + scstc &= ~(STCconst | STCimmutable | STCmanifest); + if (stc & (STCgshared | STCshared | STCtls)) + scstc &= ~(STCgshared | STCshared | STCtls); + scstc |= stc; + + setScopeNewSc(sc, scstc, sc->linkage, sc->protection, sc->explicitProtection, sc->structalign); + } +} + void StorageClassDeclaration::semantic(Scope *sc) { if (decl) { -#if 1 unsigned scstc = sc->stc; /* These sets of storage classes are mutually exclusive, @@ -361,29 +418,6 @@ scstc |= stc; semanticNewSc(sc, scstc, sc->linkage, sc->protection, sc->explicitProtection, sc->structalign); -#else - unsigned stc_save = sc->stc; - - /* These sets of storage classes are mutually exclusive, - * so choose the innermost or most recent one. - */ - if (stc & (STCauto | STCscope | STCstatic | STCextern | STCmanifest)) - sc->stc &= ~(STCauto | STCscope | STCstatic | STCextern | STCmanifest); - if (stc & (STCauto | STCscope | STCstatic | STCtls | STCmanifest | STCgshared)) - sc->stc &= ~(STCauto | STCscope | STCstatic | STCtls | STCmanifest | STCgshared); - if (stc & (STCconst | STCimmutable | STCmanifest)) - sc->stc &= ~(STCconst | STCimmutable | STCmanifest); - if (stc & (STCgshared | STCshared | STCtls)) - sc->stc &= ~(STCgshared | STCshared | STCtls); - sc->stc |= stc; - for (unsigned i = 0; i < decl->dim; i++) - { - Dsymbol *s = (Dsymbol *)decl->data[i]; - - s->semantic(sc); - } - sc->stc = stc_save; -#endif } } @@ -402,22 +436,24 @@ { STCstatic, TOKstatic }, { STCextern, TOKextern }, { STCconst, TOKconst }, - { STCimmutable, TOKimmutable }, - { STCshared, TOKshared }, { STCfinal, TOKfinal }, { STCabstract, TOKabstract }, { STCsynchronized, TOKsynchronized }, { STCdeprecated, TOKdeprecated }, { STCoverride, TOKoverride }, + { STClazy, TOKlazy }, + { STCalias, TOKalias }, + { STCout, TOKout }, + { STCin, TOKin }, +#if DMDV2 + { STCimmutable, TOKimmutable }, + { STCshared, TOKshared }, { STCnothrow, TOKnothrow }, { STCpure, TOKpure }, { STCref, TOKref }, { STCtls, TOKtls }, { STCgshared, TOKgshared }, - { STClazy, TOKlazy }, - { STCalias, TOKalias }, - { STCout, TOKout }, - { STCin, TOKin }, +#endif }; for (int i = 0; i < sizeof(table)/sizeof(table[0]); i++) @@ -454,25 +490,21 @@ return ld; } +void LinkDeclaration::setScope(Scope *sc) +{ + //printf("LinkDeclaration::setScope(linkage = %d, decl = %p)\n", linkage, decl); + if (decl) + { + setScopeNewSc(sc, sc->stc, linkage, sc->protection, sc->explicitProtection, sc->structalign); + } +} + void LinkDeclaration::semantic(Scope *sc) { //printf("LinkDeclaration::semantic(linkage = %d, decl = %p)\n", linkage, decl); if (decl) { -#if 1 semanticNewSc(sc, sc->stc, linkage, sc->protection, sc->explicitProtection, sc->structalign); -#else - enum LINK linkage_save = sc->linkage; - - sc->linkage = linkage; - for (unsigned i = 0; i < decl->dim; i++) - { - Dsymbol *s = (Dsymbol *)decl->data[i]; - - s->semantic(sc); - } - sc->linkage = linkage_save; -#endif } } @@ -544,27 +576,19 @@ return pd; } +void ProtDeclaration::setScope(Scope *sc) +{ + if (decl) + { + setScopeNewSc(sc, sc->stc, sc->linkage, protection, 1, sc->structalign); + } +} + void ProtDeclaration::semantic(Scope *sc) { if (decl) { -#if 1 semanticNewSc(sc, sc->stc, sc->linkage, protection, 1, sc->structalign); -#else - enum PROT protection_save = sc->protection; - int explicitProtection_save = sc->explicitProtection; - - sc->protection = protection; - sc->explicitProtection = 1; - for (unsigned i = 0; i < decl->dim; i++) - { - Dsymbol *s = (Dsymbol *)decl->data[i]; - - s->semantic(sc); - } - sc->protection = protection_save; - sc->explicitProtection = explicitProtection_save; -#endif } } @@ -611,44 +635,21 @@ return ad; } +void AlignDeclaration::setScope(Scope *sc) +{ + //printf("\tAlignDeclaration::setScope '%s'\n",toChars()); + if (decl) + { + setScopeNewSc(sc, sc->stc, sc->linkage, sc->protection, sc->explicitProtection, salign); + } +} + void AlignDeclaration::semantic(Scope *sc) { -// LDC -// we only support packed structs, as from the spec: align(1) struct Packed { ... } -// other alignments are simply ignored. my tests show this is what llvm-gcc does too ... - //printf("\tAlignDeclaration::semantic '%s'\n",toChars()); if (decl) { -#if 1 semanticNewSc(sc, sc->stc, sc->linkage, sc->protection, sc->explicitProtection, salign); -#else - unsigned salign_save = sc->structalign; - -#if IN_DMD - sc->structalign = salign; -#endif - for (unsigned i = 0; i < decl->dim; i++) - { - Dsymbol *s = (Dsymbol *)decl->data[i]; - -#if IN_LLVM - if (s->isStructDeclaration() && salign == 1) - { - sc->structalign = salign; - s->semantic(sc); - sc->structalign = salign_save; - } - else - { -#endif - s->semantic(sc); -#if IN_LLVM - } -#endif - } - sc->structalign = salign_save; -#endif } else assert(0 && "what kind of align use triggers this?"); @@ -870,6 +871,39 @@ return pd; } +void PragmaDeclaration::setScope(Scope *sc) +{ +#if TARGET_NET + if (ident == Lexer::idPool("assembly")) + { + if (!args || args->dim != 1) + { + error("pragma has invalid number of arguments"); + } + else + { + Expression *e = (Expression *)args->data[0]; + e = e->semantic(sc); + e = e->optimize(WANTvalue | WANTinterpret); + args->data[0] = (void *)e; + if (e->op != TOKstring) + { + error("string expected, not '%s'", e->toChars()); + } + PragmaScope* pragma = new PragmaScope(this, sc->parent, static_cast<StringExp*>(e)); + + assert(sc); + pragma->setScope(sc); + + //add to module members + assert(sc->module); + assert(sc->module->members); + sc->module->members->push(pragma); + } + } +#endif // TARGET_NET +} + void PragmaDeclaration::semantic(Scope *sc) { // Should be merged with PragmaStatement @@ -892,7 +926,7 @@ if (e->op == TOKstring) { StringExp *se = (StringExp *)e; - fprintf(stdmsg, "%.*s", (int)se->len, (char*)se->string); + fprintf(stdmsg, "%.*s", (int)se->len, (char *)se->string); } else error("string expected for message, not '%s'", e->toChars()); @@ -981,22 +1015,6 @@ #if TARGET_NET else if (ident == Lexer::idPool("assembly")) { - if (!args || args->dim != 1) - error("pragma has invalid number of arguments"); - else - { - Expression *e = (Expression *)args->data[0]; - e = e->semantic(sc); - e = e->optimize(WANTvalue | WANTinterpret); - args->data[0] = (void *)e; - if (e->op != TOKstring) - { - error("string expected, not '%s'", e->toChars()); - } - PragmaScope* pragma = new PragmaScope(this, sc->parent, static_cast<StringExp*>(e)); - decl = new Array; - decl->push(pragma); - } } #endif // TARGET_NET // LDC