Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changeset 583

Show
Ignore:
Timestamp:
07/24/10 05:22:54 (14 years ago)
Author:
walter
Message:

workaround for another fwd reference anonymous enum bug

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/dmd-1.x/src/backend/cod3.c

    r582 r583  
    29312931#endif 
    29322932 
    29332933  if (b) 
    29342934  {     bn = b->Bnext; 
    29352935        usespace = (config.flags4 & CFG4space && b->BC != BCasm); 
    29362936        useopsize = (I16 || (config.flags4 & CFG4space && b->BC != BCasm)); 
    29372937  } 
    29382938  else 
    29392939  {     bn = NULL; 
    29402940        usespace = (config.flags4 & CFG4space); 
    29412941        useopsize = (I16 || config.flags4 & CFG4space); 
    29422942  } 
    29432943  for (; c; c = code_next(c)) 
    29442944  { 
    29452945    L1: 
    29462946        op = c->Iop; 
    29472947        if (op == 0x0F) 
    29482948            ins = inssize2[c->Iop2]; 
    29492949        else 
    29502950            ins = inssize[c->Iop]; 
    2951         if (I32 && ins & M)            // if modregrm byte 
     2951        if (ins & M)            // if modregrm byte 
    29522952        {   int shortop = (c->Iflags & CFopsize) ? !I16 : I16; 
    29532953            int local_BPRM = BPRM; 
    29542954 
    29552955            if (c->Iflags & CFaddrsize) 
    29562956                local_BPRM ^= 5 ^ 6;    // toggle between 5 and 6 
    29572957 
    29582958            unsigned rm = c->Irm; 
    29592959            unsigned reg = rm & modregrm(0,7,0);          // isolate reg field 
    29602960            unsigned ereg = rm & 7; 
    29612961            //printf("c = %p, op = %02x rm = %02x\n", c, op, rm); 
    29622962 
    29632963            /* If immediate second operand      */ 
    29642964            if ((ins & T || op == 0xF6 || op == 0xF7) && 
    29652965                c->IFL2 == FLconst) 
    29662966            { 
    29672967                int flags = c->Iflags & CFpsw;      /* if want result in flags */ 
    29682968                targ_long u = c->IEV2.Vuns; 
    29692969                if (ins & E) 
    29702970                    u = (signed char) u; 
    29712971                else if (shortop) 
     
    33083308                            case 5:     rm = modregrm(3,0,DI);  goto L6; 
    33093309                            case 7:     rm = modregrm(3,0,BX);  goto L6; 
    33103310                            L6:     c->Irm = rm + reg; 
    33113311                                    c->Iop = 0x8B; 
    33123312                                    break; 
    33133313                        } 
    33143314                    } 
    33153315                } 
    33163316 
    33173317                /* replace LEA reg,0[BP] with MOV reg,BP        */ 
    33183318                else if (mod == modregrm(1,0,0) && rm == local_BPRM && 
    33193319                        c->IFL1 == FLconst && c->IEVpointer1 == 0) 
    33203320                {       c->Iop = 0x8B;          /* MOV reg,BP   */ 
    33213321                        c->Irm = modregrm(3,0,BP) + reg; 
    33223322                } 
    33233323            } 
    33243324 
    33253325            // Replace [R13] with 0[R13] 
    33263326            if (c->Irex & REX_B && (c->Irm & modregrm(3,0,5)) == modregrm(0,0,5)) 
    33273327            { 
     3328printf("test1\n"); 
    33283329                c->Irm |= modregrm(1,0,0); 
    33293330                c->IFL1 = FLconst; 
    33303331                c->IEVpointer1 = 0; 
    33313332            } 
    33323333        } 
    33333334        else 
    33343335        { 
    33353336            switch (op) 
    33363337            { 
    33373338                default: 
    33383339                    if ((op & 0xF0) != 0x70) 
    33393340                        break; 
    33403341                case JMP: 
    33413342                    switch (c->IFL2) 
    33423343                    {   case FLcode: 
    33433344                                if (c->IEV2.Vcode == code_next(c)) 
    33443345                                {       c->Iop = NOP; 
    33453346                                        continue; 
    33463347                                } 
    33473348                                break; 
     
    33823383            } 
    33833384        } 
    33843385  } 
    33853386#if 0 
    33863387  if (1 || debugc) { 
    33873388      printf("-pinholeopt(%p)\n",cstart); 
    33883389        for (c = cstart; c; c = code_next(c)) 
    33893390            c->print(); 
    33903391  } 
    33913392#endif 
    33923393} 
    33933394 
    33943395#ifdef DEBUG 
    33953396STATIC void pinholeopt_unittest() 
    33963397{ 
    33973398    //printf("pinholeopt_unittest()\n"); 
    33983399    struct CS { unsigned model,op,ea,ev1,ev2,flags; } tests[][2] = 
    33993400    { 
    34003401        // XOR reg,immed                            NOT regL 
    34013402        {{ 16,0x81,modregrm(3,6,BX),0,0xFF,0 },    { 0,0xF6,modregrm(3,2,BX),0,0xFF }}, 
     3403 
     3404        // MOV 0[BX],3                               MOV [BX],3 
     3405        {{ 16,0xC7,modregrm(2,0,7),0,3},           { 0,0xC7,modregrm(0,0,7),0,3 }}, 
    34023406 
    34033407#if 0 // only if config.flags4 & CFG4space 
    34043408        // TEST regL,immed8 
    34053409        {{ 0,0xF6,modregrm(3,0,BX),0,0xFF,0 },    { 0,0x84,modregrm(3,BX,BX),0,0xFF }}, 
    34063410        {{ 0,0xF7,modregrm(3,0,BX),0,0xFF,0 },    { 0,0x84,modregrm(3,BX,BX),0,0xFF }}, 
    34073411        {{ 64,0xF6,modregrmx(3,0,R8),0,0xFF,0 },  { 0,0x84,modregxrmx(3,R8,R8),0,0xFF }}, 
    34083412        {{ 64,0xF7,modregrmx(3,0,R8),0,0xFF,0 },  { 0,0x84,modregxrmx(3,R8,R8),0,0xFF }}, 
    34093413#endif 
    34103414 
    34113415        // PUSH immed => PUSH immed8 
    34123416        {{ 0,0x68,0,0,0 },    { 0,0x6A,0,0,0 }}, 
    34133417        {{ 0,0x68,0,0,0x7F }, { 0,0x6A,0,0,0x7F }}, 
    34143418        {{ 0,0x68,0,0,0x80 }, { 0,0x68,0,0,0x80 }}, 
    34153419        {{ 16,0x68,0,0,0,CFopsize },    { 0,0x6A,0,0,0,CFopsize }}, 
    34163420        {{ 16,0x68,0,0,0x7F,CFopsize }, { 0,0x6A,0,0,0x7F,CFopsize }}, 
    34173421        {{ 16,0x68,0,0,0x80,CFopsize }, { 0,0x68,0,0,0x80,CFopsize }}, 
    34183422        {{ 16,0x68,0,0,0x10000,0 },     { 0,0x6A,0,0,0x10000,0 }}, 
    34193423        {{ 16,0x68,0,0,0x10000,CFopsize }, { 0,0x68,0,0,0x10000,CFopsize }}, 
    34203424        {{ 32,0x68,0,0,0,CFopsize },    { 0,0x6A,0,0,0,CFopsize }}, 
    34213425        {{ 32,0x68,0,0,0x7F,CFopsize }, { 0,0x6A,0,0,0x7F,CFopsize }}, 
  • branches/dmd-1.x/src/dsymbol.c

    r510 r583  
    268268/************************************* 
    269269 * Set scope for future semantic analysis so we can 
    270270 * deal better with forward references. 
    271271 */ 
    272272 
    273273void Dsymbol::setScope(Scope *sc) 
    274274{ 
    275275    //printf("Dsymbol::setScope() %p %s\n", this, toChars()); 
    276276    if (!sc->nofree) 
    277277        sc->setNoFree();                // may need it even after semantic() finishes 
    278278    scope = sc; 
    279279} 
    280280 
    281281void Dsymbol::importAll(Scope *sc) 
    282282{ 
    283283} 
    284284 
    285285/************************************* 
    286286 * Does semantic analysis on the public face of declarations. 
    287287 */ 
     288 
     289void Dsymbol::semantic0(Scope *sc) 
     290{ 
     291} 
    288292 
    289293void Dsymbol::semantic(Scope *sc) 
    290294{ 
    291295    error("%p has no semantic routine", this); 
    292296} 
    293297 
    294298/************************************* 
    295299 * Does semantic analysis on initializers and members of aggregates. 
    296300 */ 
    297301 
    298302void Dsymbol::semantic2(Scope *sc) 
    299303{ 
    300304    // Most Dsymbols have no further semantic analysis needed 
    301305} 
    302306 
    303307/************************************* 
    304308 * Does semantic analysis on function bodies. 
    305309 */ 
    306310 
    307311void Dsymbol::semantic3(Scope *sc) 
  • branches/dmd-1.x/src/dsymbol.h

    r473 r583  
    126126    int isAnonymous(); 
    127127    void error(Loc loc, const char *format, ...); 
    128128    void error(const char *format, ...); 
    129129    void checkDeprecated(Loc loc, Scope *sc); 
    130130    Module *getModule(); 
    131131    Dsymbol *pastMixin(); 
    132132    Dsymbol *toParent(); 
    133133    Dsymbol *toParent2(); 
    134134    TemplateInstance *inTemplateInstance(); 
    135135 
    136136    int dyncast() { return DYNCAST_DSYMBOL; }   // kludge for template.isSymbol() 
    137137 
    138138    static Array *arraySyntaxCopy(Array *a); 
    139139 
    140140    virtual const char *toPrettyChars(); 
    141141    virtual const char *kind(); 
    142142    virtual Dsymbol *toAlias();                 // resolve real symbol 
    143143    virtual int addMember(Scope *sc, ScopeDsymbol *s, int memnum); 
    144144    virtual void setScope(Scope *sc); 
    145145    virtual void importAll(Scope *sc); 
     146    virtual void semantic0(Scope *sc); 
    146147    virtual void semantic(Scope *sc); 
    147148    virtual void semantic2(Scope *sc); 
    148149    virtual void semantic3(Scope *sc); 
    149150    virtual void inlineScan(); 
    150151    virtual Dsymbol *search(Loc loc, Identifier *ident, int flags); 
    151152    Dsymbol *search_correct(Identifier *id); 
    152153    Dsymbol *searchX(Loc loc, Scope *sc, Identifier *id); 
    153154    virtual int overloadInsert(Dsymbol *s); 
    154155#ifdef _DH 
    155156    char *toHChars(); 
    156157    virtual void toHBuffer(OutBuffer *buf, HdrGenState *hgs); 
    157158#endif 
    158159    virtual void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 
    159160    virtual void toDocBuffer(OutBuffer *buf); 
    160161    virtual void toJsonBuffer(OutBuffer *buf); 
    161162    virtual unsigned size(Loc loc); 
    162163    virtual int isforwardRef(); 
    163164    virtual void defineRef(Dsymbol *s); 
    164165    virtual AggregateDeclaration *isThis();     // is a 'this' required to access the member 
    165166    virtual ClassDeclaration *isClassMember();  // are we a member of a class? 
  • branches/dmd-1.x/src/enum.c

    r428 r583  
    3030    defaultval = 0; 
    3131    sinit = NULL; 
    3232    isdeprecated = 0; 
    3333} 
    3434 
    3535Dsymbol *EnumDeclaration::syntaxCopy(Dsymbol *s) 
    3636{ 
    3737    Type *t = NULL; 
    3838    if (memtype) 
    3939        t = memtype->syntaxCopy(); 
    4040 
    4141    EnumDeclaration *ed; 
    4242    if (s) 
    4343    {   ed = (EnumDeclaration *)s; 
    4444        ed->memtype = t; 
    4545    } 
    4646    else 
    4747        ed = new EnumDeclaration(loc, ident, t); 
    4848    ScopeDsymbol::syntaxCopy(ed); 
    4949    return ed; 
     50} 
     51 
     52void EnumDeclaration::semantic0(Scope *sc) 
     53{ 
     54    /* This function is a hack to get around a significant problem. 
     55     * The members of anonymous enums, like: 
     56     *  enum { A, B, C } 
     57     * don't get installed into the symbol table until after they are 
     58     * semantically analyzed, yet they're supposed to go into the enclosing 
     59     * scope's table. Hence, when forward referenced, they come out as 
     60     * 'undefined'. The real fix is to add them in at addSymbol() time. 
     61     * But to get code to compile, we'll just do this quick hack at the moment 
     62     * to compile it if it doesn't depend on anything else. 
     63     */ 
     64 
     65    if (isdone || !scope) 
     66        return; 
     67    if (!isAnonymous() || memtype) 
     68        return; 
     69    for (int i = 0; i < members->dim; i++) 
     70    { 
     71        EnumMember *em = ((Dsymbol *)members->data[i])->isEnumMember(); 
     72        if (em && em->value) 
     73            return; 
     74    } 
     75 
     76    // Can do it 
     77    semantic(sc); 
    5078} 
    5179 
    5280void EnumDeclaration::semantic(Scope *sc) 
    5381{   int i; 
    5482    uinteger_t number; 
    5583    Type *t; 
    5684    Scope *sce; 
    5785 
    5886    //printf("EnumDeclaration::semantic(sd = %p, '%s')\n", sc->scopesym, sc->scopesym->toChars()); 
    5987    if (!memtype) 
    6088        memtype = Type::tint32; 
    6189 
    6290    if (symtab)                 // if already done 
    6391    {   if (isdone || !scope) 
    6492            return;             // semantic() already completed 
    6593    } 
    6694    else 
    6795        symtab = new DsymbolTable(); 
    6896 
    6997    Scope *scx = NULL; 
  • branches/dmd-1.x/src/enum.h

    r428 r583  
    3030{   /* enum ident : memtype { ... } 
    3131     */ 
    3232    Type *type;                 // the TypeEnum 
    3333    Type *memtype;              // type of the members 
    3434 
    3535#if DMDV1 
    3636    dinteger_t maxval; 
    3737    dinteger_t minval; 
    3838    dinteger_t defaultval;      // default initializer 
    3939#else 
    4040    Expression *maxval; 
    4141    Expression *minval; 
    4242    Expression *defaultval;     // default initializer 
    4343#endif 
    4444    int isdeprecated; 
    4545    int isdone;                 // 0: not done 
    4646                                // 1: semantic() successfully completed 
    4747 
    4848    EnumDeclaration(Loc loc, Identifier *id, Type *memtype); 
    4949    Dsymbol *syntaxCopy(Dsymbol *s); 
     50    void semantic0(Scope *sc); 
    5051    void semantic(Scope *sc); 
    5152    int oneMember(Dsymbol **ps); 
    5253    void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 
    5354    Type *getType(); 
    5455    const char *kind(); 
    5556#if DMDV2 
    5657    Dsymbol *search(Loc, Identifier *ident, int flags); 
    5758#endif 
    5859    int isDeprecated();                 // is Dsymbol deprecated? 
    5960 
    6061    void emitComment(Scope *sc); 
    6162    void toJsonBuffer(OutBuffer *buf); 
    6263    void toDocBuffer(OutBuffer *buf); 
    6364 
    6465    EnumDeclaration *isEnumDeclaration() { return this; } 
    6566 
    6667    void toObjFile(int multiobj);                       // compile to .obj file 
    6768    void toDebug(); 
    6869    int cvMember(unsigned char *p); 
    6970 
  • branches/dmd-1.x/src/module.c

    r569 r583  
    744744    } 
    745745 
    746746    // Add all symbols into module's symbol table 
    747747    symtab = new DsymbolTable(); 
    748748    for (int i = 0; i < members->dim; i++) 
    749749    {   Dsymbol *s = (Dsymbol *)members->data[i]; 
    750750        s->addMember(NULL, sc->scopesym, 1); 
    751751    } 
    752752 
    753753    /* Set scope for the symbols so that if we forward reference 
    754754     * a symbol, it can possibly be resolved on the spot. 
    755755     * If this works out well, it can be extended to all modules 
    756756     * before any semantic() on any of them. 
    757757     */ 
    758758    for (int i = 0; i < members->dim; i++) 
    759759    {   Dsymbol *s = (Dsymbol *)members->data[i]; 
    760760        s->setScope(sc); 
    761761    } 
    762762#endif 
    763763 
     764    // Do semantic() on members that don't depend on others 
     765    for (int i = 0; i < members->dim; i++) 
     766    {   Dsymbol *s = (Dsymbol *)members->data[i]; 
     767 
     768        //printf("\tModule('%s'): '%s'.semantic0()\n", toChars(), s->toChars()); 
     769        s->semantic0(sc); 
     770    } 
     771 
    764772    // Pass 1 semantic routines: do public side of the definition 
    765773    for (int i = 0; i < members->dim; i++) 
    766774    {   Dsymbol *s = (Dsymbol *)members->data[i]; 
    767775 
    768776        //printf("\tModule('%s'): '%s'.semantic()\n", toChars(), s->toChars()); 
    769777        s->semantic(sc); 
    770778        runDeferredSemantic(); 
    771779    } 
    772780 
    773781    if (!scope) 
    774782    {   sc = sc->pop(); 
    775783        sc->pop();              // 2 pops because Scope::createGlobal() created 2 
    776784    } 
    777785    semanticRun = semanticstarted; 
    778786    //printf("-Module::semantic(this = %p, '%s'): parent = %p\n", this, toChars(), parent); 
    779787} 
    780788 
    781789void Module::semantic2() 
    782790{   int i; 
    783791 
  • trunk/src/backend/cod3.c

    r582 r583  
    29312931#endif 
    29322932 
    29332933  if (b) 
    29342934  {     bn = b->Bnext; 
    29352935        usespace = (config.flags4 & CFG4space && b->BC != BCasm); 
    29362936        useopsize = (I16 || (config.flags4 & CFG4space && b->BC != BCasm)); 
    29372937  } 
    29382938  else 
    29392939  {     bn = NULL; 
    29402940        usespace = (config.flags4 & CFG4space); 
    29412941        useopsize = (I16 || config.flags4 & CFG4space); 
    29422942  } 
    29432943  for (; c; c = code_next(c)) 
    29442944  { 
    29452945    L1: 
    29462946        op = c->Iop; 
    29472947        if (op == 0x0F) 
    29482948            ins = inssize2[c->Iop2]; 
    29492949        else 
    29502950            ins = inssize[c->Iop]; 
    2951         if (I32 && ins & M)            // if modregrm byte 
     2951        if (ins & M)            // if modregrm byte 
    29522952        {   int shortop = (c->Iflags & CFopsize) ? !I16 : I16; 
    29532953            int local_BPRM = BPRM; 
    29542954 
    29552955            if (c->Iflags & CFaddrsize) 
    29562956                local_BPRM ^= 5 ^ 6;    // toggle between 5 and 6 
    29572957 
    29582958            unsigned rm = c->Irm; 
    29592959            unsigned reg = rm & modregrm(0,7,0);          // isolate reg field 
    29602960            unsigned ereg = rm & 7; 
    29612961            //printf("c = %p, op = %02x rm = %02x\n", c, op, rm); 
    29622962 
    29632963            /* If immediate second operand      */ 
    29642964            if ((ins & T || op == 0xF6 || op == 0xF7) && 
    29652965                c->IFL2 == FLconst) 
    29662966            { 
    29672967                int flags = c->Iflags & CFpsw;      /* if want result in flags */ 
    29682968                targ_long u = c->IEV2.Vuns; 
    29692969                if (ins & E) 
    29702970                    u = (signed char) u; 
    29712971                else if (shortop) 
     
    33083308                            case 5:     rm = modregrm(3,0,DI);  goto L6; 
    33093309                            case 7:     rm = modregrm(3,0,BX);  goto L6; 
    33103310                            L6:     c->Irm = rm + reg; 
    33113311                                    c->Iop = 0x8B; 
    33123312                                    break; 
    33133313                        } 
    33143314                    } 
    33153315                } 
    33163316 
    33173317                /* replace LEA reg,0[BP] with MOV reg,BP        */ 
    33183318                else if (mod == modregrm(1,0,0) && rm == local_BPRM && 
    33193319                        c->IFL1 == FLconst && c->IEVpointer1 == 0) 
    33203320                {       c->Iop = 0x8B;          /* MOV reg,BP   */ 
    33213321                        c->Irm = modregrm(3,0,BP) + reg; 
    33223322                } 
    33233323            } 
    33243324 
    33253325            // Replace [R13] with 0[R13] 
    33263326            if (c->Irex & REX_B && (c->Irm & modregrm(3,0,5)) == modregrm(0,0,5)) 
    33273327            { 
     3328printf("test1\n"); 
    33283329                c->Irm |= modregrm(1,0,0); 
    33293330                c->IFL1 = FLconst; 
    33303331                c->IEVpointer1 = 0; 
    33313332            } 
    33323333        } 
    33333334        else 
    33343335        { 
    33353336            switch (op) 
    33363337            { 
    33373338                default: 
    33383339                    if ((op & 0xF0) != 0x70) 
    33393340                        break; 
    33403341                case JMP: 
    33413342                    switch (c->IFL2) 
    33423343                    {   case FLcode: 
    33433344                                if (c->IEV2.Vcode == code_next(c)) 
    33443345                                {       c->Iop = NOP; 
    33453346                                        continue; 
    33463347                                } 
    33473348                                break; 
     
    33823383            } 
    33833384        } 
    33843385  } 
    33853386#if 0 
    33863387  if (1 || debugc) { 
    33873388      printf("-pinholeopt(%p)\n",cstart); 
    33883389        for (c = cstart; c; c = code_next(c)) 
    33893390            c->print(); 
    33903391  } 
    33913392#endif 
    33923393} 
    33933394 
    33943395#ifdef DEBUG 
    33953396STATIC void pinholeopt_unittest() 
    33963397{ 
    33973398    //printf("pinholeopt_unittest()\n"); 
    33983399    struct CS { unsigned model,op,ea,ev1,ev2,flags; } tests[][2] = 
    33993400    { 
    34003401        // XOR reg,immed                            NOT regL 
    34013402        {{ 16,0x81,modregrm(3,6,BX),0,0xFF,0 },    { 0,0xF6,modregrm(3,2,BX),0,0xFF }}, 
     3403 
     3404        // MOV 0[BX],3                               MOV [BX],3 
     3405        {{ 16,0xC7,modregrm(2,0,7),0,3},           { 0,0xC7,modregrm(0,0,7),0,3 }}, 
    34023406 
    34033407#if 0 // only if config.flags4 & CFG4space 
    34043408        // TEST regL,immed8 
    34053409        {{ 0,0xF6,modregrm(3,0,BX),0,0xFF,0 },    { 0,0x84,modregrm(3,BX,BX),0,0xFF }}, 
    34063410        {{ 0,0xF7,modregrm(3,0,BX),0,0xFF,0 },    { 0,0x84,modregrm(3,BX,BX),0,0xFF }}, 
    34073411        {{ 64,0xF6,modregrmx(3,0,R8),0,0xFF,0 },  { 0,0x84,modregxrmx(3,R8,R8),0,0xFF }}, 
    34083412        {{ 64,0xF7,modregrmx(3,0,R8),0,0xFF,0 },  { 0,0x84,modregxrmx(3,R8,R8),0,0xFF }}, 
    34093413#endif 
    34103414 
    34113415        // PUSH immed => PUSH immed8 
    34123416        {{ 0,0x68,0,0,0 },    { 0,0x6A,0,0,0 }}, 
    34133417        {{ 0,0x68,0,0,0x7F }, { 0,0x6A,0,0,0x7F }}, 
    34143418        {{ 0,0x68,0,0,0x80 }, { 0,0x68,0,0,0x80 }}, 
    34153419        {{ 16,0x68,0,0,0,CFopsize },    { 0,0x6A,0,0,0,CFopsize }}, 
    34163420        {{ 16,0x68,0,0,0x7F,CFopsize }, { 0,0x6A,0,0,0x7F,CFopsize }}, 
    34173421        {{ 16,0x68,0,0,0x80,CFopsize }, { 0,0x68,0,0,0x80,CFopsize }}, 
    34183422        {{ 16,0x68,0,0,0x10000,0 },     { 0,0x6A,0,0,0x10000,0 }}, 
    34193423        {{ 16,0x68,0,0,0x10000,CFopsize }, { 0,0x68,0,0,0x10000,CFopsize }}, 
    34203424        {{ 32,0x68,0,0,0,CFopsize },    { 0,0x6A,0,0,0,CFopsize }}, 
    34213425        {{ 32,0x68,0,0,0x7F,CFopsize }, { 0,0x6A,0,0,0x7F,CFopsize }}, 
  • trunk/src/dsymbol.c

    r510 r583  
    268268/************************************* 
    269269 * Set scope for future semantic analysis so we can 
    270270 * deal better with forward references. 
    271271 */ 
    272272 
    273273void Dsymbol::setScope(Scope *sc) 
    274274{ 
    275275    //printf("Dsymbol::setScope() %p %s\n", this, toChars()); 
    276276    if (!sc->nofree) 
    277277        sc->setNoFree();                // may need it even after semantic() finishes 
    278278    scope = sc; 
    279279} 
    280280 
    281281void Dsymbol::importAll(Scope *sc) 
    282282{ 
    283283} 
    284284 
    285285/************************************* 
    286286 * Does semantic analysis on the public face of declarations. 
    287287 */ 
     288 
     289void Dsymbol::semantic0(Scope *sc) 
     290{ 
     291} 
    288292 
    289293void Dsymbol::semantic(Scope *sc) 
    290294{ 
    291295    error("%p has no semantic routine", this); 
    292296} 
    293297 
    294298/************************************* 
    295299 * Does semantic analysis on initializers and members of aggregates. 
    296300 */ 
    297301 
    298302void Dsymbol::semantic2(Scope *sc) 
    299303{ 
    300304    // Most Dsymbols have no further semantic analysis needed 
    301305} 
    302306 
    303307/************************************* 
    304308 * Does semantic analysis on function bodies. 
    305309 */ 
    306310 
    307311void Dsymbol::semantic3(Scope *sc) 
  • trunk/src/dsymbol.h

    r473 r583  
    128128    int isAnonymous(); 
    129129    void error(Loc loc, const char *format, ...); 
    130130    void error(const char *format, ...); 
    131131    void checkDeprecated(Loc loc, Scope *sc); 
    132132    Module *getModule(); 
    133133    Dsymbol *pastMixin(); 
    134134    Dsymbol *toParent(); 
    135135    Dsymbol *toParent2(); 
    136136    TemplateInstance *inTemplateInstance(); 
    137137 
    138138    int dyncast() { return DYNCAST_DSYMBOL; }   // kludge for template.isSymbol() 
    139139 
    140140    static Dsymbols *arraySyntaxCopy(Dsymbols *a); 
    141141 
    142142    virtual const char *toPrettyChars(); 
    143143    virtual const char *kind(); 
    144144    virtual Dsymbol *toAlias();                 // resolve real symbol 
    145145    virtual int addMember(Scope *sc, ScopeDsymbol *s, int memnum); 
    146146    virtual void setScope(Scope *sc); 
    147147    virtual void importAll(Scope *sc); 
     148    virtual void semantic0(Scope *sc); 
    148149    virtual void semantic(Scope *sc); 
    149150    virtual void semantic2(Scope *sc); 
    150151    virtual void semantic3(Scope *sc); 
    151152    virtual void inlineScan(); 
    152153    virtual Dsymbol *search(Loc loc, Identifier *ident, int flags); 
    153154    Dsymbol *search_correct(Identifier *id); 
    154155    Dsymbol *searchX(Loc loc, Scope *sc, Identifier *id); 
    155156    virtual int overloadInsert(Dsymbol *s); 
    156157#ifdef _DH 
    157158    char *toHChars(); 
    158159    virtual void toHBuffer(OutBuffer *buf, HdrGenState *hgs); 
    159160#endif 
    160161    virtual void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 
    161162    virtual void toDocBuffer(OutBuffer *buf); 
    162163    virtual void toJsonBuffer(OutBuffer *buf); 
    163164    virtual unsigned size(Loc loc); 
    164165    virtual int isforwardRef(); 
    165166    virtual void defineRef(Dsymbol *s); 
    166167    virtual AggregateDeclaration *isThis();     // is a 'this' required to access the member 
    167168    virtual ClassDeclaration *isClassMember();  // are we a member of a class? 
  • trunk/src/enum.c

    r428 r583  
    3333    sinit = NULL; 
    3434    isdeprecated = 0; 
    3535    isdone = 0; 
    3636} 
    3737 
    3838Dsymbol *EnumDeclaration::syntaxCopy(Dsymbol *s) 
    3939{ 
    4040    Type *t = NULL; 
    4141    if (memtype) 
    4242        t = memtype->syntaxCopy(); 
    4343 
    4444    EnumDeclaration *ed; 
    4545    if (s) 
    4646    {   ed = (EnumDeclaration *)s; 
    4747        ed->memtype = t; 
    4848    } 
    4949    else 
    5050        ed = new EnumDeclaration(loc, ident, t); 
    5151    ScopeDsymbol::syntaxCopy(ed); 
    5252    return ed; 
     53} 
     54 
     55void EnumDeclaration::semantic0(Scope *sc) 
     56{ 
     57    /* This function is a hack to get around a significant problem. 
     58     * The members of anonymous enums, like: 
     59     *  enum { A, B, C } 
     60     * don't get installed into the symbol table until after they are 
     61     * semantically analyzed, yet they're supposed to go into the enclosing 
     62     * scope's table. Hence, when forward referenced, they come out as 
     63     * 'undefined'. The real fix is to add them in at addSymbol() time. 
     64     * But to get code to compile, we'll just do this quick hack at the moment 
     65     * to compile it if it doesn't depend on anything else. 
     66     */ 
     67 
     68    if (isdone || !scope) 
     69        return; 
     70    if (!isAnonymous() || memtype) 
     71        return; 
     72    for (int i = 0; i < members->dim; i++) 
     73    { 
     74        EnumMember *em = ((Dsymbol *)members->data[i])->isEnumMember(); 
     75        if (em && (em->type || em->value)) 
     76            return; 
     77    } 
     78 
     79    // Can do it 
     80    semantic(sc); 
    5381} 
    5482 
    5583void EnumDeclaration::semantic(Scope *sc) 
    5684{ 
    5785    Type *t; 
    5886    Scope *sce; 
    5987 
    6088    //printf("EnumDeclaration::semantic(sd = %p, '%s') %s\n", sc->scopesym, sc->scopesym->toChars(), toChars()); 
    6189    //printf("EnumDeclaration::semantic() %s\n", toChars()); 
    6290    if (!members)               // enum ident; 
    6391        return; 
    6492 
    6593    if (!memtype && !isAnonymous()) 
    6694    {   // Set memtype if we can to reduce fwd reference errors 
    6795        memtype = Type::tint32; // case 1)  enum ident { ... } 
    6896    } 
    6997 
    7098    if (symtab)                 // if already done 
    7199    {   if (isdone || !scope) 
    72100            return;             // semantic() already completed 
  • trunk/src/enum.h

    r428 r583  
    3030{   /* enum ident : memtype { ... } 
    3131     */ 
    3232    Type *type;                 // the TypeEnum 
    3333    Type *memtype;              // type of the members 
    3434 
    3535#if DMDV1 
    3636    dinteger_t maxval; 
    3737    dinteger_t minval; 
    3838    dinteger_t defaultval;      // default initializer 
    3939#else 
    4040    Expression *maxval; 
    4141    Expression *minval; 
    4242    Expression *defaultval;     // default initializer 
    4343#endif 
    4444    int isdeprecated; 
    4545    int isdone;                 // 0: not done 
    4646                                // 1: semantic() successfully completed 
    4747 
    4848    EnumDeclaration(Loc loc, Identifier *id, Type *memtype); 
    4949    Dsymbol *syntaxCopy(Dsymbol *s); 
     50    void semantic0(Scope *sc); 
    5051    void semantic(Scope *sc); 
    5152    int oneMember(Dsymbol **ps); 
    5253    void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 
    5354    Type *getType(); 
    5455    const char *kind(); 
    5556#if DMDV2 
    5657    Dsymbol *search(Loc, Identifier *ident, int flags); 
    5758#endif 
    5859    int isDeprecated();                 // is Dsymbol deprecated? 
    5960 
    6061    void emitComment(Scope *sc); 
    6162    void toJsonBuffer(OutBuffer *buf); 
    6263    void toDocBuffer(OutBuffer *buf); 
    6364 
    6465    EnumDeclaration *isEnumDeclaration() { return this; } 
    6566 
    6667    void toObjFile(int multiobj);                       // compile to .obj file 
    6768    void toDebug(); 
    6869    int cvMember(unsigned char *p); 
    6970 
  • trunk/src/module.c

    r569 r583  
    754754    } 
    755755 
    756756    // Add all symbols into module's symbol table 
    757757    symtab = new DsymbolTable(); 
    758758    for (int i = 0; i < members->dim; i++) 
    759759    {   Dsymbol *s = (Dsymbol *)members->data[i]; 
    760760        s->addMember(NULL, sc->scopesym, 1); 
    761761    } 
    762762 
    763763    /* Set scope for the symbols so that if we forward reference 
    764764     * a symbol, it can possibly be resolved on the spot. 
    765765     * If this works out well, it can be extended to all modules 
    766766     * before any semantic() on any of them. 
    767767     */ 
    768768    for (int i = 0; i < members->dim; i++) 
    769769    {   Dsymbol *s = (Dsymbol *)members->data[i]; 
    770770        s->setScope(sc); 
    771771    } 
    772772#endif 
    773773 
     774    // Do semantic() on members that don't depend on others 
     775    for (int i = 0; i < members->dim; i++) 
     776    {   Dsymbol *s = (Dsymbol *)members->data[i]; 
     777 
     778        //printf("\tModule('%s'): '%s'.semantic0()\n", toChars(), s->toChars()); 
     779        s->semantic0(sc); 
     780    } 
     781 
    774782    // Pass 1 semantic routines: do public side of the definition 
    775783    for (int i = 0; i < members->dim; i++) 
    776784    {   Dsymbol *s = (Dsymbol *)members->data[i]; 
    777785 
    778786        //printf("\tModule('%s'): '%s'.semantic()\n", toChars(), s->toChars()); 
    779787        s->semantic(sc); 
    780788        runDeferredSemantic(); 
    781789    } 
    782790 
    783791    if (!scope) 
    784792    {   sc = sc->pop(); 
    785793        sc->pop();              // 2 pops because Scope::createGlobal() created 2 
    786794    } 
    787795    semanticRun = semanticstarted; 
    788796    //printf("-Module::semantic(this = %p, '%s'): parent = %p\n", this, toChars(), parent); 
    789797} 
    790798 
    791799void Module::semantic2() 
    792800{   int i; 
    793801