Changeset 251
- Timestamp:
- 11/18/09 01:54:37 (2 years ago)
- Files:
-
- branches/dmd-1.x/src/backend/rtlsym.h (modified) (1 diff)
- branches/dmd-1.x/src/e2ir.c (modified) (1 diff)
- branches/dmd-1.x/src/expression.c (modified) (2 diffs)
- trunk/src/backend/rtlsym.h (modified) (1 diff)
- trunk/src/e2ir.c (modified) (1 diff)
- trunk/src/expression.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/dmd-1.x/src/backend/rtlsym.h
r190 r251 76 76 SYMBOL_MARS(NEWARRAYMT, FLfunc,FREGSAVED,"_d_newarraymT", 0, t) \ 77 77 SYMBOL_MARS(NEWARRAYMIT, FLfunc,FREGSAVED,"_d_newarraymiT", 0, t) \ 78 78 SYMBOL_MARS(ARRAYLITERALT, FLfunc,FREGSAVED,"_d_arrayliteralT", 0, t) \ 79 79 SYMBOL_MARS(ASSOCARRAYLITERALT, FLfunc,FREGSAVED,"_d_assocarrayliteralT", 0, t) \ 80 80 SYMBOL_MARS(CALLFINALIZER, FLfunc,FREGSAVED,"_d_callfinalizer", 0, t) \ 81 81 SYMBOL_MARS(CALLINTERFACEFINALIZER, FLfunc,FREGSAVED,"_d_callinterfacefinalizer", 0, t) \ 82 82 SYMBOL_MARS(DELCLASS, FLfunc,FREGSAVED,"_d_delclass", 0, t) \ 83 83 SYMBOL_MARS(DELINTERFACE, FLfunc,FREGSAVED,"_d_delinterface", 0, t) \ 84 84 SYMBOL_MARS(ALLOCMEMORY, FLfunc,FREGSAVED,"_d_allocmemory", 0, t) \ 85 85 SYMBOL_MARS(DELARRAY, FLfunc,FREGSAVED,"_d_delarray", 0, t) \ 86 86 SYMBOL_MARS(DELARRAYT, FLfunc,FREGSAVED,"_d_delarray_t", 0, t) \ 87 87 SYMBOL_MARS(DELMEMORY, FLfunc,FREGSAVED,"_d_delmemory", 0, t) \ 88 88 SYMBOL_MARS(INTERFACE, FLfunc,FREGSAVED,"_d_interface_vtbl", 0, t) \ 89 89 SYMBOL_MARS(DYNAMIC_CAST, FLfunc,FREGSAVED,"_d_dynamic_cast", 0, t) \ 90 90 SYMBOL_MARS(INTERFACE_CAST,FLfunc,FREGSAVED,"_d_interface_cast", 0, t) \ 91 91 SYMBOL_MARS(FATEXIT, FLfunc,FREGSAVED,"_fatexit", 0, t) \ 92 92 SYMBOL_MARS(ARRAYCATT, FLfunc,FREGSAVED,"_d_arraycatT", 0, t) \ 93 93 SYMBOL_MARS(ARRAYCATNT, FLfunc,FREGSAVED,"_d_arraycatnT", 0, t) \ 94 94 SYMBOL_MARS(ARRAYAPPENDT, FLfunc,FREGSAVED,"_d_arrayappendT", 0, t) \ 95 95 SYMBOL_MARS(ARRAYAPPENDCT, FLfunc,FREGSAVED,"_d_arrayappendcT", 0, t) \ 96 SYMBOL_MARS(ARRAYAPPENDCD, FLfunc,FREGSAVED,"_d_arrayappendcd", 0, t) \ 97 SYMBOL_MARS(ARRAYAPPENDWD, FLfunc,FREGSAVED,"_d_arrayappendwd", 0, t) \ 96 98 SYMBOL_MARS(ARRAYSETLENGTHT,FLfunc,FREGSAVED,"_d_arraysetlengthT", 0, t) \ 97 99 SYMBOL_MARS(ARRAYSETLENGTHIT,FLfunc,FREGSAVED,"_d_arraysetlengthiT", 0, t) \ 98 100 SYMBOL_MARS(ARRAYCOPY, FLfunc,FREGSAVED,"_d_arraycopy", 0, t) \ 99 101 SYMBOL_MARS(ARRAYASSIGN, FLfunc,FREGSAVED,"_d_arrayassign", 0, t) \ 100 102 SYMBOL_MARS(ARRAYCTOR, FLfunc,FREGSAVED,"_d_arrayctor", 0, t) \ 101 103 SYMBOL_MARS(ARRAYSETASSIGN, FLfunc,FREGSAVED,"_d_arraysetassign", 0, t) \ 102 104 SYMBOL_MARS(ARRAYSETCTOR, FLfunc,FREGSAVED,"_d_arraysetctor", 0, t) \ 103 105 SYMBOL_MARS(ARRAYCAST, FLfunc,FREGSAVED,"_d_arraycast", 0, t) \ 104 106 SYMBOL_MARS(ARRAYCAST_FROMBIT, FLfunc,FREGSAVED,"_d_arraycast_frombit", 0, t) \ 105 107 SYMBOL_MARS(ARRAYEQ, FLfunc,FREGSAVED,"_adEq", 0, t) \ 106 108 SYMBOL_MARS(ARRAYEQ2, FLfunc,FREGSAVED,"_adEq2", 0, t) \ 107 109 SYMBOL_MARS(ARRAYEQBIT, FLfunc,FREGSAVED,"_adEqBit", 0, t) \ 108 110 SYMBOL_MARS(ARRAYCMP, FLfunc,FREGSAVED,"_adCmp", 0, t) \ 109 111 SYMBOL_MARS(ARRAYCMP2, FLfunc,FREGSAVED,"_adCmp2", 0, t) \ 110 112 SYMBOL_MARS(ARRAYCMPCHAR, FLfunc,FREGSAVED,"_adCmpChar", 0, t) \ 111 113 SYMBOL_MARS(ARRAYCMPBIT, FLfunc,FREGSAVED,"_adCmpBit", 0, t) \ 112 114 SYMBOL_MARS(OBJ_EQ, FLfunc,FREGSAVED,"_d_obj_eq", 0, t) \ 113 115 SYMBOL_MARS(OBJ_CMP, FLfunc,FREGSAVED,"_d_obj_cmp", 0, t) \ 114 116 \ 115 117 SYMBOL_Z(EXCEPT_HANDLER2, FLfunc,fregsaved,"_except_handler2", 0, 0) \ branches/dmd-1.x/src/e2ir.c
r206 r251 2614 2614 2615 2615 2616 2616 /*************************************** 2617 2617 */ 2618 2618 2619 2619 elem *MinAssignExp::toElem(IRState *irs) 2620 2620 { 2621 2621 return toElemBin(irs,OPminass); 2622 2622 } 2623 2623 2624 2624 /*************************************** 2625 2625 */ 2626 2626 2627 2627 elem *CatAssignExp::toElem(IRState *irs) 2628 2628 { 2629 2629 //printf("CatAssignExp::toElem('%s')\n", toChars()); 2630 2630 elem *e; 2631 2631 Type *tb1 = e1->type->toBasetype(); 2632 2632 Type *tb2 = e2->type->toBasetype(); 2633 2633 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); 2640 2639 e1 = el_una(OPaddr, TYnptr, e1); 2641 2640 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) 2644 2657 { 2645 2658 e2 = el_una(OPstrpar, TYstruct, e2); 2646 2659 e2->Enumbytes = e2->E1->Enumbytes; 2647 2660 assert(e2->Enumbytes); 2648 2661 } 2649 2662 2650 2663 Type *tb1n = tb1->nextOf()->toBasetype(); 2651 2664 if ((tb2->ty == Tarray || tb2->ty == Tsarray) && 2652 2665 tb1n->equals(tb2->nextOf()->toBasetype())) 2653 2666 { // 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); 2656 2668 e = el_bin(OPcall, TYdarray, el_var(rtlsym[RTLSYM_ARRAYAPPENDT]), ep); 2657 #else2658 ep = el_params(el_long(TYint, tb1n->size()), e2, e1, NULL);2659 e = el_bin(OPcall, TYdarray, el_var(rtlsym[RTLSYM_ARRAYAPPEND]), ep);2660 #endif2661 2669 } 2662 2670 else 2663 2671 { // 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); 2666 2673 e = el_bin(OPcall, TYdarray, el_var(rtlsym[RTLSYM_ARRAYAPPENDCT]), ep); 2667 #else2668 ep = el_params(e2, el_long(TYint, tb1n->size()), e1, NULL);2669 e = el_bin(OPcall, TYdarray, el_var(rtlsym[RTLSYM_ARRAYAPPENDC]), ep);2670 #endif2671 2674 } 2672 2675 el_setLoc(e,loc); 2673 2676 } 2674 2677 else 2675 2678 assert(0); 2676 2679 return e; 2677 2680 } 2678 2681 2679 2682 2680 2683 /*************************************** 2681 2684 */ 2682 2685 2683 2686 elem *DivAssignExp::toElem(IRState *irs) 2684 2687 { 2685 2688 return toElemBin(irs,OPdivass); 2686 2689 } 2687 2690 2688 2691 2689 2692 /*************************************** 2690 2693 */ branches/dmd-1.x/src/expression.c
r250 r251 8355 8355 e2 = resolveProperties(sc, e2); 8356 8356 8357 8357 e = op_overload(sc); 8358 8358 if (e) 8359 8359 return e; 8360 8360 8361 8361 if (e1->op == TOKslice) 8362 8362 { SliceExp *se = (SliceExp *)e1; 8363 8363 8364 8364 if (se->e1->type->toBasetype()->ty == Tsarray) 8365 8365 error("cannot append to static array %s", se->e1->type->toChars()); 8366 8366 } 8367 8367 8368 8368 e1 = e1->modifiableLvalue(sc, e1); 8369 8369 8370 8370 Type *tb1 = e1->type->toBasetype(); 8371 8371 Type *tb2 = e2->type->toBasetype(); 8372 8372 8373 8373 e2->rvalue(); 8374 8374 8375 Type *tb1next = tb1->nextOf(); 8376 8375 8377 if ((tb1->ty == Tarray) && 8376 8378 (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 ) 8379 8384 ) 8380 8385 { // Append array 8381 8386 e2 = e2->castTo(sc, e1->type); 8382 8387 type = e1->type; 8383 8388 e = this; 8384 8389 } 8385 8390 else if ((tb1->ty == Tarray) && 8386 e2->implicitConvTo(tb1 ->nextOf())8391 e2->implicitConvTo(tb1next) 8387 8392 ) 8388 8393 { // Append element 8389 e2 = e2->castTo(sc, tb1 ->nextOf());8394 e2 = e2->castTo(sc, tb1next); 8390 8395 type = e1->type; 8391 8396 e = this; 8392 8397 } 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 } 8393 8411 else 8394 8412 { 8395 8413 error("cannot append type %s to type %s", tb2->toChars(), tb1->toChars()); 8396 type = Type::tint32; 8397 e = this; 8414 e = new ErrorExp(); 8398 8415 } 8399 8416 return e; 8400 8417 } 8401 8418 8402 8419 /************************************************************/ 8403 8420 8404 8421 MulAssignExp::MulAssignExp(Loc loc, Expression *e1, Expression *e2) 8405 8422 : BinExp(loc, TOKmulass, sizeof(MulAssignExp), e1, e2) 8406 8423 { 8407 8424 } 8408 8425 8409 8426 Expression *MulAssignExp::semantic(Scope *sc) 8410 8427 { Expression *e; 8411 8428 8412 8429 BinExp::semantic(sc); 8413 8430 e2 = resolveProperties(sc, e2); 8414 8431 8415 8432 e = op_overload(sc); 8416 8433 if (e) 8417 8434 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 8418 8444 8419 8445 if (e1->op == TOKslice) 8420 8446 { // T[] -= ... 8421 8447 typeCombine(sc); 8422 8448 type = e1->type; 8423 8449 return arrayOp(sc); 8424 8450 } 8425 8451 8426 8452 e1 = e1->modifiableLvalue(sc, e1); 8427 8453 e1->checkScalar(); 8428 8454 e1->checkNoBool(); 8429 8455 type = e1->type; 8430 8456 typeCombine(sc); 8431 8457 e1->checkArithmetic(); 8432 8458 e2->checkArithmetic(); 8433 8459 checkComplexMulAssign(); 8434 8460 if (e2->type->isfloating()) 8435 8461 { Type *t1; 8436 8462 Type *t2; 8437 8463 … … 8462 8488 } 8463 8489 return this; 8464 8490 } 8465 8491 8466 8492 /************************************************************/ 8467 8493 8468 8494 DivAssignExp::DivAssignExp(Loc loc, Expression *e1, Expression *e2) 8469 8495 : BinExp(loc, TOKdivass, sizeof(DivAssignExp), e1, e2) 8470 8496 { 8471 8497 } 8472 8498 8473 8499 Expression *DivAssignExp::semantic(Scope *sc) 8474 8500 { Expression *e; 8475 8501 8476 8502 BinExp::semantic(sc); 8477 8503 e2 = resolveProperties(sc, e2); 8478 8504 8479 8505 e = op_overload(sc); 8480 8506 if (e) 8481 8507 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 8482 8517 8483 8518 if (e1->op == TOKslice) 8484 8519 { // T[] -= ... 8485 8520 typeCombine(sc); 8486 8521 type = e1->type; 8487 8522 return arrayOp(sc); 8488 8523 } 8489 8524 8490 8525 e1 = e1->modifiableLvalue(sc, e1); 8491 8526 e1->checkScalar(); 8492 8527 e1->checkNoBool(); 8493 8528 type = e1->type; 8494 8529 typeCombine(sc); 8495 8530 e1->checkArithmetic(); 8496 8531 e2->checkArithmetic(); 8497 8532 checkComplexMulAssign(); 8498 8533 if (e2->type->isimaginary()) 8499 8534 { Type *t1; 8500 8535 Type *t2; 8501 8536 trunk/src/backend/rtlsym.h
r192 r251 76 76 SYMBOL_MARS(NEWARRAYMT, FLfunc,FREGSAVED,"_d_newarraymT", 0, t) \ 77 77 SYMBOL_MARS(NEWARRAYMIT, FLfunc,FREGSAVED,"_d_newarraymiT", 0, t) \ 78 78 SYMBOL_MARS(ARRAYLITERALT, FLfunc,FREGSAVED,"_d_arrayliteralT", 0, t) \ 79 79 SYMBOL_MARS(ASSOCARRAYLITERALT, FLfunc,FREGSAVED,"_d_assocarrayliteralT", 0, t) \ 80 80 SYMBOL_MARS(CALLFINALIZER, FLfunc,FREGSAVED,"_d_callfinalizer", 0, t) \ 81 81 SYMBOL_MARS(CALLINTERFACEFINALIZER, FLfunc,FREGSAVED,"_d_callinterfacefinalizer", 0, t) \ 82 82 SYMBOL_MARS(DELCLASS, FLfunc,FREGSAVED,"_d_delclass", 0, t) \ 83 83 SYMBOL_MARS(DELINTERFACE, FLfunc,FREGSAVED,"_d_delinterface", 0, t) \ 84 84 SYMBOL_MARS(ALLOCMEMORY, FLfunc,FREGSAVED,"_d_allocmemory", 0, t) \ 85 85 SYMBOL_MARS(DELARRAY, FLfunc,FREGSAVED,"_d_delarray", 0, t) \ 86 86 SYMBOL_MARS(DELARRAYT, FLfunc,FREGSAVED,"_d_delarray_t", 0, t) \ 87 87 SYMBOL_MARS(DELMEMORY, FLfunc,FREGSAVED,"_d_delmemory", 0, t) \ 88 88 SYMBOL_MARS(INTERFACE, FLfunc,FREGSAVED,"_d_interface_vtbl", 0, t) \ 89 89 SYMBOL_MARS(DYNAMIC_CAST, FLfunc,FREGSAVED,"_d_dynamic_cast", 0, t) \ 90 90 SYMBOL_MARS(INTERFACE_CAST,FLfunc,FREGSAVED,"_d_interface_cast", 0, t) \ 91 91 SYMBOL_MARS(FATEXIT, FLfunc,FREGSAVED,"_fatexit", 0, t) \ 92 92 SYMBOL_MARS(ARRAYCATT, FLfunc,FREGSAVED,"_d_arraycatT", 0, t) \ 93 93 SYMBOL_MARS(ARRAYCATNT, FLfunc,FREGSAVED,"_d_arraycatnT", 0, t) \ 94 94 SYMBOL_MARS(ARRAYAPPENDT, FLfunc,FREGSAVED,"_d_arrayappendT", 0, t) \ 95 95 SYMBOL_MARS(ARRAYAPPENDCT, FLfunc,FREGSAVED,"_d_arrayappendcT", 0, t) \ 96 SYMBOL_MARS(ARRAYAPPENDCD, FLfunc,FREGSAVED,"_d_arrayappendcd", 0, t) \ 97 SYMBOL_MARS(ARRAYAPPENDWD, FLfunc,FREGSAVED,"_d_arrayappendwd", 0, t) \ 96 98 SYMBOL_MARS(ARRAYSETLENGTHT,FLfunc,FREGSAVED,"_d_arraysetlengthT", 0, t) \ 97 99 SYMBOL_MARS(ARRAYSETLENGTHIT,FLfunc,FREGSAVED,"_d_arraysetlengthiT", 0, t) \ 98 100 SYMBOL_MARS(ARRAYCOPY, FLfunc,FREGSAVED,"_d_arraycopy", 0, t) \ 99 101 SYMBOL_MARS(ARRAYASSIGN, FLfunc,FREGSAVED,"_d_arrayassign", 0, t) \ 100 102 SYMBOL_MARS(ARRAYCTOR, FLfunc,FREGSAVED,"_d_arrayctor", 0, t) \ 101 103 SYMBOL_MARS(ARRAYSETASSIGN, FLfunc,FREGSAVED,"_d_arraysetassign", 0, t) \ 102 104 SYMBOL_MARS(ARRAYSETCTOR, FLfunc,FREGSAVED,"_d_arraysetctor", 0, t) \ 103 105 SYMBOL_MARS(ARRAYCAST, FLfunc,FREGSAVED,"_d_arraycast", 0, t) \ 104 106 SYMBOL_MARS(ARRAYCAST_FROMBIT, FLfunc,FREGSAVED,"_d_arraycast_frombit", 0, t) \ 105 107 SYMBOL_MARS(ARRAYEQ, FLfunc,FREGSAVED,"_adEq", 0, t) \ 106 108 SYMBOL_MARS(ARRAYEQ2, FLfunc,FREGSAVED,"_adEq2", 0, t) \ 107 109 SYMBOL_MARS(ARRAYEQBIT, FLfunc,FREGSAVED,"_adEqBit", 0, t) \ 108 110 SYMBOL_MARS(ARRAYCMP, FLfunc,FREGSAVED,"_adCmp", 0, t) \ 109 111 SYMBOL_MARS(ARRAYCMP2, FLfunc,FREGSAVED,"_adCmp2", 0, t) \ 110 112 SYMBOL_MARS(ARRAYCMPCHAR, FLfunc,FREGSAVED,"_adCmpChar", 0, t) \ 111 113 SYMBOL_MARS(ARRAYCMPBIT, FLfunc,FREGSAVED,"_adCmpBit", 0, t) \ 112 114 SYMBOL_MARS(OBJ_EQ, FLfunc,FREGSAVED,"_d_obj_eq", 0, t) \ 113 115 SYMBOL_MARS(OBJ_CMP, FLfunc,FREGSAVED,"_d_obj_cmp", 0, t) \ 114 116 \ 115 117 SYMBOL_Z(EXCEPT_HANDLER2, FLfunc,fregsaved,"_except_handler2", 0, 0) \ trunk/src/e2ir.c
r246 r251 2898 2898 2899 2899 2900 2900 /*************************************** 2901 2901 */ 2902 2902 2903 2903 elem *MinAssignExp::toElem(IRState *irs) 2904 2904 { 2905 2905 return toElemBin(irs,OPminass); 2906 2906 } 2907 2907 2908 2908 /*************************************** 2909 2909 */ 2910 2910 2911 2911 elem *CatAssignExp::toElem(IRState *irs) 2912 2912 { 2913 2913 //printf("CatAssignExp::toElem('%s')\n", toChars()); 2914 2914 elem *e; 2915 2915 Type *tb1 = e1->type->toBasetype(); 2916 2916 Type *tb2 = e2->type->toBasetype(); 2917 2917 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); 2924 2923 e1 = el_una(OPaddr, TYnptr, e1); 2925 2924 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); 2927 2940 if (tybasic(e2->Ety) == TYstruct || tybasic(e2->Ety) == TYarray) 2928 2941 { 2929 2942 e2 = el_una(OPstrpar, TYstruct, e2); 2930 2943 e2->Enumbytes = e2->E1->Enumbytes; 2931 2944 assert(e2->Enumbytes); 2932 2945 } 2933 2946 2934 2947 Type *tb1n = tb1->nextOf()->toBasetype(); 2935 2948 if ((tb2->ty == Tarray || tb2->ty == Tsarray) && 2936 2949 tb1n->equals(tb2->nextOf()->toBasetype())) 2937 2950 { // 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); 2940 2952 e = el_bin(OPcall, TYdarray, el_var(rtlsym[RTLSYM_ARRAYAPPENDT]), ep); 2941 #else2942 ep = el_params(el_long(TYint, tb1n->size()), e2, e1, NULL);2943 e = el_bin(OPcall, TYdarray, el_var(rtlsym[RTLSYM_ARRAYAPPEND]), ep);2944 #endif2945 2953 } 2946 2954 else 2947 2955 { // 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); 2950 2957 e = el_bin(OPcall, TYdarray, el_var(rtlsym[RTLSYM_ARRAYAPPENDCT]), ep); 2951 #else2952 ep = el_params(e2, el_long(TYint, tb1n->size()), e1, NULL);2953 e = el_bin(OPcall, TYdarray, el_var(rtlsym[RTLSYM_ARRAYAPPENDC]), ep);2954 #endif2955 2958 } 2956 2959 el_setLoc(e,loc); 2957 2960 } 2958 2961 else 2959 2962 assert(0); 2960 2963 return e; 2961 2964 } 2962 2965 2963 2966 2964 2967 /*************************************** 2965 2968 */ 2966 2969 2967 2970 elem *DivAssignExp::toElem(IRState *irs) 2968 2971 { 2969 2972 return toElemBin(irs,OPdivass); 2970 2973 } 2971 2974 2972 2975 2973 2976 /*************************************** 2974 2977 */ trunk/src/expression.c
r249 r251 439 439 } 440 440 } 441 441 } 442 442 443 443 // Inline expand all the tuples 444 444 while (arg->op == TOKtuple) 445 445 { TupleExp *te = (TupleExp *)arg; 446 446 447 447 exps->remove(i); // remove arg 448 448 exps->insert(i, te->exps); // replace with tuple contents 449 449 if (i == exps->dim) 450 450 return; // empty tuple, no more arguments 451 451 arg = (Expression *)exps->data[i]; 452 452 } 453 453 } 454 454 } 455 455 } 456 456 457 457 Expressions *arrayExpressionToCommonType(Scope *sc, Expressions *exps, Type **pt) 458 458 { 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 */ 459 490 IntegerExp integerexp(0); 460 491 CondExp condexp(0, &integerexp, NULL, NULL); 461 492 462 493 Type *t0 = NULL; 463 494 Expression *e0; 464 495 int j0; 465 for ( int i = 0; i < exps->dim; i++)496 for (size_t i = 0; i < exps->dim; i++) 466 497 { Expression *e = (Expression *)exps->data[i]; 467 498 468 499 e = resolveProperties(sc, e); 469 500 if (!e->type) 470 501 { error("%s has no value", e->toChars()); 471 502 e = new ErrorExp(); 472 503 } 473 504 474 505 if (t0) 475 506 { if (t0 != e->type) 476 507 { 477 508 /* This applies ?: to merge the types. It's backwards; 478 509 * ?: should call this function to merge types. 479 510 */ 480 511 condexp.type = NULL; 481 512 condexp.e1 = e0; 482 513 condexp.e2 = e; 483 514 condexp.semantic(sc); 484 515 exps->data[j0] = (void *)condexp.e1; 485 516 e = condexp.e2; 486 517 t0 = e->type; 487 518 } 488 519 } 489 520 else 490 521 { j0 = i; 491 522 e0 = e; 492 523 t0 = e->type; 493 524 } 494 525 exps->data[i] = (void *)e; 495 526 } 496 527 497 528 if (t0) 498 529 { 499 for ( int i = 0; i < exps->dim; i++)530 for (size_t i = 0; i < exps->dim; i++) 500 531 { Expression *e = (Expression *)exps->data[i]; 501 532 e = e->implicitCastTo(sc, t0); 502 533 exps->data[i] = (void *)e; 503 534 } 504 535 } 505 536 else 506 537 t0 = Type::tvoid; // [] is typed as void[] 507 538 if (pt) 508 539 *pt = t0; 509 540 510 541 // Eventually, we want to make this copy-on-write 511 542 return exps; 543 #endif 512 544 } 513 545 514 546 /**************************************** 515 547 * Preprocess arguments to function. 516 548 */ 517 549 518 550 void preFunctionArguments(Loc loc, Scope *sc, Expressions *exps) 519 551 { 520 552 if (exps) 521 553 { 522 554 expandTuples(exps); 523 555 524 556 for (size_t i = 0; i < exps->dim; i++) 525 557 { Expression *arg = (Expression *)exps->data[i]; 526 558 527 559 if (!arg->type) 528 560 { 529 561 #ifdef DEBUG 530 562 if (!global.gag) 531 563 printf("1: \n"); … … 8873 8905 e2 = resolveProperties(sc, e2); 8874 8906 8875 8907 e = op_overload(sc); 8876 8908 if (e) 8877 8909 return e; 8878 8910 8879 8911 if (e1->op == TOKslice) 8880 8912 { SliceExp *se = (SliceExp *)e1; 8881 8913 8882 8914 if (se->e1->type->toBasetype()->ty == Tsarray) 8883 8915 error("cannot append to static array %s", se->e1->type->toChars()); 8884 8916 } 8885 8917 8886 8918 e1 = e1->modifiableLvalue(sc, e1); 8887 8919 8888 8920 Type *tb1 = e1->type->toBasetype(); 8889 8921 Type *tb2 = e2->type->toBasetype(); 8890 8922 8891 8923 e2->rvalue(); 8892 8924 8925 Type *tb1next = tb1->nextOf(); 8926 8893 8927 if ((tb1->ty == Tarray) && 8894 8928 (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 ) 8897 8934 ) 8898 8935 { // Append array 8899 8936 e2 = e2->castTo(sc, e1->type); 8900 8937 type = e1->type; 8901 8938 e = this; 8902 8939 } 8903 8940 else if ((tb1->ty == Tarray) && 8904 e2->implicitConvTo(tb1 ->nextOf())8941 e2->implicitConvTo(tb1next) 8905 8942 ) 8906 8943 { // Append element 8907 e2 = e2->castTo(sc, tb1 ->nextOf());8944 e2 = e2->castTo(sc, tb1next); 8908 8945 type = e1->type; 8909 8946 e = this; 8910 8947 } 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 } 8911 8961 else 8912 8962 { 8913 8963 error("cannot append type %s to type %s", tb2->toChars(), tb1->toChars()); 8914 type = Type::tint32; 8915 e = this; 8964 e = new ErrorExp(); 8916 8965 } 8917 8966 return e; 8918 8967 } 8919 8968 8920 8969 /************************************************************/ 8921 8970 8922 8971 MulAssignExp::MulAssignExp(Loc loc, Expression *e1, Expression *e2) 8923 8972 : BinExp(loc, TOKmulass, sizeof(MulAssignExp), e1, e2) 8924 8973 { 8925 8974 } 8926 8975 8927 8976 Expression *MulAssignExp::semantic(Scope *sc) 8928 8977 { Expression *e; 8929 8978 8930 8979 BinExp::semantic(sc); 8931 8980 e2 = resolveProperties(sc, e2); 8932 8981 8933 8982 e = op_overload(sc); 8934 8983 if (e) 8935 8984 return e; 8936 8985 8986 #if DMDV2 8937 8987 if (e1->op == TOKarraylength) 8938 8988 { 8939 8989 e = ArrayLengthExp::rewriteOpAssign(this); 8940 8990 e = e->semantic(sc); 8941 8991 return e; 8942 8992 } 8993 #endif 8943 8994 8944 8995 if (e1->op == TOKslice) 8945 8996 { // T[] -= ... 8946 8997 typeCombine(sc); 8947 8998 type = e1->type; 8948 8999 return arrayOp(sc); 8949 9000 } 8950 9001 8951 9002 e1 = e1->modifiableLvalue(sc, e1); 8952 9003 e1->checkScalar(); 8953 9004 e1->checkNoBool(); 8954 9005 type = e1->type; 8955 9006 typeCombine(sc); 8956 9007 e1->checkArithmetic(); 8957 9008 e2->checkArithmetic(); 8958 9009 checkComplexMulAssign(); 8959 9010 if (e2->type->isfloating()) 8960 9011 { Type *t1; 8961 9012 Type *t2; 8962 9013 … … 8988 9039 return this; 8989 9040 } 8990 9041 8991 9042 /************************************************************/ 8992 9043 8993 9044 DivAssignExp::DivAssignExp(Loc loc, Expression *e1, Expression *e2) 8994 9045 : BinExp(loc, TOKdivass, sizeof(DivAssignExp), e1, e2) 8995 9046 { 8996 9047 } 8997 9048 8998 9049 Expression *DivAssignExp::semantic(Scope *sc) 8999 9050 { Expression *e; 9000 9051 9001 9052 BinExp::semantic(sc); 9002 9053 e2 = resolveProperties(sc, e2); 9003 9054 9004 9055 e = op_overload(sc); 9005 9056 if (e) 9006 9057 return e; 9007 9058 9059 #if DMDV2 9008 9060 if (e1->op == TOKarraylength) 9009 9061 { 9010 9062 e = ArrayLengthExp::rewriteOpAssign(this); 9011 9063 e = e->semantic(sc); 9012 9064 return e; 9013 9065 } 9066 #endif 9014 9067 9015 9068 if (e1->op == TOKslice) 9016 9069 { // T[] -= ... 9017 9070 typeCombine(sc); 9018 9071 type = e1->type; 9019 9072 return arrayOp(sc); 9020 9073 } 9021 9074 9022 9075 e1 = e1->modifiableLvalue(sc, e1); 9023 9076 e1->checkScalar(); 9024 9077 e1->checkNoBool(); 9025 9078 type = e1->type; 9026 9079 typeCombine(sc); 9027 9080 e1->checkArithmetic(); 9028 9081 e2->checkArithmetic(); 9029 9082 checkComplexMulAssign(); 9030 9083 if (e2->type->isimaginary()) 9031 9084 { Type *t1; 9032 9085 Type *t2; 9033 9086
