comparison dmd/template.c @ 1607:207a8a438dea

Merge DMD r253: refactor: Argument => Parameter --- dmd/arrayop.c | 30 ++++---- dmd/arraytypes.h | 2 +- dmd/class.c | 8 +- dmd/declaration.c | 10 ++-- dmd/declaration.h | 16 ++-- dmd/doc.c | 12 ++-- dmd/dsymbol.c | 4 +- dmd/expression.c | 48 +++++++------- dmd/expression.h | 32 +++++----- dmd/func.c | 78 +++++++++++----------- dmd/init.c | 2 +- dmd/interpret.c | 8 +- dmd/mtype.c | 190 ++++++++++++++++++++++++++-------------------------- dmd/mtype.h | 32 +++++----- dmd/opover.c | 34 +++++----- dmd/parse.c | 40 ++++++------ dmd/parse.h | 2 +- dmd/statement.c | 90 +++++++++++++------------- dmd/statement.h | 14 ++-- dmd/struct.c | 8 +- dmd/template.c | 30 ++++---- gen/functions.cpp | 10 ++-- gen/functions.h | 2 +- gen/tocall.cpp | 10 ++-- gen/typinf.cpp | 6 +- 25 files changed, 359 insertions(+), 359 deletions(-)
author Leandro Lucarella <llucax@gmail.com>
date Wed, 06 Jan 2010 15:18:20 -0300
parents def7a1d494fd
children 1d0220dd613a
comparison
equal deleted inserted replaced
1606:1b24e9c7cc26 1607:207a8a438dea
845 #endif 845 #endif
846 846
847 assert(fd->type->ty == Tfunction); 847 assert(fd->type->ty == Tfunction);
848 fdtype = (TypeFunction *)fd->type; 848 fdtype = (TypeFunction *)fd->type;
849 849
850 nfparams = Argument::dim(fdtype->parameters); // number of function parameters 850 nfparams = Parameter::dim(fdtype->parameters); // number of function parameters
851 nfargs = fargs ? fargs->dim : 0; // number of function arguments 851 nfargs = fargs ? fargs->dim : 0; // number of function arguments
852 852
853 /* Check for match of function arguments with variadic template 853 /* Check for match of function arguments with variadic template
854 * parameter, such as: 854 * parameter, such as:
855 * 855 *
875 * type identifiers. 875 * type identifiers.
876 * Set the index of this function parameter to fptupindex. 876 * Set the index of this function parameter to fptupindex.
877 */ 877 */
878 for (fptupindex = 0; fptupindex < nfparams; fptupindex++) 878 for (fptupindex = 0; fptupindex < nfparams; fptupindex++)
879 { 879 {
880 Argument *fparam = (Argument *)fdtype->parameters->data[fptupindex]; 880 Parameter *fparam = (Parameter *)fdtype->parameters->data[fptupindex];
881 if (fparam->type->ty != Tident) 881 if (fparam->type->ty != Tident)
882 continue; 882 continue;
883 TypeIdentifier *tid = (TypeIdentifier *)fparam->type; 883 TypeIdentifier *tid = (TypeIdentifier *)fparam->type;
884 if (!tp->ident->equals(tid->ident) || tid->idents.dim) 884 if (!tp->ident->equals(tid->ident) || tid->idents.dim)
885 continue; 885 continue;
949 break; 949 break;
950 i += tuple_dim - 1; 950 i += tuple_dim - 1;
951 continue; 951 continue;
952 } 952 }
953 953
954 Argument *fparam = Argument::getNth(fdtype->parameters, i); 954 Parameter *fparam = Parameter::getNth(fdtype->parameters, i);
955 955
956 if (i >= nfargs) // if not enough arguments 956 if (i >= nfargs) // if not enough arguments
957 { 957 {
958 if (fparam->defaultArg) 958 if (fparam->defaultArg)
959 { /* Default arguments do not participate in template argument 959 { /* Default arguments do not participate in template argument
994 if (!m && fparam->type->toBasetype()->ty == Tdelegate) 994 if (!m && fparam->type->toBasetype()->ty == Tdelegate)
995 { 995 {
996 TypeDelegate *td = (TypeDelegate *)fparam->type->toBasetype(); 996 TypeDelegate *td = (TypeDelegate *)fparam->type->toBasetype();
997 TypeFunction *tf = (TypeFunction *)td->next; 997 TypeFunction *tf = (TypeFunction *)td->next;
998 998
999 if (!tf->varargs && Argument::dim(tf->parameters) == 0) 999 if (!tf->varargs && Parameter::dim(tf->parameters) == 0)
1000 { 1000 {
1001 m = farg->type->deduceType(paramscope, tf->next, parameters, &dedtypes); 1001 m = farg->type->deduceType(paramscope, tf->next, parameters, &dedtypes);
1002 if (!m && tf->next->toBasetype()->ty == Tvoid) 1002 if (!m && tf->next->toBasetype()->ty == Tvoid)
1003 m = MATCHconvert; 1003 m = MATCHconvert;
1004 } 1004 }
1742 TypeFunction *tp = (TypeFunction *)tparam; 1742 TypeFunction *tp = (TypeFunction *)tparam;
1743 if (varargs != tp->varargs || 1743 if (varargs != tp->varargs ||
1744 linkage != tp->linkage) 1744 linkage != tp->linkage)
1745 return MATCHnomatch; 1745 return MATCHnomatch;
1746 1746
1747 size_t nfargs = Argument::dim(this->parameters); 1747 size_t nfargs = Parameter::dim(this->parameters);
1748 size_t nfparams = Argument::dim(tp->parameters); 1748 size_t nfparams = Parameter::dim(tp->parameters);
1749 1749
1750 /* See if tuple match 1750 /* See if tuple match
1751 */ 1751 */
1752 if (nfparams > 0 && nfargs >= nfparams - 1) 1752 if (nfparams > 0 && nfargs >= nfparams - 1)
1753 { 1753 {
1754 /* See if 'A' of the template parameter matches 'A' 1754 /* See if 'A' of the template parameter matches 'A'
1755 * of the type of the last function parameter. 1755 * of the type of the last function parameter.
1756 */ 1756 */
1757 Argument *fparam = Argument::getNth(tp->parameters, nfparams - 1); 1757 Parameter *fparam = Parameter::getNth(tp->parameters, nfparams - 1);
1758 if (fparam->type->ty != Tident) 1758 if (fparam->type->ty != Tident)
1759 goto L1; 1759 goto L1;
1760 TypeIdentifier *tid = (TypeIdentifier *)fparam->type; 1760 TypeIdentifier *tid = (TypeIdentifier *)fparam->type;
1761 if (tid->idents.dim) 1761 if (tid->idents.dim)
1762 goto L1; 1762 goto L1;
1785 { // Existing deduced argument must be a tuple, and must match 1785 { // Existing deduced argument must be a tuple, and must match
1786 Tuple *t = isTuple(o); 1786 Tuple *t = isTuple(o);
1787 if (!t || t->objects.dim != tuple_dim) 1787 if (!t || t->objects.dim != tuple_dim)
1788 return MATCHnomatch; 1788 return MATCHnomatch;
1789 for (size_t i = 0; i < tuple_dim; i++) 1789 for (size_t i = 0; i < tuple_dim; i++)
1790 { Argument *arg = Argument::getNth(this->parameters, nfparams - 1 + i); 1790 { Parameter *arg = Parameter::getNth(this->parameters, nfparams - 1 + i);
1791 if (!arg->type->equals((Object *)t->objects.data[i])) 1791 if (!arg->type->equals((Object *)t->objects.data[i]))
1792 return MATCHnomatch; 1792 return MATCHnomatch;
1793 } 1793 }
1794 } 1794 }
1795 else 1795 else
1796 { // Create new tuple 1796 { // Create new tuple
1797 Tuple *t = new Tuple(); 1797 Tuple *t = new Tuple();
1798 t->objects.setDim(tuple_dim); 1798 t->objects.setDim(tuple_dim);
1799 for (size_t i = 0; i < tuple_dim; i++) 1799 for (size_t i = 0; i < tuple_dim; i++)
1800 { Argument *arg = Argument::getNth(this->parameters, nfparams - 1 + i); 1800 { Parameter *arg = Parameter::getNth(this->parameters, nfparams - 1 + i);
1801 t->objects.data[i] = (void *)arg->type; 1801 t->objects.data[i] = (void *)arg->type;
1802 } 1802 }
1803 dedtypes->data[tupi] = (void *)t; 1803 dedtypes->data[tupi] = (void *)t;
1804 } 1804 }
1805 nfparams--; // don't consider the last parameter for type deduction 1805 nfparams--; // don't consider the last parameter for type deduction
1810 if (nfargs != nfparams) 1810 if (nfargs != nfparams)
1811 return MATCHnomatch; 1811 return MATCHnomatch;
1812 L2: 1812 L2:
1813 for (size_t i = 0; i < nfparams; i++) 1813 for (size_t i = 0; i < nfparams; i++)
1814 { 1814 {
1815 Argument *a = Argument::getNth(this->parameters, i); 1815 Parameter *a = Parameter::getNth(this->parameters, i);
1816 Argument *ap = Argument::getNth(tp->parameters, i); 1816 Parameter *ap = Parameter::getNth(tp->parameters, i);
1817 if (a->storageClass != ap->storageClass || 1817 if (a->storageClass != ap->storageClass ||
1818 !a->type->deduceType(sc, ap->type, parameters, dedtypes)) 1818 !a->type->deduceType(sc, ap->type, parameters, dedtypes))
1819 return MATCHnomatch; 1819 return MATCHnomatch;
1820 } 1820 }
1821 } 1821 }
2404 2404
2405 if (specType) 2405 if (specType)
2406 printf("\tSpecialization: %s\n", specType->toChars()); 2406 printf("\tSpecialization: %s\n", specType->toChars());
2407 if (defaultType) 2407 if (defaultType)
2408 printf("\tDefault: %s\n", defaultType->toChars()); 2408 printf("\tDefault: %s\n", defaultType->toChars());
2409 printf("\tArgument: %s\n", t ? t->toChars() : "NULL"); 2409 printf("\tParameter: %s\n", t ? t->toChars() : "NULL");
2410 printf("\tDeduced Type: %s\n", ta->toChars()); 2410 printf("\tDeduced Type: %s\n", ta->toChars());
2411 } 2411 }
2412 2412
2413 2413
2414 void TemplateTypeParameter::toCBuffer(OutBuffer *buf, HdrGenState *hgs) 2414 void TemplateTypeParameter::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
2620 printf(" %s\n", ident->toChars()); 2620 printf(" %s\n", ident->toChars());
2621 2621
2622 Dsymbol *sa = isDsymbol(oded); 2622 Dsymbol *sa = isDsymbol(oded);
2623 assert(sa); 2623 assert(sa);
2624 2624
2625 printf("\tArgument alias: %s\n", sa->toChars()); 2625 printf("\tParameter alias: %s\n", sa->toChars());
2626 } 2626 }
2627 2627
2628 void TemplateAliasParameter::toCBuffer(OutBuffer *buf, HdrGenState *hgs) 2628 void TemplateAliasParameter::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
2629 { 2629 {
2630 buf->writestring("alias "); 2630 buf->writestring("alias ");
2864 2864
2865 Expression *ea = isExpression(oded); 2865 Expression *ea = isExpression(oded);
2866 2866
2867 if (specValue) 2867 if (specValue)
2868 printf("\tSpecialization: %s\n", specValue->toChars()); 2868 printf("\tSpecialization: %s\n", specValue->toChars());
2869 printf("\tArgument Value: %s\n", ea ? ea->toChars() : "NULL"); 2869 printf("\tParameter Value: %s\n", ea ? ea->toChars() : "NULL");
2870 } 2870 }
2871 2871
2872 2872
2873 void TemplateValueParameter::toCBuffer(OutBuffer *buf, HdrGenState *hgs) 2873 void TemplateValueParameter::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
2874 { 2874 {
3578 size_t dim = tt->arguments->dim; 3578 size_t dim = tt->arguments->dim;
3579 tiargs->remove(j); 3579 tiargs->remove(j);
3580 if (dim) 3580 if (dim)
3581 { tiargs->reserve(dim); 3581 { tiargs->reserve(dim);
3582 for (size_t i = 0; i < dim; i++) 3582 for (size_t i = 0; i < dim; i++)
3583 { Argument *arg = (Argument *)tt->arguments->data[i]; 3583 { Parameter *arg = (Parameter *)tt->arguments->data[i];
3584 tiargs->insert(j + i, arg->type); 3584 tiargs->insert(j + i, arg->type);
3585 } 3585 }
3586 } 3586 }
3587 j--; 3587 j--;
3588 } 3588 }