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

Changeset 317

Show
Ignore:
Timestamp:
12/29/09 05:09:42 (15 years ago)
Author:
walter
Message:

bugzilla 3611 Enum forward referencing regression

Files:

Legend:

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

    r189 r317  
    3838    t = memtype->syntaxCopy(); 
    3939 
    4040    EnumDeclaration *ed; 
    4141    if (s) 
    4242    {   ed = (EnumDeclaration *)s; 
    4343    ed->memtype = t; 
    4444    } 
    4545    else 
    4646    ed = new EnumDeclaration(loc, ident, t); 
    4747    ScopeDsymbol::syntaxCopy(ed); 
    4848    return ed; 
    4949} 
    5050 
    5151void EnumDeclaration::semantic(Scope *sc) 
    5252{   int i; 
    5353    uinteger_t number; 
    5454    Type *t; 
    5555    Scope *sce; 
    5656 
    5757    //printf("EnumDeclaration::semantic(sd = %p, '%s')\n", sc->scopesym, sc->scopesym->toChars()); 
    58     if (symtab)         // if already done 
    59     return; 
    6058    if (!memtype) 
    6159    memtype = Type::tint32; 
     60 
     61    if (symtab)         // if already done 
     62    {   if (!scope) 
     63        return;     // semantic() already completed 
     64    } 
     65    else 
     66    symtab = new DsymbolTable(); 
     67 
     68    Scope *scx = NULL; 
     69    if (scope) 
     70    {   sc = scope; 
     71        scx = scope;            // save so we don't make redundant copies 
     72        scope = NULL; 
     73    } 
     74 
    6275    if (sc->stc & STCdeprecated) 
    6376    isdeprecated = 1; 
    6477 
    6578    parent = sc->scopesym; 
    6679    memtype = memtype->semantic(loc, sc); 
    6780 
    6881    /* Check to see if memtype is forward referenced 
    6982     */ 
    7083    if (memtype->ty == Tenum) 
    7184    {   EnumDeclaration *sym = (EnumDeclaration *)memtype->toDsymbol(sc); 
    7285    if (!sym->memtype) 
    7386    { 
    7487        error("base enum %s is forward referenced", sym->toChars()); 
    7588        memtype = Type::tint32; 
    7689    } 
    7790    } 
    7891 
    7992    if (!memtype->isintegral()) 
    8093    {   error("base type must be of integral type, not %s", memtype->toChars()); 
    8194    memtype = Type::tint32; 
  • branches/dmd-1.x/src/mtype.c

    r315 r317  
    38483848unsigned TypeEnum::alignsize() 
    38493849{ 
    38503850    if (!sym->memtype) 
    38513851    { 
    38523852#ifdef DEBUG 
    38533853    printf("1: "); 
    38543854#endif 
    38553855    error(0, "enum %s is forward referenced", sym->toChars()); 
    38563856    return 4; 
    38573857    } 
    38583858    return sym->memtype->alignsize(); 
    38593859} 
    38603860 
    38613861Dsymbol *TypeEnum::toDsymbol(Scope *sc) 
    38623862{ 
    38633863    return sym; 
    38643864} 
    38653865 
    38663866Type *TypeEnum::toBasetype() 
    38673867{ 
     3868    if (sym->scope) 
     3869    { 
     3870    sym->semantic(NULL);    // attempt to resolve forward reference 
     3871    } 
    38683872    if (!sym->memtype) 
    38693873    { 
    38703874#ifdef DEBUG 
    38713875    printf("2: "); 
    38723876#endif 
    38733877    error(sym->loc, "enum %s is forward referenced", sym->toChars()); 
    38743878    return terror; 
    38753879    } 
    38763880    return sym->memtype->toBasetype(); 
    38773881} 
    38783882 
    38793883void TypeEnum::toDecoBuffer(OutBuffer *buf) 
    38803884{   char *name; 
    38813885 
    38823886    name = sym->mangle(); 
    38833887//    if (name[0] == '_' && name[1] == 'D') 
    38843888//  name += 2; 
    38853889    buf->printf("%c%s", mangleChar[ty], name); 
    38863890} 
    38873891 
  • trunk/src/mtype.c

    r312 r317  
    59665966unsigned TypeEnum::alignsize() 
    59675967{ 
    59685968    if (!sym->memtype) 
    59695969    { 
    59705970#ifdef DEBUG 
    59715971    printf("1: "); 
    59725972#endif 
    59735973    error(0, "enum %s is forward referenced", sym->toChars()); 
    59745974    return 4; 
    59755975    } 
    59765976    return sym->memtype->alignsize(); 
    59775977} 
    59785978 
    59795979Dsymbol *TypeEnum::toDsymbol(Scope *sc) 
    59805980{ 
    59815981    return sym; 
    59825982} 
    59835983 
    59845984Type *TypeEnum::toBasetype() 
    59855985{ 
     5986    if (sym->scope) 
     5987    { 
     5988    sym->semantic(NULL);    // attempt to resolve forward reference 
     5989    } 
    59865990    if (!sym->memtype) 
    59875991    { 
    59885992#ifdef DEBUG 
    59895993    printf("2: "); 
    59905994#endif 
    59915995    error(sym->loc, "enum %s is forward referenced", sym->toChars()); 
    59925996    return tint32; 
    59935997    } 
    59945998    return sym->memtype->toBasetype(); 
    59955999} 
    59966000 
    59976001void TypeEnum::toDecoBuffer(OutBuffer *buf, int flag) 
    59986002{ 
    59996003    const char *name = sym->mangle(); 
    60006004    Type::toDecoBuffer(buf, flag); 
    60016005    buf->printf("%s", name); 
    60026006} 
    60036007 
    60046008void TypeEnum::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) 
    60056009{ 
  • trunk/src/optimize.c

    r304 r317  
    813813} 
    814814 
    815815Expression *EqualExp::optimize(int result) 
    816816{   Expression *e; 
    817817 
    818818    //printf("EqualExp::optimize(result = %x) %s\n", result, toChars()); 
    819819    e1 = e1->optimize(WANTvalue | (result & WANTinterpret)); 
    820820    e2 = e2->optimize(WANTvalue | (result & WANTinterpret)); 
    821821    e = this; 
    822822 
    823823    Expression *e1 = fromConstInitializer(result, this->e1); 
    824824    Expression *e2 = fromConstInitializer(result, this->e2); 
    825825 
    826826    e = Equal(op, type, e1, e2); 
    827827    if (e == EXP_CANT_INTERPRET) 
    828828    e = this; 
    829829    return e; 
    830830} 
    831831 
    832832Expression *IdentityExp::optimize(int result) 
    833 {   Expression *e; 
    834  
     833
    835834    //printf("IdentityExp::optimize(result = %d) %s\n", result, toChars()); 
    836835    e1 = e1->optimize(WANTvalue | (result & WANTinterpret)); 
    837836    e2 = e2->optimize(WANTvalue | (result & WANTinterpret)); 
    838     e = this; 
     837    Expression *e = this; 
    839838 
    840839    if ((this->e1->isConst()     && this->e2->isConst()) || 
    841840    (this->e1->op == TOKnull && this->e2->op == TOKnull)) 
    842841    { 
    843842    e = Identity(op, type, this->e1, this->e2); 
    844843    if (e == EXP_CANT_INTERPRET) 
    845844        e = this; 
    846845    } 
    847846    return e; 
    848847} 
    849848 
    850849Expression *IndexExp::optimize(int result) 
    851850{   Expression *e; 
    852851 
    853852    //printf("IndexExp::optimize(result = %d) %s\n", result, toChars()); 
    854853    Expression *e1 = this->e1->optimize(WANTvalue | (result & WANTinterpret)); 
    855854    e1 = fromConstInitializer(result, e1); 
    856855    if (this->e1->op == TOKvar) 
    857856    {   VarExp *ve = (VarExp *)this->e1; 
    858857    if (ve->var->storage_class & STCmanifest)