Mercurial > projects > ldc
comparison dmd/template.c @ 1618:a87f1d6ff48e
Merge DMD r303: harmonize
---
dmd/expression.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++-----
dmd/expression.h | 8 +++++
dmd/template.c | 27 ++++++++++++-------
3 files changed, 95 insertions(+), 18 deletions(-)
author | Leandro Lucarella <llucax@gmail.com> |
---|---|
date | Wed, 06 Jan 2010 15:18:21 -0300 |
parents | 3da302cc4966 |
children | 44b145be2ef5 |
comparison
equal
deleted
inserted
replaced
1617:6820110de311 | 1618:a87f1d6ff48e |
---|---|
760 size_t nargsi; // array size of targsi | 760 size_t nargsi; // array size of targsi |
761 int fptupindex = -1; | 761 int fptupindex = -1; |
762 int tuple_dim = 0; | 762 int tuple_dim = 0; |
763 MATCH match = MATCHexact; | 763 MATCH match = MATCHexact; |
764 FuncDeclaration *fd = onemember->toAlias()->isFuncDeclaration(); | 764 FuncDeclaration *fd = onemember->toAlias()->isFuncDeclaration(); |
765 TypeFunction *fdtype; // type of fd | 765 Parameters *fparameters; // function parameter list |
766 int fvarargs; // function varargs | |
766 Objects dedtypes; // for T:T*, the dedargs is the T*, dedtypes is the T | 767 Objects dedtypes; // for T:T*, the dedargs is the T*, dedtypes is the T |
767 | 768 |
768 #if 0 | 769 #if 0 |
769 printf("\nTemplateDeclaration::deduceFunctionTemplateMatch() %s\n", toChars()); | 770 printf("\nTemplateDeclaration::deduceFunctionTemplateMatch() %s\n", toChars()); |
770 for (i = 0; i < fargs->dim; i++) | 771 for (i = 0; i < fargs->dim; i++) |
771 { Expression *e = (Expression *)fargs->data[i]; | 772 { Expression *e = (Expression *)fargs->data[i]; |
772 printf("\tfarg[%d] is %s, type is %s\n", i, e->toChars(), e->type->toChars()); | 773 printf("\tfarg[%d] is %s, type is %s\n", i, e->toChars(), e->type->toChars()); |
773 } | 774 } |
775 printf("fd = %s\n", fd->toChars()); | |
776 printf("fd->type = %p\n", fd->type); | |
774 #endif | 777 #endif |
775 | 778 |
776 assert((size_t)scope > 0x10000); | 779 assert((size_t)scope > 0x10000); |
777 | 780 |
778 dedargs->setDim(parameters->dim); | 781 dedargs->setDim(parameters->dim); |
847 if (oarg) printf("%s", oarg->toChars()); | 850 if (oarg) printf("%s", oarg->toChars()); |
848 printf("\n"); | 851 printf("\n"); |
849 } | 852 } |
850 #endif | 853 #endif |
851 | 854 |
852 assert(fd->type->ty == Tfunction); | 855 fparameters = fd->getParameters(&fvarargs); |
853 fdtype = (TypeFunction *)fd->type; | 856 nfparams = Parameter::dim(fparameters); // number of function parameters |
854 | |
855 nfparams = Parameter::dim(fdtype->parameters); // number of function parameters | |
856 nfargs = fargs ? fargs->dim : 0; // number of function arguments | 857 nfargs = fargs ? fargs->dim : 0; // number of function arguments |
857 | 858 |
858 /* Check for match of function arguments with variadic template | 859 /* Check for match of function arguments with variadic template |
859 * parameter, such as: | 860 * parameter, such as: |
860 * | 861 * |
880 * type identifiers. | 881 * type identifiers. |
881 * Set the index of this function parameter to fptupindex. | 882 * Set the index of this function parameter to fptupindex. |
882 */ | 883 */ |
883 for (fptupindex = 0; fptupindex < nfparams; fptupindex++) | 884 for (fptupindex = 0; fptupindex < nfparams; fptupindex++) |
884 { | 885 { |
885 Parameter *fparam = (Parameter *)fdtype->parameters->data[fptupindex]; | 886 Parameter *fparam = (Parameter *)fparameters->data[fptupindex]; |
886 if (fparam->type->ty != Tident) | 887 if (fparam->type->ty != Tident) |
887 continue; | 888 continue; |
888 TypeIdentifier *tid = (TypeIdentifier *)fparam->type; | 889 TypeIdentifier *tid = (TypeIdentifier *)fparam->type; |
889 if (!tp->ident->equals(tid->ident) || tid->idents.dim) | 890 if (!tp->ident->equals(tid->ident) || tid->idents.dim) |
890 continue; | 891 continue; |
891 | 892 |
892 if (fdtype->varargs) // variadic function doesn't | 893 if (fvarargs) // variadic function doesn't |
893 goto Lnomatch; // go with variadic template | 894 goto Lnomatch; // go with variadic template |
894 | 895 |
895 /* The types of the function arguments | 896 /* The types of the function arguments |
896 * now form the tuple argument. | 897 * now form the tuple argument. |
897 */ | 898 */ |
914 L1: | 915 L1: |
915 if (nfparams == nfargs) | 916 if (nfparams == nfargs) |
916 ; | 917 ; |
917 else if (nfargs > nfparams) | 918 else if (nfargs > nfparams) |
918 { | 919 { |
919 if (fdtype->varargs == 0) | 920 if (fvarargs == 0) |
920 goto Lnomatch; // too many args, no match | 921 goto Lnomatch; // too many args, no match |
921 match = MATCHconvert; // match ... with a conversion | 922 match = MATCHconvert; // match ... with a conversion |
922 } | 923 } |
923 | 924 |
924 L2: | 925 L2: |
954 break; | 955 break; |
955 i += tuple_dim - 1; | 956 i += tuple_dim - 1; |
956 continue; | 957 continue; |
957 } | 958 } |
958 | 959 |
959 Parameter *fparam = Parameter::getNth(fdtype->parameters, i); | 960 Parameter *fparam = Parameter::getNth(fparameters, i); |
960 | 961 |
961 if (i >= nfargs) // if not enough arguments | 962 if (i >= nfargs) // if not enough arguments |
962 { | 963 { |
963 if (fparam->defaultArg) | 964 if (fparam->defaultArg) |
964 { /* Default arguments do not participate in template argument | 965 { /* Default arguments do not participate in template argument |
1018 } | 1019 } |
1019 | 1020 |
1020 /* The following code for variadic arguments closely | 1021 /* The following code for variadic arguments closely |
1021 * matches TypeFunction::callMatch() | 1022 * matches TypeFunction::callMatch() |
1022 */ | 1023 */ |
1023 if (!(fdtype->varargs == 2 && i + 1 == nfparams)) | 1024 if (!(fvarargs == 2 && i + 1 == nfparams)) |
1024 goto Lnomatch; | 1025 goto Lnomatch; |
1025 | 1026 |
1026 /* Check for match with function parameter T... | 1027 /* Check for match with function parameter T... |
1027 */ | 1028 */ |
1028 Type *tb = fparam->type->toBasetype(); | 1029 Type *tb = fparam->type->toBasetype(); |
1130 | 1131 |
1131 #if DMDV2 | 1132 #if DMDV2 |
1132 if (constraint) | 1133 if (constraint) |
1133 { /* Check to see if constraint is satisfied. | 1134 { /* Check to see if constraint is satisfied. |
1134 */ | 1135 */ |
1136 makeParamNamesVisibleInConstraint(paramscope); | |
1135 Expression *e = constraint->syntaxCopy(); | 1137 Expression *e = constraint->syntaxCopy(); |
1136 paramscope->flags |= SCOPEstaticif; | 1138 paramscope->flags |= SCOPEstaticif; |
1137 e = e->semantic(paramscope); | 1139 e = e->semantic(paramscope); |
1138 e = e->optimize(WANTvalue | WANTinterpret); | 1140 e = e->optimize(WANTvalue | WANTinterpret); |
1139 if (e->isBool(TRUE)) | 1141 if (e->isBool(TRUE)) |
3260 #endif | 3262 #endif |
3261 assert(tdtypes.dim == ti->tdtypes.dim); | 3263 assert(tdtypes.dim == ti->tdtypes.dim); |
3262 | 3264 |
3263 // Nesting must match | 3265 // Nesting must match |
3264 if (isnested != ti->isnested) | 3266 if (isnested != ti->isnested) |
3267 { | |
3268 //printf("test2 isnested %s ti->isnested %s\n", isnested ? isnested->toChars() : "", ti->isnested ? ti->isnested->toChars() : ""); | |
3265 continue; | 3269 continue; |
3270 } | |
3266 #if 0 | 3271 #if 0 |
3267 if (isnested && sc->parent != ti->parent) | 3272 if (isnested && sc->parent != ti->parent) |
3268 continue; | 3273 continue; |
3269 #endif | 3274 #endif |
3270 for (size_t j = 0; j < tdtypes.dim; j++) | 3275 for (size_t j = 0; j < tdtypes.dim; j++) |
3271 { Object *o1 = (Object *)tdtypes.data[j]; | 3276 { Object *o1 = (Object *)tdtypes.data[j]; |
3272 Object *o2 = (Object *)ti->tdtypes.data[j]; | 3277 Object *o2 = (Object *)ti->tdtypes.data[j]; |
3273 if (!match(o1, o2, tempdecl, sc)) | 3278 if (!match(o1, o2, tempdecl, sc)) |
3279 { | |
3274 goto L1; | 3280 goto L1; |
3281 } | |
3275 } | 3282 } |
3276 | 3283 |
3277 // It's a match | 3284 // It's a match |
3278 inst = ti; | 3285 inst = ti; |
3279 parent = ti->parent; | 3286 parent = ti->parent; |