Skip to content

Commit

Permalink
optimize typeCombine call
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Feb 23, 2014
1 parent d40b16b commit 926aac1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 81 deletions.
3 changes: 2 additions & 1 deletion src/cast.c
Expand Up @@ -2850,6 +2850,7 @@ int typeMerge(Scope *sc, Expression *e, Type **pt, Expression **pe1, Expression

/************************************
* Bring leaves to common type.
* Returns ErrorExp if error occurs. otherwise returns NULL.
*/

Expression *typeCombine(BinExp *be, Scope *sc)
Expand All @@ -2875,7 +2876,7 @@ Expression *typeCombine(BinExp *be, Scope *sc)
return be->e1;
if (be->e2->op == TOKerror)
return be->e2;
return be;
return NULL;

Lerror:
Expression *ex = be->incompatibleTypes();
Expand Down
96 changes: 20 additions & 76 deletions src/expression.c
Expand Up @@ -6513,6 +6513,7 @@ Expression *BinAssignExp::semantic(Scope *sc)

if (e1->op == TOKarraylength)
{
// arr.length op= e2;
e = ArrayLengthExp::rewriteOpAssign(this);
e = e->semantic(sc);
return e;
Expand All @@ -6521,10 +6522,7 @@ Expression *BinAssignExp::semantic(Scope *sc)
{
// T[] op= ...
if (Expression *ex = typeCombine(this, sc))
{
if (ex->op == TOKerror)
return ex;
}
return ex;
type = e1->type;
return arrayOp(this, sc);
}
Expand All @@ -6551,10 +6549,7 @@ Expression *BinAssignExp::semantic(Scope *sc)
return scaleFactor(this, sc);

if (Expression *ex = typeCombine(this, sc))
{
if (ex->op == TOKerror)
return ex;
}
return ex;

if (arith)
{
Expand Down Expand Up @@ -11477,10 +11472,7 @@ Expression *PowAssignExp::semantic(Scope *sc)
{
// T[] ^^= ...
if (Expression *ex = typeCombine(this, sc))
{
if (ex->op == TOKerror)
return ex;
}
return ex;

// Check element types are arithmetic
Type *tb1 = e1->type->nextOf()->toBasetype();
Expand Down Expand Up @@ -11583,10 +11575,7 @@ Expression *AddExp::semantic(Scope *sc)
}

if (Expression *ex = typeCombine(this, sc))
{
if (ex->op == TOKerror)
return ex;
}
return ex;

Type *tb = type->toBasetype();
if (tb->ty == Tarray || tb->ty == Tsarray)
Expand Down Expand Up @@ -11678,10 +11667,7 @@ Expression *MinExp::semantic(Scope *sc)

// make sure pointer types are compatible
if (Expression *ex = typeCombine(this, sc))
{
if (ex->op == TOKerror)
return ex;
}
return ex;

type = Type::tptrdiff_t;
stride = t2->nextOf()->size();
Expand Down Expand Up @@ -11712,10 +11698,7 @@ Expression *MinExp::semantic(Scope *sc)
}

if (Expression *ex = typeCombine(this, sc))
{
if (ex->op == TOKerror)
return ex;
}
return ex;

Type *tb = type->toBasetype();
if (tb->ty == Tarray || tb->ty == Tsarray)
Expand Down Expand Up @@ -11859,10 +11842,7 @@ Expression *CatExp::semantic(Scope *sc)
}

if (Expression *ex = typeCombine(this, sc))
{
if (ex->op == TOKerror)
return ex;
}
return ex;
type = type->toHeadMutable();

Type *tb = type->toBasetype();
Expand Down Expand Up @@ -11927,10 +11907,7 @@ Expression *MulExp::semantic(Scope *sc)
return e;

if (Expression *ex = typeCombine(this, sc))
{
if (ex->op == TOKerror)
return ex;
}
return ex;

Type *tb = type->toBasetype();
if (tb->ty == Tarray || tb->ty == Tsarray)
Expand Down Expand Up @@ -12018,10 +11995,7 @@ Expression *DivExp::semantic(Scope *sc)
return e;

if (Expression *ex = typeCombine(this, sc))
{
if (ex->op == TOKerror)
return ex;
}
return ex;

Type *tb = type->toBasetype();
if (tb->ty == Tarray || tb->ty == Tsarray)
Expand Down Expand Up @@ -12108,10 +12082,7 @@ Expression *ModExp::semantic(Scope *sc)
return e;

if (Expression *ex = typeCombine(this, sc))
{
if (ex->op == TOKerror)
return ex;
}
return ex;

Type *tb = type->toBasetype();
if (tb->ty == Tarray || tb->ty == Tsarray)
Expand Down Expand Up @@ -12186,10 +12157,7 @@ Expression *PowExp::semantic(Scope *sc)
return e;

if (Expression *ex = typeCombine(this, sc))
{
if (ex->op == TOKerror)
return ex;
}
return ex;

Type *tb = type->toBasetype();
if (tb->ty == Tarray || tb->ty == Tsarray)
Expand Down Expand Up @@ -12258,10 +12226,7 @@ Expression *PowExp::semantic(Scope *sc)
// Leave handling of PowExp to the backend, or throw
// an error gracefully if no backend support exists.
if (Expression *ex = typeCombine(this, sc))
{
if (ex->op == TOKerror)
return ex;
}
return ex;
return this;
}
e = new ScopeExp(loc, mmath);
Expand Down Expand Up @@ -12400,10 +12365,7 @@ Expression *AndExp::semantic(Scope *sc)
}

