Changeset 251
- Timestamp:
- 11/18/09 01:54:37 (10 months 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) (3 diffs)
- trunk/src/backend/rtlsym.h (modified) (1 diff)
- trunk/src/e2ir.c (modified) (2 diffs)
- trunk/src/expression.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/dmd-1.x/src/backend/rtlsym.h
r190 r251 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) \ branches/dmd-1.x/src/e2ir.c
r206 r251 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); branches/dmd-1.x/src/expression.c
r250 r251 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 /************************************************************/ … … 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; … … 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; trunk/src/backend/rtlsym.h
r192 r251 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) \ trunk/src/e2ir.c
r246 r251 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); … … 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); trunk/src/expression.c
r249 r251 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()); … … 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 } … … 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 */ … … 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 /************************************************************/ … … 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; … … 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;
