diff dmd/TemplateInstance.d @ 130:60bb0fe4563e

dmdfe 2.037 first main iteration
author Eldar Insafutdinov <e.insafutdinov@gmail.com>
date Thu, 09 Sep 2010 22:51:44 +0100
parents e6e542f37b94
children 206db751bd4c
line wrap: on
line diff
--- a/dmd/TemplateInstance.d	Sun Sep 05 15:32:22 2010 +0400
+++ b/dmd/TemplateInstance.d	Thu Sep 09 22:51:44 2010 +0100
@@ -24,7 +24,7 @@
 import dmd.TOK;
 import dmd.TY;
 import dmd.TypeTuple;
-import dmd.Argument;
+import dmd.Parameter;
 import dmd.WANT;
 import dmd.ExpInitializer;
 import dmd.Array;
@@ -750,7 +750,48 @@
 	    *ps = null;
 	    return true;
 	}
-	
+    
+    /*****************************************************
+     * Determine if template instance is really a template function,
+     * and that template function needs to infer types from the function
+     * arguments.
+     */
+
+    bool 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 != 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 = cast(TypeFunction)fd.type;
+	    if (Parameter.dim(fdtype.parameters) &&
+	        (tp || tiargs.dim < td.parameters.dim))
+	        return true;
+        }
+        //printf("false\n");
+        return false;
+    }
+    
     override string toChars()
 	{
 		scope OutBuffer buf = new OutBuffer();