mirror of https://github.com/swig/swig
Add support for %typemap and member function pointers with qualifiers
This commit is contained in:
parent
45c161dfce
commit
c4e280024f
|
@ -563,6 +563,7 @@ CPP11_TEST_CASES += \
|
|||
cpp11_raw_string_literals \
|
||||
cpp11_ref_qualifiers \
|
||||
cpp11_ref_qualifiers_rvalue_unignore \
|
||||
cpp11_ref_qualifiers_typemaps \
|
||||
cpp11_result_of \
|
||||
cpp11_rvalue_reference \
|
||||
cpp11_rvalue_reference2 \
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
%module cpp11_ref_qualifiers_typemaps
|
||||
|
||||
%typemap(in) SWIGTYPE (CLASS::*) %{
|
||||
_this_will_fail_to_compile_if_used_
|
||||
%}
|
||||
|
||||
// typemaps to completely ignore the input parm and override it
|
||||
%typemap(in) short (Funcs::*ff)(bool) const %{ $1 = &Funcs::FF2; %}
|
||||
%typemap(in) short (Funcs::*cc)(bool) & %{ $1 = &Funcs::CC5; %}
|
||||
%typemap(in) short (Funcs::*gg)(bool) const & %{ $1 = &Funcs::GG8; %}
|
||||
%typemap(in) short (Funcs::*hh)(bool) && %{ $1 = &Funcs::HH11; %}
|
||||
|
||||
%typemap(in) short (Funcs::*)(bool) const %{ $1 = &Funcs::FF3; %}
|
||||
%typemap(in) short (Funcs::*)(bool) & %{ $1 = &Funcs::CC6; %}
|
||||
%typemap(in) short (Funcs::*)(bool) const & %{ $1 = &Funcs::GG9; %}
|
||||
%typemap(in) short (Funcs::*)(bool) && %{ $1 = &Funcs::HH12; %}
|
||||
|
||||
%inline %{
|
||||
struct Funcs {
|
||||
short FF1(bool) const { return 1; }
|
||||
short FF2(bool) const { return 2; }
|
||||
short FF3(bool) const { return 3; }
|
||||
short CC4(bool) & { return 4; }
|
||||
short CC5(bool) & { return 5; }
|
||||
short CC6(bool) & { return 6; }
|
||||
short GG7(bool) const & { return 7; }
|
||||
short GG8(bool) const & { return 8; }
|
||||
short GG9(bool) const & { return 9; }
|
||||
short HH10(bool) && { return 10; }
|
||||
short HH11(bool) && { return 11; }
|
||||
short HH12(bool) && { return 12; }
|
||||
};
|
||||
struct TypemapsNamedParms
|
||||
{
|
||||
short fff(short (Funcs::*ff)(bool) const) {
|
||||
Funcs funcs;
|
||||
return (funcs.*ff)(true);
|
||||
}
|
||||
short ccc(short (Funcs::*cc)(bool) &) {
|
||||
Funcs funcs;
|
||||
return (funcs.*cc)(true);
|
||||
}
|
||||
short ggg(short (Funcs::*gg)(bool) const &) {
|
||||
Funcs funcs;
|
||||
return (funcs.*gg)(true);
|
||||
}
|
||||
short hhh(short (Funcs::*hh)(bool) &&) {
|
||||
return (Funcs().*hh)(true);
|
||||
}
|
||||
};
|
||||
struct TypemapsUnnamedParms
|
||||
{
|
||||
short fff(short (Funcs::*f)(bool) const) {
|
||||
Funcs funcs;
|
||||
return (funcs.*f)(true);
|
||||
}
|
||||
short ccc(short (Funcs::*c)(bool) &) {
|
||||
Funcs funcs;
|
||||
return (funcs.*c)(true);
|
||||
}
|
||||
short ggg(short (Funcs::*g)(bool) const &) {
|
||||
Funcs funcs;
|
||||
return (funcs.*g)(true);
|
||||
}
|
||||
short hhh(short (Funcs::*h)(bool) &&) {
|
||||
return (Funcs().*h)(true);
|
||||
}
|
||||
};
|
||||
%}
|
||||
|
||||
%constant short (Funcs::*FF1_MFP)(bool) const = &Funcs::FF1;
|
||||
%constant short (Funcs::*CC4_MFP)(bool) & = &Funcs::CC4;
|
||||
%constant short (Funcs::*GG7_MFP)(bool) const & = &Funcs::GG7;
|
||||
%constant short (Funcs::*HH10_MFP)(bool) && = &Funcs::HH10;
|
|
@ -0,0 +1,39 @@
|
|||
import cpp11_ref_qualifiers_typemaps.*;
|
||||
|
||||
public class cpp11_ref_qualifiers_typemaps_runme {
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("cpp11_ref_qualifiers_typemaps");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String argv[])
|
||||
{
|
||||
{
|
||||
TypemapsNamedParms tm = new TypemapsNamedParms();
|
||||
if (tm.fff(cpp11_ref_qualifiers_typemaps.FF1_MFP) != 2)
|
||||
throw new RuntimeException("failed");
|
||||
if (tm.ccc(cpp11_ref_qualifiers_typemaps.CC4_MFP) != 5)
|
||||
throw new RuntimeException("failed");
|
||||
if (tm.ggg(cpp11_ref_qualifiers_typemaps.GG7_MFP) != 8)
|
||||
throw new RuntimeException("failed");
|
||||
if (tm.hhh(cpp11_ref_qualifiers_typemaps.HH10_MFP) != 11)
|
||||
throw new RuntimeException("failed");
|
||||
}
|
||||
{
|
||||
TypemapsUnnamedParms tm = new TypemapsUnnamedParms();
|
||||
if (tm.fff(cpp11_ref_qualifiers_typemaps.FF1_MFP) != 3)
|
||||
throw new RuntimeException("failed");
|
||||
if (tm.ccc(cpp11_ref_qualifiers_typemaps.CC4_MFP) != 6)
|
||||
throw new RuntimeException("failed");
|
||||
if (tm.ggg(cpp11_ref_qualifiers_typemaps.GG7_MFP) != 9)
|
||||
throw new RuntimeException("failed");
|
||||
if (tm.hhh(cpp11_ref_qualifiers_typemaps.HH10_MFP) != 12)
|
||||
throw new RuntimeException("failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1895,7 +1895,7 @@ constant_directive : CONSTANT identifier EQUAL definetype SEMI {
|
|||
$$ = 0;
|
||||
}
|
||||
}
|
||||
/* Member const function pointers . eg.
|
||||
/* Member function pointers with qualifiers. eg.
|
||||
%constant short (Funcs::*pmf)(bool) const = &Funcs::F; */
|
||||
| CONSTANT type direct_declarator LPAREN parms RPAREN cv_ref_qualifier def_args SEMI {
|
||||
if (($8.type != T_ERROR) && ($8.type != T_SYMBOL)) {
|
||||
|
@ -5116,7 +5116,7 @@ parameter_declarator : declarator def_args {
|
|||
$$.id = 0;
|
||||
$$.defarg = $1.rawval ? $1.rawval : $1.val;
|
||||
}
|
||||
/* Member const function pointer parameters. eg.
|
||||
/* Member function pointers with qualifiers. eg.
|
||||
int f(short (Funcs::*parm)(bool) const); */
|
||||
| direct_declarator LPAREN parms RPAREN cv_ref_qualifier {
|
||||
SwigType *t;
|
||||
|
@ -5174,6 +5174,27 @@ plain_declarator : declarator {
|
|||
$$.parms = 0;
|
||||
}
|
||||
}
|
||||
/* Member function pointers with qualifiers. eg.
|
||||
int f(short (Funcs::*parm)(bool) const) */
|
||||
| direct_declarator LPAREN parms RPAREN cv_ref_qualifier {
|
||||
SwigType *t;
|
||||
$$ = $1;
|
||||
t = NewStringEmpty();
|
||||
SwigType_add_function(t, $3);
|
||||
if ($5.qualifier)
|
||||
SwigType_push(t, $5.qualifier);
|
||||
if (!$$.have_parms) {
|
||||
$$.parms = $3;
|
||||
$$.have_parms = 1;
|
||||
}
|
||||
if (!$$.type) {
|
||||
$$.type = t;
|
||||
} else {
|
||||
SwigType_push(t, $$.type);
|
||||
Delete($$.type);
|
||||
$$.type = t;
|
||||
}
|
||||
}
|
||||
| empty {
|
||||
$$.type = 0;
|
||||
$$.id = 0;
|
||||
|
|
Loading…
Reference in New Issue