mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-01-11 18:33:14 +01:00
Merge DMD r274: harmonization
--- dmd/expression.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++- dmd/template.c | 41 +++++++++++++++++++++++++++++++++++ dmd/template.h | 1 + 3 files changed, 103 insertions(+), 1 deletions(-)
This commit is contained in:
@@ -5895,7 +5895,66 @@ Expression *DotTemplateInstanceExp::syntaxCopy()
|
||||
}
|
||||
|
||||
Expression *DotTemplateInstanceExp::semantic(Scope *sc)
|
||||
{ Dsymbol *s;
|
||||
{
|
||||
#if 1
|
||||
#if LOGSEMANTIC
|
||||
printf("DotTemplateInstanceExp::semantic('%s')\n", toChars());
|
||||
#endif
|
||||
Expression *eleft;
|
||||
Expression *e = new DotIdExp(loc, e1, ti->name);
|
||||
L1:
|
||||
e = e->semantic(sc);
|
||||
if (e->op == TOKdottd)
|
||||
{
|
||||
DotTemplateExp *dte = (DotTemplateExp *)e;
|
||||
TemplateDeclaration *td = dte->td;
|
||||
eleft = dte->e1;
|
||||
ti->tempdecl = td;
|
||||
ti->semantic(sc);
|
||||
Dsymbol *s = ti->inst->toAlias();
|
||||
Declaration *v = s->isDeclaration();
|
||||
if (v)
|
||||
{ e = new DotVarExp(loc, eleft, v);
|
||||
e = e->semantic(sc);
|
||||
return e;
|
||||
}
|
||||
e = new ScopeExp(loc, ti);
|
||||
e = new DotExp(loc, eleft, e);
|
||||
e = e->semantic(sc);
|
||||
return e;
|
||||
}
|
||||
else if (e->op == TOKimport)
|
||||
{ ScopeExp *se = (ScopeExp *)e;
|
||||
TemplateDeclaration *td = se->sds->isTemplateDeclaration();
|
||||
if (!td)
|
||||
{ error("%s is not a template", e->toChars());
|
||||
return new ErrorExp();
|
||||
}
|
||||
ti->tempdecl = td;
|
||||
e = new ScopeExp(loc, ti);
|
||||
e = e->semantic(sc);
|
||||
return e;
|
||||
}
|
||||
else if (e->op == TOKdotexp)
|
||||
{ DotExp *de = (DotExp *)e;
|
||||
|
||||
if (de->e2->op == TOKimport)
|
||||
{ // This should *really* be moved to ScopeExp::semantic()
|
||||
ScopeExp *se = (ScopeExp *)de->e2;
|
||||
de->e2 = new DsymbolExp(loc, se->sds);
|
||||
de->e2 = de->e2->semantic(sc);
|
||||
}
|
||||
|
||||
if (de->e2->op == TOKtemplate)
|
||||
{ TemplateExp *te = (TemplateExp *) de->e2;
|
||||
e = new DotTemplateExp(loc,de->e1,te->td);
|
||||
}
|
||||
goto L1;
|
||||
}
|
||||
error("%s isn't a template", e->toChars());
|
||||
return new ErrorExp();
|
||||
#else
|
||||
Dsymbol *s;
|
||||
Dsymbol *s2;
|
||||
TemplateDeclaration *td;
|
||||
Expression *e;
|
||||
@@ -6011,6 +6070,7 @@ Expression *DotTemplateInstanceExp::semantic(Scope *sc)
|
||||
|
||||
Lerr:
|
||||
return new IntegerExp(loc, 0, Type::tint32);
|
||||
#endif
|
||||
}
|
||||
|
||||
void DotTemplateInstanceExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
|
||||
|
||||
@@ -4086,6 +4086,47 @@ void TemplateInstance::declareParameters(Scope *sc)
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************
|
||||
* Determine if template instance is really a template function,
|
||||
* and that template function needs to infer types from the function
|
||||
* arguments.
|
||||
*/
|
||||
|
||||
int TemplateInstance::needsTypeInference(Scope *sc)
|
||||
{
|
||||
//printf("TemplateInstance::needsTypeInference() %s\n", toChars());
|
||||
if (!tempdecl)
|
||||
tempdecl = findTemplateDeclaration(sc);
|
||||
for (TemplateDeclaration *td = tempdecl; td; td = td->overnext)
|
||||
{
|
||||
/* If any of the overloaded template declarations need inference,
|
||||
* then return TRUE
|
||||
*/
|
||||
FuncDeclaration *fd;
|
||||
if (!td->onemember ||
|
||||
(fd = td->onemember->toAlias()->isFuncDeclaration()) == NULL ||
|
||||
fd->type->ty != Tfunction)
|
||||
{
|
||||
/* Not a template function, therefore type inference is not possible.
|
||||
*/
|
||||
//printf("false\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Determine if the instance arguments, tiargs, are all that is necessary
|
||||
* to instantiate the template.
|
||||
*/
|
||||
TemplateTupleParameter *tp = td->isVariadic();
|
||||
//printf("tp = %p, td->parameters->dim = %d, tiargs->dim = %d\n", tp, td->parameters->dim, tiargs->dim);
|
||||
TypeFunction *fdtype = (TypeFunction *)fd->type;
|
||||
if (Parameter::dim(fdtype->parameters) &&
|
||||
(tp || tiargs->dim < td->parameters->dim))
|
||||
return TRUE;
|
||||
}
|
||||
//printf("false\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void TemplateInstance::semantic2(Scope *sc)
|
||||
{ int i;
|
||||
|
||||
|
||||
@@ -309,6 +309,7 @@ struct TemplateInstance : ScopeDsymbol
|
||||
Dsymbol *toAlias(); // resolve real symbol
|
||||
const char *kind();
|
||||
int oneMember(Dsymbol **ps);
|
||||
int needsTypeInference(Scope *sc);
|
||||
char *toChars();
|
||||
char *mangle();
|
||||
void printInstantiationTrace();
|
||||
|
||||
Reference in New Issue
Block a user