Changeset 840

Show
Ignore:
Timestamp:
11/17/07 18:52:40 (10 months ago)
Author:
Gregor
Message:

rebuild/*: Merged dmdfe2 r838 (DMD 2.007)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/docs/ChangeLog

    r831 r840  
    55        - DSSS no longer builds libraries or performs incremental compilation 
    66          with DMD, as neither of these build strategies is supportable. 
     7        - Rebuild: Merged DMD 2.007. 
    78 
    890.73 from 0.72: 
  • trunk/rebuild/aggregate.h

    r660 r840  
    11 
    22// Compiler implementation of the D programming language 
    3 // Copyright (c) 1999-2006 by Digital Mars 
     3// Copyright (c) 1999-2007 by Digital Mars 
    44// All Rights Reserved 
    55// written by Walter Bright 
     
    149149}; 
    150150 
    151 #define CLASSINFO_SIZE  (0x3C+12) // value of ClassInfo.size 
     151#define CLASSINFO_SIZE  (0x3C+16) // value of ClassInfo.size 
    152152 
    153153struct ClassDeclaration : AggregateDeclaration 
     
    176176 
    177177    ClassInfoDeclaration *vclassinfo;   // the ClassInfo object for this ClassDeclaration 
    178     int com;                // !=0 if this is a COM class 
     178    int com;                // !=0 if this is a COM class (meaning 
     179                    // it derives from IUnknown) 
    179180    int isauto;             // !=0 if this is an auto class 
    180181    int isabstract;         // !=0 if abstract class 
     
    193194 
    194195    Dsymbol *search(Loc, Identifier *ident, int flags); 
     196    int isFuncHidden(FuncDeclaration *fd); 
    195197    FuncDeclaration *findFunc(Identifier *ident, TypeFunction *tf); 
    196198    void interfaceSemantic(Scope *sc); 
    197199    int isNested(); 
    198200    int isCOMclass(); 
     201    virtual int isCOMinterface(); 
     202    virtual int isCPPinterface(); 
    199203    int isAbstract(); 
    200204    virtual int vtblOffset(); 
     
    220224struct InterfaceDeclaration : ClassDeclaration 
    221225{ 
     226    int cpp;                // !=0 if this is a C++ interface 
     227 
    222228    InterfaceDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses); 
    223229    Dsymbol *syntaxCopy(Dsymbol *s); 
     
    227233    char *kind(); 
    228234    int vtblOffset(); 
     235    int isCPPinterface(); 
     236    virtual int isCOMinterface(); 
    229237 
    230238    InterfaceDeclaration *isInterfaceDeclaration() { return this; } 
  • trunk/rebuild/cast.c

    r785 r840  
    9696    toChars(), type->toChars(), t->toChars()); 
    9797#endif 
     98    //static int nest; if (++nest == 10) halt(); 
    9899    if (!type) 
    99100    {   //error("%s is not an expression", toChars()); 
     
    101102    } 
    102103    Expression *e = optimize(WANTvalue | WANTflags); 
     104    if (e->type == t) 
     105    return MATCHexact; 
    103106    if (e != this) 
    104     {   //printf("optimzed to %s\n", e->toChars()); 
     107    {   //printf("optimized to %s\n", e->toChars()); 
    105108    return e->implicitConvTo(t); 
    106109    } 
     
    481484    { 
    482485    // Look for pointers to functions where the functions are overloaded. 
    483     VarExp *ve; 
    484     FuncDeclaration *f; 
    485486 
    486487    t = t->toBasetype(); 
     488 
     489    if (e1->op == TOKoverloadset && 
     490        (t->ty == Tpointer || t->ty == Tdelegate) && t->nextOf()->ty == Tfunction) 
     491    {   OverExp *eo = (OverExp *)e1; 
     492        FuncDeclaration *f = NULL; 
     493        for (int i = 0; i < eo->vars->a.dim; i++) 
     494        {   Dsymbol *s = (Dsymbol *)eo->vars->a.data[i]; 
     495        FuncDeclaration *f2 = s->isFuncDeclaration(); 
     496        assert(f2); 
     497        if (f2->overloadExactMatch(t->nextOf())) 
     498        {   if (f) 
     499            /* Error if match in more than one overload set, 
     500             * even if one is a 'better' match than the other. 
     501             */ 
     502            ScopeDsymbol::multiplyDefined(loc, f, f2); 
     503            else 
     504            f = f2; 
     505            result = MATCHexact; 
     506        } 
     507        } 
     508    } 
     509 
    487510    if (type->ty == Tpointer && type->nextOf()->ty == Tfunction && 
    488511        t->ty == Tpointer && t->nextOf()->ty == Tfunction && 
     
    494517         */ 
    495518        assert(0); 
    496         ve = (VarExp *)e1; 
    497         f = ve->var->isFuncDeclaration(); 
     519        VarExp *ve = (VarExp *)e1; 
     520        FuncDeclaration *f = ve->var->isFuncDeclaration(); 
    498521        if (f && f->overloadExactMatch(t->nextOf())) 
    499522        result = MATCHexact; 
     
    593616    toChars(), type->toChars(), t->toChars()); 
    594617#endif 
     618    if (type == t) 
     619    return this; 
    595620    e = this; 
    596621    tb = t->toBasetype(); 
     
    693718Expression *StringExp::castTo(Scope *sc, Type *t) 
    694719{ 
     720    /* This follows copy-on-write; any changes to 'this' 
     721     * will result in a copy. 
     722     * The this->string member is considered immutable. 
     723     */ 
    695724    StringExp *se; 
    696725    Type *tb; 
    697     int unique
     726    int copied = 0
    698727 
    699728    //printf("StringExp::castTo(t = %s), '%s' committed = %d\n", t->toChars(), toChars(), committed); 
     
    703732    error("cannot convert string literal to void*"); 
    704733    } */ 
     734 
     735    se = this; 
     736    if (!committed) 
     737    {   se = (StringExp *)copy(); 
     738    se->committed = 1; 
     739    copied = 1; 
     740    } 
     741 
     742    if (type == t) 
     743    { 
     744    return se; 
     745    } 
    705746 
    706747    tb = t->toBasetype(); 
     
    709750    return Expression::castTo(sc, t); 
    710751 
    711     se = this; 
    712     unique = 0; 
    713     if (!committed) 
    714     { 
    715     // Copy when committing the type 
    716     void *s; 
    717  
    718     s = (unsigned char *)mem.malloc((len + 1) * sz); 
    719     memcpy(s, string, (len + 1) * sz); 
    720     se = new StringExp(loc, s, len); 
    721     se->type = type; 
    722     se->sz = sz; 
    723     se->committed = 0; 
    724     unique = 1;     // this is the only instance 
    725     } 
    726     se->type = type->toBasetype(); 
    727     if (tb == se->type) 
    728     {   se->type = t; 
    729     se->committed = 1; 
     752    Type *typeb = type->toBasetype(); 
     753    if (typeb == tb) 
     754    { 
     755    if (!copied) 
     756    {   se = (StringExp *)copy(); 
     757        copied = 1; 
     758    } 
     759    se->type = t; 
    730760    return se; 
    731761    } 
    732762 
    733763    if (tb->ty != Tsarray && tb->ty != Tarray && tb->ty != Tpointer) 
    734     {   se->committed = 1; 
     764    {   if (!copied) 
     765    {   se = (StringExp *)copy(); 
     766        copied = 1; 
     767    } 
    735768    goto Lcast; 
    736769    } 
    737     if (se->type->ty != Tsarray && se->type->ty != Tarray && se->type->ty != Tpointer) 
    738     {   se->committed = 1; 
     770    if (typeb->ty != Tsarray && typeb->ty != Tarray && typeb->ty != Tpointer) 
     771    {   if (!copied) 
     772    {   se = (StringExp *)copy(); 
     773        copied = 1; 
     774    } 
    739775    goto Lcast; 
    740776    } 
    741777 
    742     if (se->committed == 1) 
    743     { 
    744     if (se->type->nextOf()->size() == tb->nextOf()->size()) 
    745     {   se->type = t; 
    746         return se; 
    747     } 
     778    if (typeb->nextOf()->size() == tb->nextOf()->size()) 
     779    { 
     780    if (!copied) 
     781    {   se = (StringExp *)copy(); 
     782        copied = 1; 
     783    } 
     784    if (tb->ty == Tsarray) 
     785        goto L2;    // handle possible change in static array dimension 
     786    se->type = t; 
     787    return se; 
     788    } 
     789 
     790    if (committed) 
    748791    goto Lcast; 
    749     } 
    750  
    751     se->committed = 1; 
    752  
    753     int tfty; 
    754     int ttty; 
    755     char *p; 
    756     size_t u; 
    757     unsigned c; 
    758     size_t newlen; 
    759792 
    760793#define X(tf,tt)    ((tf) * 256 + (tt)) 
    761794    { 
    762795    OutBuffer buffer; 
    763     newlen = 0; 
    764     tfty = se->type->nextOf()->toBasetype()->ty; 
    765     ttty = tb->nextOf()->toBasetype()->ty; 
     796    size_t newlen = 0; 
     797    int tfty = typeb->nextOf()->toBasetype()->ty; 
     798    int ttty = tb->nextOf()->toBasetype()->ty; 
    766799    switch (X(tfty, ttty)) 
    767800    { 
     
    772805 
    773806    case X(Tchar, Twchar): 
    774         for (u = 0; u < len;) 
    775         { 
    776         p = utf_decodeChar((unsigned char *)se->string, len, &u, &c); 
     807        for (size_t u = 0; u < len;) 
     808        {  unsigned c; 
     809        char *p = utf_decodeChar((unsigned char *)se->string, len, &u, &c); 
    777810        if (p) 
    778811            error("%s", p); 
     
    785818 
    786819    case X(Tchar, Tdchar): 
    787         for (u = 0; u < len;) 
    788         { 
    789         p = utf_decodeChar((unsigned char *)se->string, len, &u, &c); 
     820        for (size_t u = 0; u < len;) 
     821        {  unsigned c; 
     822        char *p = utf_decodeChar((unsigned char *)se->string, len, &u, &c); 
    790823        if (p) 
    791824            error("%s", p); 
     
    797830 
    798831    case X(Twchar,Tchar): 
    799         for (u = 0; u < len;) 
    800         { 
    801         p = utf_decodeWchar((unsigned short *)se->string, len, &u, &c); 
     832        for (size_t u = 0; u < len;) 
     833        {  unsigned c; 
     834        char *p = utf_decodeWchar((unsigned short *)se->string, len, &u, &c); 
    802835        if (p) 
    803836            error("%s", p); 
     
    810843 
    811844    case X(Twchar,Tdchar): 
    812         for (u = 0; u < len;) 
    813         { 
    814         p = utf_decodeWchar((unsigned short *)se->string, len, &u, &c); 
     845        for (size_t u = 0; u < len;) 
     846        {  unsigned c; 
     847        char *p = utf_decodeWchar((unsigned short *)se->string, len, &u, &c); 
    815848        if (p) 
    816849            error("%s", p); 
     
    822855 
    823856    case X(Tdchar,Tchar): 
    824         for (u = 0; u < len; u++) 
    825         { 
    826         c = ((unsigned *)se->string)[u]; 
     857        for (size_t u = 0; u < len; u++) 
     858        { 
     859        unsigned c = ((unsigned *)se->string)[u]; 
    827860        if (!utf_isValidDchar(c)) 
    828861            error("invalid UCS-32 char \\U%08x", c); 
     
    836869 
    837870    case X(Tdchar,Twchar): 
    838         for (u = 0; u < len; u++) 
    839         { 
    840         c = ((unsigned *)se->string)[u]; 
     871        for (size_t u = 0; u < len; u++) 
     872        { 
     873        unsigned c = ((unsigned *)se->string)[u]; 
    841874        if (!utf_isValidDchar(c)) 
    842875            error("invalid UCS-32 char \\U%08x", c); 
     
    850883 
    851884    L1: 
    852         if (!unique) 
    853         se = new StringExp(loc, NULL, 0); 
     885        if (!copied) 
     886        {   se = (StringExp *)copy(); 
     887        copied = 1; 
     888        } 
    854889        se->string = buffer.extractData(); 
    855890        se->len = newlen; 
     
    858893 
    859894    default: 
    860         if (se->type->nextOf()->size() == tb->nextOf()->size()) 
    861         {   se->type = t; 
    862         return se; 
    863         } 
     895        assert(typeb->nextOf()->size() != tb->nextOf()->size()); 
    864896        goto Lcast; 
    865897    } 
    866898    } 
    867899#undef X 
     900L2: 
     901    assert(copied); 
    868902 
    869903    // See if need to truncate or extend the literal 
     
    877911    if (dim2 != se->len) 
    878912    { 
     913        // Copy when changing the string literal 
    879914        unsigned newsz = se->sz; 
    880  
    881         if (unique && dim2 < se->len) 
    882         {   se->len = dim2; 
    883         // Add terminating 0 
    884         memset((unsigned char *)se->string + dim2 * newsz, 0, newsz); 
    885         } 
    886         else 
    887         { 
    888         // Copy when changing the string literal 
    889         void *s; 
    890         int d; 
    891  
    892         d = (dim2 < se->len) ? dim2 : se->len; 
    893         s = (unsigned char *)mem.malloc((dim2 + 1) * newsz); 
    894         memcpy(s, se->string, d * newsz); 
    895         // Extend with 0, add terminating 0 
    896         memset((char *)s + d * newsz, 0, (dim2 + 1 - d) * newsz); 
    897         se = new StringExp(loc, s, dim2); 
    898         se->committed = 1;  // it now has a firm type 
    899         se->sz = newsz; 
    900         } 
     915        void *s; 
     916        int d; 
     917 
     918        d = (dim2 < se->len) ? dim2 : se->len; 
     919        s = (unsigned char *)mem.malloc((dim2 + 1) * newsz); 
     920        memcpy(s, se->string, d * newsz); 
     921        // Extend with 0, add terminating 0 
     922        memset((char *)s + d * newsz, 0, (dim2 + 1 - d) * newsz); 
     923        se->string = s; 
     924        se->len = dim2; 
    901925    } 
    902926    } 
     
    906930Lcast: 
    907931    Expression *e = new CastExp(loc, se, t); 
    908     e->type = t; 
     932    e->type = t;   // so semantic() won't be run on e 
    909933    return e; 
    910934} 
     
    925949    { 
    926950    // Look for pointers to functions where the functions are overloaded. 
    927     VarExp *ve; 
    928     FuncDeclaration *f; 
     951 
     952    if (e1->op == TOKoverloadset && 
     953        (t->ty == Tpointer || t->ty == Tdelegate) && t->nextOf()->ty == Tfunction) 
     954    {   OverExp *eo = (OverExp *)e1; 
     955        FuncDeclaration *f = NULL; 
     956        for (int i = 0; i < eo->vars->a.dim; i++) 
     957        {   Dsymbol *s = (Dsymbol *)eo->vars->a.data[i]; 
     958        FuncDeclaration *f2 = s->isFuncDeclaration(); 
     959        assert(f2); 
     960        if (f2->overloadExactMatch(t->nextOf())) 
     961        {   if (f) 
     962            /* Error if match in more than one overload set, 
     963             * even if one is a 'better' match than the other. 
     964             */ 
     965            ScopeDsymbol::multiplyDefined(loc, f, f2); 
     966            else 
     967            f = f2; 
     968        } 
     969        } 
     970        if (f) 
     971        {   f->tookAddressOf = 1; 
     972        SymOffExp *se = new SymOffExp(loc, f, 0, 0); 
     973        se->semantic(sc); 
     974        // Let SymOffExp::castTo() do the heavy lifting 
     975        return se->castTo(sc, t); 
     976        } 
     977    } 
     978 
    929979 
    930980    if (type->ty == Tpointer && type->nextOf()->ty == Tfunction && 
     
    932982        e1->op == TOKvar) 
    933983    { 
    934         ve = (VarExp *)e1; 
    935         f = ve->var->isFuncDeclaration(); 
     984        VarExp *ve = (VarExp *)e1; 
     985        FuncDeclaration *f = ve->var->isFuncDeclaration(); 
    936986        if (f) 
    937987        { 
     988        assert(0);  // should be SymOffExp instead 
    938989        f = f->overloadExactMatch(tb->nextOf()); 
    939990        if (f) 
     
    9671018Expression *ArrayLiteralExp::castTo(Scope *sc, Type *t) 
    9681019{ 
     1020#if 0 
     1021    printf("ArrayLiteralExp::castTo(this=%s, type=%s, t=%s)\n", 
     1022    toChars(), type->toChars(), t->toChars()); 
     1023#endif 
     1024    if (type == t) 
     1025    return this; 
    9691026    Type *typeb = type->toBasetype(); 
    9701027    Type *tb = t->toBasetype(); 
     
    10611118            e->type = t; 
    10621119            } 
     1120            f->tookAddressOf = 1; 
    10631121            return e; 
    10641122        } 
     
    11021160            if (f->tintro && f->tintro->nextOf()->isBaseOf(f->type->nextOf(), &offset) && offset) 
    11031161            error("%s", msg); 
     1162            f->tookAddressOf = 1; 
    11041163            e = new DelegateExp(loc, e1, f); 
    11051164            e->type = t; 
     
    11151174    {   int offset; 
    11161175 
     1176    func->tookAddressOf = 1; 
    11171177    if (func->tintro && func->tintro->nextOf()->isBaseOf(func->type->nextOf(), &offset) && offset) 
    11181178        error("%s", msg); 
     
    11541214    Type *t = Type::tptrdiff_t; 
    11551215 
    1156     stride = t1b->nextOf()->size(); 
     1216    stride = t1b->nextOf()->size(loc); 
    11571217    if (!t->equals(t2b)) 
    11581218        e2 = e2->castTo(sc, t); 
     
    11671227    Expression *e; 
    11681228 
    1169     stride = t2b->nextOf()->size(); 
     1229    stride = t2b->nextOf()->size(loc); 
    11701230    if (!t->equals(t1b)) 
    11711231        e = e1->castTo(sc, t); 
     
    11921252    TY ty; 
    11931253 
    1194     //printf("BinExp::typeCombine()\n"); 
     1254    //printf("BinExp::typeCombine() %s\n", toChars()); 
    11951255    //dump(0); 
    11961256 
     
    12621322    if ((t1->ty == Tsarray || t1->ty == Tarray) && 
    12631323        (t2->ty == Tsarray || t2->ty == Tarray) && 
    1264         (t1->nextOf()->mod || t2->nextOf()->mod)) 
    1265     { 
    1266         t1 = t1->constOf(); 
    1267         t2 = t2->constOf(); 
     1324        (t1->nextOf()->mod || t2->nextOf()->mod) && 
     1325        (t1->nextOf()->mod != t2->nextOf()->mod) 
     1326       ) 
     1327    { 
     1328        t1 = t1->nextOf()->mutableOf()->constOf()->arrayOf(); 
     1329        t2 = t2->nextOf()->mutableOf()->constOf()->arrayOf(); 
     1330//t1 = t1->constOf(); 
     1331//t2 = t2->constOf(); 
     1332        e1 = e1->castTo(sc, t1); 
     1333        e2 = e2->castTo(sc, t2); 
     1334        goto Lagain; 
    12681335    } 
    12691336    } 
     
    12911358    else if (t1n->mod != t2n->mod) 
    12921359    { 
    1293         t1 = t1->constOf(); 
    1294         t2 = t2->constOf(); 
     1360        t1 = t1n->mutableOf()->constOf()->pointerTo(); 
     1361        t2 = t2n->mutableOf()->constOf()->pointerTo(); 
    12951362        goto Lagain; 
    12961363    } 
     
    13471414        ) 
    13481415    { 
    1349     t1 = t1->constOf(); 
    1350     t2 = t2->constOf(); 
     1416    if (t1->ty == Tpointer) 
     1417        t1 = t1->nextOf()->mutableOf()->constOf()->pointerTo(); 
     1418    else 
     1419        t1 = t1->nextOf()->mutableOf()->constOf()->arrayOf(); 
     1420 
     1421    if (t2->ty == Tpointer) 
     1422        t2 = t2->nextOf()->mutableOf()->constOf()->pointerTo(); 
     1423    else 
     1424        t2 = t2->nextOf()->mutableOf()->constOf()->arrayOf(); 
    13511425    goto Lagain; 
    13521426    } 
     
    14201494    if (!type) 
    14211495    type = t; 
     1496#if 0 
     1497    printf("-BinExp::typeCombine() %s\n", toChars()); 
     1498    if (e1->type) printf("\tt1 = %s\n", e1->type->toChars()); 
     1499    if (e2->type) printf("\tt2 = %s\n", e2->type->toChars()); 
     1500    printf("\ttype = %s\n", type->toChars()); 
     1501#endif 
    14221502    //dump(0); 
    14231503    return this; 
  • trunk/rebuild/class.c

    r785 r840  
    11 
    22// Compiler implementation of the D programming language 
    3 // Copyright (c) 1999-2006 by Digital Mars 
     3// Copyright (c) 1999-2007 by Digital Mars 
    44// All Rights Reserved 
    55// written by Walter Bright 
     
    148148        } 
    149149 
     150#if V2 
    150151        if (id == Id::TypeInfo_Const) 
    151152        {   if (Type::typeinfoconst) 
     
    159160        Type::typeinfoinvariant = this; 
    160161        } 
     162#endif 
    161163    } 
    162164 
     
    181183 
    182184    com = 0; 
    183 #if 0 
    184     if (id == Id::IUnknown)     // IUnknown is the root of all COM objects 
    185     com = 1; 
    186 #endif 
    187185    isauto = 0; 
    188186    isabstract = 0; 
     
    261259    methods.setDim(0); 
    262260#endif 
     261 
     262    if (sc->stc & STCdeprecated) 
     263    { 
     264    isdeprecated = 1; 
     265    } 
     266 
     267    if (sc->linkage == LINKcpp) 
     268    error("cannot create C++ classes"); 
    263269 
    264270    // Expand any tuples in baseclasses[] 
     
    299305    { 
    300306        tc = (TypeClass *)(tb); 
     307 
     308        if (tc->sym->isDeprecated()) 
     309        { 
     310        if (!isDeprecated()) 
     311        { 
     312            // Deriving from deprecated class makes this one deprecated too 
     313            isdeprecated = 1; 
     314 
     315            tc->checkDeprecated(loc, sc); 
     316        } 
     317        } 
     318 
    301319        if (tc->sym->isInterfaceDeclaration()) 
    302320        ; 
     
    353371    else 
    354372    { 
     373        if (tc->sym->isDeprecated()) 
     374        { 
     375        if (!isDeprecated()) 
     376        { 
     377            // Deriving from deprecated class makes this one deprecated too 
     378            isdeprecated = 1; 
     379 
     380            tc->checkDeprecated(loc, sc); 
     381        } 
     382        } 
     383 
    355384        // Check for duplicate interfaces 
    356385        for (size_t j = (baseClass ? 1 : 0); j < i; j++) 
     
    493522    if (storage_class & STCabstract) 
    494523    isabstract = 1; 
    495     if (storage_class & STCdeprecated) 
    496     isdeprecated = 1; 
    497524 
    498525    sc = sc->push(this); 
     
    767794} 
    768795 
     796/********************************************************** 
     797 * fd is in the vtbl[] for this class. 
     798 * Return 1 if function is hidden (not findable through search). 
     799 */ 
     800 
     801#if V2 
     802int isf(void *param, FuncDeclaration *fd) 
     803{ 
     804    //printf("param = %p, fd = %p %s\n", param, fd, fd->toChars()); 
     805    return param == fd; 
     806} 
     807 
     808int ClassDeclaration::isFuncHidden(FuncDeclaration *fd) 
     809{ 
     810    //printf("ClassDeclaration::isFuncHidden(%s)\n", fd->toChars()); 
     811    Dsymbol *s = search(0, fd->ident, 4|2); 
     812    if (!s) 
     813    {   //printf("not found\n"); 
     814    /* Because, due to a hack, if there are multiple definitions 
     815     * of fd->ident, NULL is returned. 
     816     */ 
     817    return 0; 
     818    } 
     819    s = s->toAlias(); 
     820    OverloadSet *os = s->isOverloadSet(); 
     821    if (os) 
     822    { 
     823    for (int i = 0; i < os->a.dim; i++) 
     824    {   Dsymbol *s = (Dsymbol *)os->a.data[i]; 
     825        FuncDeclaration *f2 = s->isFuncDeclaration(); 
     826        if (f2 && overloadApply(f2, &isf, fd)) 
     827        return 0; 
     828    } 
     829    return 1; 
     830    } 
     831    else 
     832    { 
     833    FuncDeclaration *fdstart = s->isFuncDeclaration(); 
     834    //printf("%s fdstart = %p\n", s->kind(), fdstart); 
     835    return !overloadApply(fdstart, &isf, fd); 
     836    } 
     837} 
     838#endif 
     839 
    769840/**************** 
    770841 * Find virtual function matching identifier and type. 
     
    804875 
    805876void ClassDeclaration::interfaceSemantic(Scope *sc) 
    806 {   int i; 
     877
     878    InterfaceDeclaration *id = isInterfaceDeclaration(); 
    807879 
    808880    vtblInterfaces = new BaseClasses(); 
    809881    vtblInterfaces->reserve(interfaces_dim); 
    810882 
    811     for (i = 0; i < interfaces_dim; i++) 
     883    for (size_t i = 0; i < interfaces_dim; i++) 
    812884    { 
    813885    BaseClass *b = interfaces[i]; 
     
    815887    // If this is an interface, and it derives from a COM interface, 
    816888    // then this is a COM interface too. 
    817     if (b->base->isCOMclass()) 
     889    if (b->base->isCOMinterface()) 
    818890        com = 1; 
     891 
     892    if (b->base->isCPPinterface() && id) 
     893        id->cpp = 1; 
    819894 
    820895    vtblInterfaces->push(b); 
     
    829904{ 
    830905    return com; 
     906} 
     907 
     908int ClassDeclaration::isCOMinterface() 
     909{ 
     910    return 0; 
     911} 
     912 
     913int ClassDeclaration::isCPPinterface() 
     914{ 
     915    return 0; 
    831916} 
    832917 
     
    897982{ 
    898983    com = 0; 
    899     if (id == Id::IUnknown)     // IUnknown is the root of all COM objects 
    900     com = 1; 
     984    cpp = 0; 
     985    if (id == Id::IUnknown) // IUnknown is the root of all COM interfaces 
     986    {   com = 1; 
     987    cpp = 1;        // IUnknown is also a C++ interface 
     988    } 
    901989} 
    902990 
     
    9381026    scx = scope;        // save so we don't make redundant copies 
    9391027    scope = NULL; 
     1028    } 
     1029 
     1030    if (sc->stc & STCdeprecated) 
     1031    { 
     1032    isdeprecated = 1; 
    9401033    } 
    9411034 
     
    9611054    } 
    9621055 
     1056    if (!baseclasses.dim && sc->linkage == LINKcpp) 
     1057    cpp = 1; 
     1058 
    9631059    // Check for errors, handle forward references 
    9641060    for (i = 0; i < baseclasses.dim; ) 
     
    10571153    sc = sc->push(this); 
    10581154    sc->parent = this; 
    1059     if (isCOMclass()) 
     1155    if (isCOMinterface()) 
    10601156    sc->linkage = LINKwindows; 
     1157    else if (isCPPinterface()) 
     1158    sc->linkage = LINKcpp; 
    10611159    sc->structalign = 8; 
    10621160    structalign = sc->structalign; 
     
    11471245/**************************************** 
    11481246 * Determine if slot 0 of the vtbl[] is reserved for something else. 
    1149  * For class objects, yes, this is where the classinfo ptr goes. 
     1247 * For class objects, yes, this is where the ClassInfo ptr goes. 
    11501248 * For COM interfaces, no. 
    11511249 * For non-COM interfaces, yes, this is where the Interface ptr goes. 
     
    11541252int InterfaceDeclaration::vtblOffset() 
    11551253{ 
    1156     if (isCOMclass()) 
     1254    if (isCOMinterface() || isCPPinterface()) 
    11571255    return 0; 
    11581256    return 1; 
     1257} 
     1258 
     1259int InterfaceDeclaration::isCOMinterface() 
     1260{ 
     1261    return com; 
     1262} 
     1263 
     1264int InterfaceDeclaration::isCPPinterface() 
     1265{ 
     1266    return cpp; 
    11591267} 
    11601268 
  • trunk/rebuild/constfold.c

    r785 r840  
    690690    assert(op == TOKequal || op == TOKnotequal); 
    691691 
    692     if (e1->op == TOKstring && e2->op == TOKstring) 
     692    if (e1->op == TOKnull) 
     693    { 
     694    if (e2->op == TOKnull) 
     695        cmp = 1; 
     696    else if (e2->op == TOKstring) 
     697    {   StringExp *es2 = (StringExp *)e2; 
     698        cmp = (0 == es2->len); 
     699    } 
     700    else if (e2->op == TOKarrayliteral) 
     701    {   ArrayLiteralExp *es2 = (ArrayLiteralExp *)e2; 
     702        cmp = !es2->elements || (0 == es2->elements->dim); 
     703    } 
     704    else 
     705        return EXP_CANT_INTERPRET; 
     706    } 
     707    else if (e2->op == TOKnull) 
     708    { 
     709    if (e1->op == TOKstring) 
     710    {   StringExp *es1 = (StringExp *)e1; 
     711        cmp = (0 == es1->len); 
     712    } 
     713    else if (e1->op == TOKarrayliteral) 
     714    {   ArrayLiteralExp *es1 = (ArrayLiteralExp *)e1; 
     715        cmp = !es1->elements || (0 == es1->elements->dim); 
     716    } 
     717    else 
     718        return EXP_CANT_INTERPRET; 
     719    } 
     720    else if (e1->op == TOKstring && e2->op == TOKstring) 
    693721    {   StringExp *es1 = (StringExp *)e1; 
    694722    StringExp *es2 = (StringExp *)e2; 
     
    722750            return EXP_CANT_INTERPRET; 
    723751        cmp = v->toInteger(); 
     752        if (cmp == 0) 
     753            break; 
     754        } 
     755    } 
     756    } 
     757    else if (e1->op == TOKarrayliteral && e2->op == TOKstring) 
     758    {   // Swap operands and use common code 
     759    Expression *e = e1; 
     760    e1 = e2; 
     761    e2 = e; 
     762    goto Lsa; 
     763    } 
     764    else if (e1->op == TOKstring && e2->op == TOKarrayliteral) 
     765    { 
     766     Lsa: 
     767    StringExp *es1 = (StringExp *)e1; 
     768    ArrayLiteralExp *es2 = (ArrayLiteralExp *)e2; 
     769    size_t dim1 = es1->len; 
     770    size_t dim2 = es2->elements ? es2->elements->dim : 0; 
     771    if (dim1 != dim2) 
     772        cmp = 0; 
     773    else 
     774    { 
     775        for (size_t i = 0; i < dim1; i++) 
     776        { 
     777        uinteger_t c = es1->charAt(i); 
     778        Expression *ee2 = (Expression *)es2->elements->data[i]; 
     779        if (ee2->isConst() != 1) 
     780            return EXP_CANT_INTERPRET; 
     781        cmp = (c == ee2->toInteger()); 
    724782        if (cmp == 0) 
    725783            break; 
     
    814872    int cmp; 
    815873 
    816     if (e1->op == TOKsymoff && e2->op == TOKsymoff) 
     874    if (e1->op == TOKnull && e2->op == TOKnull) 
     875    { 
     876    cmp = 1; 
     877    } 
     878    else if (e1->op == TOKsymoff && e2->op == TOKsymoff) 
    817879    { 
    818880    SymOffExp *es1 = (SymOffExp *)e1; 
     
    10761138    else 
    10771139    { 
    1078     // error("cannot cast %s to %s", e1->type->toChars(), type->toChars()); 
     1140    // error(loc, "cannot cast %s to %s", e1->type->toChars(), type->toChars()); 
    10791141    e = new IntegerExp(loc, 0, type); 
    10801142    } 
     
    11231185 
    11241186    if (i >= es1->len) {} 
    1125         // e1->error("string index %ju is out of bounds [0 .. %zu]", i, es1->len); 
    1126     else 
    1127     {   integer_t value; 
    1128  
    1129         switch (es1->sz) 
    1130         { 
    1131         case 1: 
    1132             value = ((unsigned char *)es1->string)[i]; 
    1133             break; 
    1134  
    1135         case 2: 
    1136             value = ((unsigned short *)es1->string)[i]; 
    1137             break; 
    1138  
    1139         case 4: 
    1140             value = ((unsigned int *)es1->string)[i]; 
    1141             break; 
    1142  
    1143         default: 
    1144             assert(0); 
    1145             break; 
    1146         } 
     1187        // e1->error("string index %ju is out of bounds [0 .. " ZU "]", i, es1->len); 
     1188    else 
     1189    {   unsigned value = es1->charAt(i); 
    11471190        e = new IntegerExp(loc, value, type); 
    11481191    } 
     
    12731316    //printf("\tt1 = %s, t2 = %s\n", t1->toChars(), t2->toChars()); 
    12741317 
    1275     if (e1->op == TOKnull && e2->op == TOKint64
     1318    if (e1->op == TOKnull && (e2->op == TOKint64 || e2->op == TOKstructliteral)
    12761319    {   e = e2; 
    12771320    goto L2; 
    12781321    } 
    1279     else if (e1->op == TOKint64 && e2->op == TOKnull) 
     1322    else if ((e1->op == TOKint64 || e1->op == TOKstructliteral) && e2->op == TOKnull) 
    12801323    {   e = e1; 
    12811324     L2: 
  • trunk/rebuild/declaration.c

    r785 r840  
    446446    { 
    447447    // Try to convert Expression to Dsymbol 
    448         if (e->op == TOKvar) 
    449     {   s = ((VarExp *)e)->var; 
     448    s = getDsymbol(e); 
     449    if (s) 
    450450        goto L2; 
    451     } 
    452         else if (e->op == TOKfunction) 
    453     {   s = ((FuncExp *)e)->fd; 
    454         goto L2; 
    455     } 
    456         else 
    457     {   //error("cannot alias an expression %s", e->toChars()); 
    458         t = e->type; 
    459     } 
     451    // error("cannot alias an expression %s", e->toChars()); 
     452    t = e->type; 
    460453    } 
    461454    else if (t) 
     
    595588    offset = 0; 
    596589    noauto = 0; 
    597     nestedref = 0; 
    598590    inuse = 0; 
    599591    ctorinit = 0; 
     
    602594    canassign = 0; 
    603595    value = NULL; 
     596    scope = NULL; 
    604597} 
    605598 
     
    649642{ 
    650643    //printf("VarDeclaration::semantic('%s', parent = '%s')\n", toChars(), sc->parent->toChars()); 
    651     //printf("type = %s\n", type->toChars()); 
     644    //printf(" type = %s\n", type->toChars()); 
     645    //printf("stc = x%x\n", sc->stc); 
    652646    //printf("linkage = %d\n", sc->linkage); 
    653647    //if (strcmp(toChars(), "mul") == 0) halt(); 
     
    747741    } 
    748742 
     743Lagain: 
    749744    if (isConst()) 
    750745    { 
     746    /* Rewrite things like: 
     747</