Resolve typedefs in parameter types after applying ctype typemap

Typedefs were not resolved for non-object types in spite of
SwigType_typedef_resolve_all() call as it didn't affect "c_parm_type".

Actually it is not even clear if resolving typedefs is a good idea as using
them probably makes the generated code more clear, but at least in the case of
nested typedefs we do need to do it as "Class::Type" can't appear in C code.
This commit is contained in:
Vadim Zeitlin 2016-04-26 14:21:51 +02:00
commit 8eba14c6e0
2 changed files with 8 additions and 5 deletions

View file

@ -53,7 +53,6 @@ FAILING_CPP_TESTS := \
arrays_global_twodim \ arrays_global_twodim \
char_strings \ char_strings \
constant_pointers \ constant_pointers \
default_arg_values \
default_args \ default_args \
default_constructor \ default_constructor \
director_enum \ director_enum \

View file

@ -817,16 +817,20 @@ ready:
String *c_parm_type = 0; String *c_parm_type = 0;
String *arg_name = NewString(""); String *arg_name = NewString("");
SwigType *tdtype = SwigType_typedef_resolve_all(type);
if (tdtype)
type = tdtype;
Printf(arg_name, "c%s", lname); Printf(arg_name, "c%s", lname);
if ((tm = Getattr(p, "tmap:ctype"))) { // set the appropriate type for parameter if ((tm = Getattr(p, "tmap:ctype"))) { // set the appropriate type for parameter
c_parm_type = Copy(tm); c_parm_type = Copy(tm);
substituteResolvedType(wrapper ? output_wrapper_def : output_wrapper_decl, type, c_parm_type); substituteResolvedType(wrapper ? output_wrapper_def : output_wrapper_decl, type, c_parm_type);
// We prefer to keep typedefs in the wrapper functions signatures as it makes them more readable, but we can't do it for nested typedefs as
// they're not valid in C, so resolve them in this case.
if (strstr(Char(c_parm_type), "::")) {
SwigType* const tdtype = SwigType_typedef_resolve_all(c_parm_type);
Delete(c_parm_type);
c_parm_type = tdtype;
}
// template handling // template handling
Replaceall(c_parm_type, "$tt", SwigType_lstr(type, 0)); Replaceall(c_parm_type, "$tt", SwigType_lstr(type, 0));
} }