changeset 1609:1d0220dd613a

Merge DMD r274: harmonization --- dmd/expression.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++- dmd/template.c | 41 +++++++++++++++++++++++++++++++++++ dmd/template.h | 1 + 3 files changed, 103 insertions(+), 1 deletions(-)
author Leandro Lucarella <llucax@gmail.com>
date Wed, 06 Jan 2010 15:18:21 -0300
parents 679d101395e8
children 4f63d530861f
files dmd/expression.c dmd/template.c dmd/template.h
diffstat 3 files changed, 103 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/dmd/expression.c	Wed Jan 06 15:18:20 2010 -0300
+++ b/dmd/expression.c	Wed Jan 06 15:18:21 2010 -0300
@@ -5895,7 +5895,66 @@
 }
 
 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 @@
 
 Lerr:
     return new IntegerExp(loc, 0, Type::tint32);
+#endif
 }
 
 void DotTemplateInstanceExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
--- a/dmd/template.c	Wed Jan 06 15:18:20 2010 -0300
+++ b/dmd/template.c	Wed Jan 06 15:18:21 2010 -0300
@@ -4086,6 +4086,47 @@
 }
 
 
+/*****************************************************
+ * 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;
 
--- a/dmd/template.h	Wed Jan 06 15:18:20 2010 -0300
+++ b/dmd/template.h	Wed Jan 06 15:18:21 2010 -0300
@@ -309,6 +309,7 @@
     Dsymbol *toAlias();			// resolve real symbol
     const char *kind();
     int oneMember(Dsymbol **ps);
+    int needsTypeInference(Scope *sc);
     char *toChars();
     char *mangle();
     void printInstantiationTrace();