Skip to content

Commit

Permalink
[Refactoring] Use resolveFuncCall in almost places
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Feb 26, 2013
1 parent 5bc2f52 commit c075a22
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 87 deletions.
48 changes: 16 additions & 32 deletions src/clone.c
Expand Up @@ -40,26 +40,20 @@ FuncDeclaration *AggregateDeclaration::hasIdentityOpAssign(Scope *sc, Dsymbol *a
Expressions ar; ar.push(er);
Expressions al; al.push(el);
FuncDeclaration *f = NULL;
if (FuncDeclaration *fd = assign->isFuncDeclaration())
{
f = fd->overloadResolve(loc, er, &ar, 1);
if (!f) f = fd->overloadResolve(loc, er, &al, 1);
}
if (TemplateDeclaration *td = assign->isTemplateDeclaration())
{
unsigned errors = global.startGagging(); // Do not report errors, even if the
unsigned oldspec = global.speculativeGag; // template opAssign fbody makes it.
global.speculativeGag = global.gag;
Scope *sc2 = sc->push();
sc2->speculative = true;

f = td->deduceFunctionTemplate(loc, sc2, NULL, er, &ar, 1);
if (!f) f = td->deduceFunctionTemplate(loc, sc2, NULL, er, &al, 1);

sc2->pop();
global.speculativeGag = oldspec;
global.endGagging(errors);
}

unsigned errors = global.startGagging(); // Do not report errors, even if the
unsigned oldspec = global.speculativeGag; // template opAssign fbody makes it.
global.speculativeGag = global.gag;
sc = sc->push();
sc->speculative = true;

f = resolveFuncCall(loc, sc, assign, NULL, er, &ar, 1);
if (!f) f = resolveFuncCall(loc, sc, assign, NULL, er, &al, 1);

sc = sc->pop();
global.speculativeGag = oldspec;
global.endGagging(errors);

if (f)
{
int varargs;
Expand Down Expand Up @@ -343,19 +337,9 @@ FuncDeclaration *StructDeclaration::buildOpEquals(Scope *sc)
arguments->push(e);

// check identity opEquals exists
FuncDeclaration *fd = eq->isFuncDeclaration();
FuncDeclaration *fd = resolveFuncCall(loc, sc, eq, NULL, e, arguments, 1);
if (fd)
{ fd = fd->overloadResolve(loc, e, arguments, 1);
if (fd && !(fd->storage_class & STCdisable))
return fd;
}

TemplateDeclaration *td = eq->isTemplateDeclaration();
if (td)
{ fd = td->deduceFunctionTemplate(loc, sc, NULL, e, arguments, 1);
if (fd && !(fd->storage_class & STCdisable))
return fd;
}
return (fd->storage_class & STCdisable) ? NULL : fd;
}
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion src/declaration.h
Expand Up @@ -726,7 +726,7 @@ FuncDeclaration *resolveFuncCall(Loc loc, Scope *sc, Dsymbol *s,
Objects *tiargs,
Expression *ethis,
Expressions *arguments,
int flags);
int flags = 0);
#endif

struct FuncAliasDeclaration : FuncDeclaration
Expand Down
55 changes: 23 additions & 32 deletions src/expression.c
Expand Up @@ -253,7 +253,7 @@ Expression *resolveProperties(Scope *sc, Expression *e)
L1:
assert(td);
unsigned errors = global.startGagging();
FuncDeclaration *fd = td->deduceFunctionTemplate(e->loc, sc, targsi, ethis, NULL, 1);
FuncDeclaration *fd = resolveFuncCall(e->loc, sc, td, targsi, ethis, NULL, 1);
if (global.endGagging(errors))
fd = NULL; // eat "is not a function template" error
if (fd && fd->type)
Expand Down Expand Up @@ -4662,7 +4662,7 @@ Expression *NewExp::semantic(Scope *sc)
newargs = new Expressions();
newargs->shift(e);

f = cd->aggNew->overloadResolve(loc, NULL, newargs);
f = resolveFuncCall(loc, sc, cd->aggNew, NULL, NULL, newargs);
allocator = f->isNewDeclaration();
assert(allocator);

Expand Down Expand Up @@ -4700,7 +4700,7 @@ Expression *NewExp::semantic(Scope *sc)
newargs = new Expressions();
newargs->shift(e);

