Changeset 251

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

bugzilla 111

Files:

Legend:

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

    r190 r251  
    7676SYMBOL_MARS(NEWARRAYMT,    FLfunc,FREGSAVED,"_d_newarraymT", 0, t) \ 
    7777SYMBOL_MARS(NEWARRAYMIT,   FLfunc,FREGSAVED,"_d_newarraymiT", 0, t) \ 
    7878SYMBOL_MARS(ARRAYLITERALT, FLfunc,FREGSAVED,"_d_arrayliteralT", 0, t) \ 
    7979SYMBOL_MARS(ASSOCARRAYLITERALT, FLfunc,FREGSAVED,"_d_assocarrayliteralT", 0, t) \ 
    8080SYMBOL_MARS(CALLFINALIZER, FLfunc,FREGSAVED,"_d_callfinalizer", 0, t) \ 
    8181SYMBOL_MARS(CALLINTERFACEFINALIZER, FLfunc,FREGSAVED,"_d_callinterfacefinalizer", 0, t) \ 
    8282SYMBOL_MARS(DELCLASS,      FLfunc,FREGSAVED,"_d_delclass", 0, t) \ 
    8383SYMBOL_MARS(DELINTERFACE,  FLfunc,FREGSAVED,"_d_delinterface", 0, t) \ 
    8484SYMBOL_MARS(ALLOCMEMORY,   FLfunc,FREGSAVED,"_d_allocmemory", 0, t) \ 
    8585SYMBOL_MARS(DELARRAY,      FLfunc,FREGSAVED,"_d_delarray", 0, t) \ 
    8686SYMBOL_MARS(DELARRAYT,     FLfunc,FREGSAVED,"_d_delarray_t", 0, t) \ 
    8787SYMBOL_MARS(DELMEMORY,     FLfunc,FREGSAVED,"_d_delmemory", 0, t) \ 
    8888SYMBOL_MARS(INTERFACE,     FLfunc,FREGSAVED,"_d_interface_vtbl", 0, t) \ 
    8989SYMBOL_MARS(DYNAMIC_CAST,  FLfunc,FREGSAVED,"_d_dynamic_cast", 0, t) \ 
    9090SYMBOL_MARS(INTERFACE_CAST,FLfunc,FREGSAVED,"_d_interface_cast", 0, t) \ 
    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) \ 
    101103SYMBOL_MARS(ARRAYSETASSIGN, FLfunc,FREGSAVED,"_d_arraysetassign", 0, t) \ 
    102104SYMBOL_MARS(ARRAYSETCTOR,  FLfunc,FREGSAVED,"_d_arraysetctor", 0, t) \ 
    103105SYMBOL_MARS(ARRAYCAST,     FLfunc,FREGSAVED,"_d_arraycast", 0, t) \ 
    104106SYMBOL_MARS(ARRAYCAST_FROMBIT, FLfunc,FREGSAVED,"_d_arraycast_frombit", 0, t) \ 
    105107SYMBOL_MARS(ARRAYEQ,       FLfunc,FREGSAVED,"_adEq", 0, t) \ 
    106108SYMBOL_MARS(ARRAYEQ2,      FLfunc,FREGSAVED,"_adEq2", 0, t) \ 
    107109SYMBOL_MARS(ARRAYEQBIT,    FLfunc,FREGSAVED,"_adEqBit", 0, t) \ 
    108110SYMBOL_MARS(ARRAYCMP,      FLfunc,FREGSAVED,"_adCmp", 0, t) \ 
    109111SYMBOL_MARS(ARRAYCMP2,     FLfunc,FREGSAVED,"_adCmp2", 0, t) \ 
    110112SYMBOL_MARS(ARRAYCMPCHAR,  FLfunc,FREGSAVED,"_adCmpChar", 0, t) \ 
    111113SYMBOL_MARS(ARRAYCMPBIT,   FLfunc,FREGSAVED,"_adCmpBit", 0, t) \ 
    112114SYMBOL_MARS(OBJ_EQ,        FLfunc,FREGSAVED,"_d_obj_eq", 0, t) \ 
    113115SYMBOL_MARS(OBJ_CMP,       FLfunc,FREGSAVED,"_d_obj_cmp", 0, t) \ 
    114116\ 
    115117SYMBOL_Z(EXCEPT_HANDLER2, FLfunc,fregsaved,"_except_handler2", 0, 0) \ 
  • branches/dmd-1.x/src/e2ir.c

    r206 r251  
    26142614 
    26152615 
    26162616/*************************************** 
    26172617 */ 
    26182618 
    26192619elem *MinAssignExp::toElem(IRState *irs) 
    26202620{ 
    26212621    return toElemBin(irs,OPminass); 
    26222622} 
    26232623 
    26242624/*************************************** 
    26252625 */ 
    26262626 
    26272627elem *CatAssignExp::toElem(IRState *irs) 
    26282628{ 
    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); 
    26762679    return e; 
    26772680} 
    26782681 
    26792682 
    26802683/*************************************** 
    26812684 */ 
    26822685 
    26832686elem *DivAssignExp::toElem(IRState *irs) 
    26842687{ 
    26852688    return toElemBin(irs,OPdivass); 
    26862689} 
    26872690 
    26882691 
    26892692/*************************************** 
    26902693 */ 
  • branches/dmd-1.x/src/expression.c

    r250 r251  
    83558355    e2 = resolveProperties(sc, e2); 
    83568356 
    83578357    e = op_overload(sc); 
    83588358    if (e) 
    83598359    return e; 
    83608360 
    83618361    if (e1->op == TOKslice) 
    83628362    {   SliceExp *se = (SliceExp *)e1; 
    83638363 
    83648364    if (se->e1->type->toBasetype()->ty == Tsarray) 
    83658365        error("cannot append to static array %s", se->e1->type->toChars()); 
    83668366    } 
    83678367 
    83688368    e1 = e1->modifiableLvalue(sc, e1); 
    83698369 
    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/************************************************************/ 
    84038420 
    84048421MulAssignExp::MulAssignExp(Loc loc, Expression *e1, Expression *e2) 
    84058422    : BinExp(loc, TOKmulass, sizeof(MulAssignExp), e1, e2) 
    84068423{ 
    84078424} 
    84088425 
    84098426Expression *MulAssignExp::semantic(Scope *sc) 
    84108427{   Expression *e; 
    84118428 
    84128429    BinExp::semantic(sc); 
    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; 
    84238449    return arrayOp(sc); 
    84248450    } 
    84258451 
    84268452    e1 = e1->modifiableLvalue(sc, e1); 
    84278453    e1->checkScalar(); 
    84288454    e1->checkNoBool(); 
    84298455    type = e1->type; 
    84308456    typeCombine(sc); 
    84318457    e1->checkArithmetic(); 
    84328458    e2->checkArithmetic(); 
    84338459    checkComplexMulAssign(); 
    84348460    if (e2->type->isfloating()) 
    84358461    {   Type *t1; 
    84368462    Type *t2; 
    84378463 
     
    84628488    } 
    84638489    return this; 
    84648490} 
    84658491 
    84668492/************************************************************/ 
    84678493 
    84688494DivAssignExp::DivAssignExp(Loc loc, Expression *e1, Expression *e2) 
    84698495    : BinExp(loc, TOKdivass, sizeof(DivAssignExp), e1, e2) 
    84708496{ 
    84718497} 
    84728498 
    84738499Expression *DivAssignExp::semantic(Scope *sc) 
    84748500{   Expression *e; 
    84758501 
    84768502    BinExp::semantic(sc); 
    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; 
    84878522    return arrayOp(sc); 
    84888523    } 
    84898524 
    84908525    e1 = e1->modifiableLvalue(sc, e1); 
    84918526    e1->checkScalar(); 
    84928527    e1->checkNoBool(); 
    84938528    type = e1->type; 
    84948529    typeCombine(sc); 
    84958530    e1->checkArithmetic(); 
    84968531    e2->checkArithmetic(); 
    84978532    checkComplexMulAssign(); 
    84988533    if (e2->type->isimaginary()) 
    84998534    {   Type *t1; 
    85008535    Type *t2; 
    85018536 
  • trunk/src/backend/rtlsym.h

    r192 r251  
    7676SYMBOL_MARS(NEWARRAYMT,    FLfunc,FREGSAVED,"_d_newarraymT", 0, t) \ 
    7777SYMBOL_MARS(NEWARRAYMIT,   FLfunc,FREGSAVED,"_d_newarraymiT", 0, t) \ 
    7878SYMBOL_MARS(ARRAYLITERALT, FLfunc,FREGSAVED,"_d_arrayliteralT", 0, t) \ 
    7979SYMBOL_MARS(ASSOCARRAYLITERALT, FLfunc,FREGSAVED,"_d_assocarrayliteralT", 0, t) \ 
    8080SYMBOL_MARS(CALLFINALIZER, FLfunc,FREGSAVED,"_d_callfinalizer", 0, t) \ 
    8181SYMBOL_MARS(CALLINTERFACEFINALIZER, FLfunc,FREGSAVED,"_d_callinterfacefinalizer", 0, t) \ 
    8282SYMBOL_MARS(DELCLASS,      FLfunc,FREGSAVED,"_d_delclass", 0, t) \ 
    8383SYMBOL_MARS(DELINTERFACE,  FLfunc,FREGSAVED,"_d_delinterface", 0, t) \ 
    8484SYMBOL_MARS(ALLOCMEMORY,   FLfunc,FREGSAVED,"_d_allocmemory", 0, t) \ 
    8585SYMBOL_MARS(DELARRAY,      FLfunc,FREGSAVED,"_d_delarray", 0, t) \ 
    8686SYMBOL_MARS(DELARRAYT,     FLfunc,FREGSAVED,"_d_delarray_t", 0, t) \ 
    8787SYMBOL_MARS(DELMEMORY,     FLfunc,FREGSAVED,"_d_delmemory", 0, t) \ 
    8888SYMBOL_MARS(INTERFACE,     FLfunc,FREGSAVED,"_d_interface_vtbl", 0, t) \ 
    8989SYMBOL_MARS(DYNAMIC_CAST,  FLfunc,FREGSAVED,"_d_dynamic_cast", 0, t) \ 
    9090SYMBOL_MARS(INTERFACE_CAST,FLfunc,FREGSAVED,"_d_interface_cast", 0, t) \ 
    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) \ 
    101103SYMBOL_MARS(ARRAYSETASSIGN, FLfunc,FREGSAVED,"_d_arraysetassign", 0, t) \ 
    102104SYMBOL_MARS(ARRAYSETCTOR,  FLfunc,FREGSAVED,"_d_arraysetctor", 0, t) \ 
    103105SYMBOL_MARS(ARRAYCAST,     FLfunc,FREGSAVED,"_d_arraycast", 0, t) \ 
    104106SYMBOL_MARS(ARRAYCAST_FROMBIT, FLfunc,FREGSAVED,"_d_arraycast_frombit", 0, t) \ 
    105107SYMBOL_MARS(ARRAYEQ,       FLfunc,FREGSAVED,"_adEq", 0, t) \ 
    106108SYMBOL_MARS(ARRAYEQ2,      FLfunc,FREGSAVED,"_adEq2", 0, t) \ 
    107109SYMBOL_MARS(ARRAYEQBIT,    FLfunc,FREGSAVED,"_adEqBit", 0, t) \ 
    108110SYMBOL_MARS(ARRAYCMP,      FLfunc,FREGSAVED,"_adCmp", 0, t) \ 
    109111SYMBOL_MARS(ARRAYCMP2,     FLfunc,FREGSAVED,"_adCmp2", 0, t) \ 
    110112SYMBOL_MARS(ARRAYCMPCHAR,  FLfunc,FREGSAVED,"_adCmpChar", 0, t) \ 
    111113SYMBOL_MARS(ARRAYCMPBIT,   FLfunc,FREGSAVED,"_adCmpBit", 0, t) \ 
    112114SYMBOL_MARS(OBJ_EQ,        FLfunc,FREGSAVED,"_d_obj_eq", 0, t) \ 
    113115SYMBOL_MARS(OBJ_CMP,       FLfunc,FREGSAVED,"_d_obj_cmp", 0, t) \ 
    114116\ 
    115117SYMBOL_Z(EXCEPT_HANDLER2, FLfunc,fregsaved,"_except_handler2", 0, 0) \ 
  • trunk/src/e2ir.c

    r246 r251  
    28982898 
    28992899 
    29002900/*************************************** 
    29012901 */ 
    29022902 
    29032903elem *MinAssignExp::toElem(IRState *irs) 
    29042904{ 
    29052905    return toElemBin(irs,OPminass); 
    29062906} 
    29072907 
    29082908/*************************************** 
    29092909 */ 
    29102910 
    29112911elem *CatAssignExp::toElem(IRState *irs) 
    29122912{ 
    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); 
    29322945    } 
    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); 
    29602963    return e; 
    29612964} 
    29622965 
    29632966 
    29642967/*************************************** 
    29652968 */ 
    29662969 
    29672970elem *DivAssignExp::toElem(IRState *irs) 
    29682971{ 
    29692972    return toElemBin(irs,OPdivass); 
    29702973} 
    29712974 
    29722975 
    29732976/*************************************** 
    29742977 */ 
  • trunk/src/expression.c

    r249 r251  
    439439            } 
    440440        } 
    441441        } 
    442442 
    443443        // Inline expand all the tuples 
    444444        while (arg->op == TOKtuple) 
    445445        {   TupleExp *te = (TupleExp *)arg; 
    446446 
    447447        exps->remove(i);        // remove arg 
    448448        exps->insert(i, te->exps);  // replace with tuple contents 
    449449        if (i == exps->dim) 
    450450            return;     // empty tuple, no more arguments 
    451451        arg = (Expression *)exps->data[i]; 
    452452        } 
    453453    } 
    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()); 
    471502        e = new ErrorExp(); 
    472503    } 
    473504 
    474505    if (t0) 
    475506    {   if (t0 != e->type) 
    476507        { 
    477508        /* This applies ?: to merge the types. It's backwards; 
    478509         * ?: should call this function to merge types. 
    479510         */ 
    480511        condexp.type = NULL; 
    481512        condexp.e1 = e0; 
    482513        condexp.e2 = e; 
    483514        condexp.semantic(sc); 
    484515        exps->data[j0] = (void *)condexp.e1; 
    485516        e = condexp.e2; 
    486517        t0 = e->type; 
    487518        } 
    488519    } 
    489520    else 
    490521    {   j0 = i; 
    491522        e0 = e; 
    492523        t0 = e->type; 
    493524    } 
    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    } 
    505536    else 
    506537    t0 = Type::tvoid;       // [] is typed as void[] 
    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 */ 
    517549 
    518550void preFunctionArguments(Loc loc, Scope *sc, Expressions *exps) 
    519551{ 
    520552    if (exps) 
    521553    { 
    522554    expandTuples(exps); 
    523555 
    524556    for (size_t i = 0; i < exps->dim; i++) 
    525557    {   Expression *arg = (Expression *)exps->data[i]; 
    526558 
    527559        if (!arg->type) 
    528560        { 
    529561#ifdef DEBUG 
    530562        if (!global.gag) 
    531563            printf("1: \n"); 
     
    88738905    e2 = resolveProperties(sc, e2); 
    88748906 
    88758907    e = op_overload(sc); 
    88768908    if (e) 
    88778909    return e; 
    88788910 
    88798911    if (e1->op == TOKslice) 
    88808912    {   SliceExp *se = (SliceExp *)e1; 
    88818913 
    88828914    if (se->e1->type->toBasetype()->ty == Tsarray) 
    88838915        error("cannot append to static array %s", se->e1->type->toChars()); 
    88848916    } 
    88858917 
    88868918    e1 = e1->modifiableLvalue(sc, e1); 
    88878919 
    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/************************************************************/ 
    89218970 
    89228971MulAssignExp::MulAssignExp(Loc loc, Expression *e1, Expression *e2) 
    89238972    : BinExp(loc, TOKmulass, sizeof(MulAssignExp), e1, e2) 
    89248973{ 
    89258974} 
    89268975 
    89278976Expression *MulAssignExp::semantic(Scope *sc) 
    89288977{   Expression *e; 
    89298978 
    89308979    BinExp::semantic(sc); 
    89318980    e2 = resolveProperties(sc, e2); 
    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; 
    89488999    return arrayOp(sc); 
    89499000    } 
    89509001 
    89519002    e1 = e1->modifiableLvalue(sc, e1); 
    89529003    e1->checkScalar(); 
    89539004    e1->checkNoBool(); 
    89549005    type = e1->type; 
    89559006    typeCombine(sc); 
    89569007    e1->checkArithmetic(); 
    89579008    e2->checkArithmetic(); 
    89589009    checkComplexMulAssign(); 
    89599010    if (e2->type->isfloating()) 
    89609011    {   Type *t1; 
    89619012    Type *t2; 
    89629013 
     
    89889039    return this; 
    89899040} 
    89909041 
    89919042/************************************************************/ 
    89929043 
    89939044DivAssignExp::DivAssignExp(Loc loc, Expression *e1, Expression *e2) 
    89949045    : BinExp(loc, TOKdivass, sizeof(DivAssignExp), e1, e2) 
    89959046{ 
    89969047} 
    89979048 
    89989049Expression *DivAssignExp::semantic(Scope *sc) 
    89999050{   Expression *e; 
    90009051 
    90019052    BinExp::semantic(sc); 
    90029053    e2 = resolveProperties(sc, e2); 
    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; 
    90199072    return arrayOp(sc); 
    90209073    } 
    90219074 
    90229075    e1 = e1->modifiableLvalue(sc, e1); 
    90239076    e1->checkScalar(); 
    90249077    e1->checkNoBool(); 
    90259078    type = e1->type; 
    90269079    typeCombine(sc); 
    90279080    e1->checkArithmetic(); 
    90289081    e2->checkArithmetic(); 
    90299082    checkComplexMulAssign(); 
    90309083    if (e2->type->isimaginary()) 
    90319084    {   Type *t1; 
    90329085    Type *t2; 
    90339086