Fix some terminology used in C++ template partial specialization and new typemap matching rules

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11982 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2010-04-09 21:40:23 +00:00
commit 01c4ab6baf
5 changed files with 26 additions and 24 deletions

View file

@ -15,10 +15,10 @@ Version 2.0.0 (in progress)
2010-04-01: wsfulton
Numerous subtle typemap matching rule fixes when using the default type. The typemap
matching rules are to take a type and find the best default typemap (SWIGTYPE, SWIGTYPE* etc),
then look for the next best match by reducing the chosen default type. The type reduction
then look for the next best match by reducing the chosen default type. The type deduction
now follows C++ template partial specialization matching rules.
Below are the set of changes made showing the default type reduction
Below are the set of changes made showing the default type deduction
along with the old reduced type and the new version of the reduced type:
SWIGTYPE const &[ANY]

View file

@ -432,7 +432,7 @@ typedef enum { ExactNoMatch = -2, PartiallySpecializedNoMatch = -1, PartiallySpe
* does_parm_match()
*
* Template argument deduction - check if a template type matches a partially specialized
* template parameter type. Reduce 'partial_parm_type' to see if it matches 'type'.
* template parameter type. Typedef reduce 'partial_parm_type' to see if it matches 'type'.
*
* type - template parameter type to match against
* partial_parm_type - partially specialized template type - a possible match
@ -664,7 +664,7 @@ static Node *template_locate(String *name, Parm *tparms, Symtab *tscope) {
if (posslen > 1) {
/* Now go through all the possibly matched partial specialization templates and look for a non-ambiguous match.
* Exact matches rank the highest and deduced parameters are ranked by how much they are reduced, eg looking for
* Exact matches rank the highest and deduced parameters are ranked by how specialized they are, eg looking for
* a match to const int *, the following rank (highest to lowest):
* const int * (exact match)
* const T *

View file

@ -290,7 +290,7 @@ int SwigType_issimple(SwigType *t) {
* Enums: enum SWIGTYPE
* Types: SWIGTYPE
*
* Examples (also see SwigType_default_reduce):
* Examples (also see SwigType_default_deduce):
*
* int [2][4]
* a(2).a(4).int
@ -354,17 +354,19 @@ SwigType *SwigType_default_create(SwigType *ty) {
}
/* -----------------------------------------------------------------------------
* SwigType_default_reduce()
* SwigType_default_deduce()
*
* This function implements type reduction used in the typemap matching rules
* and is very close to the type reduction used in partial template specialization.
* This function implements type deduction used in the typemap matching rules
* and is very close to the type deduction used in partial template specialization
* matching in that the most specialized type is always chosen.
* SWIGTYPE is used as the generic type. The basic idea is to repeatedly call
* this function to reduce the type until it is reduced to nothing.
* this function to find a deduced type unless until nothing matches.
*
* The type t must have already been converted to the default type via a call to
* SwigType_default_create() before calling this function.
*
* Example reductions (matching the examples described in SwigType_default_create):
* Example deductions (matching the examples described in SwigType_default_create),
* where the the most specialized matches are highest in the list:
*
* a(ANY).a(ANY).SWIGTYPE
* a(ANY).a().SWIGTYPE
@ -385,7 +387,7 @@ SwigType *SwigType_default_create(SwigType *ty) {
* SWIGTYPE
* ----------------------------------------------------------------------------- */
SwigType *SwigType_default_reduce(SwigType *t) {
SwigType *SwigType_default_deduce(SwigType *t) {
SwigType *r = NewStringEmpty();
List *l;
Iterator it;
@ -402,37 +404,37 @@ SwigType *SwigType_default_reduce(SwigType *t) {
String *subtype = Getitem(l, numitems-2); /* last but one */
if (SwigType_isarray(subtype)) {
if (is_enum) {
/* enum reduction, enum SWIGTYPE => SWIGTYPE */
/* enum deduction, enum SWIGTYPE => SWIGTYPE */
Setitem(l, numitems-1, NewString("SWIGTYPE"));
} else {
/* array reduction, a(ANY). => a(). => p. */
String *reduced_subtype = 0;
/* array deduction, a(ANY). => a(). => p. */
String *deduced_subtype = 0;
if (Strcmp(subtype, "a().") == 0) {
reduced_subtype = NewString("p.");
deduced_subtype = NewString("p.");
} else if (Strcmp(subtype, "a(ANY).") == 0) {
reduced_subtype = NewString("a().");
deduced_subtype = NewString("a().");
} else {
assert(0);
}
Setitem(l, numitems-2, reduced_subtype);
Setitem(l, numitems-2, deduced_subtype);
}
} else if (SwigType_ismemberpointer(subtype)) {
/* member pointer reduction, m(CLASS). => p. */
/* member pointer deduction, m(CLASS). => p. */
Setitem(l, numitems-2, NewString("p."));
} else if (is_enum && !SwigType_isqualifier(subtype)) {
/* enum reduction, enum SWIGTYPE => SWIGTYPE */
/* enum deduction, enum SWIGTYPE => SWIGTYPE */
Setitem(l, numitems-1, NewString("SWIGTYPE"));
} else {
/* simple type reduction, eg, r.p.p. => r.p. */
/* simple type deduction, eg, r.p.p. => r.p. */
/* also function pointers eg, p.f(ANY). => p. */
Delitem(l, numitems-2);
}
} else {
if (is_enum) {
/* enum reduction, enum SWIGTYPE => SWIGTYPE */
/* enum deduction, enum SWIGTYPE => SWIGTYPE */
Setitem(l, numitems-1, NewString("SWIGTYPE"));
} else {
/* delete the only item, we are done with reduction */
/* delete the only item, we are done with deduction */
Delitem(l, 0);
}
}

View file

@ -173,7 +173,7 @@ extern "C" {
extern SwigType *SwigType_array_type(SwigType *t);
extern String *SwigType_default(SwigType *t);
extern SwigType *SwigType_default_create(SwigType *ty);
extern SwigType *SwigType_default_reduce(SwigType *t);
extern SwigType *SwigType_default_deduce(SwigType *t);
extern void SwigType_typename_replace(SwigType *t, String *pat, String *rep);
extern SwigType *SwigType_remove_global_scope_prefix(const SwigType *t);
extern SwigType *SwigType_alttype(SwigType *t, int ltmap);

View file

@ -787,7 +787,7 @@ static Hash *typemap_search(const_String_or_char_ptr tmap_method, SwigType *type
goto ret_result;
{
SwigType *nprim = SwigType_default_reduce(primitive);
SwigType *nprim = SwigType_default_deduce(primitive);
Delete(primitive);
primitive = nprim;
}