| | 450 | } |
|---|
| | 451 | |
|---|
| | 452 | Expressions *arrayExpressionToCommonType(Scope *sc, Expressions *exps, Type **pt) |
|---|
| | 453 | { |
|---|
| | 454 | #if DMDV1 |
|---|
| | 455 | /* The first element sets the type |
|---|
| | 456 | */ |
|---|
| | 457 | Type *t0 = NULL; |
|---|
| | 458 | for (size_t i = 0; i < exps->dim; i++) |
|---|
| | 459 | { Expression *e = (Expression *)exps->data[i]; |
|---|
| | 460 | |
|---|
| | 461 | if (!e->type) |
|---|
| | 462 | { error("%s has no value", e->toChars()); |
|---|
| | 463 | e = new ErrorExp(); |
|---|
| | 464 | } |
|---|
| | 465 | e = resolveProperties(sc, e); |
|---|
| | 466 | |
|---|
| | 467 | if (!t0) |
|---|
| | 468 | t0 = e->type; |
|---|
| | 469 | else |
|---|
| | 470 | e = e->implicitCastTo(sc, t0); |
|---|
| | 471 | exps->data[i] = (void *)e; |
|---|
| | 472 | } |
|---|
| | 473 | |
|---|
| | 474 | if (!t0) |
|---|
| | 475 | t0 = Type::tvoid; |
|---|
| | 476 | if (pt) |
|---|
| | 477 | *pt = t0; |
|---|
| | 478 | |
|---|
| | 479 | // Eventually, we want to make this copy-on-write |
|---|
| | 480 | return exps; |
|---|
| | 481 | #endif |
|---|
| | 482 | #if DMDV2 |
|---|
| | 483 | /* The type is determined by applying ?: to each pair. |
|---|
| | 484 | */ |
|---|
| | 485 | IntegerExp integerexp(0); |
|---|
| | 486 | CondExp condexp(0, &integerexp, NULL, NULL); |
|---|
| | 487 | |
|---|
| | 488 | Type *t0 = NULL; |
|---|
| | 489 | Expression *e0; |
|---|
| | 490 | int j0; |
|---|
| | 491 | for (size_t i = 0; i < exps->dim; i++) |
|---|
| | 492 | { Expression *e = (Expression *)exps->data[i]; |
|---|
| | 493 | |
|---|
| | 494 | e = resolveProperties(sc, e); |
|---|
| | 495 | if (!e->type) |
|---|
| | 496 | { error("%s has no value", e->toChars()); |
|---|
| | 497 | e = new ErrorExp(); |
|---|
| | 498 | } |
|---|
| | 499 | |
|---|
| | 500 | if (t0) |
|---|
| | 501 | { if (t0 != e->type) |
|---|
| | 502 | { |
|---|
| | 503 | /* This applies ?: to merge the types. It's backwards; |
|---|
| | 504 | * ?: should call this function to merge types. |
|---|
| | 505 | */ |
|---|
| | 506 | condexp.type = NULL; |
|---|
| | 507 | condexp.e1 = e0; |
|---|
| | 508 | condexp.e2 = e; |
|---|
| | 509 | condexp.semantic(sc); |
|---|
| | 510 | exps->data[j0] = (void *)condexp.e1; |
|---|
| | 511 | e = condexp.e2; |
|---|
| | 512 | t0 = e->type; |
|---|
| | 513 | } |
|---|
| | 514 | } |
|---|
| | 515 | else |
|---|
| | 516 | { j0 = i; |
|---|
| | 517 | e0 = e; |
|---|
| | 518 | t0 = e->type; |
|---|
| | 519 | } |
|---|
| | 520 | exps->data[i] = (void *)e; |
|---|
| | 521 | } |
|---|
| | 522 | |
|---|
| | 523 | if (t0) |
|---|
| | 524 | { |
|---|
| | 525 | for (size_t i = 0; i < exps->dim; i++) |
|---|
| | 526 | { Expression *e = (Expression *)exps->data[i]; |
|---|
| | 527 | e = e->implicitCastTo(sc, t0); |
|---|
| | 528 | exps->data[i] = (void *)e; |
|---|
| | 529 | } |
|---|
| | 530 | } |
|---|
| | 531 | else |
|---|
| | 532 | t0 = Type::tvoid; // [] is typed as void[] |
|---|
| | 533 | if (pt) |
|---|
| | 534 | *pt = t0; |
|---|
| | 535 | |
|---|
| | 536 | // Eventually, we want to make this copy-on-write |
|---|
| | 537 | return exps; |
|---|
| | 538 | #endif |
|---|
| 2971 | | for (size_t i = 0; i < keys->dim; i++) |
|---|
| 2972 | | { Expression *key = (Expression *)keys->data[i]; |
|---|
| 2973 | | Expression *value = (Expression *)values->data[i]; |
|---|
| 2974 | | |
|---|
| 2975 | | key = key->semantic(sc); |
|---|
| 2976 | | value = value->semantic(sc); |
|---|
| 2977 | | |
|---|
| 2978 | | keys->data[i] = (void *)key; |
|---|
| 2979 | | values->data[i] = (void *)value; |
|---|
| 2980 | | } |
|---|
| | 3058 | arrayExpressionSemantic(keys, sc); |
|---|
| | 3059 | arrayExpressionSemantic(values, sc); |
|---|
| 2989 | | for (size_t i = 0; i < keys->dim; i++) |
|---|
| 2990 | | { Expression *key = (Expression *)keys->data[i]; |
|---|
| 2991 | | Expression *value = (Expression *)values->data[i]; |
|---|
| 2992 | | |
|---|
| 2993 | | if (!key->type) |
|---|
| 2994 | | error("%s has no value", key->toChars()); |
|---|
| 2995 | | if (!value->type) |
|---|
| 2996 | | error("%s has no value", value->toChars()); |
|---|
| 2997 | | key = resolveProperties(sc, key); |
|---|
| 2998 | | value = resolveProperties(sc, value); |
|---|
| 2999 | | |
|---|
| 3000 | | if (!tkey) |
|---|
| 3001 | | tkey = key->type; |
|---|
| 3002 | | else |
|---|
| 3003 | | key = key->implicitCastTo(sc, tkey); |
|---|
| 3004 | | keys->data[i] = (void *)key; |
|---|
| 3005 | | |
|---|
| 3006 | | if (!tvalue) |
|---|
| 3007 | | tvalue = value->type; |
|---|
| 3008 | | else |
|---|
| 3009 | | value = value->implicitCastTo(sc, tvalue); |
|---|
| 3010 | | values->data[i] = (void *)value; |
|---|
| 3011 | | } |
|---|
| 3012 | | |
|---|
| 3013 | | if (!tkey) |
|---|
| 3014 | | tkey = Type::tvoid; |
|---|
| 3015 | | if (!tvalue) |
|---|
| 3016 | | tvalue = Type::tvoid; |
|---|
| | 3068 | |
|---|
| | 3069 | Type *tkey = NULL; |
|---|
| | 3070 | Type *tvalue = NULL; |
|---|
| | 3071 | keys = arrayExpressionToCommonType(sc, keys, &tkey); |
|---|
| | 3072 | values = arrayExpressionToCommonType(sc, values, &tvalue); |
|---|
| | 3073 | |
|---|