Skip to content

Commit

Permalink
overloadApply takes a delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Sep 15, 2015
1 parent f39fd49 commit 9df839c
Showing 1 changed file with 32 additions and 31 deletions.
63 changes: 32 additions & 31 deletions src/func.d
Expand Up @@ -3792,84 +3792,85 @@ extern (C++) Expression addInvariant(Loc loc, Scope* sc, AggregateDeclaration ad
}

/***************************************************
* Visit each overloaded function/template in turn, and call
* (*fp)(param, s) on it.
* Exit when no more, or (*fp)(param, f) returns nonzero.
* Visit each overloaded function/template in turn, and call dg(s) on it.
* Exit when no more, or dg(s) returns nonzero.
* Returns:
* ==0 continue
* !=0 done
*/
extern (C++) int overloadApply(Dsymbol fstart, void* param, int function(void*, Dsymbol) fp)
extern (D) int overloadApply(Dsymbol fstart, scope int delegate(Dsymbol) dg)
{
Dsymbol d;
Dsymbol next;
for (d = fstart; d; d = next)
for (Dsymbol d = fstart; d; d = next)
{
if (OverDeclaration od = d.isOverDeclaration())
if (auto od = d.isOverDeclaration())
{
if (od.hasOverloads)
{
if (int r = overloadApply(od.aliassym, param, fp))
if (int r = overloadApply(od.aliassym, dg))
return r;
}
else
{
if (int r = (*fp)(param, od.aliassym))
if (int r = dg(od.aliassym))
return r;
}
next = od.overnext;
}
else if (FuncAliasDeclaration fa = d.isFuncAliasDeclaration())
else if (auto fa = d.isFuncAliasDeclaration())
{
if (fa.hasOverloads)
{
if (int r = overloadApply(fa.funcalias, param, fp))
if (int r = overloadApply(fa.funcalias, dg))
return r;
}
else
else if (auto fd = fa.toAliasFunc())
{
FuncDeclaration fd = fa.toAliasFunc();
if (!fd)
{
d.error("is aliased to a function");
break;
}
if (int r = (*fp)(param, fd))
if (int r = dg(fd))
return r;
}
else
{
d.error("is aliased to a function");
break;
}
next = fa.overnext;
}
else if (AliasDeclaration ad = d.isAliasDeclaration())
else if (auto ad = d.isAliasDeclaration())
{
next = ad.toAlias();
if (next == ad)
break;
if (next == fstart)
break;
}
else if (TemplateDeclaration td = d.isTemplateDeclaration())
else if (auto td = d.isTemplateDeclaration())
{
if (int r = (*fp)(param, td))
if (int r = dg(td))
return r;
next = td.overnext;
}
else
else if (auto fd = d.isFuncDeclaration())
{
FuncDeclaration fd = d.isFuncDeclaration();
if (!fd)
{
d.error("is aliased to a function");
break;
// BUG: should print error message?
}
if (int r = (*fp)(param, fd))
if (int r = dg(fd))
return r;
next = fd.overnext;
}
else
{
d.error("is aliased to a function");
break;
// BUG: should print error message?
}
}
return 0;
}

extern (C++) int overloadApply(Dsymbol fstart, void* param, int function(void*, Dsymbol) fp)
{
return overloadApply(fstart, s => (*fp)(param, s));
}

extern (C++) static void MODMatchToBuffer(OutBuffer* buf, ubyte lhsMod, ubyte rhsMod)
{
bool bothMutable = ((lhsMod & rhsMod) == 0);
Expand Down

0 comments on commit 9df839c

Please sign in to comment.