Changeset 251

Show
Ignore:
Timestamp:
11/18/09 01:54:37 (10 months ago)
Author:
walter
Message:

bugzilla 111

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/dmd-1.x/src/backend/rtlsym.h

    r190 r251  
    9191SYMBOL_MARS(FATEXIT,       FLfunc,FREGSAVED,"_fatexit", 0, t) \ 
    9292SYMBOL_MARS(ARRAYCATT,     FLfunc,FREGSAVED,"_d_arraycatT", 0, t) \ 
    9393SYMBOL_MARS(ARRAYCATNT,    FLfunc,FREGSAVED,"_d_arraycatnT", 0, t) \ 
    9494SYMBOL_MARS(ARRAYAPPENDT,  FLfunc,FREGSAVED,"_d_arrayappendT", 0, t) \ 
    9595SYMBOL_MARS(ARRAYAPPENDCT,  FLfunc,FREGSAVED,"_d_arrayappendcT", 0, t) \ 
     96SYMBOL_MARS(ARRAYAPPENDCD,  FLfunc,FREGSAVED,"_d_arrayappendcd", 0, t) \ 
     97SYMBOL_MARS(ARRAYAPPENDWD,  FLfunc,FREGSAVED,"_d_arrayappendwd", 0, t) \ 
    9698SYMBOL_MARS(ARRAYSETLENGTHT,FLfunc,FREGSAVED,"_d_arraysetlengthT", 0, t) \ 
    9799SYMBOL_MARS(ARRAYSETLENGTHIT,FLfunc,FREGSAVED,"_d_arraysetlengthiT", 0, t) \ 
    98100SYMBOL_MARS(ARRAYCOPY,     FLfunc,FREGSAVED,"_d_arraycopy", 0, t) \ 
    99101SYMBOL_MARS(ARRAYASSIGN,   FLfunc,FREGSAVED,"_d_arrayassign", 0, t) \ 
    100102SYMBOL_MARS(ARRAYCTOR,     FLfunc,FREGSAVED,"_d_arrayctor", 0, t) \ 
  • branches/dmd-1.x/src/e2ir.c

    r206 r251  
    26292629    //printf("CatAssignExp::toElem('%s')\n", toChars()); 
    26302630    elem *e; 
    26312631    Type *tb1 = e1->type->toBasetype(); 
    26322632    Type *tb2 = e2->type->toBasetype(); 
    26332633 
    2634     if (tb1->ty == Tarray || tb2->ty == Tsarray) 
    2635     {   elem *e1; 
    2636     elem *e2; 
    2637     elem *ep; 
    2638  
    2639     e1 = this->e1->toElem(irs); 
     2634    if (tb1->ty == Tarray && tb2->ty == Tdchar && 
     2635    (tb1->nextOf()->ty == Tchar || tb1->nextOf()->ty == Twchar)) 
     2636    {   // Append dchar to char[] or wchar[] 
     2637 
     2638    elem *e1 = this->e1->toElem(irs); 
    26402639    e1 = el_una(OPaddr, TYnptr, e1); 
    26412640 
    2642     e2 = this->e2->toElem(irs); 
    2643     if (tybasic(e2->Ety) == TYstruct) 
     2641    elem *e2 = this->e2->toElem(irs); 
     2642 
     2643    elem *ep = el_params(e2, e1, NULL); 
     2644    int rtl = (tb1->nextOf()->ty == Tchar) 
     2645        ? RTLSYM_ARRAYAPPENDCD 
     2646        : RTLSYM_ARRAYAPPENDWD; 
     2647    e = el_bin(OPcall, TYdarray, el_var(rtlsym[rtl]), ep); 
     2648    el_setLoc(e,loc); 
     2649    } 
     2650    else if (tb1->ty == Tarray || tb2->ty == Tsarray) 
     2651    { 
     2652    elem *e1 = this->e1->toElem(irs); 
     2653    e1 = el_una(OPaddr, TYnptr, e1); 
     2654 
     2655    elem *e2 = this->e2->toElem(irs); 
     2656    if (tybasic(e2->Ety) == TYstruct || tybasic(e2->Ety) == TYarray) 
    26442657    { 
    26452658        e2 = el_una(OPstrpar, TYstruct, e2); 
    26462659        e2->Enumbytes = e2->E1->Enumbytes; 
    26472660        assert(e2->Enumbytes); 
    26482661    } 
    26492662 
    26502663    Type *tb1n = tb1->nextOf()->toBasetype(); 
    26512664    if ((tb2->ty == Tarray || tb2->ty == Tsarray) && 
    26522665        tb1n->equals(tb2->nextOf()->toBasetype())) 
    26532666    {   // Append array 
    2654 #if 1 
    2655         ep = el_params(e2, e1, this->e1->type->getTypeInfo(NULL)->toElem(irs), NULL); 
     2667        elem *ep = el_params(e2, e1, this->e1->type->getTypeInfo(NULL)->toElem(irs), NULL); 
    26562668        e = el_bin(OPcall, TYdarray, el_var(rtlsym[RTLSYM_ARRAYAPPENDT]), ep); 
    2657 #else 
    2658         ep = el_params(el_long(TYint, tb1n->size()), e2, e1, NULL); 
    2659         e = el_bin(OPcall, TYdarray, el_var(rtlsym[RTLSYM_ARRAYAPPEND]), ep); 
    2660 #endif 
    26612669    } 
    26622670    else 
    26632671    {   // Append element 
    2664 #if 1 
    2665         ep = el_params(e2, e1, this->e1->type->getTypeInfo(NULL)->toElem(irs), NULL); 
     2672        elem *ep = el_params(e2, e1, this->e1->type->getTypeInfo(NULL)->toElem(irs), NULL); 
    26662673        e = el_bin(OPcall, TYdarray, el_var(rtlsym[RTLSYM_ARRAYAPPENDCT]), ep); 
    2667 #else 
    2668         ep = el_params(e2, el_long(TYint, tb1n->size()), e1, NULL); 
    2669         e = el_bin(OPcall, TYdarray, el_var(rtlsym[RTLSYM_ARRAYAPPENDC]), ep); 
    2670 #endif 
    26712674    } 
    26722675    el_setLoc(e,loc); 
    26732676    } 
    26742677    else 
    26752678    assert(0); 
  • branches/dmd-1.x/src/expression.c

    r250 r251  
    83708370    Type *tb1 = e1->type->toBasetype(); 
    83718371    Type *tb2 = e2->type->toBasetype(); 
    83728372 
    83738373    e2->rvalue(); 
    83748374 
     8375    Type *tb1next = tb1->nextOf(); 
     8376 
    83758377    if ((tb1->ty == Tarray) && 
    83768378    (tb2->ty == Tarray || tb2->ty == Tsarray) && 
    8377     e2->implicitConvTo(e1->type) 
    8378     //e1->type->next->equals(e2->type->next) 
     8379    (e2->implicitConvTo(e1->type) 
     8380#if DMDV2 
     8381     || tb2->nextOf()->implicitConvTo(tb1next) 
     8382#endif 
     8383    ) 
    83798384       ) 
    83808385    {   // Append array 
    83818386    e2 = e2->castTo(sc, e1->type); 
    83828387    type = e1->type; 
    83838388    e = this; 
    83848389    } 
    83858390    else if ((tb1->ty == Tarray) && 
    8386     e2->implicitConvTo(tb1->nextOf()
     8391    e2->implicitConvTo(tb1next
    83878392       ) 
    83888393    {   // Append element 
    8389     e2 = e2->castTo(sc, tb1->nextOf()); 
     8394    e2 = e2->castTo(sc, tb1next); 
    83908395    type = e1->type; 
    83918396    e = this; 
    83928397    } 
     8398    else if (tb1->ty == Tarray && 
     8399    (tb1next->ty == Tchar || tb1next->ty == Twchar) && 
     8400    e2->implicitConvTo(Type::tdchar) 
     8401       ) 
     8402    {   // Append dchar to char[] or wchar[] 
     8403    e2 = e2->castTo(sc, Type::tdchar); 
     8404    type = e1->type; 
     8405    e = this; 
     8406 
     8407    /* Do not allow appending wchar to char[] because if wchar happens 
     8408     * to be a surrogate pair, nothing good can result. 
     8409     */ 
     8410    } 
    83938411    else 
    83948412    { 
    83958413    error("cannot append type %s to type %s", tb2->toChars(), tb1->toChars()); 
    8396     type = Type::tint32; 
    8397     e = this; 
     8414    e = new ErrorExp(); 
    83988415    } 
    83998416    return e; 
    84008417} 
    84018418 
    84028419/************************************************************/ 
     
    84138430    e2 = resolveProperties(sc, e2); 
    84148431 
    84158432    e = op_overload(sc); 
    84168433    if (e) 
    84178434    return e; 
     8435 
     8436#if DMDV2 
     8437    if (e1->op == TOKarraylength) 
     8438    { 
     8439    e = ArrayLengthExp::rewriteOpAssign(this); 
     8440    e = e->semantic(sc); 
     8441    return e; 
     8442    } 
     8443#endif 
    84188444 
    84198445    if (e1->op == TOKslice) 
    84208446    {   // T[] -= ... 
    84218447    typeCombine(sc); 
    84228448    type = e1->type; 
     
    84778503    e2 = resolveProperties(sc, e2); 
    84788504 
    84798505    e = op_overload(sc); 
    84808506    if (e) 
    84818507    return e; 
     8508 
     8509#if DMDV2 
     8510    if (e1->op == TOKarraylength) 
     8511    { 
     8512    e = ArrayLengthExp::rewriteOpAssign(this); 
     8513    e = e->semantic(sc); 
     8514    return e; 
     8515    } 
     8516#endif 
    84828517 
    84838518    if (e1->op == TOKslice) 
    84848519    {   // T[] -= ... 
    84858520    typeCombine(sc); 
    84868521    type = e1->type; 
  • trunk/src/backend/rtlsym.h

    r192 r251  
    9191SYMBOL_MARS(FATEXIT,       FLfunc,FREGSAVED,"_fatexit", 0, t) \ 
    9292SYMBOL_MARS(ARRAYCATT,     FLfunc,FREGSAVED,"_d_arraycatT", 0, t) \ 
    9393SYMBOL_MARS(ARRAYCATNT,    FLfunc,FREGSAVED,"_d_arraycatnT", 0, t) \ 
    9494SYMBOL_MARS(ARRAYAPPENDT,  FLfunc,FREGSAVED,"_d_arrayappendT", 0, t) \ 
    9595SYMBOL_MARS(ARRAYAPPENDCT,  FLfunc,FREGSAVED,"_d_arrayappendcT", 0, t) \ 
     96SYMBOL_MARS(ARRAYAPPENDCD,  FLfunc,FREGSAVED,"_d_arrayappendcd", 0, t) \ 
     97SYMBOL_MARS(ARRAYAPPENDWD,  FLfunc,FREGSAVED,"_d_arrayappendwd", 0, t) \ 
    9698SYMBOL_MARS(ARRAYSETLENGTHT,FLfunc,FREGSAVED,"_d_arraysetlengthT", 0, t) \ 
    9799SYMBOL_MARS(ARRAYSETLENGTHIT,FLfunc,FREGSAVED,"_d_arraysetlengthiT", 0, t) \ 
    98100SYMBOL_MARS(ARRAYCOPY,     FLfunc,FREGSAVED,"_d_arraycopy", 0, t) \ 
    99101SYMBOL_MARS(ARRAYASSIGN,   FLfunc,FREGSAVED,"_d_arrayassign", 0, t) \ 
    100102SYMBOL_MARS(ARRAYCTOR,     FLfunc,FREGSAVED,"_d_arrayctor", 0, t) \ 
  • trunk/src/e2ir.c

    r246 r251  
    29132913    //printf("CatAssignExp::toElem('%s')\n", toChars()); 
    29142914    elem *e; 
    29152915    Type *tb1 = e1->type->toBasetype(); 
    29162916    Type *tb2 = e2->type->toBasetype(); 
    29172917 
    2918     if (tb1->ty == Tarray || tb2->ty == Tsarray) 
    2919     {   elem *e1; 
    2920     elem *e2; 
    2921     elem *ep; 
    2922  
    2923     e1 = this->e1->toElem(irs); 
     2918    if (tb1->ty == Tarray && tb2->ty == Tdchar && 
     2919    (tb1->nextOf()->ty == Tchar || tb1->nextOf()->ty == Twchar)) 
     2920    {   // Append dchar to char[] or wchar[] 
     2921 
     2922    elem *e1 = this->e1->toElem(irs); 
    29242923    e1 = el_una(OPaddr, TYnptr, e1); 
    29252924 
    2926     e2 = this->e2->toElem(irs); 
     2925    elem *e2 = this->e2->toElem(irs); 
     2926 
     2927    elem *ep = el_params(e2, e1, NULL); 
     2928    int rtl = (tb1->nextOf()->ty == Tchar) 
     2929        ? RTLSYM_ARRAYAPPENDCD 
     2930        : RTLSYM_ARRAYAPPENDWD; 
     2931    e = el_bin(OPcall, TYdarray, el_var(rtlsym[rtl]), ep); 
     2932    el_setLoc(e,loc); 
     2933    } 
     2934    else if (tb1->ty == Tarray || tb2->ty == Tsarray) 
     2935    { 
     2936    elem *e1 = this->e1->toElem(irs); 
     2937    e1 = el_una(OPaddr, TYnptr, e1); 
     2938 
     2939    elem *e2 = this->e2->toElem(irs); 
    29272940    if (tybasic(e2->Ety) == TYstruct || tybasic(e2->Ety) == TYarray) 
    29282941    { 
    29292942        e2 = el_una(OPstrpar, TYstruct, e2); 
    29302943        e2->Enumbytes = e2->E1->Enumbytes; 
    29312944        assert(e2->Enumbytes); 
     
    29332946 
    29342947    Type *tb1n = tb1->nextOf()->toBasetype(); 
    29352948    if ((tb2->ty == Tarray || tb2->ty == Tsarray) && 
    29362949        tb1n->equals(tb2->nextOf()->toBasetype())) 
    29372950    {   // Append array 
    2938 #if 1 
    2939         ep = el_params(e2, e1, this->e1->type->getTypeInfo(NULL)->toElem(irs), NULL); 
     2951        elem *ep = el_params(e2, e1, this->e1->type->getTypeInfo(NULL)->toElem(irs), NULL); 
    29402952        e = el_bin(OPcall, TYdarray, el_var(rtlsym[RTLSYM_ARRAYAPPENDT]), ep); 
    2941 #else 
    2942         ep = el_params(el_long(TYint, tb1n->size()), e2, e1, NULL); 
    2943         e = el_bin(OPcall, TYdarray, el_var(rtlsym[RTLSYM_ARRAYAPPEND]), ep); 
    2944 #endif 
    29452953    } 
    29462954    else 
    29472955    {   // Append element 
    2948 #if 1 
    2949         ep = el_params(e2, e1, this->e1->type->getTypeInfo(NULL)->toElem(irs), NULL); 
     2956        elem *ep = el_params(e2, e1, this->e1->type->getTypeInfo(NULL)->toElem(irs), NULL); 
    29502957        e = el_bin(OPcall, TYdarray, el_var(rtlsym[RTLSYM_ARRAYAPPENDCT]), ep); 
    2951 #else 
    2952         ep = el_params(e2, el_long(TYint, tb1n->size()), e1, NULL); 
    2953         e = el_bin(OPcall, TYdarray, el_var(rtlsym[RTLSYM_ARRAYAPPENDC]), ep); 
    2954 #endif 
    29552958    } 
    29562959    el_setLoc(e,loc); 
    29572960    } 
    29582961    else 
    29592962    assert(0); 
  • trunk/src/expression.c

    r249 r251  
    454454    } 
    455455} 
    456456 
    457457Expressions *arrayExpressionToCommonType(Scope *sc, Expressions *exps, Type **pt) 
    458458{ 
     459#if DMDV1 
     460    /* The first element sets the type 
     461     */ 
     462    Type *t0 = NULL; 
     463    for (size_t i = 0; i < exps->dim; i++) 
     464    {   Expression *e = (Expression *)exps->data[i]; 
     465 
     466    if (!e->type) 
     467    {   error("%s has no value", e->toChars()); 
     468        e = new ErrorExp(); 
     469    } 
     470    e = resolveProperties(sc, e); 
     471 
     472    if (!t0) 
     473        t0 = e->type; 
     474    else 
     475        e = e->implicitCastTo(sc, t0); 
     476    exps->data[i] = (void *)e; 
     477    } 
     478 
     479    if (!t0) 
     480    t0 = Type::tvoid; 
     481    if (pt) 
     482    *pt = t0; 
     483 
     484    // Eventually, we want to make this copy-on-write 
     485    return exps; 
     486#endif 
     487#if DMDV2 
     488    /* The type is determined by applying ?: to each pair. 
     489     */ 
    459490    IntegerExp integerexp(0); 
    460491    CondExp condexp(0, &integerexp, NULL, NULL); 
    461492 
    462493    Type *t0 = NULL; 
    463494    Expression *e0; 
    464495    int j0; 
    465     for (int i = 0; i < exps->dim; i++) 
     496    for (size_t i = 0; i < exps->dim; i++) 
    466497    {   Expression *e = (Expression *)exps->data[i]; 
    467498 
    468499    e = resolveProperties(sc, e); 
    469500    if (!e->type) 
    470501    {   error("%s has no value", e->toChars()); 
     
    494525    exps->data[i] = (void *)e; 
    495526    } 
    496527 
    497528    if (t0) 
    498529    { 
    499     for (int i = 0; i < exps->dim; i++) 
     530    for (size_t i = 0; i < exps->dim; i++) 
    500531    {   Expression *e = (Expression *)exps->data[i]; 
    501532        e = e->implicitCastTo(sc, t0); 
    502533        exps->data[i] = (void *)e; 
    503534    } 
    504535    } 
     
    507538    if (pt) 
    508539    *pt = t0; 
    509540 
    510541    // Eventually, we want to make this copy-on-write 
    511542    return exps; 
     543#endif 
    512544} 
    513545 
    514546/**************************************** 
    515547 * Preprocess arguments to function. 
    516548 */ 
     
    88888920    Type *tb1 = e1->type->toBasetype(); 
    88898921    Type *tb2 = e2->type->toBasetype(); 
    88908922 
    88918923    e2->rvalue(); 
    88928924 
     8925    Type *tb1next = tb1->nextOf(); 
     8926 
    88938927    if ((tb1->ty == Tarray) && 
    88948928    (tb2->ty == Tarray || tb2->ty == Tsarray) && 
    8895     (e2->implicitConvTo(e1->type) || 
    8896      tb2->nextOf()->implicitConvTo(tb1->nextOf())) 
     8929    (e2->implicitConvTo(e1->type) 
     8930#if DMDV2 
     8931     || tb2->nextOf()->implicitConvTo(tb1next) 
     8932#endif 
     8933    ) 
    88978934       ) 
    88988935    {   // Append array 
    88998936    e2 = e2->castTo(sc, e1->type); 
    89008937    type = e1->type; 
    89018938    e = this; 
    89028939    } 
    89038940    else if ((tb1->ty == Tarray) && 
    8904     e2->implicitConvTo(tb1->nextOf()
     8941    e2->implicitConvTo(tb1next
    89058942       ) 
    89068943    {   // Append element 
    8907     e2 = e2->castTo(sc, tb1->nextOf()); 
     8944    e2 = e2->castTo(sc, tb1next); 
    89088945    type = e1->type; 
    89098946    e = this; 
    89108947    } 
     8948    else if (tb1->ty == Tarray && 
     8949    (tb1next->ty == Tchar || tb1next->ty == Twchar) && 
     8950    e2->implicitConvTo(Type::tdchar) 
     8951       ) 
     8952    {   // Append dchar to char[] or wchar[] 
     8953    e2 = e2->castTo(sc, Type::tdchar); 
     8954    type = e1->type; 
     8955    e = this; 
     8956 
     8957    /* Do not allow appending wchar to char[] because if wchar happens 
     8958     * to be a surrogate pair, nothing good can result. 
     8959     */ 
     8960    } 
    89118961    else 
    89128962    { 
    89138963    error("cannot append type %s to type %s", tb2->toChars(), tb1->toChars()); 
    8914     type = Type::tint32; 
    8915     e = this; 
     8964    e = new ErrorExp(); 
    89168965    } 
    89178966    return e; 
    89188967} 
    89198968 
    89208969/************************************************************/ 
     
    89328981 
    89338982    e = op_overload(sc); 
    89348983    if (e) 
    89358984    return e; 
    89368985 
     8986#if DMDV2 
    89378987    if (e1->op == TOKarraylength) 
    89388988    { 
    89398989    e = ArrayLengthExp::rewriteOpAssign(this); 
    89408990    e = e->semantic(sc); 
    89418991    return e; 
    89428992    } 
     8993#endif 
    89438994 
    89448995    if (e1->op == TOKslice) 
    89458996    {   // T[] -= ... 
    89468997    typeCombine(sc); 
    89478998    type = e1->type; 
     
    90039054 
    90049055    e = op_overload(sc); 
    90059056    if (e) 
    90069057    return e; 
    90079058 
     9059#if DMDV2 
    90089060    if (e1->op == TOKarraylength) 
    90099061    { 
    90109062    e = ArrayLengthExp::rewriteOpAssign(this); 
    90119063    e = e->semantic(sc); 
    90129064    return e; 
    90139065    } 
     9066#endif 
    90149067 
    90159068    if (e1->op == TOKslice) 
    90169069    {   // T[] -= ... 
    90179070    typeCombine(sc); 
    90189071    type = e1->type;