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

Changeset 478

Show
Ignore:
Timestamp:
05/10/10 18:43:10 (15 years ago)
Author:
walter
Message:

bugzilla 945 template forward reference with named nested struct only

Files:

Legend:

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

    r473 r478  
    22632263            { 
    22642264                e = type->defaultInit(); 
    22652265                e->loc = loc; 
    22662266                return e; 
    22672267            } 
    22682268        } 
    22692269        e = new VarExp(loc, v); 
    22702270        e->type = type; 
    22712271        e = e->semantic(sc); 
    22722272        return e->deref(); 
    22732273    } 
    22742274    fld = s->isFuncLiteralDeclaration(); 
    22752275    if (fld) 
    22762276    {   //printf("'%s' is a function literal\n", fld->toChars()); 
    22772277        e = new FuncExp(loc, fld); 
    22782278        return e->semantic(sc); 
    22792279    } 
    22802280    f = s->isFuncDeclaration(); 
    22812281    if (f) 
    22822282    {   //printf("'%s' is a function\n", f->toChars()); 
     2283 
     2284        if (!f->originalType && f->scope)       // semantic not yet run 
     2285            f->semantic(f->scope); 
    22832286        if (!f->type->deco) 
    22842287        { 
    22852288            error("forward reference to %s", toChars()); 
    22862289            return new ErrorExp(); 
    22872290        } 
    22882291        return new VarExp(loc, f); 
    22892292    } 
    22902293    cd = s->isClassDeclaration(); 
    22912294    if (cd && thiscd && cd->isBaseOf(thiscd, NULL) && sc->func->needThis()) 
    22922295    { 
    22932296        // We need to add an implicit 'this' if cd is this class or a base class. 
    22942297        DotTypeExp *dte; 
    22952298 
    22962299        dte = new DotTypeExp(loc, new ThisExp(loc), s); 
    22972300        return dte->semantic(sc); 
    22982301    } 
    22992302    imp = s->isImport(); 
    23002303    if (imp) 
    23012304    { 
    23022305        if (!imp->pkg) 
  • branches/dmd-1.x/src/func.c

    r428 r478  
    116116#if 0 
    117117    printf("FuncDeclaration::semantic(sc = %p, this = %p, '%s', linkage = %d)\n", sc, this, toPrettyChars(), sc->linkage); 
    118118    if (isFuncLiteralDeclaration()) 
    119119        printf("\tFuncLiteralDeclaration()\n"); 
    120120    printf("sc->parent = %s, parent = %s\n", sc->parent->toChars(), parent ? parent->toChars() : ""); 
    121121    printf("type: %p, %s\n", type, type->toChars()); 
    122122#endif 
    123123 
    124124    if (semanticRun != PASSinit && isFuncLiteralDeclaration()) 
    125125    { 
    126126        /* Member functions that have return types that are 
    127127         * forward references can have semantic() run more than 
    128128         * once on them. 
    129129         * See test\interface2.d, test20 
    130130         */ 
    131131        return; 
    132132    } 
    133133    parent = sc->parent; 
    134134    Dsymbol *parent = toParent(); 
    135135 
    136     if (semanticRun == PASSsemanticdone) 
     136    if (semanticRun >= PASSsemanticdone) 
    137137    { 
    138138        if (!parent->isClassDeclaration()) 
    139139            return; 
    140140        // need to re-run semantic() in order to set the class's vtbl[] 
    141141    } 
    142142    else 
    143143    { 
    144144        assert(semanticRun <= PASSsemantic); 
    145145        semanticRun = PASSsemantic; 
    146146    } 
    147147 
    148148    unsigned dprogress_save = Module::dprogress; 
    149149 
    150150    foverrides.setDim(0);       // reset in case semantic() is being retried for this function 
    151151 
    152152    if (!type->deco) 
    153153    { 
    154154        type = type->semantic(loc, sc); 
    155155    } 
    156156    //type->print(); 
  • branches/dmd-1.x/src/struct.c

    r428 r478  
    154154 
    155155void AggregateDeclaration::addField(Scope *sc, VarDeclaration *v) 
    156156{ 
    157157    unsigned memsize;           // size of member 
    158158    unsigned memalignsize;      // size of member for alignment purposes 
    159159    unsigned xalign;            // alignment boundaries 
    160160 
    161161    //printf("AggregateDeclaration::addField('%s') %s\n", v->toChars(), toChars()); 
    162162 
    163163    // Check for forward referenced types which will fail the size() call 
    164164    Type *t = v->type->toBasetype(); 
    165165    if (t->ty == Tstruct /*&& isStructDeclaration()*/) 
    166166    {   TypeStruct *ts = (TypeStruct *)t; 
    167167#if DMDV2 
    168168        if (ts->sym == this) 
    169169        { 
    170170            error("cannot have field %s with same struct type", v->toChars()); 
    171171        } 
    172172#endif 
    173173 
     174        if (ts->sym->sizeok != 1 && ts->sym->scope) 
     175            ts->sym->semantic(NULL); 
    174176        if (ts->sym->sizeok != 1) 
    175177        { 
    176178            sizeok = 2;         // cannot finish; flag as forward referenced 
    177179            return; 
    178180        } 
    179181    } 
    180182    if (t->ty == Tident) 
    181183    { 
    182184        sizeok = 2;             // cannot finish; flag as forward referenced 
    183185        return; 
    184186    } 
    185187 
    186188    memsize = v->type->size(loc); 
    187189    memalignsize = v->type->alignsize(); 
    188190    xalign = v->type->memalign(sc->structalign); 
    189191    alignmember(xalign, memalignsize, &sc->offset); 
    190192    v->offset = sc->offset; 
    191193    sc->offset += memsize; 
    192194    if (sc->offset > structsize) 
    193195        structsize = sc->offset; 
  • trunk/src/expression.c

    r477 r478  
    258258                     s = s->toParent()) 
    259259                {   FuncDeclaration *f = s->isFuncDeclaration(); 
    260260                    if (f->vthis) 
    261261                    { 
    262262                        //printf("rewriting e1 to %s's this\n", f->toChars()); 
    263263                        n++; 
    264264                        e1 = new VarExp(loc, f->vthis); 
    265265                    } 
    266266                } 
    267267                if (s && s->isClassDeclaration()) 
    268268                {   e1->type = s->isClassDeclaration()->type; 
    269269                    if (n > 1) 
    270270                        e1 = e1->semantic(sc); 
    271271                } 
    272272                else 
    273273                    e1 = e1->semantic(sc); 
    274274                goto L1; 
    275275            } 
    276276            /* Can't find a path from e1 to ad 
    277277             */ 
    278 printf("t->ty = %d\n", t->ty); 
    279278            e1->error("this for %s needs to be type %s not type %s", 
    280279                var->toChars(), ad->toChars(), t->toChars()); 
    281280            e1 = new ErrorExp(); 
    282281        } 
    283282    } 
    284283    return e1; 
    285284} 
    286285 
    287286/***************************************** 
    288287 * Determine if 'this' is available. 
    289288 * If it is, return the FuncDeclaration that has it. 
    290289 */ 
    291290 
    292291FuncDeclaration *hasThis(Scope *sc) 
    293292{   FuncDeclaration *fd; 
    294293    FuncDeclaration *fdthis; 
    295294 
    296295    //printf("hasThis()\n"); 
    297296    fdthis = sc->parent->isFuncDeclaration(); 
    298297    //printf("fdthis = %p, '%s'\n", fdthis, fdthis ? fdthis->toChars() : ""); 
     
    24282427            } 
    24292428            e = e->semantic(sc); 
    24302429            return e; 
    24312430        } 
    24322431 
    24332432        e = new VarExp(loc, v); 
    24342433        e->type = type; 
    24352434        e = e->semantic(sc); 
    24362435        return e->deref(); 
    24372436    } 
    24382437    fld = s->isFuncLiteralDeclaration(); 
    24392438    if (fld) 
    24402439    {   //printf("'%s' is a function literal\n", fld->toChars()); 
    24412440        e = new FuncExp(loc, fld); 
    24422441        return e->semantic(sc); 
    24432442    } 
    24442443    f = s->isFuncDeclaration(); 
    24452444    if (f) 
    24462445    {   //printf("'%s' is a function\n", f->toChars()); 
    24472446 
     2447        if (!f->originalType && f->scope)       // semantic not yet run 
     2448            f->semantic(f->scope); 
    24482449        if (!f->type->deco) 
    24492450        { 
    24502451            error("forward reference to %s", toChars()); 
    24512452            return new ErrorExp(); 
    24522453        } 
    24532454        return new VarExp(loc, f, hasOverloads); 
    24542455    } 
    24552456    o = s->isOverloadSet(); 
    24562457    if (o) 
    24572458    {   //printf("'%s' is an overload set\n", o->toChars()); 
    24582459        return new OverExp(o); 
    24592460    } 
    24602461    cd = s->isClassDeclaration(); 
    24612462    if (cd && thiscd && cd->isBaseOf(thiscd, NULL) && sc->func->needThis()) 
    24622463    { 
    24632464        // We need to add an implicit 'this' if cd is this class or a base class. 
    24642465        DotTypeExp *dte; 
    24652466 
    24662467        dte = new DotTypeExp(loc, new ThisExp(loc), s); 
    24672468        return dte->semantic(sc); 
  • trunk/src/func.c

    r436 r478  
    117117    printf("FuncDeclaration::semantic(sc = %p, this = %p, '%s', linkage = %d)\n", sc, this, toPrettyChars(), sc->linkage); 
    118118    if (isFuncLiteralDeclaration()) 
    119119        printf("\tFuncLiteralDeclaration()\n"); 
    120120    printf("sc->parent = %s, parent = %s\n", sc->parent->toChars(), parent ? parent->toChars() : ""); 
    121121    printf("type: %p, %s\n", type, type->toChars()); 
    122122#endif 
    123123 
    124124    if (semanticRun != PASSinit && isFuncLiteralDeclaration()) 
    125125    { 
    126126        /* Member functions that have return types that are 
    127127         * forward references can have semantic() run more than 
    128128         * once on them. 
    129129         * See test\interface2.d, test20 
    130130         */ 
    131131        return; 
    132132    } 
    133133 
    134134    parent = sc->parent; 
    135135    Dsymbol *parent = toParent(); 
    136136 
    137     if (semanticRun == PASSsemanticdone) 
     137    if (semanticRun >= PASSsemanticdone) 
    138138    { 
    139139        if (!parent->isClassDeclaration()) 
    140140            return; 
    141141        // need to re-run semantic() in order to set the class's vtbl[] 
    142142    } 
    143143    else 
    144144    { 
    145145        assert(semanticRun <= PASSsemantic); 
    146146        semanticRun = PASSsemantic; 
    147147    } 
    148148 
    149149    unsigned dprogress_save = Module::dprogress; 
    150150 
    151151    foverrides.setDim(0);       // reset in case semantic() is being retried for this function 
    152152 
    153153    storage_class |= sc->stc & ~STCref; 
    154154    //printf("function storage_class = x%llx, sc->stc = x%llx, %x\n", storage_class, sc->stc, Declaration::isFinal()); 
    155155 
    156156    if (!originalType) 
    157157        originalType = type; 
  • trunk/src/struct.c

    r428 r478  
    162162    unsigned xalign;            // alignment boundaries 
    163163 
    164164    //printf("AggregateDeclaration::addField('%s') %s\n", v->toChars(), toChars()); 
    165165    assert(!(v->storage_class & (STCstatic | STCextern | STCparameter | STCtls))); 
    166166 
    167167    // Check for forward referenced types which will fail the size() call 
    168168    Type *t = v->type->toBasetype(); 
    169169    if (v->storage_class & STCref) 
    170170    {   // References are the size of a pointer 
    171171        t = Type::tvoidptr; 
    172172    } 
    173173    if (t->ty == Tstruct /*&& isStructDeclaration()*/) 
    174174    {   TypeStruct *ts = (TypeStruct *)t; 
    175175#if DMDV2 
    176176        if (ts->sym == this) 
    177177        { 
    178178            error("cannot have field %s with same struct type", v->toChars()); 
    179179        } 
    180180#endif 
    181181 
     182        if (ts->sym->sizeok != 1 && ts->sym->scope) 
     183            ts->sym->semantic(NULL); 
    182184        if (ts->sym->sizeok != 1) 
    183185        { 
    184186            sizeok = 2;         // cannot finish; flag as forward referenced 
    185187            return; 
    186188        } 
    187189    } 
    188190    if (t->ty == Tident) 
    189191    { 
    190192        sizeok = 2;             // cannot finish; flag as forward referenced 
    191193        return; 
    192194    } 
    193195 
    194196    memsize = t->size(loc); 
    195197    memalignsize = t->alignsize(); 
    196198    xalign = t->memalign(sc->structalign); 
    197199    alignmember(xalign, memalignsize, &sc->offset); 
    198200    v->offset = sc->offset; 
    199201    sc->offset += memsize; 
    200202    if (sc->offset > structsize) 
    201203        structsize = sc->offset;