diff dmd/template.c @ 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 207a8a438dea
children 4f63d530861f
line wrap: on
line diff
--- 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;