FuncDeclaration *f = sd->aggNew->overloadResolve(loc, NULL, newargs);
FuncDeclaration *f = resolveFuncCall(loc, sc, sd->aggNew, NULL, NULL, newargs);
allocator = f->isNewDeclaration();
assert(allocator);

Expand Down Expand Up @@ -7981,25 +7981,23 @@ Expression *CallExp::semantic(Scope *sc)
ue1 = NULL;
}

Dsymbol *s;
if (e1->op == TOKdotvar)
{ // Do overload resolution
{
dve = (DotVarExp *)(e1);

f = dve->var->isFuncDeclaration();
assert(f);
f = f->overloadResolve(loc, ue1, arguments);

ad = f->toParent()->isAggregateDeclaration();
s = dve->var;
}
else
{ dte = (DotTemplateExp *)(e1);
TemplateDeclaration *td = dte->td;
assert(td);
f = td->deduceFunctionTemplate(loc, sc, targsi, ue1, arguments);
if (!f)
return new ErrorExp();
ad = td->toParent()->isAggregateDeclaration();
s = dte->td;
}

// Do overload resolution
f = resolveFuncCall(loc, sc, s, targsi, ue1, arguments);
if (!f)
return new ErrorExp();
ad = f->toParent2()->isAggregateDeclaration();

if (f->needThis())
{
ue->e1 = getRightThis(loc, sc, ad, ue->e1, f);
Expand Down Expand Up @@ -8166,16 +8164,7 @@ Expression *CallExp::semantic(Scope *sc)
Dsymbol *s = NULL;
for (size_t i = 0; i < eo->vars->a.dim; i++)
{ s = eo->vars->a[i];
FuncDeclaration *f2 = s->isFuncDeclaration();
if (f2)
{
f2 = f2->overloadResolve(loc, ethis, arguments, 1);
}
else
{ TemplateDeclaration *td = s->isTemplateDeclaration();
assert(td);
f2 = td->deduceFunctionTemplate(loc, sc, targsi, ethis, arguments, 1);
}
FuncDeclaration *f2 = resolveFuncCall(loc, sc, s, targsi, ethis, arguments, 1);
if (f2)
{ if (f)
/* Error if match in more than one overload set,
Expand Down Expand Up @@ -8231,7 +8220,7 @@ Expression *CallExp::semantic(Scope *sc)
else if (e1->op == TOKtemplate)
{
TemplateExp *te = (TemplateExp *)e1;
f = te->td->deduceFunctionTemplate(loc, sc, targsi, NULL, arguments);
f = resolveFuncCall(loc, sc, te->td, targsi, NULL, arguments);
if (!f)
{ if (tierror)
tierror->error("errors instantiating template"); // give better error message
Expand Down Expand Up @@ -8315,7 +8304,7 @@ Expression *CallExp::semantic(Scope *sc)
assert(f);

if (ve->hasOverloads)
f = f->overloadResolve(loc, NULL, arguments, 2);
f = resolveFuncCall(loc, sc, f, targsi, NULL, arguments, 2);
else
{
TypeFunction *tf = (TypeFunction *)f->type;
Expand All @@ -8340,6 +8329,8 @@ Expression *CallExp::semantic(Scope *sc)
return new ErrorExp();
}
}
if (!f)
return new ErrorExp();

if (f->needThis())
{
Expand Down Expand Up @@ -10358,11 +10349,11 @@ Expression *AssignExp::semantic(Scope *sc)
Expressions a;
a.push(e2);

fd = td->deduceFunctionTemplate(loc, sc, targsi, ethis, &a, 1);
fd = resolveFuncCall(loc, sc, td, targsi, ethis, &a, 1);
if (fd && fd->type)
goto Lsetter;

fd = td->deduceFunctionTemplate(loc, sc, targsi, ethis, NULL, 1);
fd = resolveFuncCall(loc, sc, td, targsi, ethis, NULL, 1);
if (fd && fd->type)
goto Lgetter;
}
Expand Down Expand Up @@ -10391,11 +10382,11 @@ Expression *AssignExp::semantic(Scope *sc)
Expressions a;
a.push(e2);

fd = f->overloadResolve(loc, ethis, &a, 1);
fd = resolveFuncCall(loc, sc, f, NULL, ethis, &a, 1);
if (fd && fd->type)
goto Lsetter;

fd = f->overloadResolve(loc, ethis, NULL, 1);
fd = resolveFuncCall(loc, sc, f, NULL, ethis, NULL, 1);
if (fd && fd->type)
goto Lgetter;

Expand Down
33 changes: 15 additions & 18 deletions src/func.c
Expand Up @@ -2561,25 +2561,21 @@ static void MODMatchToBuffer(OutBuffer *buf, unsigned char lhsMod, unsigned char

FuncDeclaration *FuncDeclaration::overloadResolve(Loc loc, Expression *ethis, Expressions *arguments, int flags)
{
TypeFunction *tf;
Match m;

#if 0
printf("FuncDeclaration::overloadResolve('%s')\n", toChars());
if (arguments)
{ int i;

for (i = 0; i < arguments->dim; i++)
{ Expression *arg;

arg = (*arguments)[i];
assert(arg->type);
printf("\t%s: ", arg->toChars());
arg->type->print();
printf("FuncDeclaration::overloadResolve('%s')\n", toChars());
if (arguments)
{
for (size_t i = 0; i < arguments->dim; i++)
{
Expression *arg = (*arguments)[i];
assert(arg->type);
printf("\t%s: ", arg->toChars());
arg->type->print();
}
}
}
#endif

Match m;
memset(&m, 0, sizeof(m));
m.last = MATCHnomatch;
overloadResolveX(&m, this, ethis, arguments);
Expand Down Expand Up @@ -2609,7 +2605,7 @@ if (arguments)
if (flags & 1) // if do not print error messages
return NULL; // no match

tf = (TypeFunction *)type;
TypeFunction *tf = (TypeFunction *)type;
if (ethis && !MODimplicitConv(ethis->type->mod, tf->mod)) // modifier mismatch
{
OutBuffer thisBuf, funcBuf;
Expand Down Expand Up @@ -2755,11 +2751,12 @@ FuncDeclaration *resolveFuncCall(Loc loc, Scope *sc, Dsymbol *s,
return NULL; // no match
FuncDeclaration *f = s->isFuncDeclaration();
if (f)
f = f->overloadResolve(loc, ethis, arguments);
f = f->overloadResolve(loc, ethis, arguments, flags);
else
{ TemplateDeclaration *td = s->isTemplateDeclaration();
assert(td);
f = td->deduceFunctionTemplate(loc, sc, tiargs, NULL, arguments, flags);
if (!sc) sc = td->scope;
f = td->deduceFunctionTemplate(loc, sc, tiargs, ethis, arguments, flags);
}
return f;
}
Expand Down
5 changes: 2 additions & 3 deletions src/mtype.c
Expand Up @@ -1251,9 +1251,8 @@ Type *Type::aliasthisOf()
}
else if (d->isFuncDeclaration())
{
FuncDeclaration *fd = (FuncDeclaration *)d;
Expression *ethis = this->defaultInit(0);
fd = fd->overloadResolve(0, ethis, NULL, 1);
FuncDeclaration *fd = resolveFuncCall(0, NULL, d, NULL, ethis, NULL, 1);
if (fd && fd->functionSemantic())
{
t = fd->type->nextOf();
Expand All @@ -1274,7 +1273,7 @@ Type *Type::aliasthisOf()
if (td)
{ assert(td->scope);
Expression *ethis = defaultInit(0);
FuncDeclaration *fd = td->deduceFunctionTemplate(0, td->scope, NULL, ethis, NULL, 1);
FuncDeclaration *fd = resolveFuncCall(0, NULL, td, NULL, ethis, NULL, 1);
if (fd && fd->functionSemantic())
{
Type *t = fd->type->nextOf();
Expand Down
2 changes: 1 addition & 1 deletion src/template.c
Expand Up @@ -2068,7 +2068,7 @@ FuncDeclaration *TemplateDeclaration::deduceFunctionTemplate(Loc loc, Scope *sc,
td->error("is not a function template");
goto Lerror;
}
fd = fd->overloadResolve(loc, ethis, fargs, flags);
fd = resolveFuncCall(loc, sc, fd, NULL, ethis, fargs, flags);
if (!fd)
continue;

Expand Down

0 comments on commit c075a22

Please sign in to comment.