Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring for function call mechanism #1695

Merged
merged 7 commits into from Feb 27, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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(sc2, loc, NULL, er, &ar, 1);
if (!f) f = td->deduceFunctionTemplate(sc2, loc, 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(sc, loc, NULL, e, arguments, 1);
if (fd && !(fd->storage_class & STCdisable))
return fd;
}
return (fd->storage_class & STCdisable) ? NULL : fd;
}
return NULL;
}
Expand Down
4 changes: 2 additions & 2 deletions src/declaration.h
Expand Up @@ -722,11 +722,11 @@ struct FuncDeclaration : Declaration
};

#if DMDV2
FuncDeclaration *resolveFuncCall(Scope *sc, Loc loc, Dsymbol *s,
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
96 changes: 42 additions & 54 deletions src/expression.c
Expand Up @@ -215,22 +215,22 @@ Expression *resolveProperties(Scope *sc, Expression *e)
//printf("resolveProperties(%s)\n", e->toChars());

TemplateDeclaration *td;
Objects *targsi;
Objects *tiargs;
Expression *ethis;
if (e->op == TOKdotti)
{
DotTemplateInstanceExp* dti = (DotTemplateInstanceExp *)e;
td = dti->getTempdecl(sc);
dti->ti->semanticTiargs(sc);
targsi = dti->ti->tiargs;
tiargs = dti->ti->tiargs;
ethis = dti->e1;
goto L1;
}
else if (e->op == TOKdottd)
{
DotTemplateExp *dte = (DotTemplateExp *)e;
td = dte->td;
targsi = NULL;
tiargs = NULL;
ethis = dte->e1;
goto L1;
}
Expand All @@ -240,20 +240,20 @@ Expression *resolveProperties(Scope *sc, Expression *e)
td = s->isTemplateDeclaration();
if (td)
{
targsi = NULL;
tiargs = NULL;
ethis = NULL;
goto L1;
}
}
else if (e->op == TOKtemplate)
{
td = ((TemplateExp *)e)->td;
targsi = NULL;
tiargs = NULL;
ethis = NULL;
L1:
assert(td);
unsigned errors = global.startGagging();
FuncDeclaration *fd = td->deduceFunctionTemplate(sc, e->loc, targsi, ethis, NULL, 1);
FuncDeclaration *fd = resolveFuncCall(e->loc, sc, td, tiargs, ethis, NULL, 1);
if (global.endGagging(errors))
fd = NULL; // eat "is not a function template" error
if (fd && fd->type)
Expand Down Expand Up @@ -4627,7 +4627,7 @@ Expression *NewExp::semantic(Scope *sc)

FuncDeclaration *f = NULL;
if (cd->ctor)
f = resolveFuncCall(sc, loc, cd->ctor, NULL, NULL, arguments, 0);
f = resolveFuncCall(loc, sc, cd->ctor, NULL, NULL, arguments, 0);
if (f)
{
checkDeprecated(sc, f);
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 All @@ -4720,7 +4720,7 @@ Expression *NewExp::semantic(Scope *sc)

FuncDeclaration *f = NULL;
if (sd->ctor)
f = resolveFuncCall(sc, loc, sd->ctor, NULL, NULL, arguments, 0);
f = resolveFuncCall(loc, sc, sd->ctor, NULL, NULL, arguments, 0);
if (f)
{
checkDeprecated(sc, f);
Expand Down Expand Up @@ -7640,7 +7640,7 @@ Expression *CallExp::semantic(Scope *sc)
{
Type *t1;
int istemp;
Objects *targsi = NULL; // initial list of template arguments
Objects *tiargs = NULL; // initial list of template arguments
TemplateInstance *tierror = NULL;
Expression *ethis = NULL;

Expand Down Expand Up @@ -7710,7 +7710,7 @@ Expression *CallExp::semantic(Scope *sc)
{
/* Go with partial explicit specialization
*/
targsi = ti->tiargs;
tiargs = ti->tiargs;
tierror = ti; // for error reporting
e1 = new IdentifierExp(loc, ti->name);
}
Expand Down Expand Up @@ -7742,7 +7742,7 @@ Expression *CallExp::semantic(Scope *sc)
{
/* Go with partial explicit specialization
*/
targsi = ti->tiargs;
tiargs = ti->tiargs;
tierror = ti; // for error reporting
e1 = new DotIdExp(loc, se->e1, ti->name);
}
Expand Down Expand Up @@ -7954,10 +7954,10 @@ Expression *CallExp::semantic(Scope *sc)

// If there was an error processing any template argument,
// return an error without trying to resolve the template.
if (targsi && targsi->dim)
if (tiargs && tiargs->dim)
{
for (size_t k = 0; k < targsi->dim; k++)
{ Object *o = (*targsi)[k];
for (size_t k = 0; k < tiargs->dim; k++)
{ Object *o = (*tiargs)[k];
if (isError(o))
return new ErrorExp();
}
Expand All @@ -7981,28 +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);
if (!arguments)
// Should fix deduceFunctionTemplate() so it works on NULL argument
arguments = new Expressions();
f = td->deduceFunctionTemplate(sc, loc, targsi, ue1, arguments);
if (!f)
return new ErrorExp();
ad = td->toParent()->isAggregateDeclaration();
s = dte->td;
}

// Do overload resolution
f = resolveFuncCall(loc, sc, s, tiargs, 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 @@ -8102,7 +8097,7 @@ Expression *CallExp::semantic(Scope *sc)
sc->callSuper |= CSXany_ctor | CSXsuper_ctor;
}

f = resolveFuncCall(sc, loc, cd->baseClass->ctor, NULL, NULL, arguments, 0);
f = resolveFuncCall(loc, sc, cd->baseClass->ctor, NULL, NULL, arguments, 0);
if (!f)
return new ErrorExp();
accessCheck(loc, sc, NULL, f);
Expand Down Expand Up @@ -8142,7 +8137,7 @@ Expression *CallExp::semantic(Scope *sc)
sc->callSuper |= CSXany_ctor | CSXthis_ctor;
}

f = resolveFuncCall(sc, loc, cd->ctor, NULL, NULL, arguments, 0);
f = resolveFuncCall(loc, sc, cd->ctor, NULL, NULL, arguments, 0);
if (!f)
return new ErrorExp();
checkDeprecated(sc, f);
Expand All @@ -8169,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(sc, loc, targsi, ethis, arguments, 1);
}
FuncDeclaration *f2 = resolveFuncCall(loc, sc, s, tiargs, ethis, arguments, 1);
if (f2)
{ if (f)
/* Error if match in more than one overload set,
Expand Down Expand Up @@ -8234,7 +8220,7 @@ Expression *CallExp::semantic(Scope *sc)
else if (e1->op == TOKtemplate)
{
TemplateExp *te = (TemplateExp *)e1;
f = te->td->deduceFunctionTemplate(sc, loc, targsi, NULL, arguments);
f = resolveFuncCall(loc, sc, te->td, tiargs, NULL, arguments);
if (!f)
{ if (tierror)
tierror->error("errors instantiating template"); // give better error message
Expand Down Expand Up @@ -8318,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, tiargs, NULL, arguments, 2);
else
{
TypeFunction *tf = (TypeFunction *)f->type;
Expand All @@ -8343,6 +8329,8 @@ Expression *CallExp::semantic(Scope *sc)
return new ErrorExp();
}
}
if (!f)
return new ErrorExp();

if (f->needThis())
{
Expand Down Expand Up @@ -10325,30 +10313,30 @@ Expression *AssignExp::semantic(Scope *sc)
* f() = value
*/
TemplateDeclaration *td;
Objects *targsi;
Objects *tiargs;
FuncDeclaration *fd;
Expression *ethis;
if (e1->op == TOKdotti)
{
DotTemplateInstanceExp* dti = (DotTemplateInstanceExp *)e1;
td = dti->getTempdecl(sc);
dti->ti->semanticTiargs(sc);
targsi = dti->ti->tiargs;
tiargs = dti->ti->tiargs;
ethis = dti->e1;
goto L3;
}
else if (e1->op == TOKdottd)
{
DotTemplateExp *dte = (DotTemplateExp *)e1;
td = dte->td;
targsi = NULL;
tiargs = NULL;
ethis = dte->e1;
goto L3;
}
else if (e1->op == TOKtemplate)
{
td = ((TemplateExp *)e1)->td;
targsi = NULL;
tiargs = NULL;
ethis = NULL;
L3:
{
Expand All @@ -10361,11 +10349,11 @@ Expression *AssignExp::semantic(Scope *sc)
Expressions a;
a.push(e2);

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

fd = td->deduceFunctionTemplate(sc, loc, targsi, ethis, NULL, 1);
fd = resolveFuncCall(loc, sc, td, tiargs, ethis, NULL, 1);
if (fd && fd->type)
goto Lgetter;
}
Expand Down Expand Up @@ -10394,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