Skip to content

Commit

Permalink
Merge pull request #3216 from yebblies/integralPromotions
Browse files Browse the repository at this point in the history
[DDMD] [refactor] Move Expression::integralPromotions into a free function
  • Loading branch information
yebblies committed Feb 6, 2014
2 parents 8c85b98 + e88f627 commit e98486a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
16 changes: 7 additions & 9 deletions src/cast.c
Expand Up @@ -2161,8 +2161,8 @@ int typeMerge(Scope *sc, Expression *e, Type **pt, Expression **pe1, Expression
if (e->op != TOKquestion ||
t1b->ty != t2b->ty && (t1b->isTypeBasic() && t2b->isTypeBasic()))
{
e1 = e1->integralPromotions(sc);
e2 = e2->integralPromotions(sc);
e1 = integralPromotions(e1, sc);
e2 = integralPromotions(e2, sc);
}

Type *t1 = e1->type;
Expand Down Expand Up @@ -2648,8 +2648,8 @@ int typeMerge(Scope *sc, Expression *e, Type **pt, Expression **pe1, Expression
{
if (t1->ty != t2->ty)
{
e1 = e1->integralPromotions(sc);
e2 = e2->integralPromotions(sc);
e1 = integralPromotions(e1, sc);
e2 = integralPromotions(e2, sc);
t1 = e1->type; t1b = t1->toBasetype();
t2 = e2->type; t2b = t2->toBasetype();
}
Expand Down Expand Up @@ -2770,15 +2770,13 @@ Expression *BinExp::typeCombine(Scope *sc)
* Don't convert <array of> to <pointer to>
*/

Expression *Expression::integralPromotions(Scope *sc)
Expression *integralPromotions(Expression *e, Scope *sc)
{
Expression *e = this;

//printf("integralPromotions %s %s\n", e->toChars(), e->type->toChars());
switch (type->toBasetype()->ty)
switch (e->type->toBasetype()->ty)
{
case Tvoid:
error("void has no value");
e->error("void has no value");
return new ErrorExp();

case Tint8:
Expand Down
8 changes: 4 additions & 4 deletions src/expression.c
Expand Up @@ -1684,7 +1684,7 @@ Type *functionParameters(Loc loc, Scope *sc, TypeFunction *tf,
if (tf->linkage != LINKd)
{
// Promote bytes, words, etc., to ints
arg = arg->integralPromotions(sc);
arg = integralPromotions(arg, sc);

// Promote floats to doubles
switch (arg->type->ty)
Expand Down Expand Up @@ -12865,7 +12865,7 @@ Expression *ShlExp::semantic(Scope *sc)
if (e1->type->toBasetype()->ty == Tvector ||
e2->type->toBasetype()->ty == Tvector)
return incompatibleTypes();
e1 = e1->integralPromotions(sc);
e1 = integralPromotions(e1, sc);
e2 = e2->castTo(sc, Type::tshiftcnt);
type = e1->type;
}
Expand All @@ -12892,7 +12892,7 @@ Expression *ShrExp::semantic(Scope *sc)
if (e1->type->toBasetype()->ty == Tvector ||
e2->type->toBasetype()->ty == Tvector)
return incompatibleTypes();
e1 = e1->integralPromotions(sc);
e1 = integralPromotions(e1, sc);
e2 = e2->castTo(sc, Type::tshiftcnt);
type = e1->type;
}
Expand All @@ -12919,7 +12919,7 @@ Expression *UshrExp::semantic(Scope *sc)
if (e1->type->toBasetype()->ty == Tvector ||
e2->type->toBasetype()->ty == Tvector)
return incompatibleTypes();
e1 = e1->integralPromotions(sc);
e1 = integralPromotions(e1, sc);
e2 = e2->castTo(sc, Type::tshiftcnt);
type = e1->type;
}
Expand Down
2 changes: 1 addition & 1 deletion src/expression.h
Expand Up @@ -86,6 +86,7 @@ Expression *resolveAliasThis(Scope *sc, Expression *e);
Expression *callCpCtor(Scope *sc, Expression *e);
Expression *resolveOpDollar(Scope *sc, ArrayExp *ae);
Expression *resolveOpDollar(Scope *sc, SliceExp *se);
Expression *integralPromotions(Expression *e, Scope *sc);

AggregateDeclaration *isAggregate(Type *t);
IntRange getIntRange(Expression *e);
Expand Down Expand Up @@ -179,7 +180,6 @@ class Expression : public RootObject
Expression *checkToPointer();
Expression *addressOf(Scope *sc);
Expression *deref();
Expression *integralPromotions(Scope *sc);

Expression *toDelegate(Scope *sc, Type *t);

Expand Down
2 changes: 1 addition & 1 deletion src/statement.c
Expand Up @@ -3135,7 +3135,7 @@ Statement *SwitchStatement::semantic(Scope *sc)
}
else
{
condition = condition->integralPromotions(sc);
condition = integralPromotions(condition, sc);
if (condition->op != TOKerror && !condition->type->isintegral())
error("'%s' must be of integral or string type, it is a %s", condition->toChars(), condition->type->toChars());
}
Expand Down

0 comments on commit e98486a

Please sign in to comment.