() for multi-argument typemaps

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11481 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2009-07-30 17:42:18 +00:00
commit bbcfa0b089
5 changed files with 50 additions and 6 deletions

View file

@ -12,6 +12,8 @@ public class runme {
throw new Exception("test failed");
if (special_variable_macros.testMary(name) != "SWIGTYPE_p_NameWrap")
throw new Exception("test failed");
if (special_variable_macros.testJim(name) != "multiname num")
throw new Exception("test failed");
NewName newName = NewName.factory("factoryname");
name = newName.getStoredName();
}

View file

@ -22,6 +22,8 @@ public class special_variable_macros_runme {
throw new RuntimeException("test failed");
if (!special_variable_macros.testMary(name).equals("SWIGTYPE_p_NameWrap"))
throw new RuntimeException("test failed");
if (!special_variable_macros.testJim(name).equals("multiname num"))
throw new RuntimeException("test failed");
NewName newName = NewName.factory("factoryname");
name = newName.getStoredName();
}

View file

@ -9,4 +9,6 @@ if special_variable_macros.testJill(name) != "jilly":
raise "test failed"
if special_variable_macros.testMary(name) != "SWIGTYPE_p_NameWrap":
raise "test failed"
if special_variable_macros.testJim(name) != "multiname num":
raise "test failed"

View file

@ -83,8 +83,32 @@ const char * testMary(Name *mary) {
//////////////////////////////////////////////////////////////////////////////////////
// Multi-arg typemap lookup
#warning TODO!!!
// One would never do something like this in reality, it just checks $typemap with multi-arg typemaps
%typemap(in) (Name *multiname, int num)($*1_type temp_name, $2_ltype temp_count)
%{
/*%typemap(in) (Name *multiname, int num) start */
temp_name = $*1_ltype("multiname num");
temp_count = strlen(temp_name.getNamePtr()->getName());
(void)$input;
$1 = temp_name.getNamePtr();
$2 = temp_count + 100;
/*%typemap(in) (Name *multiname, int num) end */
%}
%typemap(in) (Name *jim, int count) {
// %typemap(in) Name *jim start
$typemap(in, (Name *multiname, int num))
// %typemap(in) Name *jim end
}
%inline %{
const char * testJim(Name *jim, int count) {
if (count != strlen(jim->getNamePtr()->getName()) + 100)
return "size check failed";
else
return jim->getName();
}
%}
//////////////////////////////////////////////////////////////////////////////////////
// A real use case for $typemap

View file

@ -17,7 +17,7 @@ char cvsroot_typemap_c[] = "$Id$";
#define SWIG_DEBUG
#endif
static void replace_embedded_typemap(String *s, String *lname, Wrapper *f);
static void replace_embedded_typemap(String *s, ParmList *parm_sublist, Wrapper *f);
/* -----------------------------------------------------------------------------
* Typemaps are stored in a collection of nested hash tables. Something like
@ -1344,7 +1344,13 @@ static String *Swig_typemap_lookup_impl(const_String_or_char_ptr tmap_method, No
if (locals && f) {
typemap_locals(s, locals, f, -1);
}
replace_embedded_typemap(s, NewString(lname), f);
{
ParmList *parm_sublist = NewParm(type, pname);
Setattr(parm_sublist, "lname", lname);
replace_embedded_typemap(s, parm_sublist, f);
Delete(parm_sublist);
}
Replace(s, "$name", pname, DOH_REPLACE_ANY);
@ -1643,7 +1649,7 @@ void Swig_typemap_attach_parms(const_String_or_char_ptr tmap_method, ParmList *p
typemap_locals(s, locals, f, argnum);
}
replace_embedded_typemap(s, Getattr(firstp, "lname"), f);
replace_embedded_typemap(s, firstp, f);
/* Replace the argument number */
sprintf(temp, "%d", argnum);
@ -1759,7 +1765,7 @@ static List *split_embedded_typemap(String *s) {
* $typemap(in, (Foo<int, bool> a, int b)) # multi-argument typemap matching %typemap(in) (Foo<int, bool> a, int b) {...}
* ----------------------------------------------------------------------------- */
static void replace_embedded_typemap(String *s, String *lname, Wrapper *f) {
static void replace_embedded_typemap(String *s, ParmList *parm_sublist, Wrapper *f) {
char *start = 0;
while ((start = strstr(Char(s), "$TYPEMAP("))) { /* note $typemap capitalisation to $TYPEMAP hack */
@ -1805,11 +1811,19 @@ static void replace_embedded_typemap(String *s, String *lname, Wrapper *f) {
* typemap matching, so split these parameters apart */
to_match_parms = Swig_cparse_parms(Getitem(l, 1));
if (to_match_parms) {
Parm *p = to_match_parms;;
Parm *p = to_match_parms;
Parm *sub_p = parm_sublist;
String *empty_string = NewStringEmpty();
String *lname = empty_string;
while (p) {
if (sub_p) {
lname = Getattr(sub_p, "lname");
sub_p = nextSibling(sub_p);
}
Setattr(p, "lname", lname);
p = nextSibling(p);
}
Delete(empty_string);
}
/* process optional extra parameters - the variable replacements (undocumented) */