Skip to content

Commit

Permalink
Use DsymbolExp.resolve in several places to reduce DsymbolExp creation
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Sep 23, 2015
1 parent be961e7 commit 0dc9bd7
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 35 deletions.
7 changes: 5 additions & 2 deletions src/aggregate.d
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,20 @@ public:
auto tiargs = new Objects();
tiargs.push(type);
auto ti = new TemplateInstance(loc, Type.rtinfo, tiargs);

Scope* sc3 = ti.tempdecl._scope.startCTFE();
sc3.tinst = sc.tinst;
sc3.minst = sc.minst;
if (isDeprecated())
sc3.stc |= STCdeprecated;

ti.semantic(sc3);
ti.semantic2(sc3);
ti.semantic3(sc3);
Expression e = new DsymbolExp(Loc(), ti.toAlias(), 0);
e = e.semantic(sc3);
auto e = DsymbolExp.resolve(Loc(), sc3, ti.toAlias(), false);

sc3.endCTFE();

e = e.ctfeInterpret();
getRTInfo = e;
}
Expand Down
40 changes: 17 additions & 23 deletions src/expression.d
Original file line number Diff line number Diff line change
Expand Up @@ -3555,6 +3555,7 @@ public:
t = (cast(TypePointer)t).next;
e = typeDotIdExp(loc, t, ident);
}
e = e.semantic(sc);
}
else
{
Expand All @@ -3564,6 +3565,7 @@ public:
if (d)
checkAccess(loc, sc, null, d);
}

/* If f is really a function template,
* then replace f with the function template declaration.
*/
Expand All @@ -3581,9 +3583,9 @@ public:
}
}
// Haven't done overload resolution yet, so pass 1
e = new DsymbolExp(loc, s, 1);
e = DsymbolExp.resolve(loc, sc, s, true);
}
return e.semantic(sc);
return e;
}
if (hasThis(sc))
{
Expand Down Expand Up @@ -5143,8 +5145,7 @@ public:
else if (s)
{
//printf("s = %s %s\n", s->kind(), s->toChars());
e = new DsymbolExp(loc, s, s.hasOverloads());
e = e.semantic(sc);
e = DsymbolExp.resolve(loc, sc, s, s.hasOverloads());
}
else
assert(0);
Expand Down Expand Up @@ -5248,10 +5249,10 @@ public:
// Same as wthis.s
e = new VarExp(loc, withsym.withstate.wthis);
e = new DotVarExp(loc, e, s.isDeclaration());
e = e.semantic(sc);
}
else
e = new DsymbolExp(loc, s, s.hasOverloads());
e = e.semantic(sc);
e = DsymbolExp.resolve(loc, sc, s, s.hasOverloads());
//printf("-1ScopeExp::semantic()\n");
return e;
}
Expand Down Expand Up @@ -5309,9 +5310,7 @@ public:
if (!fd)
return Expression.toLvalue(sc, e);
assert(sc);
Expression ex = new DsymbolExp(loc, fd, 1);
ex = ex.semantic(sc);
return ex;
return DsymbolExp.resolve(loc, sc, fd, true);
}

