Skip to content

Commit

Permalink
Merge pull request #5129 from WalterBright/scopeclass
Browse files Browse the repository at this point in the history
inline.d: struct => scope class to eliminate use of pointers
  • Loading branch information
yebblies committed Sep 28, 2015
2 parents 58220eb + 9896d42 commit 983b184
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions src/inline.d
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ public:
* o Copying the trees of the function to be inlined
* o Renaming the variables
*/
struct InlineDoState
final class InlineDoState
{
// inline context
VarDeclaration vthis;
Expand All @@ -423,18 +423,24 @@ struct InlineDoState
FuncDeclaration fd; // function being inlined (old parent)
// inline result
bool foundReturn;

this(Dsymbol parent, FuncDeclaration fd)
{
this.parent = parent;
this.fd = fd;
}
}

Statement inlineAsStatement(Statement s, InlineDoState* ids)
Statement inlineAsStatement(Statement s, InlineDoState ids)
{
extern (C++) final class InlineAsStatement : Visitor
{
alias visit = super.visit;
public:
InlineDoState* ids;
InlineDoState ids;
Statement result;

extern (D) this(InlineDoState* ids)
extern (D) this(InlineDoState ids)
{
this.ids = ids;
}
Expand Down Expand Up @@ -549,16 +555,16 @@ Statement inlineAsStatement(Statement s, InlineDoState* ids)

/***********************************************************
*/
Expression doInline(Statement s, InlineDoState* ids)
Expression doInline(Statement s, InlineDoState ids)
{
extern (C++) final class InlineStatement : Visitor
{
alias visit = super.visit;
public:
InlineDoState* ids;
InlineDoState ids;
Expression result;

extern (D) this(InlineDoState* ids)
extern (D) this(InlineDoState ids)
{
this.ids = ids;
}
Expand Down Expand Up @@ -710,16 +716,16 @@ Expression doInline(Statement s, InlineDoState* ids)

/***********************************************************
*/
Expression doInline(Expression e, InlineDoState* ids)
Expression doInline(Expression e, InlineDoState ids)
{
extern (C++) final class InlineExpression : Visitor
{
alias visit = super.visit;
public:
InlineDoState* ids;
InlineDoState ids;
Expression result;

extern (D) this(InlineDoState* ids)
extern (D) this(InlineDoState ids)
{
this.ids = ids;
}
Expand Down Expand Up @@ -1888,17 +1894,14 @@ void expandInline(FuncDeclaration fd, FuncDeclaration parent, Expression eret,
Expression ethis, Expressions* arguments, bool asStatements,
out Expression eresult, out Statement sresult, out bool again)
{
InlineDoState ids;
Expression e = null;
Statements* as = null;
TypeFunction tf = cast(TypeFunction)fd.type;
static if (LOG || CANINLINE_LOG)
{
printf("FuncDeclaration::expandInline('%s')\n", fd.toChars());
}
memset(&ids, 0, ids.sizeof);
ids.parent = parent;
ids.fd = fd;
scope ids = new InlineDoState(parent, fd);

// When the function is actually expanded
if (TemplateInstance ti = fd.isInstantiated())
Expand Down Expand Up @@ -2051,15 +2054,15 @@ void expandInline(FuncDeclaration fd, FuncDeclaration parent, Expression eret,
e = null;
}
fd.inlineNest++;
Statement s = inlineAsStatement(fd.fbody, &ids);
Statement s = inlineAsStatement(fd.fbody, ids);
as.push(s);
sresult = new ScopeStatement(Loc(), new CompoundStatement(Loc(), as));
fd.inlineNest--;
}
else
{
fd.inlineNest++;
Expression eb = doInline(fd.fbody, &ids);
Expression eb = doInline(fd.fbody, ids);
e = Expression.combine(e, eb);
fd.inlineNest--;
//eb->type->print();
Expand Down Expand Up @@ -2141,8 +2144,6 @@ public Expression inlineCopy(Expression e, Scope* sc)
e.error("cannot inline default argument %s", e.toChars());
return new ErrorExp();
}
InlineDoState ids;
memset(&ids, 0, ids.sizeof);
ids.parent = sc.parent;
return doInline(e, &ids);
scope ids = new InlineDoState(sc.parent, null);
return doInline(e, ids);
}

0 comments on commit 983b184

Please sign in to comment.