Changeset 774
- Timestamp:
- 12/05/10 03:02:54 (14 years ago)
- Files:
-
- trunk/src/cast.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/cast.c
r767 r774 432 432 { assert(t->mod == MODimmutable); 433 433 te = te->invariantOf(); 434 434 } 435 435 MATCH m2 = e->implicitConvTo(te); 436 436 //printf("\t%s => %s, match = %d\n", e->toChars(), te->toChars(), m2); 437 437 if (m2 < m) 438 438 m = m2; 439 439 } 440 440 } 441 441 return m; 442 442 } 443 443 #endif 444 444 445 445 MATCH StringExp::implicitConvTo(Type *t) 446 446 { MATCH m; 447 447 448 448 #if 0 449 449 printf("StringExp::implicitConvTo(this=%s, committed=%d, type=%s, t=%s)\n", 450 450 toChars(), committed, type->toChars(), t->toChars()); 451 451 #endif 452 if (!committed)453 {454 452 if (!committed && t->ty == Tpointer && t->nextOf()->ty == Tvoid) 455 453 { 456 454 return MATCHnomatch; 457 455 } 458 456 if (type->ty == Tsarray || type->ty == Tarray || type->ty == Tpointer) 459 457 { 460 458 TY tyn = type->nextOf()->ty; 461 459 if (tyn == Tchar || tyn == Twchar || tyn == Tdchar) 462 460 { Type *tn; 463 461 MATCH m; 464 462 465 463 switch (t->ty) 466 464 { 467 465 case Tsarray: 468 466 if (type->ty == Tsarray) 469 467 { 470 468 if (((TypeSArray *)type)->dim->toInteger() != 471 469 ((TypeSArray *)t)->dim->toInteger()) 472 470 return MATCHnomatch; 473 471 TY tynto = t->nextOf()->ty; 474 if (tynto == Tchar || tynto == Twchar || tynto == Tdchar) 472 if (tynto == tyn) 473 return MATCHexact; 474 if (!committed && (tynto == Tchar || tynto == Twchar || tynto == Tdchar)) 475 475 return MATCHexact; 476 476 } 477 477 else if (type->ty == Tarray) 478 478 { 479 479 if (length() > 480 480 ((TypeSArray *)t)->dim->toInteger()) 481 481 return MATCHnomatch; 482 482 TY tynto = t->nextOf()->ty; 483 if (tynto == Tchar || tynto == Twchar || tynto == Tdchar) 483 if (tynto == tyn) 484 return MATCHexact; 485 if (!committed && (tynto == Tchar || tynto == Twchar || tynto == Tdchar)) 484 486 return MATCHexact; 485 487 } 486 488 case Tarray: 487 489 case Tpointer: 488 490 tn = t->nextOf(); 489 491 m = MATCHexact; 490 492 if (type->nextOf()->mod != tn->mod) 491 493 { if (!tn->isConst()) 492 494 return MATCHnomatch; 493 495 m = MATCHconst; 494 496 } 495 497 switch (tn->ty) 496 498 { 497 499 case Tchar: 498 500 case Twchar: 499 501 case Tdchar: 500 return m; 502 if (!committed) 503 return m; 504 break; 501 505 } 502 506 break; 503 507 } 504 508 } 505 }506 509 } 507 510 return Expression::implicitConvTo(t); 508 511 #if 0 509 512 m = (MATCH)type->implicitConvTo(t); 510 513 if (m) 511 514 { 512 515 return m; 513 516 } 514 517 515 518 return MATCHnomatch; 516 519 #endif 517 520 } 518 521 519 522 MATCH ArrayLiteralExp::implicitConvTo(Type *t) 520 523 { MATCH result = MATCHexact; 521 524 522 525 #if 0 523 526 printf("ArrayLiteralExp::implicitConvTo(this=%s, type=%s, t=%s)\n", 524 527 toChars(), type->toChars(), t->toChars()); 525 528 #endif