override bool checkValue()
Expand Down Expand Up @@ -6559,10 +6558,10 @@ public:
}
if (ea)
{
Dsymbol sym = getDsymbol(ea);
if (sym)
ea = new DsymbolExp(loc, sym);
ea = ea.semantic(sc);
if (auto sym = getDsymbol(ea))
ea = DsymbolExp.resolve(loc, sc, sym, false);
else
ea = ea.semantic(sc);
ea = resolveProperties(sc, ea);
ta = ea.type;
if (ea.op == TOKtype)
Expand Down Expand Up @@ -8167,8 +8166,7 @@ public:
if (fd.isNested() || fd.isFuncLiteralDeclaration())
{
// (e1, fd)
Expression e = new DsymbolExp(loc, fd);
e = e.semantic(sc);
auto e = DsymbolExp.resolve(loc, sc, fd, false);
return Expression.combine(e1, e);
}
type = fd.type;
Expand Down Expand Up @@ -8457,8 +8455,7 @@ public:
}
if (e1.op == TOKtype)
{
e = new DsymbolExp(loc, s);
e = e.semantic(sc);
e = DsymbolExp.resolve(loc, sc, s, false);
return e;
}
e = new ScopeExp(loc, ti);
Expand Down Expand Up @@ -8514,8 +8511,7 @@ public:
{
// This should *really* be moved to ScopeExp::semantic()
ScopeExp se = cast(ScopeExp)de.e2;
de.e2 = new DsymbolExp(loc, se.sds);
de.e2 = de.e2.semantic(sc);
de.e2 = DsymbolExp.resolve(loc, sc, se.sds, false);
}
if (de.e2.op == TOKtemplate)
{
Expand Down Expand Up @@ -8881,8 +8877,7 @@ public:
{
// Perhaps this should be moved to ScopeExp::semantic()
ScopeExp se = cast(ScopeExp)e1;
e1 = new DsymbolExp(loc, se.sds);
e1 = e1.semantic(sc);
e1 = DsymbolExp.resolve(loc, sc, se.sds, false);
}
else if (e1.op == TOKsymoff && (cast(SymOffExp)e1).hasOverloads)
{
Expand All @@ -8903,8 +8898,7 @@ public:
{
// This should *really* be moved to ScopeExp::semantic()
ScopeExp se = cast(ScopeExp)de.e2;
de.e2 = new DsymbolExp(loc, se.sds);
de.e2 = de.e2.semantic(sc);
de.e2 = DsymbolExp.resolve(loc, sc, se.sds, false);
}
if (de.e2.op == TOKtemplate)
{
Expand Down
2 changes: 1 addition & 1 deletion src/func.d
Original file line number Diff line number Diff line change
Expand Up @@ -2087,7 +2087,7 @@ public:
if (isStatic())
{
// The monitor is in the ClassInfo
vsync = new DotIdExp(loc, new DsymbolExp(loc, cd), Id.classinfo);
vsync = new DotIdExp(loc, DsymbolExp.resolve(loc, sc2, cd, false), Id.classinfo);
}
else
{
Expand Down
14 changes: 6 additions & 8 deletions src/mtype.d
Original file line number Diff line number Diff line change
Expand Up @@ -6829,8 +6829,8 @@ public:
if (tindex)
eindex = new TypeExp(loc, tindex);
else if (sindex)
eindex = new DsymbolExp(loc, sindex);
Expression e = new IndexExp(loc, new DsymbolExp(loc, s), eindex);
eindex = DsymbolExp.resolve(loc, sc, sindex, false);
Expression e = new IndexExp(loc, DsymbolExp.resolve(loc, sc, s, false), eindex);
e = e.semantic(sc);
if (e.op == TOKerror)
*pt = Type.terror;
Expand All @@ -6844,7 +6844,7 @@ public:
if (tindex)
tindex.resolve(loc, sc, &eindex, &tindex, &sindex);
if (sindex)
eindex = new DsymbolExp(loc, sindex);
eindex = DsymbolExp.resolve(loc, sc, sindex, false);
if (!eindex)
{
.error(loc, "index is %s not an expression", oindex.toChars());
Expand Down Expand Up @@ -7014,7 +7014,7 @@ public:
VarDeclaration v = s.isVarDeclaration();
FuncDeclaration f = s.isFuncDeclaration();
if (intypeid || !v && !f)
e = new DsymbolExp(loc, s);
e = DsymbolExp.resolve(loc, sc, s, false);
else
e = new VarExp(loc, s.isDeclaration());
resolveExprType(loc, sc, e, i, pe, pt);
Expand Down Expand Up @@ -8013,8 +8013,7 @@ public:
}
if (s.isImport() || s.isModule() || s.isPackage())
{
e = new DsymbolExp(e.loc, s, 0);
e = e.semantic(sc);
e = DsymbolExp.resolve(e.loc, sc, s, false);
return e;
}
OverloadSet o = s.isOverloadSet();
Expand Down Expand Up @@ -8868,8 +8867,7 @@ public:
}
if (s.isImport() || s.isModule() || s.isPackage())
{
e = new DsymbolExp(e.loc, s, 0);
e = e.semantic(sc);
e = DsymbolExp.resolve(e.loc, sc, s, false);
return e;
}
OverloadSet o = s.isOverloadSet();
Expand Down
2 changes: 1 addition & 1 deletion src/traits.d
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ extern (C++) Expression semanticTraits(TraitsExp e, Scope* sc)
return ex.semantic(sc);
}
}
return (new DsymbolExp(e.loc, s)).semantic(sc);
return DsymbolExp.resolve(e.loc, sc, s, false);
}
else if (e.ident == Id.hasMember || e.ident == Id.getMember || e.ident == Id.getOverloads || e.ident == Id.getVirtualMethods || e.ident == Id.getVirtualFunctions)
{
Expand Down

0 comments on commit 0dc9bd7

Please sign in to comment.