Skip to content

Commit

Permalink
Simplify code by using helper constructors in ExpStatement and CallExp
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Jul 3, 2015
1 parent 92c3700 commit fd976fa
Showing 1 changed file with 10 additions and 22 deletions.
32 changes: 10 additions & 22 deletions src/statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -1860,8 +1860,7 @@ Statement *ForeachStatement::semantic(Scope *sc)
Initializer *ie = new ExpInitializer(Loc(), new IntegerExp(k));
VarDeclaration *var = new VarDeclaration(loc, p->type, p->ident, ie);
var->storage_class |= STCmanifest;
DeclarationExp *de = new DeclarationExp(loc, var);
st->push(new ExpStatement(loc, de));
st->push(new ExpStatement(loc, var));
p = (*parameters)[1]; // value
}
// Declare value
Expand Down Expand Up @@ -1943,8 +1942,7 @@ Statement *ForeachStatement::semantic(Scope *sc)
return new ErrorStatement();
}
}
DeclarationExp *de = new DeclarationExp(loc, var);
st->push(new ExpStatement(loc, de));
st->push(new ExpStatement(loc, var));

st->push(body->syntaxCopy());
s = new CompoundStatement(loc, st);
Expand Down Expand Up @@ -2254,8 +2252,7 @@ Statement *ForeachStatement::semantic(Scope *sc)
ve->storage_class |= STCforeach;
ve->storage_class |= p->storageClass & (STCin | STCout | STCref | STC_TYPECTOR);

DeclarationExp *de = new DeclarationExp(loc, ve);
makeargs = new ExpStatement(loc, de);
makeargs = new ExpStatement(loc, ve);
}
else
{
Expand All @@ -2264,7 +2261,7 @@ Statement *ForeachStatement::semantic(Scope *sc)
VarDeclaration *vd = new VarDeclaration(loc, NULL, id, ei);
vd->storage_class |= STCtemp | STCctfe | STCref | STCforeach;

makeargs = new ExpStatement(loc, new DeclarationExp(loc, vd));
makeargs = new ExpStatement(loc, vd);

Declaration *d = sfront->isDeclaration();
if (FuncDeclaration *f = d->isFuncDeclaration())
Expand Down Expand Up @@ -2316,8 +2313,7 @@ Statement *ForeachStatement::semantic(Scope *sc)

VarDeclaration *var = new VarDeclaration(loc, p->type, p->ident, new ExpInitializer(loc, exp));
var->storage_class |= STCctfe | STCref | STCforeach;
DeclarationExp *de = new DeclarationExp(loc, var);
makeargs = new CompoundStatement(loc, makeargs, new ExpStatement(loc, de));
makeargs = new CompoundStatement(loc, makeargs, new ExpStatement(loc, var));
}

}
Expand Down Expand Up @@ -2568,34 +2564,28 @@ Statement *ForeachStatement::semantic(Scope *sc)
fdapply = FuncDeclaration::genCfunc(params, Type::tint32, fdname);

ec = new VarExp(Loc(), fdapply);
Expressions *exps = new Expressions();
if (tab->ty == Tsarray)
aggr = aggr->castTo(sc, tn->arrayOf());
exps->push(aggr);
// paint delegate argument to the type runtime expects
if (!dgty->equals(flde->type)) {
flde = new CastExp(loc, flde, flde->type);
flde->type = dgty;
}
exps->push(flde);
e = new CallExp(loc, ec, exps);
e = new CallExp(loc, ec, aggr, flde);
e->type = Type::tint32; // don't run semantic() on e
}
else if (tab->ty == Tdelegate)
{
/* Call:
* aggr(flde)
*/
Expressions *exps = new Expressions();
exps->push(flde);
if (aggr->op == TOKdelegate &&
((DelegateExp *)aggr)->func->isNested())
{
// See Bugzilla 3560
e = new CallExp(loc, ((DelegateExp *)aggr)->e1, exps);
aggr = ((DelegateExp *)aggr)->e1;
}
else
e = new CallExp(loc, aggr, exps);
e = new CallExp(loc, aggr, flde);
e = e->semantic(sc);
if (e->op == TOKerror)
goto Lerror2;
Expand All @@ -2608,14 +2598,12 @@ Statement *ForeachStatement::semantic(Scope *sc)
else
{
assert(tab->ty == Tstruct || tab->ty == Tclass);
Expressions *exps = new Expressions();
assert(sapply);
/* Call:
* aggr.apply(flde)
*/
ec = new DotIdExp(loc, aggr, sapply->ident);
exps->push(flde);
e = new CallExp(loc, ec, exps);
e = new CallExp(loc, ec, flde);
e = e->semantic(sc);
if (e->op == TOKerror)
goto Lerror2;
Expand Down Expand Up @@ -4537,7 +4525,7 @@ Statement *WithStatement::semantic(Scope *sc)
init = new ExpInitializer(loc, exp);
wthis = new VarDeclaration(loc, exp->type, Identifier::generateId("__withtmp"), init);
wthis->storage_class |= STCtemp;
ExpStatement *es = new ExpStatement(loc, new DeclarationExp(loc, wthis));
ExpStatement *es = new ExpStatement(loc, wthis);
exp = new VarExp(loc, wthis);
Statement *ss = new ScopeStatement(loc, new CompoundStatement(loc, es, this));
return ss->semantic(sc);
Expand Down

0 comments on commit fd976fa

Please sign in to comment.