Skip to content

Commit

Permalink
Merge pull request #5257 from 9rnsr/refactor_aliasthis
Browse files Browse the repository at this point in the history
Refactor around alias this handling code
  • Loading branch information
dnadlinger committed Nov 16, 2015
2 parents 34cf3f8 + a93b056 commit e538d60
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 66 deletions.
10 changes: 1 addition & 9 deletions src/aliasthis.d
Expand Up @@ -70,20 +70,12 @@ public:
.error(loc, "undefined identifier %s", ident.toChars());
return;
}
else if (ad.aliasthis && s != ad.aliasthis)
if (ad.aliasthis && s != ad.aliasthis)
{
.error(loc, "there can be only one alias this");
return;
}

if (ad.type.ty == Tstruct && (cast(TypeStruct)ad.type).sym != ad)
{
AggregateDeclaration ad2 = (cast(TypeStruct)ad.type).sym;
assert(ad2.type == Type.terror);
ad.aliasthis = ad2.aliasthis;
return;
}

/* disable the alias this conversion so the implicit conversion check
* doesn't use it.
*/
Expand Down
110 changes: 53 additions & 57 deletions src/mtype.d
Expand Up @@ -2030,64 +2030,60 @@ public:

final Type aliasthisOf()
{
AggregateDeclaration ad = isAggregate(this);
if (ad && ad.aliasthis)
auto ad = isAggregate(this);
if (!ad || !ad.aliasthis)
return null;

auto s = ad.aliasthis;
if (s.isAliasDeclaration())
s = s.toAlias();

if (s.isTupleDeclaration())
return null;

if (auto vd = s.isVarDeclaration())
{
Dsymbol s = ad.aliasthis;
if (s.isAliasDeclaration())
s = s.toAlias();
Declaration d = s.isDeclaration();
if (d && !d.isTupleDeclaration())
{
assert(d.type);
Type t = d.type;
if (d.isVarDeclaration() && d.needThis())
{
t = t.addMod(this.mod);
}
else if (d.isFuncDeclaration())
{
FuncDeclaration fd = resolveFuncCall(Loc(), null, d, null, this, null, 1);
if (fd && fd.errors)
return Type.terror;
if (fd && !fd.type.nextOf() && !fd.functionSemantic())
fd = null;
if (fd)
{
t = fd.type.nextOf();
if (!t) // issue 14185
return Type.terror;
t = t.substWildTo(mod == 0 ? MODmutable : mod);
}
else
return Type.terror;
}
return t;
}
EnumDeclaration ed = s.isEnumDeclaration();
if (ed)
{
Type t = ed.type;
return t;
}
TemplateDeclaration td = s.isTemplateDeclaration();
if (td)
{
assert(td._scope);
FuncDeclaration fd = resolveFuncCall(Loc(), null, td, null, this, null, 1);
if (fd && fd.errors)
return Type.terror;
if (fd && fd.functionSemantic())
{
Type t = fd.type.nextOf();
t = t.substWildTo(mod == 0 ? MODmutable : mod);
return t;
}
else
return Type.terror;
}
//printf("%s\n", s->kind());
auto t = vd.type;
if (vd.needThis())
t = t.addMod(this.mod);
return t;
}
if (auto fd = s.isFuncDeclaration())
{
fd = resolveFuncCall(Loc(), null, fd, null, this, null, 1);
if (!fd || fd.errors || !fd.functionSemantic())
return Type.terror;

auto t = fd.type.nextOf();
if (!t) // issue 14185
return Type.terror;
t = t.substWildTo(mod == 0 ? MODmutable : mod);
return t;
}
if (auto d = s.isDeclaration())
{
assert(d.type);
return d.type;
}
if (auto ed = s.isEnumDeclaration())
{
return ed.type;
}
if (auto td = s.isTemplateDeclaration())
{
assert(td._scope);
auto fd = resolveFuncCall(Loc(), null, td, null, this, null, 1);
if (!fd || fd.errors || !fd.functionSemantic())
return Type.terror;

auto t = fd.type.nextOf();
if (!t)
return Type.terror;
t = t.substWildTo(mod == 0 ? MODmutable : mod);
return t;
}

//printf("%s\n", s.kind());
return null;
}

Expand Down Expand Up @@ -8135,7 +8131,7 @@ public:
override MATCH implicitConvTo(Type to)
{
MATCH m;
//printf("TypeStruct::implicitConvTo(%s => %s)\n", toChars(), to->toChars());
//printf("TypeStruct::implicitConvTo(%s => %s)\n", toChars(), to.toChars());
if (ty == to.ty && sym == (cast(TypeStruct)to).sym)
{
m = MATCHexact; // exact match
Expand Down

0 comments on commit e538d60

Please sign in to comment.