Changeset 903

Show
Ignore:
Timestamp:
06/29/08 19:09:51 (4 months ago)
Author:
Gregor
Message:

MERGE: dmdfe-2.0 r902 (DMD 2.015)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/rebuild/aggregate.h

    r884 r903  
    107107{ 
    108108    int zeroInit;       // !=0 if initialize with 0 fill 
     109#if V2 
    109110    int hasIdentityAssign;  // !=0 if has identity opAssign 
    110111    FuncDeclaration *cpctor;    // generated copy-constructor, if any 
     
    112113    FuncDeclarations postblits; // Array of postblit functions 
    113114    FuncDeclaration *postblit;  // aggregate postblit 
     115#endif 
    114116 
    115117    StructDeclaration(Loc loc, Identifier *id); 
     
    200202    VarDeclaration *vthis;      // 'this' parameter if this class is nested 
    201203 
     204    int inuse;              // to prevent recursive attempts 
     205 
    202206    ClassDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses); 
    203207    Dsymbol *syntaxCopy(Dsymbol *s); 
  • trunk/rebuild/attrib.c

    r884 r903  
    5353int AttribDeclaration::addMember(Scope *sc, ScopeDsymbol *sd, int memnum) 
    5454{ 
    55     unsigned i; 
    5655    int m = 0; 
    5756    Array *d = include(sc, sd); 
     
    5958    if (d) 
    6059    { 
    61     for (i = 0; i < d->dim; i++) 
    62     {   Dsymbol *s; 
    63  
    64         s = (Dsymbol *)d->data[i]; 
     60    for (unsigned i = 0; i < d->dim; i++) 
     61    {   Dsymbol *s = (Dsymbol *)d->data[i]; 
    6562        m |= s->addMember(sc, sd, m | memnum); 
    6663    } 
     
    7370    Array *d = include(sc, NULL); 
    7471 
    75     //printf("\tAttribDeclaration::semantic '%s'\n",toChars()); 
     72    //printf("\tAttribDeclaration::semantic '%s', d = %p\n",toChars(), d); 
    7673    if (d) 
    7774    { 
     
    8784void AttribDeclaration::semantic2(Scope *sc) 
    8885{ 
    89     unsigned i; 
    9086    Array *d = include(sc, NULL); 
    9187 
    9288    if (d) 
    9389    { 
    94     for (i = 0; i < d->dim; i++) 
    95     {   Dsymbol *s; 
    96  
    97         s = (Dsymbol *)d->data[i]; 
     90    for (unsigned i = 0; i < d->dim; i++) 
     91    {   Dsymbol *s = (Dsymbol *)d->data[i]; 
    9892        s->semantic2(sc); 
    9993    } 
     
    10397void AttribDeclaration::semantic3(Scope *sc) 
    10498{ 
    105     unsigned i; 
    10699    Array *d = include(sc, NULL); 
    107100 
    108101    if (d) 
    109102    { 
    110     for (i = 0; i < d->dim; i++) 
    111     {   Dsymbol *s; 
    112  
    113         s = (Dsymbol *)d->data[i]; 
     103    for (unsigned i = 0; i < d->dim; i++) 
     104    {   Dsymbol *s = (Dsymbol *)d->data[i]; 
    114105        s->semantic3(sc); 
    115106    } 
     
    119110void AttribDeclaration::inlineScan() 
    120111{ 
    121     unsigned i; 
    122112    Array *d = include(NULL, NULL); 
    123113 
    124114    if (d) 
    125115    { 
    126     for (i = 0; i < d->dim; i++) 
    127     {   Dsymbol *s; 
    128  
    129         s = (Dsymbol *)d->data[i]; 
     116    for (unsigned i = 0; i < d->dim; i++) 
     117    {   Dsymbol *s = (Dsymbol *)d->data[i]; 
    130118        //printf("AttribDeclaration::inlineScan %s\n", s->toChars()); 
    131119        s->inlineScan(); 
     
    138126    if (comment) 
    139127    { 
    140     unsigned i; 
    141128    Array *d = include(NULL, NULL); 
    142129 
    143130    if (d) 
    144131    { 
    145         for (i = 0; i < d->dim; i++) 
    146         {   Dsymbol *s; 
    147  
    148         s = (Dsymbol *)d->data[i]; 
     132        for (unsigned i = 0; i < d->dim; i++) 
     133        {   Dsymbol *s = (Dsymbol *)d->data[i]; 
    149134        //printf("AttribDeclaration::addComment %s\n", s->toChars()); 
    150135        s->addComment(comment); 
     
    164149//  return; 
    165150 
    166     unsigned i; 
    167151    Array *d = include(NULL, NULL); 
    168152 
    169153    if (d) 
    170154    { 
    171     for (i = 0; i < d->dim; i++) 
    172     {   Dsymbol *s; 
    173  
    174         s = (Dsymbol *)d->data[i]; 
     155    for (unsigned i = 0; i < d->dim; i++) 
     156    {   Dsymbol *s = (Dsymbol *)d->data[i]; 
    175157        //printf("AttribDeclaration::emitComment %s\n", s->toChars()); 
    176158        s->emitComment(sc); 
     
    209191void AttribDeclaration::checkCtorConstInit() 
    210192{ 
    211     unsigned i; 
    212193    Array *d = include(NULL, NULL); 
    213194 
    214195    if (d) 
    215196    { 
    216     for (i = 0; i < d->dim; i++) 
    217     {   Dsymbol *s; 
    218  
    219         s = (Dsymbol *)d->data[i]; 
     197    for (unsigned i = 0; i < d->dim; i++) 
     198    {   Dsymbol *s = (Dsymbol *)d->data[i]; 
    220199        s->checkCtorConstInit(); 
    221200    } 
     
    227206 
    228207void AttribDeclaration::addLocalClass(ClassDeclarations *aclasses) 
    229 {   unsigned i; 
     208{ 
    230209    Array *d = include(NULL, NULL); 
    231210 
    232211    if (d) 
    233212    { 
    234     for (i = 0; i < d->dim; i++) 
    235     {   Dsymbol *s; 
    236  
    237         s = (Dsymbol *)d->data[i]; 
     213    for (unsigned i = 0; i < d->dim; i++) 
     214    {   Dsymbol *s = (Dsymbol *)d->data[i]; 
    238215        s->addLocalClass(aclasses); 
    239216    } 
     
    314291    if (stc & (STCauto | STCscope | STCstatic | STCextern | STCmanifest)) 
    315292        sc->stc &= ~(STCauto | STCscope | STCstatic | STCextern | STCmanifest); 
     293    if (stc & (STCauto | STCscope | STCstatic | STCtls | STCmanifest)) 
     294        sc->stc &= ~(STCauto | STCscope | STCstatic | STCtls | STCmanifest); 
    316295    if (stc & (STCconst | STCinvariant | STCmanifest)) 
    317296        sc->stc &= ~(STCconst | STCinvariant | STCmanifest); 
     
    350329    { STCdeprecated,   TOKdeprecated }, 
    351330    { STCoverride,     TOKoverride }, 
     331    { STCnothrow,      TOKnothrow }, 
     332    { STCpure,         TOKpure }, 
     333    { STCtls,          TOKtls }, 
    352334    }; 
    353335 
     
    614596    sc = sc->push(); 
    615597    sc->anonAgg = &aad; 
    616     sc->stc &= ~(STCauto | STCscope | STCstatic); 
     598    sc->stc &= ~(STCauto | STCscope | STCstatic | STCtls); 
    617599    sc->inunion = isunion; 
    618600    sc->offset = 0; 
     
    841823        if (!sa || !sa->isFuncDeclaration()) 
    842824        error("function name expected for start address, not '%s'", e->toChars()); 
     825    } 
     826    goto Lnodecl; 
     827    } 
     828    else if (global.params.ignoreUnsupportedPragmas) 
     829    { 
     830    if (global.params.verbose) 
     831    { 
     832        / * Print unrecognized pragmas 
     833         * / 
     834        printf("pragma    %s", ident->toChars()); 
     835        if (args) 
     836        { 
     837        for (size_t i = 0; i < args->dim; i++) 
     838        { 
     839            Expression *e = (Expression *)args->data[i]; 
     840            e = e->semantic(sc); 
     841            e = e->optimize(WANTvalue | WANTinterpret); 
     842            if (i == 0) 
     843            printf(" ("); 
     844            else 
     845            printf(","); 
     846            printf("%s", e->toChars()); 
     847        } 
     848        if (args->dim) 
     849            printf(")"); 
     850        } 
     851        printf("\n"); 
    843852    } 
    844853    goto Lnodecl; 
     
    930939void PragmaDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) 
    931940{ 
    932     buf->printf("pragma(%s", ident->toChars()); 
    933     if (args) 
    934     { 
    935     for (size_t i = 0; i < args->dim; i++) 
    936     { 
    937         Expression *e = (Expression *)args->data[i]; 
    938  
    939         buf->writestring(", "); 
    940         e->toCBuffer(buf, hgs); 
    941     } 
    942     } 
    943     buf->writestring(")"); 
     941    buf->printf("pragma (%s", ident->toChars()); 
     942    if (args && args->dim) 
     943    { 
     944        buf->writestring(", "); 
     945        argsToCBuffer(buf, args, hgs); 
     946    } 
     947    buf->writeByte(')'); 
    944948    AttribDeclaration::toCBuffer(buf, hgs); 
    945949} 
     
    11391143int StaticIfDeclaration::addMember(Scope *sc, ScopeDsymbol *sd, int memnum) 
    11401144{ 
     1145    //printf("StaticIfDeclaration::addMember() '%s'\n",toChars()); 
    11411146    /* This is deferred until semantic(), so that 
    11421147     * expressions in the condition can refer to declarations 
     
    11651170    Array *d = include(sc, sd); 
    11661171 
    1167     //printf("\tStaticIfDeclaration::semantic '%s'\n",toChars()); 
     1172    //printf("\tStaticIfDeclaration::semantic '%s', d = %p\n",toChars(), d); 
    11681173    if (d) 
    11691174    { 
     
    11951200    this->exp = exp; 
    11961201    this->sd = NULL; 
     1202    this->compiled = 0; 
    11971203} 
    11981204 
     
    12061212int CompileDeclaration::addMember(Scope *sc, ScopeDsymbol *sd, int memnum) 
    12071213{ 
     1214    //printf("CompileDeclaration::addMember(sc = %p)\n", sc); 
    12081215    this->sd = sd; 
     1216    if (memnum == 0) 
     1217    {   /* No members yet, so parse the mixin now 
     1218     */ 
     1219    compileIt(sc); 
     1220    memnum |= AttribDeclaration::addMember(sc, sd, memnum); 
     1221    compiled = 1; 
     1222    } 
    12091223    return memnum; 
    12101224} 
    12111225 
    1212 void CompileDeclaration::semantic(Scope *sc) 
    1213 { 
    1214     //printf("CompileDeclaration::semantic()\n"); 
     1226void CompileDeclaration::compileIt(Scope *sc) 
     1227{ 
     1228    //printf("CompileDeclaration::compileIt()\n"); 
    12151229    exp = exp->semantic(sc); 
    12161230    exp = resolveProperties(sc, exp); 
     
    12181232    if (exp->op != TOKstring) 
    12191233    {   //error("argument to mixin must be a string, not (%s)", exp->toChars()); 
    1220     return; 
    1221     } 
    1222     StringExp *se = (StringExp *)exp; 
    1223     se = se->toUTF8(sc); 
    1224     Parser p(sc->module, (unsigned char *)se->string, se->len, 0); 
    1225     p.loc = loc; 
    1226     p.nextToken(); 
    1227     decl = p.parseDeclDefs(0); 
    1228     if (p.token.value != TOKeof) 
    1229     { 
    1230     //error("incomplete mixin declaration (%s)", se->toChars()); 
    1231     } 
    1232  
    1233     AttribDeclaration::addMember(sc, sd, 0); 
     1234    } 
     1235    else 
     1236    { 
     1237    StringExp *se = (StringExp *)exp; 
     1238    se = se->toUTF8(sc); 
     1239    Parser p(sc->module, (unsigned char *)se->string, se->len, 0); 
     1240    p.loc = loc; 
     1241    p.nextToken(); 
     1242    decl = p.parseDeclDefs(0); 
     1243    /*if (p.token.value != TOKeof) 
     1244        error("incomplete mixin declaration (%s)", se->toChars());*/ 
     1245    } 
     1246
     1247 
     1248void CompileDeclaration::semantic(Scope *sc) 
     1249
     1250    //printf("CompileDeclaration::semantic()\n"); 
     1251 
     1252    if (!compiled) 
     1253    { 
     1254    compileIt(sc); 
     1255    AttribDeclaration::addMember(sc, sd, 0); 
     1256    compiled = 1; 
     1257    } 
    12341258    AttribDeclaration::semantic(sc); 
    12351259} 
  • trunk/rebuild/attrib.h

    r459 r903  
    158158 
    159159    ScopeDsymbol *sd; 
     160    int compiled; 
    160161 
    161162    CompileDeclaration(Loc loc, Expression *exp); 
    162163    Dsymbol *syntaxCopy(Dsymbol *s); 
    163164    int addMember(Scope *sc, ScopeDsymbol *sd, int memnum); 
     165    void compileIt(Scope *sc); 
    164166    void semantic(Scope *sc); 
    165167    void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 
  • trunk/rebuild/cast.c

    r884 r903  
    11 
    2 // Copyright (c) 1999-2007 by Digital Mars 
     2// Copyright (c) 1999-2008 by Digital Mars 
    33// All Rights Reserved 
    44// written by Walter Bright 
     
    3232Expression *Expression::implicitCastTo(Scope *sc, Type *t) 
    3333{ 
    34     //printf("Expression::implicitCastTo(%s) => %s\n", type->toChars(), t->toChars()); 
    35     //printf("%s\n", toChars()); 
     34    //printf("Expression::implicitCastTo(%s of type %s) => %s\n", toChars(), type->toChars(), t->toChars()); 
    3635 
    3736    MATCH match = implicitConvTo(t); 
     
    104103    toChars(), type->toChars(), t->toChars()); 
    105104#endif 
    106     //static int nest; if (++nest == 50) halt(); 
     105    //static int nest; if (++nest == 10) halt(); 
    107106    if (!type) 
    108107    {   //error("%s is not an expression", toChars()); 
     
    10871086{ 
    10881087#if 0 
    1089     printf("ArrayLiteralExp::castTo(this=%s, type=%s, t=%s)\n", 
     1088    printf("ArrayLiteralExp::castTo(this=%s, type=%s, => %s)\n", 
    10901089    toChars(), type->toChars(), t->toChars()); 
    10911090#endif 
     
    10971096    if ((tb->ty == Tarray || tb->ty == Tsarray) && 
    10981097    (typeb->ty == Tarray || typeb->ty == Tsarray) && 
    1099     tb->nextOf()->toBasetype()->ty != Tvoid) 
     1098    // Not trying to convert non-void[] to void[] 
     1099    !(tb->nextOf()->toBasetype()->ty == Tvoid && typeb->nextOf()->toBasetype()->ty != Tvoid)) 
    11001100    { 
    11011101    if (tb->ty == Tsarray) 
     
    13181318} 
    13191319 
    1320 /************************************ 
    1321  * Bring leaves to common type. 
     1320/************************************** 
     1321 * Combine types. 
     1322 * Output: 
     1323 *  *pt merged type, if *pt is not NULL 
     1324 *  *pe1    rewritten e1 
     1325 *  *pe2    rewritten e2 
     1326 * Returns: 
     1327 *  !=0 success 
     1328 *  0   failed 
    13221329 */ 
    13231330 
    1324 Expression *BinExp::typeCombine(Scope *sc) 
    1325 
    1326     Type *t1; 
    1327     Type *t2; 
    1328     Type *t; 
    1329     TY ty; 
    1330  
    1331     //printf("BinExp::typeCombine() %s\n", toChars()); 
     1331int typeMerge(Scope *sc, Type **pt, Expression **pe1, Expression **pe2) 
     1332
     1333    //printf("typeMerge() %s\n", toChars()); 
    13321334    //dump(0); 
    13331335 
    1334     e1 = e1->integralPromotions(sc); 
    1335     e2 = e2->integralPromotions(sc); 
    1336  
    1337     // BUG: do toBasetype() 
    1338     t1 = e1->type; 
    1339     t2 = e2->type; 
     1336    Expression *e1 = (*pe1)->integralPromotions(sc); 
     1337    Expression *e2 = (*pe2)->integralPromotions(sc); 
     1338 
     1339    Type *t1 = e1->type; 
     1340    Type *t2 = e2->type; 
    13401341    assert(t1); 
    1341     t = t1; 
     1342    Type *t = t1; 
    13421343 
    13431344    //if (t1) printf("\tt1 = %s\n", t1->toChars()); 
     
    13511352    Type *t2b = t2->toBasetype(); 
    13521353 
    1353     ty = (TY)Type::impcnvResult[t1b->ty][t2b->ty]; 
     1354    TY ty = (TY)Type::impcnvResult[t1b->ty][t2b->ty]; 
    13541355    if (ty != Terror) 
    13551356    {   TY ty1; 
     
    13631364        if (t1 == t2) 
    13641365        { 
    1365         if (!type) 
    1366             type = t1; 
    1367         return this; 
     1366        t = t1; 
     1367        goto Lret; 
    13681368        } 
    13691369 
    13701370        if (t1b == t2b) 
    13711371        { 
    1372         if (!type) 
    1373             type = t1b; 
    1374         return this; 
    1375         } 
    1376     } 
    1377  
    1378     if (!type) 
    1379         type = Type::basic[ty]; 
     1372        t = t1b; 
     1373        goto Lret; 
     1374        } 
     1375    } 
     1376 
     1377    t = Type::basic[ty]; 
    13801378 
    13811379    t1 = Type::basic[ty1]; 
     
    13831381    e1 = e1->castTo(sc, t1); 
    13841382    e2 = e2->castTo(sc, t2); 
    1385 #if 0 
    1386     if (type != Type::basic[ty]) 
    1387     {   t = type; 
    1388         type = Type::basic[ty]; 
    1389         return castTo(sc, t); 
    1390     } 
    1391 #endif 
    13921383    //printf("after typeCombine():\n"); 
    13931384    //dump(0); 
    13941385    //printf("ty = %d, ty1 = %d, ty2 = %d\n", ty, ty1, ty2); 
    1395     return this
     1386    goto Lret
    13961387    } 
    13971388 
    13981389    t1 = t1b; 
    13991390    t2 = t2b; 
     1391 
     1392Lagain: 
     1393    if (t1 == t2) 
     1394    { 
     1395    } 
     1396    else if (t1->ty == Tpointer && t2->ty == Tpointer) 
     1397    { 
     1398    // Bring pointers to compatible type 
     1399    Type *t1n = t1->nextOf(); 
     1400    Type *t2n = t2->nextOf(); 
     1401 
     1402    if (t1n == t2n) 
     1403        ; 
     1404    else if (t1n->ty == Tvoid)  // pointers to void are always compatible 
     1405        t = t2; 
     1406    else if (t2n->ty == Tvoid) 
     1407        ; 
     1408    else if (t1n->mod != t2n->mod) 
     1409    { 
     1410        t1 = t1n->mutableOf()->constOf()->pointerTo(); 
     1411        t2 = t2n->mutableOf()->constOf()->pointerTo(); 
     1412        t = t1; 
     1413        goto Lagain; 
     1414    } 
     1415    else if (t1n->ty == Tclass && t2n->ty == Tclass) 
     1416    {   ClassDeclaration *cd1 = t1n->isClassHandle(); 
     1417        ClassDeclaration *cd2 = t2n->isClassHandle(); 
     1418        int offset; 
     1419 
     1420        if (cd1->isBaseOf(cd2, &offset)) 
     1421        { 
     1422        if (offset) 
     1423            e2 = e2->castTo(sc, t); 
     1424        } 
     1425        else if (cd2->isBaseOf(cd1, &offset)) 
     1426        { 
     1427        t = t2; 
     1428        if (offset) 
     1429            e1 = e1->castTo(sc, t); 
     1430        } 
     1431        else 
     1432        goto Lincompatible; 
     1433    } 
     1434    else 
     1435        goto Lincompatible; 
     1436    } 
     1437    else if ((t1->ty == Tsarray || t1->ty == Tarray) && 
     1438         e2->op == TOKnull && t2->ty == Tpointer && t2->nextOf()->ty == Tvoid) 
     1439    {   /*  (T[n] op void*) 
     1440     *  (T[] op void*) 
     1441     */ 
     1442    goto Lx1; 
     1443    } 
     1444    else if ((t2->ty == Tsarray || t2->ty == Tarray) && 
     1445         e1->op == TOKnull && t1->ty == Tpointer && t1->nextOf()->ty == Tvoid) 
     1446    {   /*  (void* op T[n]) 
     1447     *  (void* op T[]) 
     1448     */ 
     1449    goto Lx2; 
     1450    } 
     1451    else if ((t1->ty == Tsarray || t1->ty == Tarray) && t1->implicitConvTo(t2)) 
     1452    { 
     1453    goto Lt2; 
     1454    } 
     1455    else if ((t2->ty == Tsarray || t2->ty == Tarray) && t2->implicitConvTo(t1)) 
     1456    { 
     1457    goto Lt1; 
     1458    } 
     1459    /* If one is mutable and the other invariant, then retry 
     1460     * with both of them as const 
     1461     */ 
     1462    else if ((t1->ty == Tsarray || t1->ty == Tarray || t1->ty == Tpointer) && 
     1463         (t2->ty == Tsarray || t2->ty == Tarray || t2->ty == Tpointer) && 
     1464         t1->nextOf()->mod != t2->nextOf()->mod 
     1465        ) 
     1466    { 
     1467    if (t1->ty == Tpointer) 
     1468        t1 = t1->nextOf()->mutableOf()->constOf()->pointerTo(); 
     1469    else 
     1470        t1 = t1->nextOf()->mutableOf()->constOf()->arrayOf(); 
     1471 
     1472    if (t2->ty == Tpointer) 
     1473        t2 = t2->nextOf()->mutableOf()->constOf()->pointerTo(); 
     1474    else 
     1475        t2 = t2->nextOf()->mutableOf()->constOf()->arrayOf(); 
     1476    t = t1; 
     1477    goto Lagain; 
     1478    } 
     1479    else if (t1->ty == Tclass || t2->ty == Tclass) 
     1480    { 
     1481    while (1) 
     1482    { 
     1483        int i1 = e2->implicitConvTo(t1); 
     1484        int i2 = e1->implicitConvTo(t2); 
     1485 
     1486        if (i1 && i2) 
     1487        { 
     1488        // We have the case of class vs. void*, so pick class 
     1489        if (t1->ty == Tpointer) 
     1490            i1 = 0; 
     1491        else if (t2->ty == Tpointer) 
     1492            i2 = 0; 
     1493        } 
     1494 
     1495        if (i2) 
     1496        { 
     1497        goto Lt2; 
     1498        } 
     1499        else if (i1) 
     1500        { 
     1501        goto Lt1; 
     1502        } 
     1503        else if (t1->ty == Tclass && t2->ty == Tclass) 
     1504        {   TypeClass *tc1 = (TypeClass *)t1; 
     1505        TypeClass *tc2 = (TypeClass *)t2; 
     1506 
     1507        /* Pick 'tightest' type 
     1508         */ 
     1509        ClassDeclaration *cd1 = tc1->sym->baseClass; 
     1510        ClassDeclaration *cd2 = tc2->sym->baseClass; 
     1511 
     1512        if (cd1 && cd2) 
     1513        {   t1 = cd1->type; 
     1514            t2 = cd2->type; 
     1515        } 
     1516        else if (cd1) 
     1517            t1 = cd1->type; 
     1518        else if (cd2) 
     1519            t2 = cd2->type; 
     1520        else 
     1521            goto Lincompatible; 
     1522        } 
     1523        else 
     1524        goto Lincompatible; 
     1525    } 
     1526    } 
     1527    else if (t1->ty == Tstruct && t2->ty == Tstruct) 
     1528    { 
     1529    if (((TypeStruct *)t1)->sym != ((TypeStruct *)t2)->sym) 
     1530        goto Lincompatible; 
     1531    } 
     1532    else if ((e1->op == TOKstring || e1->op == TOKnull) && e1->implicitConvTo(t2)) 
     1533    { 
     1534    goto Lt2; 
     1535    } 
     1536    else if ((e2->op == TOKstring || e2->op == TOKnull) && e2->implicitConvTo(t1)) 
     1537    { 
     1538    goto Lt1; 
     1539    } 
     1540    else if (t1->ty == Tsarray && t2->ty == Tsarray && 
     1541         e2->implicitConvTo(t1->nextOf()->arrayOf())) 
     1542    { 
     1543     Lx1: 
     1544    t = t1->nextOf()->arrayOf(); 
     1545    e1 = e1->castTo(sc, t); 
     1546    e2 = e2->castTo(sc, t); 
     1547    } 
     1548    else if (t1->ty == Tsarray && t2->ty == Tsarray && 
     1549         e1->implicitConvTo(t2->nextOf()->arrayOf())) 
     1550    { 
     1551     Lx2: 
     1552    t = t2->nextOf()->arrayOf(); 
     1553    e1 = e1->castTo(sc, t); 
     1554    e2 = e2->castTo(sc, t); 
     1555    } 
     1556    else if (t1->isintegral() && t2->isintegral()) 
     1557    { 
     1558    assert(0); 
     1559    } 
     1560    else 
     1561    { 
     1562     Lincompatible: 
     1563    return 0; 
     1564    } 
     1565Lret: 
     1566    if (!*pt) 
     1567    *pt = t; 
     1568    *pe1 = e1; 
     1569    *pe2 = e2; 
     1570#if 0 
     1571    printf("-typeMerge() %s\n", toChars()); 
     1572    if (e1->type) printf("\tt1 = %s\n", e1->type->toChars()); 
     1573    if (e2->type) printf("\tt2 = %s\n", e2->type->toChars()); 
     1574    printf("\ttype = %s\n", type->toChars()); 
     1575#endif 
     1576    //dump(0); 
     1577    return 1; 
     1578 
     1579 
     1580Lt1: 
     1581    e2 = e2->castTo(sc, t1); 
     1582    t = t1; 
     1583    goto Lret; 
     1584 
     1585Lt2: 
     1586    e1 = e1->castTo(sc, t2); 
     1587    t = t2; 
     1588    goto Lret; 
     1589} 
     1590 
     1591/************************************ 
     1592 * Bring leaves to common type. 
     1593 */ 
     1594 
     1595Expression *BinExp::typeCombine(Scope *sc) 
     1596{ 
     1597    Type *t1 = e1->type->toBasetype(); 
     1598    Type *t2 = e2->type->toBasetype(); 
    14001599 
    14011600    if (op == TOKcat) 
     
    14191618        else 
    14201619        e2 = e2->castTo(sc, t2); 
    1421         t = t1; 
    1422         goto Lagain; 
    1423     } 
    1424     } 
    1425  
    1426 Lagain: 
    1427     if (t1 == t2) 
    1428     { 
    1429     if ((t1->ty == Tstruct || t1->ty == Tclass) && 
    1430         (op == TOKmin || op == TOKadd)) 
    1431         goto Lincompatible; 
    1432     } 
    1433     else if (t1->ty == Tpointer && t2->ty == Tpointer) 
    1434     { 
    1435     // Bring pointers to compatible type 
    1436     Type *t1n = t1->nextOf(); 
    1437     Type *t2n = t2->nextOf(); 
    1438  
    1439     if (t1n == t2n) 
    1440         ; 
    1441     else if (t1n->ty == Tvoid)  // pointers to void are always compatible 
    1442         t = t2; 
    1443     else if (t2n->ty == Tvoid) 
    1444         ; 
    1445     else if (t1n->mod != t2n->mod) 
    1446     { 
    1447         t1 = t1n->mutableOf()->constOf()->pointerTo(); 
    1448         t2 = t2n->mutableOf()->constOf()->pointerTo(); 
    1449         t = t1; 
    1450         goto Lagain; 
    1451     } 
    1452     else if (t1n->ty == Tclass && t2n->ty == Tclass) 
    1453     {   ClassDeclaration *cd1 = t1n->isClassHandle(); 
    1454         ClassDeclaration *cd2 = t2n->isClassHandle(); 
    1455         int offset; 
    1456  
    1457         if (cd1->isBaseOf(cd2, &offset)) 
    1458         { 
    1459         if (offset) 
    1460             e2 = e2->castTo(sc, t); 
    1461         } 
    1462         else if (cd2->isBaseOf(cd1, &offset)) 
    1463         { 
    1464         t = t2; 
    1465         if (offset) 
    1466             e1 = e1->castTo(sc, t); 
    1467         } 
    1468         else 
    1469         goto Lincompatible; 
    1470     } 
    1471     else 
    1472         goto Lincompatible; 
    1473     } 
    1474     else if ((t1->ty == Tsarray || t1->ty == Tarray) && 
    1475          e2->op == TOKnull && t2->ty == Tpointer && t2->nextOf()->ty == Tvoid) 
    1476     {   /*  (T[n] op void*) 
    1477      *  (T[] op void*) 
    1478      */ 
    1479     goto Lx1; 
    1480     } 
    1481     else if ((t2->ty == Tsarray || t2->ty == Tarray) && 
    1482          e1->op == TOKnull && t1->ty == Tpointer && t1->nextOf()->ty == Tvoid) 
    1483     {   /*  (void* op T[n]) 
    1484      *  (void* op T[]) 
    1485      */ 
    1486     goto Lx2; 
    1487     } 
    1488     else if ((t1->ty == Tsarray || t1->ty == Tarray) && t1->implicitConvTo(t2)) 
    1489     { 
    1490     goto Lt2; 
    1491     } 
    1492     else if ((t2->ty == Tsarray || t2->ty == Tarray) && t2->implicitConvTo(t1)) 
    1493     { 
    1494     goto Lt1; 
    1495     } 
    1496     /* If one is mutable and the other invariant, then retry 
    1497      * with both of them as const 
    1498      */ 
    1499     else if ((t1->ty == Tsarray || t1->ty == Tarray || t1->ty == Tpointer) && 
    1500          (t2->ty == Tsarray || t2->ty == Tarray || t2->ty == Tpointer) && 
    1501          t1->nextOf()->mod != t2->nextOf()->mod 
    1502         ) 
    1503     { 
    1504     if (t1->ty == Tpointer) 
    1505         t1 = t1->nextOf()->mutableOf()->constOf()->pointerTo(); 
    1506     else 
    1507         t1 = t1->nextOf()->mutableOf()->constOf()->arrayOf(); 
    1508  
    1509     if (t2->ty == Tpointer) 
    1510         t2 = t2->nextOf()->mutableOf()->constOf()->pointerTo(); 
    1511     else 
    1512         t2 = t2->nextOf()->mutableOf()->constOf()->arrayOf(); 
    1513     t = t1; 
    1514     goto Lagain; 
    1515     } 
    1516     else if (t1->ty == Tclass || t2->ty == Tclass) 
    1517     {   int i1; 
    1518     int i2; 
    1519  
    1520     i1 = e2->implicitConvTo(t1); 
    1521     i2 = e1->implicitConvTo(t2); 
    1522  
    1523     if (i1 && i2) 
    1524     { 
    1525         // We have the case of class vs. void*, so pick class 
    1526         if (t1->ty == Tpointer) 
    1527         i1 = 0; 
    1528         else if (t2->ty == Tpointer) 
    1529         i2 = 0; 
    1530     } 
    1531  
    1532     if (i2) 
    1533     { 
    1534         goto Lt2; 
    1535     } 
    1536     else if (i1) 
    1537     { 
    1538         goto Lt1; 
    1539     } 
    1540     else 
    1541         goto Lincompatible; 
    1542     } 
    1543     else if (t1->ty == Tstruct && t2->ty == Tstruct) 
    1544     { 
    1545     if (((TypeStruct *)t1)->sym != ((TypeStruct *)t2)->sym) 
    1546         goto Lincompatible; 
    1547     } 
    1548     else if ((e1->op == TOKstring || e1->op == TOKnull) && e1->implicitConvTo(t2)) 
    1549     { 
    1550     goto Lt2; 
    1551     } 
    1552     else if ((e2->op == TOKstring || e2->op == TOKnull) && e2->implicitConvTo(t1)) 
    1553     { 
    1554     goto Lt1; 
    1555     } 
    1556     else if (t1->ty == Tsarray && t2->ty == Tsarray && 
    1557          e2->implicitConvTo(t1->nextOf()->arrayOf())) 
    1558     { 
    1559      Lx1: 
    1560     t = t1->nextOf()->arrayOf(); 
    1561     e1 = e1->castTo(sc, t); 
    1562     e2 = e2->castTo(sc, t); 
    1563     } 
    1564     else if (t1->ty == Tsarray && t2->ty == Tsarray && 
    1565          e1->implicitConvTo(t2->nextOf()->arrayOf())) 
    1566     { 
    1567      Lx2: 
    1568     t = t2->nextOf()->arrayOf(); 
    1569     e1 = e1->castTo(sc, t); 
    1570     e2 = e2->castTo(sc, t); 
    1571     } 
    1572     else if (t1->isintegral() && t2->isintegral()) 
    1573     { 
    1574     assert(0); 
    1575     } 
    1576     else 
    1577     { 
    1578      Lincompatible: 
    1579     incompatibleTypes(); 
    1580     } 
    1581 Lret: 
    1582     if (!type) 
    1583     type = t; 
    1584 #if 0 
    1585     printf("-BinExp::typeCombine() %s\n", toChars()); 
    1586     if (e1->type) printf("\tt1 = %s\n", e1->type->toChars()); 
    1587     if (e2->type) printf("\tt2 = %s\n", e2->type->toChars()); 
    1588     printf("\ttype = %s\n", type->toChars()); 
    1589 #endif 
    1590     //dump(0); 
     1620    } 
     1621    } 
     1622    else if (op == TOKmin || op == TOKadd) 
     1623    { 
     1624    if (t1 == t2 && (t1->ty == Tstruct || t1->ty == Tclass)) 
     1625        goto Lerror; 
     1626    } 
     1627 
     1628    if (!typeMerge(sc, &type, &e1, &e2)) 
     1629    goto Lerror; 
    15911630    return this; 
    15921631 
    1593  
    1594 Lt1: 
    1595     e2 = e2->castTo(sc, t1); 
    1596     t = t1; 
    1597     goto Lret; 
    1598  
    1599 Lt2: 
    1600     e1 = e1->castTo(sc, t2); 
    1601     t = t2; 
    1602     goto Lret; 
     1632Lerror: 
     1633    incompatibleTypes(); 
     1634    type = Type::terror; 
     1635    return this; 
    16031636} 
    16041637 
  • trunk/rebuild/class.c

    r884 r903  
    187187    isnested = 0; 
    188188    vthis = NULL; 
     189    inuse = 0; 
    189190} 
    190191 
     
    530531    sc = sc->push(this); 
    531532    sc->stc &= ~(STCfinal | STCauto | STCscope | STCstatic | 
    532          STCabstract | STCdeprecated | STCconst | STCinvariant); 
     533         STCabstract | STCdeprecated | STCconst | STCinvariant | STCtls); 
    533534    sc->stc |= storage_class & (STCconst | STCinvariant); 
    534535    sc->parent = this; 
     
    575576    scope->module->addDeferredSemantic(this); 
    576577 
    577     //printf("\tsemantic('%s') failed\n", toChars()); 
     578    //printf("\tsemantic('%s') failed due to forward references\n", toChars()); 
    578579    return; 
    579580    } 
     
    815816int ClassDeclaration::isFuncHidden(FuncDeclaration *fd) 
    816817{ 
    817     //printf("ClassDeclaration::isFuncHidden(%s)\n", fd->toChars()); 
     818    //printf("ClassDeclaration::isFuncHidden(class = %s, fd = %s)\n", toChars(), fd->toChars()); 
    818819    Dsymbol *s = search(0, fd->ident, 4|2); 
    819820    if (!s) 
     
    10141015 
    10151016    //printf("InterfaceDeclaration::semantic(%s), type = %p\n", toChars(), type); 
     1017    if (inuse) 
     1018    return; 
    10161019    if (!scope) 
    10171020    {   type = type->semantic(loc, sc); 
     
    11011104        continue; 
    11021105        } 
    1103         if (!b->base->symtab || b->base->scope
     1106        if (!b->base->symtab || b->base->scope || b->base->inuse
    11041107        { 
    11051108        //error("forward reference of base class %s", baseClass->toChars()); 
     
    11681171    sc = sc->push(this); 
    11691172    sc->stc &= ~(STCfinal | STCauto | STCscope | STCstatic | 
    1170                  STCabstract | STCdeprecated | STCconst | STCinvariant); 
     1173                 STCabstract | STCdeprecated | STCconst | STCinvariant | STCtls); 
    11711174    sc->stc |= storage_class & (STCconst | STCinvariant); 
    11721175    sc->parent = this; 
     
    11781181    structalign = sc->structalign; 
    11791182    sc->offset = 8; 
     1183    inuse++; 
    11801184    for (i = 0; i < members->dim; i++) 
    11811185    { 
     
    11831187    s->semantic(sc); 
    11841188    } 
     1189    inuse--; 
    11851190    //members->print(); 
    11861191    sc->pop(); 
  • trunk/rebuild/constfold.c

    r884 r903  
    11001100    return expType(to, e1); 
    11011101 
     1102    Type *tb = to->toBasetype(); 
     1103    Type *typeb = type->toBasetype(); 
     1104 
     1105    if (e1->op == TOKstring) 
     1106    { 
     1107    if (tb->ty == Tarray && typeb->ty == Tarray && 
     1108        tb->nextOf()->size() == typeb->nextOf()->size()) 
     1109    { 
     1110        return expType(to, e1); 
     1111    } 
     1112    } 
     1113 
    11021114    if (e1->isConst() != 1) 
    11031115    return EXP_CANT_INTERPRET; 
    11041116 
    1105     Type *tb = to->toBasetype(); 
    11061117    if (tb->ty == Tbool) 
    11071118    e = new IntegerExp(loc, e1->toInteger() != 0, type); 
     
    11121123        real_t r = e1->toReal(); 
    11131124 
    1114         switch (type->toBasetype()->ty) 
     1125        switch (typeb->ty) 
    11151126        { 
    11161127        case Tin