if (Expression *ex = typeCombine(this, sc))
{
if (ex->op == TOKerror)
return ex;
}
return ex;

Type *tb = type->toBasetype();
if (tb->ty == Tarray || tb->ty == Tsarray)
Expand Down Expand Up @@ -12452,10 +12414,7 @@ Expression *OrExp::semantic(Scope *sc)
}

if (Expression *ex = typeCombine(this, sc))
{
if (ex->op == TOKerror)
return ex;
}
return ex;

Type *tb = type->toBasetype();
if (tb->ty == Tarray || tb->ty == Tsarray)
Expand Down Expand Up @@ -12504,10 +12463,7 @@ Expression *XorExp::semantic(Scope *sc)
}

if (Expression *ex = typeCombine(this, sc))
{
if (ex->op == TOKerror)
return ex;
}
return ex;

Type *tb = type->toBasetype();
if (tb->ty == Tarray || tb->ty == Tsarray)
Expand Down Expand Up @@ -12756,10 +12712,7 @@ Expression *CmpExp::semantic(Scope *sc)
}

if (Expression *ex = typeCombine(this, sc))
{
if (ex->op == TOKerror)
return ex;
}
return ex;

type = Type::tboolean;

Expand Down Expand Up @@ -13035,10 +12988,7 @@ Expression *EqualExp::semantic(Scope *sc)
}

if (Expression *ex = typeCombine(this, sc))
{
if (ex->op == TOKerror)
return ex;
}
return ex;

type = Type::tboolean;

Expand Down Expand Up @@ -13078,10 +13028,7 @@ Expression *IdentityExp::semantic(Scope *sc)
type = Type::tboolean;

if (Expression *ex = typeCombine(this, sc))
{
if (ex->op == TOKerror)
return ex;
}
return ex;

if (e1->type != e2->type && e1->type->isfloating() && e2->type->isfloating())
{
Expand Down Expand Up @@ -13156,10 +13103,7 @@ Expression *CondExp::semantic(Scope *sc)
else
{
if (Expression *ex = typeCombine(this, sc))
{
if (ex->op == TOKerror)
return ex;
}
return ex;
switch (e1->type->toBasetype()->ty)
{
case Tcomplex32:
Expand Down
5 changes: 1 addition & 4 deletions src/statement.c
Expand Up @@ -2273,10 +2273,7 @@ Statement *ForeachRangeStatement::semantic(Scope *sc)
{
AddExp ea(loc, lwr, upr);
if (Expression *ex = typeCombine(&ea, sc))
{
if (ex->op == TOKerror)
return new ErrorStatement();
}
return new ErrorStatement();
arg->type = ea.type;
lwr = ea.e1;
upr = ea.e2;
Expand Down

0 comments on commit 926aac1

Please sign in to comment.