comparison 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
comparison
equal deleted inserted replaced
129:010eb8f0e18d 130:60bb0fe4563e
22 import dmd.Tuple; 22 import dmd.Tuple;
23 import dmd.STC; 23 import dmd.STC;
24 import dmd.TOK; 24 import dmd.TOK;
25 import dmd.TY; 25 import dmd.TY;
26 import dmd.TypeTuple; 26 import dmd.TypeTuple;
27 import dmd.Argument; 27 import dmd.Parameter;
28 import dmd.WANT; 28 import dmd.WANT;
29 import dmd.ExpInitializer; 29 import dmd.ExpInitializer;
30 import dmd.Array; 30 import dmd.Array;
31 import dmd.DsymbolTable; 31 import dmd.DsymbolTable;
32 import dmd.Scope; 32 import dmd.Scope;
748 override bool oneMember(Dsymbol* ps) 748 override bool oneMember(Dsymbol* ps)
749 { 749 {
750 *ps = null; 750 *ps = null;
751 return true; 751 return true;
752 } 752 }
753 753
754 /*****************************************************
755 * Determine if template instance is really a template function,
756 * and that template function needs to infer types from the function
757 * arguments.
758 */
759
760 bool needsTypeInference(Scope sc)
761 {
762 //printf("TemplateInstance::needsTypeInference() %s\n", toChars());
763 if (!tempdecl)
764 tempdecl = findTemplateDeclaration(sc);
765 for (TemplateDeclaration td = tempdecl; td; td = td.overnext)
766 {
767 /* If any of the overloaded template declarations need inference,
768 * then return TRUE
769 */
770 FuncDeclaration fd;
771 if (!td.onemember ||
772 (fd = td.onemember.toAlias().isFuncDeclaration()) == null ||
773 fd.type.ty != TY.Tfunction)
774 {
775 /* Not a template function, therefore type inference is not possible.
776 */
777 //printf("false\n");
778 return false;
779 }
780
781 /* Determine if the instance arguments, tiargs, are all that is necessary
782 * to instantiate the template.
783 */
784 TemplateTupleParameter tp = td.isVariadic();
785 //printf("tp = %p, td->parameters->dim = %d, tiargs->dim = %d\n", tp, td->parameters->dim, tiargs->dim);
786 TypeFunction fdtype = cast(TypeFunction)fd.type;
787 if (Parameter.dim(fdtype.parameters) &&
788 (tp || tiargs.dim < td.parameters.dim))
789 return true;
790 }
791 //printf("false\n");
792 return false;
793 }
794
754 override string toChars() 795 override string toChars()
755 { 796 {
756 scope OutBuffer buf = new OutBuffer(); 797 scope OutBuffer buf = new OutBuffer();
757 HdrGenState hgs; 798 HdrGenState hgs;
758 799