Skip to content

Commit

Permalink
Refactor: ThisExp.var is always used as VarDeclaration
Browse files Browse the repository at this point in the history
Remove `isVarDeclaration()` calls.
  • Loading branch information
9rnsr committed Oct 9, 2015
1 parent c9c0f20 commit cd02d56
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/delegatize.d
Expand Up @@ -131,9 +131,8 @@ extern (C++) bool lambdaCheckForNestedRef(Expression e, Scope* sc)

override void visit(ThisExp e)
{
VarDeclaration v = e.var.isVarDeclaration();
if (v)
result = v.checkNestedReference(sc, Loc());
if (e.var)
result = e.var.checkNestedReference(sc, Loc());
}

override void visit(DeclarationExp e)
Expand Down
17 changes: 14 additions & 3 deletions src/expression.d
Expand Up @@ -3883,7 +3883,7 @@ public:
extern (C++) class ThisExp : Expression
{
public:
Declaration var;
VarDeclaration var;

final extern (D) this(Loc loc)
{
Expand All @@ -3899,7 +3899,9 @@ public:
}
if (type)
return this;

FuncDeclaration fd = hasThis(sc); // fd is the uplevel function with the 'this' variable

/* Special case for typeof(this) and typeof(super) since both
* should work even if they are not inside a non-static member function
*/
Expand Down Expand Up @@ -3929,15 +3931,17 @@ public:
}
if (!fd)
goto Lerr;

assert(fd.vthis);
var = fd.vthis;
assert(var.parent);
type = var.type;
if (var.isVarDeclaration().checkNestedReference(sc, loc))
if (var.checkNestedReference(sc, loc))
return new ErrorExp();
if (!sc.intypeof)
sc.callSuper |= CSXthis;
return this;

Lerr:
error("'this' is only defined in non-static member functions, not %s", sc.parent.toChars());
return new ErrorExp();
Expand Down Expand Up @@ -3994,9 +3998,11 @@ public:
}
if (type)
return this;

FuncDeclaration fd = hasThis(sc);
ClassDeclaration cd;
Dsymbol s;

/* Special case for typeof(this) and typeof(super) since both
* should work even if they are not inside a non-static member function
*/
Expand Down Expand Up @@ -4026,8 +4032,10 @@ public:
}
if (!fd)
goto Lerr;

var = fd.vthis;
assert(var && var.parent);

s = fd.toParent();
while (s && s.isTemplateInstance())
s = s.toParent();
Expand All @@ -4048,11 +4056,14 @@ public:
type = cd.baseClass.type;
type = type.castMod(var.type.mod);
}
if (var.isVarDeclaration().checkNestedReference(sc, loc))

if (var.checkNestedReference(sc, loc))
return new ErrorExp();

if (!sc.intypeof)
sc.callSuper |= CSXsuper;
return this;

Lerr:
error("'super' is only allowed in non-static class member functions");
return new ErrorExp();
Expand Down
2 changes: 1 addition & 1 deletion src/expression.h
Expand Up @@ -321,7 +321,7 @@ class DsymbolExp : public Expression
class ThisExp : public Expression
{
public:
Declaration *var;
VarDeclaration *var;

ThisExp(Loc loc);
Expression *semantic(Scope *sc);
Expand Down

0 comments on commit cd02d56

Please sign in to comment.