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

Changeset 319

Show
Ignore:
Timestamp:
12/30/09 00:11:16 (15 years ago)
Author:
walter
Message:

bugzilla 400 forward reference error; no propety X for type Y (struct within struct)

Files:

Legend:

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

    r262 r319  
    572572#endif 
    573573    } 
    574574    sc->protection = PROTpublic; 
    575575    sc->explicitProtection = 0; 
    576576    sc->structalign = 8; 
    577577    structalign = sc->structalign; 
    578578    if (baseClass) 
    579579    {   sc->offset = baseClass->structsize; 
    580580    alignsize = baseClass->alignsize; 
    581581//  if (isnested) 
    582582//      sc->offset += PTRSIZE;  // room for uplevel context pointer 
    583583    } 
    584584    else 
    585585    {   sc->offset = PTRSIZE * 2;   // allow room for __vptr and __monitor 
    586586    alignsize = PTRSIZE; 
    587587    } 
    588588    structsize = sc->offset; 
    589589    Scope scsave = *sc; 
    590590    int members_dim = members->dim; 
    591591    sizeok = 0; 
     592 
     593    /* Set scope so if there are forward references, we still might be able to 
     594     * resolve individual members like enums. 
     595     */ 
    592596    for (i = 0; i < members_dim; i++) 
    593     { 
    594     Dsymbol *s = (Dsymbol *)members->data[i]; 
     597    {   Dsymbol *s = (Dsymbol *)members->data[i]; 
     598    /* There are problems doing this in the general case because 
     599     * Scope keeps track of things like 'offset' 
     600     */ 
     601    if (s->isEnumDeclaration() || (s->isAggregateDeclaration() && s->ident)) 
     602    { 
     603        //printf("setScope %s %s\n", s->kind(), s->toChars()); 
     604        s->setScope(sc); 
     605    } 
     606    } 
     607 
     608    for (i = 0; i < members_dim; i++) 
     609    {   Dsymbol *s = (Dsymbol *)members->data[i]; 
    595610    s->semantic(sc); 
    596611    } 
    597612 
    598613    if (sizeok == 2) 
    599614    {   // semantic() failed because of forward references. 
    600615    // Unwind what we did, and defer it for later 
    601616    fields.setDim(0); 
    602617    structsize = 0; 
    603618    alignsize = 0; 
    604619    structalign = 0; 
    605620 
    606621    sc = sc->pop(); 
    607622 
    608623    scope = scx ? scx : new Scope(*sc); 
    609624    scope->setNoFree(); 
    610625    scope->module->addDeferredSemantic(this); 
    611626 
    612627    //printf("\tsemantic('%s') failed due to forward references\n", toChars()); 
    613628    return; 
    614629    } 
  • branches/dmd-1.x/src/struct.c

    r318 r319  
    280280    if (sizeok == 0)        // if not already done the addMember step 
    281281    { 
    282282    for (i = 0; i < members->dim; i++) 
    283283    { 
    284284        Dsymbol *s = (Dsymbol *)members->data[i]; 
    285285        //printf("adding member '%s' to '%s'\n", s->toChars(), this->toChars()); 
    286286        s->addMember(sc, this, 1); 
    287287    } 
    288288    } 
    289289 
    290290    sizeok = 0; 
    291291    sc2 = sc->push(this); 
    292292    sc2->stc = 0; 
    293293    sc2->parent = this; 
    294294    if (isUnionDeclaration()) 
    295295    sc2->inunion = 1; 
    296296    sc2->protection = PROTpublic; 
    297297    sc2->explicitProtection = 0; 
    298298 
    299299    int members_dim = members->dim; 
     300 
     301    /* Set scope so if there are forward references, we still might be able to 
     302     * resolve individual members like enums. 
     303     */ 
     304    for (int i = 0; i < members_dim; i++) 
     305    {   Dsymbol *s = (Dsymbol *)members->data[i]; 
     306    /* There are problems doing this in the general case because 
     307     * Scope keeps track of things like 'offset' 
     308     */ 
     309    if (s->isEnumDeclaration() || (s->isAggregateDeclaration() && s->ident)) 
     310    { 
     311        //printf("setScope %s %s\n", s->kind(), s->toChars()); 
     312        s->setScope(sc2); 
     313    } 
     314    } 
     315 
    300316    for (i = 0; i < members_dim; i++) 
    301317    { 
    302318    Dsymbol *s = (Dsymbol *)members->data[i]; 
    303319    s->semantic(sc2); 
    304320    if (isUnionDeclaration()) 
    305321        sc2->offset = 0; 
    306322#if 0 
    307323    if (sizeok == 2) 
    308324    {   //printf("forward reference\n"); 
    309325        break; 
    310326    } 
    311327#endif 
    312328    } 
    313329 
    314330    /* The TypeInfo_Struct is expecting an opEquals and opCmp with 
    315331     * a parameter that is a pointer to the struct. But if there 
    316332     * isn't one, but is an opEquals or opCmp with a value, write 
    317333     * another that is a shell around the value: 
    318334     *  int opCmp(struct *p) { return opCmp(*p); } 
    319335     */ 
  • trunk/src/class.c

    r305 r319  
    589589#endif 
    590590    } 
    591591    sc->protection = PROTpublic; 
    592592    sc->explicitProtection = 0; 
    593593    sc->structalign = 8; 
    594594    structalign = sc->structalign; 
    595595    if (baseClass) 
    596596    {   sc->offset = baseClass->structsize; 
    597597    alignsize = baseClass->alignsize; 
    598598//  if (isnested) 
    599599//      sc->offset += PTRSIZE;  // room for uplevel context pointer 
    600600    } 
    601601    else 
    602602    {   sc->offset = PTRSIZE * 2;   // allow room for __vptr and __monitor 
    603603    alignsize = PTRSIZE; 
    604604    } 
    605605    structsize = sc->offset; 
    606606    Scope scsave = *sc; 
    607607    int members_dim = members->dim; 
    608608    sizeok = 0; 
     609 
     610    /* Set scope so if there are forward references, we still might be able to 
     611     * resolve individual members like enums. 
     612     */ 
    609613    for (i = 0; i < members_dim; i++) 
    610     { 
    611     Dsymbol *s = (Dsymbol *)members->data[i]; 
     614    {   Dsymbol *s = (Dsymbol *)members->data[i]; 
     615    /* There are problems doing this in the general case because 
     616     * Scope keeps track of things like 'offset' 
     617     */ 
     618    if (s->isEnumDeclaration() || (s->isAggregateDeclaration() && s->ident)) 
     619    { 
     620        //printf("setScope %s %s\n", s->kind(), s->toChars()); 
     621        s->setScope(sc); 
     622    } 
     623    } 
     624 
     625    for (i = 0; i < members_dim; i++) 
     626    {   Dsymbol *s = (Dsymbol *)members->data[i]; 
    612627    s->semantic(sc); 
    613628    } 
    614629 
    615630    if (sizeok == 2) 
    616631    {   // semantic() failed because of forward references. 
    617632    // Unwind what we did, and defer it for later 
    618633    fields.setDim(0); 
    619634    structsize = 0; 
    620635    alignsize = 0; 
    621636    structalign = 0; 
    622637 
    623638    sc = sc->pop(); 
    624639 
    625640    scope = scx ? scx : new Scope(*sc); 
    626641    scope->setNoFree(); 
    627642    scope->module->addDeferredSemantic(this); 
    628643 
    629644    //printf("\tsemantic('%s') failed due to forward references\n", toChars()); 
    630645    return; 
    631646    } 
  • trunk/src/mars.c

    r286 r319  
    151151{ 
    152152    if (!global.gag) 
    153153    { 
    154154    char *p = loc.toChars(); 
    155155 
    156156    if (*p) 
    157157        fprintf(stdmsg, "%s: ", p); 
    158158    mem.free(p); 
    159159 
    160160    fprintf(stdmsg, "Error: "); 
    161161#if _MSC_VER 
    162162    // MS doesn't recognize %zu format 
    163163    OutBuffer tmp; 
    164164    tmp.vprintf(format, ap); 
    165165    fprintf(stdmsg, "%s", tmp.toChars()); 
    166166#else 
    167167    vfprintf(stdmsg, format, ap); 
    168168#endif 
    169169    fprintf(stdmsg, "\n"); 
    170170    fflush(stdmsg); 
    171 //halt(); 
     171halt(); 
    172172    } 
    173173    global.errors++; 
    174174} 
    175175 
    176176/*************************************** 
    177177 * Call this after printing out fatal error messages to clean up and exit 
    178178 * the compiler. 
    179179 */ 
    180180 
    181181void fatal() 
    182182{ 
    183183#if 0 
    184184    halt(); 
    185185#endif 
    186186    exit(EXIT_FAILURE); 
    187187} 
    188188 
    189189/************************************** 
    190190 * Try to stop forgetting to remove the breakpoints from 
    191191 * release builds. 
  • trunk/src/struct.c

    r318 r319  
    340340            t = Type::tvoidptr; // t should not be a ref type 
    341341                    assert(!vthis); 
    342342                    vthis = new ThisDeclaration(loc, t); 
    343343            //vthis->storage_class |= STCref; 
    344344                    members->push(vthis); 
    345345                } 
    346346            } 
    347347        } 
    348348    } 
    349349 
    350350    sizeok = 0; 
    351351    sc2 = sc->push(this); 
    352352    sc2->stc &= storage_class & STC_TYPECTOR; 
    353353    sc2->parent = this; 
    354354    if (isUnionDeclaration()) 
    355355    sc2->inunion = 1; 
    356356    sc2->protection = PROTpublic; 
    357357    sc2->explicitProtection = 0; 
    358358 
    359359    int members_dim = members->dim; 
     360 
     361    /* Set scope so if there are forward references, we still might be able to 
     362     * resolve individual members like enums. 
     363     */ 
     364    for (int i = 0; i < members_dim; i++) 
     365    {   Dsymbol *s = (Dsymbol *)members->data[i]; 
     366    /* There are problems doing this in the general case because 
     367     * Scope keeps track of things like 'offset' 
     368     */ 
     369    if (s->isEnumDeclaration() || (s->isAggregateDeclaration() && s->ident)) 
     370    { 
     371        //printf("setScope %s %s\n", s->kind(), s->toChars()); 
     372        s->setScope(sc2); 
     373    } 
     374    } 
     375 
    360376    for (int i = 0; i < members_dim; i++) 
    361377    { 
    362378    Dsymbol *s = (Dsymbol *)members->data[i]; 
    363379    s->semantic(sc2); 
    364380    if (isUnionDeclaration()) 
    365381        sc2->offset = 0; 
    366382#if 0 
    367383    if (sizeok == 2) 
    368384    {   //printf("forward reference\n"); 
    369385        break; 
    370386    } 
    371387#endif 
    372388    Type *t; 
    373389    if (s->isDeclaration() && 
    374390        (t = s->isDeclaration()->type) != NULL && 
    375391        t->toBasetype()->ty == Tstruct) 
    376392    {   StructDeclaration *sd = (StructDeclaration *)t->toDsymbol(sc); 
    377393        if (sd->isnested) 
    378394        error("inner struct %s cannot be a field", sd->toChars()); 
    379395    }