mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-09-25 23:00:20 +02:00
Merge DMD r250: harmonize
--- dmd/expression.c | 133 ++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 95 insertions(+), 38 deletions(-)
This commit is contained in:
+95
-38
@@ -463,6 +463,95 @@ void expandTuples(Expressions *exps)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Expressions *arrayExpressionToCommonType(Scope *sc, Expressions *exps, Type **pt)
|
||||||
|
{
|
||||||
|
#if DMDV1
|
||||||
|
/* The first element sets the type
|
||||||
|
*/
|
||||||
|
Type *t0 = NULL;
|
||||||
|
for (size_t i = 0; i < exps->dim; i++)
|
||||||
|
{ Expression *e = (Expression *)exps->data[i];
|
||||||
|
|
||||||
|
if (!e->type)
|
||||||
|
{ error("%s has no value", e->toChars());
|
||||||
|
e = new ErrorExp();
|
||||||
|
}
|
||||||
|
e = resolveProperties(sc, e);
|
||||||
|
|
||||||
|
if (!t0)
|
||||||
|
t0 = e->type;
|
||||||
|
else
|
||||||
|
e = e->implicitCastTo(sc, t0);
|
||||||
|
exps->data[i] = (void *)e;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!t0)
|
||||||
|
t0 = Type::tvoid;
|
||||||
|
if (pt)
|
||||||
|
*pt = t0;
|
||||||
|
|
||||||
|
// Eventually, we want to make this copy-on-write
|
||||||
|
return exps;
|
||||||
|
#endif
|
||||||
|
#if DMDV2
|
||||||
|
/* The type is determined by applying ?: to each pair.
|
||||||
|
*/
|
||||||
|
IntegerExp integerexp(0);
|
||||||
|
CondExp condexp(0, &integerexp, NULL, NULL);
|
||||||
|
|
||||||
|
Type *t0 = NULL;
|
||||||
|
Expression *e0;
|
||||||
|
int j0;
|
||||||
|
for (size_t i = 0; i < exps->dim; i++)
|
||||||
|
{ Expression *e = (Expression *)exps->data[i];
|
||||||
|
|
||||||
|
e = resolveProperties(sc, e);
|
||||||
|
if (!e->type)
|
||||||
|
{ error("%s has no value", e->toChars());
|
||||||
|
e = new ErrorExp();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (t0)
|
||||||
|
{ if (t0 != e->type)
|
||||||
|
{
|
||||||
|
/* This applies ?: to merge the types. It's backwards;
|
||||||
|
* ?: should call this function to merge types.
|
||||||
|
*/
|
||||||
|
condexp.type = NULL;
|
||||||
|
condexp.e1 = e0;
|
||||||
|
condexp.e2 = e;
|
||||||
|
condexp.semantic(sc);
|
||||||
|
exps->data[j0] = (void *)condexp.e1;
|
||||||
|
e = condexp.e2;
|
||||||
|
t0 = e->type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ j0 = i;
|
||||||
|
e0 = e;
|
||||||
|
t0 = e->type;
|
||||||
|
}
|
||||||
|
exps->data[i] = (void *)e;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (t0)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < exps->dim; i++)
|
||||||
|
{ Expression *e = (Expression *)exps->data[i];
|
||||||
|
e = e->implicitCastTo(sc, t0);
|
||||||
|
exps->data[i] = (void *)e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
t0 = Type::tvoid; // [] is typed as void[]
|
||||||
|
if (pt)
|
||||||
|
*pt = t0;
|
||||||
|
|
||||||
|
// Eventually, we want to make this copy-on-write
|
||||||
|
return exps;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************
|
/****************************************
|
||||||
* Preprocess arguments to function.
|
* Preprocess arguments to function.
|
||||||
*/
|
*/
|
||||||
@@ -2984,24 +3073,14 @@ Expression *AssocArrayLiteralExp::syntaxCopy()
|
|||||||
|
|
||||||
Expression *AssocArrayLiteralExp::semantic(Scope *sc)
|
Expression *AssocArrayLiteralExp::semantic(Scope *sc)
|
||||||
{ Expression *e;
|
{ Expression *e;
|
||||||
Type *tkey = NULL;
|
|
||||||
Type *tvalue = NULL;
|
|
||||||
|
|
||||||
#if LOGSEMANTIC
|
#if LOGSEMANTIC
|
||||||
printf("AssocArrayLiteralExp::semantic('%s')\n", toChars());
|
printf("AssocArrayLiteralExp::semantic('%s')\n", toChars());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Run semantic() on each element
|
// Run semantic() on each element
|
||||||
for (size_t i = 0; i < keys->dim; i++)
|
arrayExpressionSemantic(keys, sc);
|
||||||
{ Expression *key = (Expression *)keys->data[i];
|
arrayExpressionSemantic(values, sc);
|
||||||
Expression *value = (Expression *)values->data[i];
|
|
||||||
|
|
||||||
key = key->semantic(sc);
|
|
||||||
value = value->semantic(sc);
|
|
||||||
|
|
||||||
keys->data[i] = (void *)key;
|
|
||||||
values->data[i] = (void *)value;
|
|
||||||
}
|
|
||||||
expandTuples(keys);
|
expandTuples(keys);
|
||||||
expandTuples(values);
|
expandTuples(values);
|
||||||
if (keys->dim != values->dim)
|
if (keys->dim != values->dim)
|
||||||
@@ -3010,34 +3089,12 @@ Expression *AssocArrayLiteralExp::semantic(Scope *sc)
|
|||||||
keys->setDim(0);
|
keys->setDim(0);
|
||||||
values->setDim(0);
|
values->setDim(0);
|
||||||
}
|
}
|
||||||
for (size_t i = 0; i < keys->dim; i++)
|
|
||||||
{ Expression *key = (Expression *)keys->data[i];
|
|
||||||
Expression *value = (Expression *)values->data[i];
|
|
||||||
|
|
||||||
if (!key->type)
|
Type *tkey = NULL;
|
||||||
error("%s has no value", key->toChars());
|
Type *tvalue = NULL;
|
||||||
if (!value->type)
|
keys = arrayExpressionToCommonType(sc, keys, &tkey);
|
||||||
error("%s has no value", value->toChars());
|
values = arrayExpressionToCommonType(sc, values, &tvalue);
|
||||||
key = resolveProperties(sc, key);
|
|
||||||
value = resolveProperties(sc, value);
|
|
||||||
|
|
||||||
if (!tkey)
|
|
||||||
tkey = key->type;
|
|
||||||
else
|
|
||||||
key = key->implicitCastTo(sc, tkey);
|
|
||||||
keys->data[i] = (void *)key;
|
|
||||||
|
|
||||||
if (!tvalue)
|
|
||||||
tvalue = value->type;
|
|
||||||
else
|
|
||||||
value = value->implicitCastTo(sc, tvalue);
|
|
||||||
values->data[i] = (void *)value;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!tkey)
|
|
||||||
tkey = Type::tvoid;
|
|
||||||
if (!tvalue)
|
|
||||||
tvalue = Type::tvoid;
|
|
||||||
type = new TypeAArray(tvalue, tkey);
|
type = new TypeAArray(tvalue, tkey);
|
||||||
type = type->semantic(loc, sc);
|
type = type->semantic(loc, sc);
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
Reference in New Issue
Block a user