Wiki Roadmap Timeline Tickets New Ticket Source Search Help / Guide About Trac Login

Changeset 1604:2afcaab30a6a

Show
Ignore:
Timestamp:
01/06/10 13:18:19 (2 years ago)
Author:
Leandro Lucarella <llucax@gmail.com>
branch:
default
Message:

Merge DMD r250: harmonize
---

dmd/expression.c | 133 ++++++++++++++++++++++++++++++++++++++---------------
1 files changed, 95 insertions(+), 38 deletions(-)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • dmd/expression.c

    r1587 r1604  
    462462    } 
    463463    } 
     464} 
     465 
     466Expressions *arrayExpressionToCommonType(Scope *sc, Expressions *exps, Type **pt) 
     467{ 
     468#if DMDV1 
     469    /* The first element sets the type 
     470     */ 
     471    Type *t0 = NULL; 
     472    for (size_t i = 0; i < exps->dim; i++) 
     473    {   Expression *e = (Expression *)exps->data[i]; 
     474 
     475    if (!e->type) 
     476    {   error("%s has no value", e->toChars()); 
     477        e = new ErrorExp(); 
     478    } 
     479    e = resolveProperties(sc, e); 
     480 
     481    if (!t0) 
     482        t0 = e->type; 
     483    else 
     484        e = e->implicitCastTo(sc, t0); 
     485    exps->data[i] = (void *)e; 
     486    } 
     487 
     488    if (!t0) 
     489    t0 = Type::tvoid; 
     490    if (pt) 
     491    *pt = t0; 
     492 
     493    // Eventually, we want to make this copy-on-write 
     494    return exps; 
     495#endif 
     496#if DMDV2 
     497    /* The type is determined by applying ?: to each pair. 
     498     */ 
     499    IntegerExp integerexp(0); 
     500    CondExp condexp(0, &integerexp, NULL, NULL); 
     501 
     502    Type *t0 = NULL; 
     503    Expression *e0; 
     504    int j0; 
     505    for (size_t i = 0; i < exps->dim; i++) 
     506    {   Expression *e = (Expression *)exps->data[i]; 
     507 
     508    e = resolveProperties(sc, e); 
     509    if (!e->type) 
     510    {   error("%s has no value", e->toChars()); 
     511        e = new ErrorExp(); 
     512    } 
     513 
     514    if (t0) 
     515    {   if (t0 != e->type) 
     516        { 
     517        /* This applies ?: to merge the types. It's backwards; 
     518         * ?: should call this function to merge types. 
     519         */ 
     520        condexp.type = NULL; 
     521        condexp.e1 = e0; 
     522        condexp.e2 = e; 
     523        condexp.semantic(sc); 
     524        exps->data[j0] = (void *)condexp.e1; 
     525        e = condexp.e2; 
     526        t0 = e->type; 
     527        } 
     528    } 
     529    else 
     530    {   j0 = i; 
     531        e0 = e; 
     532        t0 = e->type; 
     533    } 
     534    exps->data[i] = (void *)e; 
     535    } 
     536 
     537    if (t0) 
     538    { 
     539    for (size_t i = 0; i < exps->dim; i++) 
     540    {   Expression *e = (Expression *)exps->data[i]; 
     541        e = e->implicitCastTo(sc, t0); 
     542        exps->data[i] = (void *)e; 
     543    } 
     544    } 
     545    else 
     546    t0 = Type::tvoid;       // [] is typed as void[] 
     547    if (pt) 
     548    *pt = t0; 
     549 
     550    // Eventually, we want to make this copy-on-write 
     551    return exps; 
     552#endif 
    464553} 
    465554 
     
    29853074Expression *AssocArrayLiteralExp::semantic(Scope *sc) 
    29863075{   Expression *e; 
    2987     Type *tkey = NULL; 
    2988     Type *tvalue = NULL; 
    29893076 
    29903077#if LOGSEMANTIC 
     
    29933080 
    29943081    // Run semantic() on each element 
    2995     for (size_t i = 0; i < keys->dim; i++) 
    2996     {   Expression *key = (Expression *)keys->data[i]; 
    2997     Expression *value = (Expression *)values->data[i]; 
    2998  
    2999     key = key->semantic(sc); 
    3000     value = value->semantic(sc); 
    3001  
    3002     keys->data[i] = (void *)key; 
    3003     values->data[i] = (void *)value; 
    3004     } 
     3082    arrayExpressionSemantic(keys, sc); 
     3083    arrayExpressionSemantic(values, sc); 
    30053084    expandTuples(keys); 
    30063085    expandTuples(values); 
     
    30113090    values->setDim(0); 
    30123091    } 
    3013     for (size_t i = 0; i < keys->dim; i++) 
    3014     {   Expression *key = (Expression *)keys->data[i]; 
    3015     Expression *value = (Expression *)values->data[i]; 
    3016  
    3017     if (!key->type) 
    3018         error("%s has no value", key->toChars()); 
    3019     if (!value->type) 
    3020         error("%s has no value", value->toChars()); 
    3021     key = resolveProperties(sc, key); 
    3022     value = resolveProperties(sc, value); 
    3023  
    3024     if (!tkey) 
    3025         tkey = key->type; 
    3026     else 
    3027         key = key->implicitCastTo(sc, tkey); 
    3028     keys->data[i] = (void *)key; 
    3029  
    3030     if (!tvalue) 
    3031         tvalue = value->type; 
    3032     else 
    3033         value = value->implicitCastTo(sc, tvalue); 
    3034     values->data[i] = (void *)value; 
    3035     } 
    3036  
    3037     if (!tkey) 
    3038     tkey = Type::tvoid; 
    3039     if (!tvalue) 
    3040     tvalue = Type::tvoid; 
     3092 
     3093    Type *tkey = NULL; 
     3094    Type *tvalue = NULL; 
     3095    keys = arrayExpressionToCommonType(sc, keys, &tkey); 
     3096    values = arrayExpressionToCommonType(sc, values, &tvalue); 
     3097 
    30413098    type = new TypeAArray(tvalue, tkey); 
    30423099    type = type->semantic(loc, sc); 
Copyright © 2008, LDC Development Team.