Merge branch 'cpp11-ref-qualifiers'

* cpp11-ref-qualifiers:
  Warnings in testcases fix
  Add support for %typemap and member function pointers with qualifiers
  Fix wrapping of some member function pointer parameters
  Add support for member function pointers with ref-qualifiers
  Add error for constructors, destructors, static methods declared with qualifiers
  Add support for conversion operators with ref-qualifiers
  Alternate function syntax parsing improvement
  Re-organise parser grammar for initializer rules
  Re-organise parser grammar for declarator and initializer rules
  Add docs for C++11 ref-qualifiers
  Add unignore for rvalue ref-qualifiers
  Improve ref-qualifier implementation
  Fix support for member const function pointer variables
  Use normal SWIG encodings for ref-qualifiers
  C++11 ref-qualifier support added
This commit is contained in:
William S Fulton 2017-09-11 19:33:27 +01:00
commit 4d2d8dd80e
32 changed files with 1247 additions and 230 deletions

View file

@ -11,6 +11,29 @@ Version 4.0.0 (in progress)
[Python] Patch #1083. Define_DEBUG to 1 to do exactly like Visual Studio
/LDd, /MDd or /MTd compiler options.
2017-08-25: wsfulton
Issue #1059. Add support for C++11 ref-qualifiers on non-static member functions.
Members with lvalue ref-qualifiers such as:
struct RQ {
void m1(int x) &;
void m2(int x) const &;
};
are wrapped like any other member function. Member functions with rvalue ref-qualifiers
are ignored by default, such as:
struct RQ {
void m3(int x) &&;
void m4(int x) const &&;
};
example.i:7: Warning 405: Method with rvalue ref-qualifier m3(int) && ignored.
example.i:8: Warning 405: Method with rvalue ref-qualifier m4(int) const && ignored.
These can be unignored and exposed to the target language, see further documentation in
CPlusPlus11.html.
2017-08-16: wsfulton
Fix #1063. Add using declarations to templates into typedef table.

View file

@ -42,6 +42,7 @@
<li><a href="#CPlusPlus11_noexcept">Exception specifications and noexcept</a>
<li><a href="#CPlusPlus11_alignment">Control and query object alignment</a>
<li><a href="#CPlusPlus11_attributes">Attributes</a>
<li><a href="#CPlusPlus11_ref_qualifiers">Methods with ref-qualifiers</a>
</ul>
<li><a href="#CPlusPlus11_standard_library_changes">Standard library changes</a>
<ul>
@ -971,6 +972,104 @@ int [[attr1]] i [[attr2, attr3]];
[[noreturn, nothrow]] void f [[noreturn]] ();
</pre></div>
<H3><a name="CPlusPlus11_ref_qualifiers">7.2.29 Methods with ref-qualifiers</a></H3>
<p>
C++11 non-static member functions can be declared with ref-qualifiers.
Member functions declared with a <tt>&amp;</tt> lvalue ref-qualifiers are wrapped like any other function without ref-qualifiers.
Member functions declared with a <tt>&amp;&amp;</tt> rvalue ref-qualifiers are ignored by default
as they are unlikely to be required from non-C++ languages where the concept of <i>rvalue-ness</i>
for the implied *this pointer does not apply.
The warning is hidden by default, but can be displayed as described in the section on <a href="Warnings.html#Warnings_nn4">Enabling extra warnings</a>.
</p>
<p>
Consider:
</p>
<div class="code"><pre>
struct RQ {
void m1(int x) &amp;;
void m2(int x) &amp;&amp;;
};
</pre></div>
<p>
The only wrapped method will be the lvalue ref-qualified method <tt>m1</tt>
and if SWIG is run with the <tt>-Wextra</tt> command-line option, the following warning will be issued indicating <tt>m2</tt> is not wrapped:
</p>
<div class="shell">
<pre>
example.i:7: Warning 405: Method with rvalue ref-qualifier m2(int) &amp;&amp; ignored.
</pre>
</div>
<p>
If you unignore the method as follows, wrappers for <tt>m2</tt> will be generated:
</p>
<div class="code"><pre>
%feature("ignore", "0") RQ::m2(int x) &amp;&amp;;
struct RQ {
void m1(int x) &amp;;
void m2(int x) &amp;&amp;;
};
</pre></div>
<p>
Inspection of the generated C++ code, will show that <tt>std::move</tt> is used on the instance
of the <tt>RQ *</tt> class:
</p>
<div class="code"><pre>
RQ *arg1 = (RQ *) 0 ;
int arg2 ;
arg1 = ...marshalled from target language...
arg2 = ...marshalled from target language...
std::move(*arg1).m2(arg2);
</pre></div>
<p>
This will compile but when run, the move effects may not be what you want.
As stated earlier, rvalue ref-qualifiers aren't really applicable outside the world of C++.
However, if you really know what you are doing, full control over the call to the method is
possible via the low-level "action" feature.
This feature completely replaces the call to the underlying function, that is, the last line in the snippet of code above.
</p>
<div class="code"><pre>
%feature("ignore", "0") RQ::m2(int x) &amp;&amp;;
%feature("action") RQ::m2(int x) &amp;&amp; %{
RQ().m2(arg2);
%}
struct RQ {
void m1(int x) &amp;;
void m2(int x) &amp;&amp;;
};
</pre></div>
<p>
resulting in:
</p>
<div class="code"><pre>
RQ *arg1 = (RQ *) 0 ;
int arg2 ;
arg1 = ...marshalled from target language...
arg2 = ...marshalled from target language...
RQ().m2(arg2);
</pre></div>
<p>
<b>Compatibility note:</b> SWIG-4.0.0 was the first version to support ref-qualifiers.
</p>
<H2><a name="CPlusPlus11_standard_library_changes">7.3 Standard library changes</a></H2>
@ -1177,5 +1276,6 @@ Phew, that is a lot of hard work to get a callback working.
You could just go with the more attractive option of just using <tt>double</tt> as the return type in the function declaration instead of <tt>result_of</tt>!
</p>
</body>
</html>

View file

@ -310,6 +310,7 @@
<li><a href="CPlusPlus11.html#CPlusPlus11_noexcept">Exception specifications and noexcept</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_alignment">Control and query object alignment</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_attributes">Attributes</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_ref_qualifiers">Methods with ref-qualifiers</a>
</ul>
<li><a href="CPlusPlus11.html#CPlusPlus11_standard_library_changes">Standard library changes</a>
<ul>

View file

@ -2409,8 +2409,8 @@ the first renaming rule found on a depth-first traversal of the class hierarchy
is used.
</li>
<li><p>The name matching rules strictly follow member qualification rules.
For example, if you have a class like this:</p>
<li><p>The name matching rules strictly follow member qualifier rules.
For example, if you have a class and member with a member that is const qualified like this:</p>
<div class="code">
<pre>
@ -2434,7 +2434,7 @@ the declaration
</div>
<p>
will not apply as there is no unqualified member <tt>bar()</tt>. The following will apply as
will not apply as there is no unqualified member <tt>bar()</tt>. The following will apply the rename as
the qualifier matches correctly:
</p>
@ -2444,6 +2444,26 @@ the qualifier matches correctly:
</pre>
</div>
<p>
Similarly for combinations of cv-qualifiers and ref-qualifiers, all the qualifiers must be specified to match correctly:
</p>
<div class="code">
<pre>
%rename(name) Jam::bar(); // will not match
%rename(name) Jam::bar() &amp;; // will not match
%rename(name) Jam::bar() const; // will not match
%rename(name) Jam::bar() const &amp;; // ok, will match
class Jam {
public:
...
void bar() const &amp;;
...
};
</pre>
</div>
<p>
An often overlooked C++ feature is that classes can define two different overloaded members
that differ only in their qualifiers, like this:
@ -2476,7 +2496,7 @@ For example we can give them separate names in the target language:
<p>
Similarly, if you
merely wanted to ignore one of the declarations, use <tt>%ignore</tt>
with the full qualification. For example, the following directive
with the full qualifier. For example, the following directive
would tell SWIG to ignore the <tt>const</tt> version of <tt>bar()</tt>
above:
</p>

View file

@ -4021,7 +4021,7 @@ struct X {
Forced inclusion of fragments can be used as a replacement for <a href="SWIG.html#SWIG_nn42">code insertion block</a>, ensuring the
code block is only generated once.
Consider the contents of FileA.i below which first uses a code insertion block and then a forced fragment inclusion to generate code:
<p>
</p>
<div class="code">
<pre>
// FileA.i
@ -4058,7 +4058,7 @@ The resulting code in the wrappers for FileB.i is:
<p>
A note of caution must be mentioned when using <tt>%fragment</tt> forced inclusion or code insertion blocks with <tt>%import</tt>.
If <tt>%import</tt> is used instead:
<p>
</p>
<div class="code">
<pre>

View file

@ -561,6 +561,9 @@ CPP11_TEST_CASES += \
cpp11_noexcept \
cpp11_null_pointer_constant \
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 \

View file

@ -0,0 +1,226 @@
%module cpp11_ref_qualifiers
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) ccextra2;
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) ccextra3;
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) cc2;
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) cc3;
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) cc5;
%include <std_string.i>
%ignore Host::h() const &;
// Basic testing
%inline %{
using std::string;
class Host {
string s;
public:
string h1() & { return string(); }
string h2() const & { return string(); }
string h3() && { return std::move(string()); }
string h4() const && { return std::move(string()); }
string h5() const { return string(); }
string h6() volatile const & { return string(); }
string h7() const volatile & { return string(); }
string h8() volatile const && { return std::move(string()); }
string h9() const volatile && { return std::move(string()); }
string h() & { return string(); }
string h() const & { return string(); }
string h() && { return std::move(string()); }
string h() const && { return std::move(string()); }
};
%}
// %feature testing
%feature("except") F1() & %{ result = "F1"; %}
%feature("except") F2 %{ result = "F2"; %}
%feature("except") F3 %{ result = "F3"; %}
%feature("except") F3() %{ _should_not_be_used_ %}
%feature("except") C1(int i) const & %{ result = "C1"; %}
%feature("except") C2 %{ result = "C2"; %}
%feature("except") C3 %{ result = "C3"; %}
%feature("except") C3(int i) %{ _should_not_be_used_ %}
%inline %{
struct Features {
string F1() & { return string(); }
string F2() & { return string(); }
string F3() & { return string(); }
string C1(int i) const & { return string(); }
string C2(int i) const & { return string(); }
string C3(int i) const & { return string(); }
};
%}
// %rename testing
%rename(RR1) R1;
%rename(RR2) R2() &;
%rename(RR3) R3;
%rename(RR3Bad) R3();
%rename(SS1) S1;
%rename(SS2) S2(int i) const &;
%rename(SS3) S3;
%rename(SS3Bad) S3(int i);
%rename(SS3BadConst) S3(int i) const;
%rename(SS3BadLValue) S3(int i) &;
%inline %{
struct Renames {
string R1() & { return string(); }
string R2() & { return string(); }
string R3() & { return string(); }
string S1(int i) const & { return string(); }
string S2(int i) const & { return string(); }
string S3(int i) const & { return string(); }
};
%}
// Conversion operators
%rename(StringConvertCopy) operator string() &;
%rename(StringConvertMove) operator string() &&;
%feature("ignore", "0") operator string() &&; // unignore as it is ignored by default
%inline %{
struct ConversionOperators {
virtual operator string() & { return string(); }
virtual operator string() && { return std::move(string()); }
virtual ~ConversionOperators() {}
};
struct ConversionOperators2 {
virtual operator string() && { return std::move(string()); }
virtual ~ConversionOperators2() {}
};
%}
%inline %{
struct Funcs {
short FF(bool) { return 0; }
short CC(bool) const & { return 0; }
};
class MemberFuncPtrs
{
public:
// member ref-qualified function pointers, unnamed parameters
int aaa1(short (Funcs::*)(bool) &) const;
int aaa2(short (Funcs::* const *&)(bool) &) const;
int aaa3(short (Funcs::* *&)(bool) &) const;
int aaa4(short (Funcs::* *const&)(bool) &) const;
int aaa5(short (Funcs::* &)(bool) &) const;
int aaa6(short (Funcs::* const)(bool) &) const;
int aaa7(short (Funcs::* const&)(bool) &) const;
int aaa8(short (Funcs::* const&)(bool) &&) const;
// member cv-qualified and ref-qualified function pointers, unnamed parameters
int bbb1(short (Funcs::*)(bool) const &) const;
int bbb2(short (Funcs::* const *&)(bool) const &) const;
int bbb3(short (Funcs::* *&)(bool) const &) const;
int bbb4(short (Funcs::* *const&)(bool) const &) const;
int bbb5(short (Funcs::* &)(bool) const &) const;
int bbb6(short (Funcs::* const)(bool) const &) const;
int bbb7(short (Funcs::* const&)(bool) const &) const;
int bbb8(short (Funcs::*)(bool) const &&) const;
// member ref-qualified function pointers, named parameters
int qqq1(short (Funcs::* qq1)(bool) &) const;
int qqq2(short (Funcs::* const *& qq2)(bool) &) const;
int qqq3(short (Funcs::* *& qq3)(bool) &) const;
int qqq4(short (Funcs::* *const& qq4)(bool) &) const;
int qqq5(short (Funcs::* & qq5)(bool) &) const;
int qqq6(short (Funcs::* const qq6)(bool) &) const;
int qqq7(short (Funcs::* const& qq7)(bool) &) const;
int qqq8(short (Funcs::* const& qq8)(bool) &&) const;
// member cv-qualified and ref-qualified function pointers, named parameters
int rrr1(short (Funcs::* rr1)(bool) const &) const;
int rrr2(short (Funcs::* const *& rr2)(bool) const &) const;
int rrr3(short (Funcs::* *& rr3)(bool) const &) const;
int rrr4(short (Funcs::* *const& rr4)(bool) const &) const;
int rrr5(short (Funcs::* & rr5)(bool) const &) const;
int rrr6(short (Funcs::* const rr6)(bool) const &) const;
int rrr7(short (Funcs::* const& rr7)(bool) const &) const;
int rrr8(short (Funcs::* rr1)(bool) const &&) const;
};
// member ref-qualified function pointers, unnamed parameters
int MemberFuncPtrs::aaa1(short (Funcs::*)(bool) &) const { return 0; }
int MemberFuncPtrs::aaa2(short (Funcs::* const *&)(bool) &) const { return 0; }
int MemberFuncPtrs::aaa3(short (Funcs::* *&)(bool) &) const { return 0; }
int MemberFuncPtrs::aaa4(short (Funcs::* *const&)(bool) &) const { return 0; }
int MemberFuncPtrs::aaa5(short (Funcs::* &)(bool) &) const { return 0; }
int MemberFuncPtrs::aaa6(short (Funcs::* const)(bool) &) const { return 0; }
int MemberFuncPtrs::aaa7(short (Funcs::* const&)(bool) &) const { return 0; }
int MemberFuncPtrs::aaa8(short (Funcs::* const&)(bool) &&) const { return 0; }
// member cv-qualified and ref-qualified function pointers, unnamed parameters
int MemberFuncPtrs::bbb1(short (Funcs::*)(bool) const &) const { return 0; }
int MemberFuncPtrs::bbb2(short (Funcs::* const *&)(bool) const &) const { return 0; }
int MemberFuncPtrs::bbb3(short (Funcs::* *&)(bool) const &) const { return 0; }
int MemberFuncPtrs::bbb4(short (Funcs::* *const&)(bool) const &) const { return 0; }
int MemberFuncPtrs::bbb5(short (Funcs::* &)(bool) const &) const { return 0; }
int MemberFuncPtrs::bbb6(short (Funcs::* const)(bool) const &) const { return 0; }
int MemberFuncPtrs::bbb7(short (Funcs::* const&)(bool) const &) const { return 0; }
int MemberFuncPtrs::bbb8(short (Funcs::*)(bool) const &&) const { return 0; }
// member ref-qualified function pointers, named parameters
int MemberFuncPtrs::qqq1(short (Funcs::* qq1)(bool) &) const { return 0; }
int MemberFuncPtrs::qqq2(short (Funcs::* const *& qq2)(bool) &) const { return 0; }
int MemberFuncPtrs::qqq3(short (Funcs::* *& qq3)(bool) &) const { return 0; }
int MemberFuncPtrs::qqq4(short (Funcs::* *const& qq4)(bool) &) const { return 0; }
int MemberFuncPtrs::qqq5(short (Funcs::* & qq5)(bool) &) const { return 0; }
int MemberFuncPtrs::qqq6(short (Funcs::* const qq6)(bool) &) const { return 0; }
int MemberFuncPtrs::qqq7(short (Funcs::* const& qq7)(bool) &) const { return 0; }
int MemberFuncPtrs::qqq8(short (Funcs::* const& qq8)(bool) &&) const { return 0; }
// member cv-qualified and ref-qualified function pointers, named parameters
int MemberFuncPtrs::rrr1(short (Funcs::* rr1)(bool) const &) const { return 0; }
int MemberFuncPtrs::rrr2(short (Funcs::* const *& rr2)(bool) const &) const { return 0; }
int MemberFuncPtrs::rrr3(short (Funcs::* *& rr3)(bool) const &) const { return 0; }
int MemberFuncPtrs::rrr4(short (Funcs::* *const& rr4)(bool) const &) const { return 0; }
int MemberFuncPtrs::rrr5(short (Funcs::* & rr5)(bool) const &) const { return 0; }
int MemberFuncPtrs::rrr6(short (Funcs::* const rr6)(bool) const &) const { return 0; }
int MemberFuncPtrs::rrr7(short (Funcs::* const& rr7)(bool) const &) const { return 0; }
int MemberFuncPtrs::rrr8(short (Funcs::* rr1)(bool) const &&) const { return 0; }
// member cv-qualified and ref-qualified pointer variables
short (Funcs::* cc1)(bool) const & = &Funcs::CC;
short (Funcs::* const * ccextra2)(bool) const & = &cc1;
short (Funcs::* * ccextra3)(bool) const & = &cc1;
short (Funcs::* *const ccextra4)(bool) const & = &cc1;
short (Funcs::* const *& cc2)(bool) const & = ccextra2;
short (Funcs::* *& cc3)(bool) const & = ccextra3;
short (Funcs::* *const& cc4)(bool) const & = ccextra4;
short (Funcs::* & cc5)(bool) const & = cc1;
short (Funcs::* const cc6)(bool) const & = &Funcs::CC;
short (Funcs::* const& cc7)(bool) const & = cc1;
%}
%inline %{
struct Funktions {
int addByValue(const int &a, int b) const & { return a+b; }
int * addByPointer(const int &a, int b) const & { static int val; val = a+b; return &val; }
int & addByReference(const int &a, int b) const & { static int val; val = a+b; return val; }
};
int call1(int (Funktions::*d)(const int &, int) const &, int a, int b) { Funktions f; return (f.*d)(a, b); }
//int call2(int * (Funktions::*d)(const int &, int) const &, int a, int b) { Funktions f; return *(f.*d)(a, b); }
//int call3(int & (Funktions::*d)(const int &, int) const &, int a, int b) { Funktions f; return (f.*d)(a, b); }
%}
%constant int (Funktions::*ADD_BY_VALUE)(const int &, int) const & = &Funktions::addByValue;

View file

@ -0,0 +1,15 @@
%module cpp11_ref_qualifiers_rvalue_unignore
// This is a minimal test that does not include any C++ headers to make sure the required
// <memory> header is generated from a fragment for the generated std::move call
// m1 and m2 are ignored by default, unignore them
%feature("ignore", "0") RefQualifier::m1() &&;
%feature("ignore", "0") RefQualifier::m2() const &&;
%inline %{
struct RefQualifier {
void m1() && {}
void m2() const && {}
};
%}

View file

@ -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;

View file

@ -0,0 +1,43 @@
%module cpp_invalid_qualifiers
// Constructors, destructors and static methods cannot have qualifiers
struct A {
~A() const;
};
struct B {
virtual ~B() const;
};
struct C {
~C() &;
};
struct D {
virtual ~D() &;
};
struct E {
~E() &&;
};
struct F {
virtual ~F() &&;
};
struct J {
J() const;
J(int) const;
};
struct K {
K() &;
K(int) &;
};
struct L {
L() &&;
L(int) &&;
};
struct M {
static void m1() const;
static void m2() &;
thread_local static void m3() &&;
static auto m4() const -> int;
static auto m5() & -> int;
static auto m6() && -> int;
};

View file

@ -0,0 +1,20 @@
cpp_invalid_qualifiers.i:5: Error: Destructor ~A() const cannot have a qualifier.
cpp_invalid_qualifiers.i:8: Error: Destructor ~B() const cannot have a qualifier.
cpp_invalid_qualifiers.i:11: Error: Destructor ~C() & cannot have a qualifier.
cpp_invalid_qualifiers.i:14: Error: Destructor ~D() & cannot have a qualifier.
cpp_invalid_qualifiers.i:17: Error: Destructor ~E() && cannot have a qualifier.
cpp_invalid_qualifiers.i:20: Error: Destructor ~F() && cannot have a qualifier.
cpp_invalid_qualifiers.i:24: Error: Constructor cannot have a qualifier.
cpp_invalid_qualifiers.i:25: Error: Constructor cannot have a qualifier.
cpp_invalid_qualifiers.i:28: Error: Constructor cannot have a qualifier.
cpp_invalid_qualifiers.i:29: Error: Constructor cannot have a qualifier.
cpp_invalid_qualifiers.i:32: Error: Constructor cannot have a qualifier.
cpp_invalid_qualifiers.i:33: Error: Constructor cannot have a qualifier.
cpp_invalid_qualifiers.i:37: Error: Static function m1() const cannot have a qualifier.
cpp_invalid_qualifiers.i:38: Error: Static function m2() & cannot have a qualifier.
cpp_invalid_qualifiers.i:39: Error: Static function m3() && cannot have a qualifier.
cpp_invalid_qualifiers.i:39: Warning 405: Method with rvalue ref-qualifier m3() && ignored.
cpp_invalid_qualifiers.i:40: Error: Static function m4() const cannot have a qualifier.
cpp_invalid_qualifiers.i:41: Error: Static function m5() & cannot have a qualifier.
cpp_invalid_qualifiers.i:42: Error: Static function m6() && cannot have a qualifier.
cpp_invalid_qualifiers.i:42: Warning 405: Method with rvalue ref-qualifier m6() && ignored.

View file

@ -0,0 +1,28 @@
%module cpp_refqualifier
%ignore Host::h_ignored;
%ignore Host::i_ignored() &&;
%ignore Host::j_ignored() const &&;
class Host {
public:
void h1() &;
void h2() const &;
void h3() &&;
void h4() const &&;
void h() &;
void h() const &;
void h() &&;
void h() const &&;
void h_ignored() &&;
void i_ignored() &&;
void i_ignored() &&;
};
%feature("ignore", "0") Unignore::k_unignored() const &&;
struct Unignore {
void k_unignored() const &&;
};

View file

@ -0,0 +1,6 @@
cpp_refqualifier.i:11: Warning 405: Method with rvalue ref-qualifier h3() && ignored.
cpp_refqualifier.i:12: Warning 405: Method with rvalue ref-qualifier h4() const && ignored.
cpp_refqualifier.i:16: Warning 405: Method with rvalue ref-qualifier h() && ignored.
cpp_refqualifier.i:17: Warning 405: Method with rvalue ref-qualifier h() const && ignored.
cpp_refqualifier.i:15: Warning 512: Overloaded method Host::h() const & ignored,
cpp_refqualifier.i:14: Warning 512: using non-const method Host::h() & instead.

View file

@ -0,0 +1,56 @@
import cpp11_ref_qualifiers.*;
public class cpp11_ref_qualifiers_runme {
static {
try {
System.loadLibrary("cpp11_ref_qualifiers");
} 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[]) {
Host h = new Host();
// Basic testing
h.h1();
h.h2();
h.h6();
h.h7();
h.h();
// %feature testing
Features f = new Features();
if (!f.F1().equals("F1")) throw new RuntimeException("Fail");
if (!f.F2().equals("F2")) throw new RuntimeException("Fail");
if (!f.F3().equals("F3")) throw new RuntimeException("Fail");
if (!f.C1(0).equals("C1")) throw new RuntimeException("Fail");
if (!f.C2(0).equals("C2")) throw new RuntimeException("Fail");
if (!f.C3(0).equals("C3")) throw new RuntimeException("Fail");
// %rename testing
Renames r = new Renames();
r.RR1();
r.RR2();
r.RR3();
r.SS1(0);
r.SS2(0);
r.SS3(0);
// Conversion operators
String s = null;
ConversionOperators co = new ConversionOperators();
s = co.StringConvertCopy();
s = co.StringConvertMove();
ConversionOperators2 co2 = new ConversionOperators2();
s = co2.StringConvertMove();
}
}

View file

@ -0,0 +1,20 @@
import cpp11_ref_qualifiers_rvalue_unignore.*;
public class cpp11_ref_qualifiers_rvalue_unignore_runme {
static {
try {
System.loadLibrary("cpp11_ref_qualifiers_rvalue_unignore");
} 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[]) {
new RefQualifier().m1();
new RefQualifier().m2();
}
}

View file

@ -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");
}
}
}

View file

@ -6,6 +6,12 @@
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) pp3;
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) pp5;
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) ccextra2;
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) ccextra3;
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) cc2;
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) cc3;
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) cc5;
%{
#if defined(__SUNPRO_CC)
#pragma error_messages (off, badargtype2w) /* Formal argument ... is being passed extern "C" ... */
@ -155,7 +161,7 @@ public:
int qqq7(short (Funcs::* const& qq7)(bool)) const;
};
// member const function pointers, unnamed parameters
// member const function pointers, unnamed parameters
int MemberFuncPtrs::aaa1(short (Funcs::* )(bool) const) const { return 0; }
int MemberFuncPtrs::aaa2(short (Funcs::* const *&)(bool) const) const { return 0; }
int MemberFuncPtrs::aaa3(short (Funcs::* *& )(bool) const) const { return 0; }
@ -191,7 +197,7 @@ int MemberFuncPtrs::qqq5(short (Funcs::* & qq5)(bool)) const { return 0; }
int MemberFuncPtrs::qqq6(short (Funcs::* const qq6)(bool)) const { return 0; }
int MemberFuncPtrs::qqq7(short (Funcs::* const& qq7)(bool)) const { return 0; }
// member function pointer variables
// member non-const function pointer variables
short (Funcs::* pp1)(bool) = &Funcs::FF;
short (Funcs::* const * extra2)(bool) = &pp1;
@ -204,4 +210,18 @@ short (Funcs::* *const& pp4)(bool) = extra4;
short (Funcs::* & pp5)(bool) = pp1;
short (Funcs::* const pp6)(bool) = &Funcs::FF;
short (Funcs::* const& pp7)(bool) = pp1;
// member const function pointer variables
short (Funcs::* cc1)(bool) const = &Funcs::CC;
short (Funcs::* const * ccextra2)(bool) const = &cc1;
short (Funcs::* * ccextra3)(bool) const = &cc1;
short (Funcs::* *const ccextra4)(bool) const = &cc1;
short (Funcs::* const *& cc2)(bool) const = ccextra2;
short (Funcs::* *& cc3)(bool) const = ccextra3;
short (Funcs::* *const& cc4)(bool) const = ccextra4;
short (Funcs::* & cc5)(bool) const = cc1;
short (Funcs::* const cc6)(bool) const = &Funcs::CC;
short (Funcs::* const& cc7)(bool) const = cc1;
%}

View file

@ -0,0 +1,45 @@
import cpp11_ref_qualifiers
h = cpp11_ref_qualifiers.Host()
# Basic testing
h.h1()
h.h2()
h.h6()
h.h7()
h.h()
# %feature testing
f = cpp11_ref_qualifiers.Features()
if f.F1() != "F1":
raise RuntimeException("Fail")
if f.F2() != "F2":
raise RuntimeException("Fail")
if f.F3() != "F3":
raise RuntimeException("Fail")
if f.C1(0) != "C1":
raise RuntimeException("Fail")
if f.C2(0) != "C2":
raise RuntimeException("Fail")
if f.C3(0) != "C3":
raise RuntimeException("Fail")
# %rename testing
r = cpp11_ref_qualifiers.Renames()
r.RR1()
r.RR2()
r.RR3()
r.SS1(0)
r.SS2(0)
r.SS3(0)
# Conversion operators
co = cpp11_ref_qualifiers.ConversionOperators()
s = co.StringConvertCopy()
s = co.StringConvertMove()
co2 = cpp11_ref_qualifiers.ConversionOperators2()
s = co2.StringConvertMove()

View file

@ -0,0 +1,4 @@
import cpp11_ref_qualifiers_rvalue_unignore
cpp11_ref_qualifiers_rvalue_unignore.RefQualifier().m1()
cpp11_ref_qualifiers_rvalue_unignore.RefQualifier().m2()

View file

@ -5,6 +5,7 @@
%inline %{
template<class Arg, typename Result> struct Functor {
virtual Result operator()(Arg x) const = 0;
virtual ~Functor() {}
};
%}

View file

@ -309,11 +309,13 @@ static int NAME(TYPE x) {
%define %$classname %$ismember,"match$parentNode$name" %enddef
%define %$isnested "match$nested"="1" %enddef
/* -----------------------------------------------------------------------------
* Include all the warnings labels and macros
* Common includes for warning labels, macros, fragments etc
* ----------------------------------------------------------------------------- */
%include <swigwarnings.swg>
%include <swigfragments.swg>
/* -----------------------------------------------------------------------------
* Overloading support

86
Lib/swigfragments.swg Normal file
View file

@ -0,0 +1,86 @@
/* -----------------------------------------------------------------------------
* swigfragments.swg
*
* Common fragments
* ----------------------------------------------------------------------------- */
/* -----------------------------------------------------------------------------
* Fragments for C header files
* ----------------------------------------------------------------------------- */
%fragment("<float.h>", "header") %{
#include <float.h>
%}
/* Default compiler options for gcc allow long_long but not LLONG_MAX.
* Define SWIG_NO_LLONG_MAX if this added limits support is not wanted. */
%fragment("<limits.h>", "header") %{
#include <limits.h>
#if !defined(SWIG_NO_LLONG_MAX)
# if !defined(LLONG_MAX) && defined(__GNUC__) && defined (__LONG_LONG_MAX__)
# define LLONG_MAX __LONG_LONG_MAX__
# define LLONG_MIN (-LLONG_MAX - 1LL)
# define ULLONG_MAX (LLONG_MAX * 2ULL + 1ULL)
# endif
#endif
%}
%fragment("<math.h>", "header") %{
#include <math.h>
%}
%fragment("<stddef.h>", "header") %{
#include <stddef.h>
%}
%fragment("<stdio.h>", "header") %{
#include <stdio.h>
#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM)
# ifndef snprintf
# define snprintf _snprintf
# endif
#endif
%}
%fragment("<stdlib.h>", "header") %{
#include <stdlib.h>
#ifdef _MSC_VER
# ifndef strtoull
# define strtoull _strtoui64
# endif
# ifndef strtoll
# define strtoll _strtoi64
# endif
#endif
%}
%fragment("<wchar.h>", "header") %{
#include <wchar.h>
#include <limits.h>
#ifndef WCHAR_MIN
# define WCHAR_MIN 0
#endif
#ifndef WCHAR_MAX
# define WCHAR_MAX 65535
#endif
%}
/* -----------------------------------------------------------------------------
* Fragments for C++ header files
* ----------------------------------------------------------------------------- */
%fragment("<algorithm>", "header") %{
#include <algorithm>
%}
%fragment("<stdexcept>", "header") %{
#include <stdexcept>
%}
%fragment("<string>", "header") %{
#include <string>
%}
%fragment("<memory>", "header") %{
#include <memory>
%}

View file

@ -96,75 +96,6 @@
* common fragments
* ------------------------------------------------------------ */
/* Default compiler options for gcc allow long_long but not LLONG_MAX.
* Define SWIG_NO_LLONG_MAX if this added limits support is not wanted. */
%fragment("<limits.h>","header") %{
#include <limits.h>
#if !defined(SWIG_NO_LLONG_MAX)
# if !defined(LLONG_MAX) && defined(__GNUC__) && defined (__LONG_LONG_MAX__)
# define LLONG_MAX __LONG_LONG_MAX__
# define LLONG_MIN (-LLONG_MAX - 1LL)
# define ULLONG_MAX (LLONG_MAX * 2ULL + 1ULL)
# endif
#endif
%}
%fragment("<math.h>","header") %{
#include <math.h>
%}
%fragment("<wchar.h>","header") %{
#include <wchar.h>
#include <limits.h>
#ifndef WCHAR_MIN
# define WCHAR_MIN 0
#endif
#ifndef WCHAR_MAX
# define WCHAR_MAX 65535
#endif
%}
%fragment("<float.h>","header") %{
#include <float.h>
%}
%fragment("<stdio.h>","header") %{
#include <stdio.h>
#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM)
# ifndef snprintf
# define snprintf _snprintf
# endif
#endif
%}
%fragment("<stdlib.h>","header") %{
#include <stdlib.h>
#ifdef _MSC_VER
# ifndef strtoull
# define strtoull _strtoui64
# endif
# ifndef strtoll
# define strtoll _strtoi64
# endif
#endif
%}
%fragment("<stddef.h>", "header") %{
#include <stddef.h>
%}
%fragment("<string>", "header") %{
#include <string>
%}
%fragment("<stdexcept>", "header") %{
#include <stdexcept>
%}
%fragment("<algorithm>", "header") %{
#include <algorithm>
%}
%fragment("SWIG_isfinite","header",fragment="<math.h>,<float.h>") %{
/* Getting isfinite working pre C99 across multiple platforms is non-trivial. Users can provide SWIG_isfinite on older platforms. */
#ifndef SWIG_isfinite

View file

@ -485,8 +485,19 @@ static void add_symbols(Node *n) {
SetFlag(n,"deleted");
SetFlag(n,"feature:ignore");
}
if (SwigType_isrvalue_reference(Getattr(n, "refqualifier"))) {
/* Ignore rvalue ref-qualifiers by default
* Use Getattr instead of GetFlag to handle explicit ignore and explicit not ignore */
if (!(Getattr(n, "feature:ignore") || Strncmp(symname, "$ignore", 7) == 0)) {
SWIG_WARN_NODE_BEGIN(n);
Swig_warning(WARN_TYPE_RVALUE_REF_QUALIFIER_IGNORED, Getfile(n), Getline(n),
"Method with rvalue ref-qualifier %s ignored.\n", Swig_name_decl(n));
SWIG_WARN_NODE_END(n);
SetFlag(n, "feature:ignore");
}
}
}
if (only_csymbol || GetFlag(n,"feature:ignore") || strncmp(Char(symname),"$ignore",7) == 0) {
if (only_csymbol || GetFlag(n, "feature:ignore") || Strncmp(symname, "$ignore", 7) == 0) {
/* Only add to C symbol table and continue */
Swig_symbol_add(0, n);
if (!only_csymbol && !GetFlag(n, "feature:ignore")) {
@ -1411,10 +1422,12 @@ static void mark_nodes_as_extend(Node *n) {
}
/* -----------------------------------------------------------------------------
* add_qualifier_to_declarator
* add_qualifier_to_declarator()
*
* Normally the qualifier is pushed on to the front of the type.
* Adding a qualifier to a pointer to member function is a special case.
* For example : typedef double (Cls::*pmf)(void) const;
* The qualifier is : q(const).
* The declarator is : m(Cls).f(void).
* We need : m(Cls).q(const).f(void).
* ----------------------------------------------------------------------------- */
@ -1422,22 +1435,39 @@ static void mark_nodes_as_extend(Node *n) {
static String *add_qualifier_to_declarator(SwigType *type, SwigType *qualifier) {
int is_pointer_to_member_function = 0;
String *decl = Copy(type);
String *poppedtype = NewString("");
assert(qualifier);
if (SwigType_ismemberpointer(decl)) {
String *memberptr = SwigType_pop(decl);
if (SwigType_isfunction(decl)) {
assert(!SwigType_isqualifier(decl));
SwigType_push(decl, qualifier);
SwigType_push(decl, memberptr);
is_pointer_to_member_function = 1;
while (decl) {
if (SwigType_ismemberpointer(decl)) {
String *memberptr = SwigType_pop(decl);
if (SwigType_isfunction(decl)) {
is_pointer_to_member_function = 1;
SwigType_push(decl, qualifier);
SwigType_push(decl, memberptr);
Insert(decl, 0, poppedtype);
Delete(memberptr);
break;
} else {
Append(poppedtype, memberptr);
}
Delete(memberptr);
} else {
Delete(decl);
decl = Copy(type);
String *popped = SwigType_pop(decl);
if (!popped)
break;
Append(poppedtype, popped);
Delete(popped);
}
Delete(memberptr);
}
if (!is_pointer_to_member_function)
if (!is_pointer_to_member_function) {
Delete(decl);
decl = Copy(type);
SwigType_push(decl, qualifier);
}
Delete(poppedtype);
return decl;
}
@ -1451,6 +1481,7 @@ static String *add_qualifier_to_declarator(SwigType *type, SwigType *qualifier)
String *rawval;
int type;
String *qualifier;
String *refqualifier;
String *bitfield;
Parm *throws;
String *throwf;
@ -1560,7 +1591,7 @@ static String *add_qualifier_to_declarator(SwigType *type, SwigType *qualifier)
/* Misc */
%type <id> identifier;
%type <dtype> initializer cpp_const exception_specification;
%type <dtype> initializer cpp_const exception_specification cv_ref_qualifier qualifiers_exception_specification;
%type <id> storage_class extern_string;
%type <pl> parms ptail rawparms varargs_parms ;
%type <pl> templateparameters templateparameterstail;
@ -1576,7 +1607,8 @@ static String *add_qualifier_to_declarator(SwigType *type, SwigType *qualifier)
%type <dtype> expr exprnum exprcompound valexpr;
%type <id> ename ;
%type <id> less_valparms_greater;
%type <str> type_qualifier ;
%type <str> type_qualifier;
%type <str> ref_qualifier;
%type <id> type_qualifier_raw;
%type <id> idstring idstringopt;
%type <id> pragma_lang;
@ -1597,7 +1629,7 @@ static String *add_qualifier_to_declarator(SwigType *type, SwigType *qualifier)
%type <node> lambda_introducer lambda_body;
%type <pl> lambda_tail;
%type <node> optional_constant_directive;
%type <str> virt_specifier_seq;
%type <str> virt_specifier_seq virt_specifier_seq_opt;
%%
@ -1863,12 +1895,12 @@ 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 CONST_QUAL def_args SEMI {
| CONSTANT type direct_declarator LPAREN parms RPAREN cv_ref_qualifier def_args SEMI {
if (($8.type != T_ERROR) && ($8.type != T_SYMBOL)) {
SwigType_add_function($2, $5);
SwigType_add_qualifier($2, "const");
SwigType_push($2, $7.qualifier);
SwigType_push($2, $3.type);
/* Sneaky callback function trick */
if (SwigType_isfunction($2)) {
@ -3058,36 +3090,37 @@ c_declaration : c_decl {
A C global declaration of some kind (may be variable, function, typedef, etc.)
------------------------------------------------------------ */
c_decl : storage_class type declarator initializer c_decl_tail {
c_decl : storage_class type declarator cpp_const initializer c_decl_tail {
String *decl = $3.type;
$$ = new_node("cdecl");
if ($4.qualifier)
decl = add_qualifier_to_declarator($3.type, $4.qualifier);
Setattr($$,"refqualifier",$4.refqualifier);
Setattr($$,"type",$2);
Setattr($$,"storage",$1);
Setattr($$,"name",$3.id);
Setattr($$,"decl",decl);
Setattr($$,"parms",$3.parms);
Setattr($$,"value",$4.val);
Setattr($$,"value",$5.val);
Setattr($$,"throws",$4.throws);
Setattr($$,"throw",$4.throwf);
Setattr($$,"noexcept",$4.nexcept);
if ($4.val && $4.type) {
if ($5.val && $5.type) {
/* store initializer type as it might be different to the declared type */
SwigType *valuetype = NewSwigType($4.type);
SwigType *valuetype = NewSwigType($5.type);
if (Len(valuetype) > 0)
Setattr($$,"valuetype",valuetype);
else
Delete(valuetype);
}
if (!$5) {
if (!$6) {
if (Len(scanner_ccode)) {
String *code = Copy(scanner_ccode);
Setattr($$,"code",code);
Delete(code);
}
} else {
Node *n = $5;
Node *n = $6;
/* Inherit attributes */
while (n) {
String *type = Copy($2);
@ -3097,8 +3130,8 @@ c_decl : storage_class type declarator initializer c_decl_tail {
Delete(type);
}
}
if ($4.bitfield) {
Setattr($$,"bitfield", $4.bitfield);
if ($5.bitfield) {
Setattr($$,"bitfield", $5.bitfield);
}
if ($3.id) {
@ -3113,29 +3146,33 @@ c_decl : storage_class type declarator initializer c_decl_tail {
String *lstr = Swig_scopename_last($3.id);
Setattr($$, "name", lstr);
Delete(lstr);
set_nextSibling($$, $5);
set_nextSibling($$, $6);
} else {
Delete($$);
$$ = $5;
$$ = $6;
}
Delete(p);
} else {
Delete($$);
$$ = $5;
$$ = $6;
}
} else {
set_nextSibling($$, $5);
set_nextSibling($$, $6);
}
} else {
Swig_error(cparse_file, cparse_line, "Missing symbol name for global declaration\n");
$$ = 0;
}
if ($4.qualifier && $1 && Strstr($1, "static"))
Swig_error(cparse_file, cparse_line, "Static function %s cannot have a qualifier.\n", Swig_name_decl($$));
}
/* Alternate function syntax introduced in C++11:
auto funcName(int x, int y) -> int; */
| storage_class AUTO declarator cpp_const ARROW cpp_alternate_rettype initializer c_decl_tail {
| storage_class AUTO declarator cpp_const ARROW cpp_alternate_rettype virt_specifier_seq_opt initializer c_decl_tail {
$$ = new_node("cdecl");
if ($4.qualifier) SwigType_push($3.type, $4.qualifier);
Setattr($$,"refqualifier",$4.refqualifier);
Setattr($$,"type",$6);
Setattr($$,"storage",$1);
Setattr($$,"name",$3.id);
@ -3145,14 +3182,14 @@ c_decl : storage_class type declarator initializer c_decl_tail {
Setattr($$,"throws",$4.throws);
Setattr($$,"throw",$4.throwf);
Setattr($$,"noexcept",$4.nexcept);
if (!$8) {
if (!$9) {
if (Len(scanner_ccode)) {
String *code = Copy(scanner_ccode);
Setattr($$,"code",code);
Delete(code);
}
} else {
Node *n = $8;
Node *n = $9;
while (n) {
String *type = Copy($6);
Setattr(n,"type",type);
@ -3173,19 +3210,22 @@ c_decl : storage_class type declarator initializer c_decl_tail {
String *lstr = Swig_scopename_last($3.id);
Setattr($$,"name",lstr);
Delete(lstr);
set_nextSibling($$, $8);
set_nextSibling($$, $9);
} else {
Delete($$);
$$ = $8;
$$ = $9;
}
Delete(p);
} else {
Delete($$);
$$ = $8;
$$ = $9;
}
} else {
set_nextSibling($$, $8);
set_nextSibling($$, $9);
}
if ($4.qualifier && $1 && Strstr($1, "static"))
Swig_error(cparse_file, cparse_line, "Static function %s cannot have a qualifier.\n", Swig_name_decl($$));
}
;
@ -3195,27 +3235,28 @@ c_decl_tail : SEMI {
$$ = 0;
Clear(scanner_ccode);
}
| COMMA declarator initializer c_decl_tail {
| COMMA declarator cpp_const initializer c_decl_tail {
$$ = new_node("cdecl");
if ($3.qualifier) SwigType_push($2.type,$3.qualifier);
Setattr($$,"refqualifier",$3.refqualifier);
Setattr($$,"name",$2.id);
Setattr($$,"decl",$2.type);
Setattr($$,"parms",$2.parms);
Setattr($$,"value",$3.val);
Setattr($$,"value",$4.val);
Setattr($$,"throws",$3.throws);
Setattr($$,"throw",$3.throwf);
Setattr($$,"noexcept",$3.nexcept);
if ($3.bitfield) {
Setattr($$,"bitfield", $3.bitfield);
if ($4.bitfield) {
Setattr($$,"bitfield", $4.bitfield);
}
if (!$4) {
if (!$5) {
if (Len(scanner_ccode)) {
String *code = Copy(scanner_ccode);
Setattr($$,"code",code);
Delete(code);
}
} else {
set_nextSibling($$,$4);
set_nextSibling($$, $5);
}
}
| LBRACE {
@ -3233,33 +3274,8 @@ c_decl_tail : SEMI {
}
;
initializer : def_args {
$$ = $1;
$$.qualifier = 0;
$$.throws = 0;
$$.throwf = 0;
$$.nexcept = 0;
}
| type_qualifier def_args {
$$ = $2;
$$.qualifier = $1;
$$.throws = 0;
$$.throwf = 0;
$$.nexcept = 0;
}
| exception_specification def_args {
$$ = $2;
$$.qualifier = 0;
$$.throws = $1.throws;
$$.throwf = $1.throwf;
$$.nexcept = $1.nexcept;
}
| type_qualifier exception_specification def_args {
$$ = $3;
$$.qualifier = $1;
$$.throws = $2.throws;
$$.throwf = $2.throwf;
$$.nexcept = $2.nexcept;
initializer : def_args {
$$ = $1;
}
;
@ -3402,7 +3418,7 @@ c_enum_decl : storage_class c_enum_key ename c_enum_inherit LBRACE enumlist RBR
Namespaceprefix = Swig_symbol_qualifiedscopename(0);
}
}
| storage_class c_enum_key ename c_enum_inherit LBRACE enumlist RBRACE declarator initializer c_decl_tail {
| storage_class c_enum_key ename c_enum_inherit LBRACE enumlist RBRACE declarator cpp_const initializer c_decl_tail {
Node *n;
SwigType *ty = 0;
String *unnamed = 0;
@ -3449,8 +3465,8 @@ c_enum_decl : storage_class c_enum_key ename c_enum_inherit LBRACE enumlist RBR
SetFlag(n,"unnamedinstance");
Delete(cty);
}
if ($10) {
Node *p = $10;
if ($11) {
Node *p = $11;
set_nextSibling(n,p);
while (p) {
SwigType *cty = Copy(ty);
@ -3958,12 +3974,12 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE {
;
cpp_opt_declarators : SEMI { $$ = 0; }
| declarator initializer c_decl_tail {
| declarator cpp_const initializer c_decl_tail {
$$ = new_node("cdecl");
Setattr($$,"name",$1.id);
Setattr($$,"decl",$1.type);
Setattr($$,"parms",$1.parms);
set_nextSibling($$,$3);
set_nextSibling($$, $4);
}
;
/* ------------------------------------------------------------
@ -4600,6 +4616,8 @@ cpp_destructor_decl : NOT idtemplate LPAREN parms RPAREN cpp_end {
Setattr($$,"noexcept",$6.nexcept);
if ($6.val)
Setattr($$,"value",$6.val);
if ($6.qualifier)
Swig_error(cparse_file, cparse_line, "Destructor %s %s cannot have a qualifier.\n", Swig_name_decl($$), SwigType_str($6.qualifier, 0));
add_symbols($$);
}
@ -4629,7 +4647,8 @@ cpp_destructor_decl : NOT idtemplate LPAREN parms RPAREN cpp_end {
Setattr($$,"decl",decl);
Delete(decl);
}
if ($7.qualifier)
Swig_error(cparse_file, cparse_line, "Destructor %s %s cannot have a qualifier.\n", Swig_name_decl($$), SwigType_str($7.qualifier, 0));
add_symbols($$);
}
;
@ -4646,6 +4665,7 @@ cpp_conversion_operator : storage_class CONVERSIONOPERATOR type pointer LPAREN p
if ($8.qualifier) {
SwigType_push($4,$8.qualifier);
}
Setattr($$,"refqualifier",$8.refqualifier);
Setattr($$,"decl",$4);
Setattr($$,"parms",$6);
Setattr($$,"conversion_operator","1");
@ -4663,6 +4683,7 @@ cpp_conversion_operator : storage_class CONVERSIONOPERATOR type pointer LPAREN p
if ($8.qualifier) {
SwigType_push(decl,$8.qualifier);
}
Setattr($$,"refqualifier",$8.refqualifier);
Setattr($$,"decl",decl);
Setattr($$,"parms",$6);
Setattr($$,"conversion_operator","1");
@ -4680,6 +4701,7 @@ cpp_conversion_operator : storage_class CONVERSIONOPERATOR type pointer LPAREN p
if ($8.qualifier) {
SwigType_push(decl,$8.qualifier);
}
Setattr($$,"refqualifier",$8.refqualifier);
Setattr($$,"decl",decl);
Setattr($$,"parms",$6);
Setattr($$,"conversion_operator","1");
@ -4699,6 +4721,7 @@ cpp_conversion_operator : storage_class CONVERSIONOPERATOR type pointer LPAREN p
if ($9.qualifier) {
SwigType_push(decl,$9.qualifier);
}
Setattr($$,"refqualifier",$9.refqualifier);
Setattr($$,"decl",decl);
Setattr($$,"parms",$7);
Setattr($$,"conversion_operator","1");
@ -4715,6 +4738,7 @@ cpp_conversion_operator : storage_class CONVERSIONOPERATOR type pointer LPAREN p
if ($7.qualifier) {
SwigType_push(t,$7.qualifier);
}
Setattr($$,"refqualifier",$7.refqualifier);
Setattr($$,"decl",t);
Setattr($$,"parms",$5);
Setattr($$,"conversion_operator","1");
@ -4785,6 +4809,9 @@ cpp_swig_directive: pragma_directive { $$ = $1; }
cpp_end : cpp_const SEMI {
Clear(scanner_ccode);
$$.val = 0;
$$.qualifier = $1.qualifier;
$$.refqualifier = $1.refqualifier;
$$.bitfield = 0;
$$.throws = $1.throws;
$$.throwf = $1.throwf;
$$.nexcept = $1.nexcept;
@ -4792,6 +4819,9 @@ cpp_end : cpp_const SEMI {
| cpp_const EQUAL default_delete SEMI {
Clear(scanner_ccode);
$$.val = $3.val;
$$.qualifier = $1.qualifier;
$$.refqualifier = $1.refqualifier;
$$.bitfield = 0;
$$.throws = $1.throws;
$$.throwf = $1.throwf;
$$.nexcept = $1.nexcept;
@ -4799,6 +4829,9 @@ cpp_end : cpp_const SEMI {
| cpp_const LBRACE {
skip_balanced('{','}');
$$.val = 0;
$$.qualifier = $1.qualifier;
$$.refqualifier = $1.refqualifier;
$$.bitfield = 0;
$$.throws = $1.throws;
$$.throwf = $1.throwf;
$$.nexcept = $1.nexcept;
@ -4809,6 +4842,7 @@ cpp_vend : cpp_const SEMI {
Clear(scanner_ccode);
$$.val = 0;
$$.qualifier = $1.qualifier;
$$.refqualifier = $1.refqualifier;
$$.bitfield = 0;
$$.throws = $1.throws;
$$.throwf = $1.throwf;
@ -4818,6 +4852,7 @@ cpp_vend : cpp_const SEMI {
Clear(scanner_ccode);
$$.val = $3.val;
$$.qualifier = $1.qualifier;
$$.refqualifier = $1.refqualifier;
$$.bitfield = 0;
$$.throws = $1.throws;
$$.throwf = $1.throwf;
@ -4827,6 +4862,7 @@ cpp_vend : cpp_const SEMI {
skip_balanced('{','}');
$$.val = 0;
$$.qualifier = $1.qualifier;
$$.refqualifier = $1.refqualifier;
$$.bitfield = 0;
$$.throws = $1.throws;
$$.throwf = $1.throwf;
@ -5080,14 +5116,15 @@ 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 CONST_QUAL {
| direct_declarator LPAREN parms RPAREN cv_ref_qualifier {
SwigType *t;
$$ = $1;
t = NewStringEmpty();
SwigType_add_function(t,$3);
SwigType_add_qualifier(t, "const");
if ($5.qualifier)
SwigType_push(t, $5.qualifier);
if (!$$.have_parms) {
$$.parms = $3;
$$.have_parms = 1;
@ -5137,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;
@ -5776,12 +5834,12 @@ direct_abstract_declarator : direct_abstract_declarator LBRACKET RBRACKET {
$$.have_parms = 1;
}
}
| direct_abstract_declarator LPAREN parms RPAREN type_qualifier {
| direct_abstract_declarator LPAREN parms RPAREN cv_ref_qualifier {
SwigType *t;
$$ = $1;
t = NewStringEmpty();
SwigType_add_function(t,$3);
SwigType_push(t, $5);
SwigType_push(t, $5.qualifier);
if (!$$.type) {
$$.type = t;
} else {
@ -5828,6 +5886,33 @@ pointer : STAR type_qualifier pointer {
}
;
/* cv-qualifier plus C++11 ref-qualifier for non-static member functions */
cv_ref_qualifier : type_qualifier {
$$.qualifier = $1;
$$.refqualifier = 0;
}
| type_qualifier ref_qualifier {
$$.qualifier = $1;
$$.refqualifier = $2;
SwigType_push($$.qualifier, $2);
}
| ref_qualifier {
$$.qualifier = NewStringEmpty();
$$.refqualifier = $1;
SwigType_push($$.qualifier, $1);
}
;
ref_qualifier : AND {
$$ = NewStringEmpty();
SwigType_add_reference($$);
}
| LAND {
$$ = NewStringEmpty();
SwigType_add_rvalue_reference($$);
}
;
type_qualifier : type_qualifier_raw {
$$ = NewStringEmpty();
if ($1) SwigType_add_qualifier($$,$1);
@ -6049,6 +6134,7 @@ definetype : { /* scanner_check_typedef(); */ } expr {
$$.rawval = NewStringf("%s", $$.val);
}
$$.qualifier = 0;
$$.refqualifier = 0;
$$.bitfield = 0;
$$.throws = 0;
$$.throwf = 0;
@ -6074,6 +6160,7 @@ deleted_definition : DELETE_KW {
$$.rawval = 0;
$$.type = T_STRING;
$$.qualifier = 0;
$$.refqualifier = 0;
$$.bitfield = 0;
$$.throws = 0;
$$.throwf = 0;
@ -6087,6 +6174,7 @@ explicit_default : DEFAULT {
$$.rawval = 0;
$$.type = T_STRING;
$$.qualifier = 0;
$$.refqualifier = 0;
$$.bitfield = 0;
$$.throws = 0;
$$.throwf = 0;
@ -6584,6 +6672,14 @@ virt_specifier_seq : OVERRIDE {
}
;
virt_specifier_seq_opt : virt_specifier_seq {
$$ = 0;
}
| empty {
$$ = 0;
}
;
exception_specification : THROW LPAREN parms RPAREN {
$$.throws = $3;
$$.throwf = NewString("1");
@ -6616,25 +6712,34 @@ exception_specification : THROW LPAREN parms RPAREN {
}
;
cpp_const : type_qualifier {
qualifiers_exception_specification : cv_ref_qualifier {
$$.throws = 0;
$$.throwf = 0;
$$.nexcept = 0;
$$.qualifier = $1;
$$.qualifier = $1.qualifier;
$$.refqualifier = $1.refqualifier;
}
| exception_specification {
$$ = $1;
$$.qualifier = 0;
$$.refqualifier = 0;
}
| type_qualifier exception_specification {
| cv_ref_qualifier exception_specification {
$$ = $2;
$$.qualifier = $1;
$$.qualifier = $1.qualifier;
$$.refqualifier = $1.refqualifier;
}
;
cpp_const : qualifiers_exception_specification {
$$ = $1;
}
| empty {
$$.throws = 0;
$$.throwf = 0;
$$.nexcept = 0;
$$.qualifier = 0;
$$.qualifier = 0;
$$.refqualifier = 0;
}
;
@ -6645,6 +6750,8 @@ ctor_end : cpp_const ctor_initializer SEMI {
$$.throws = $1.throws;
$$.throwf = $1.throwf;
$$.nexcept = $1.nexcept;
if ($1.qualifier)
Swig_error(cparse_file, cparse_line, "Constructor cannot have a qualifier.\n");
}
| cpp_const ctor_initializer LBRACE {
skip_balanced('{','}');
@ -6653,6 +6760,8 @@ ctor_end : cpp_const ctor_initializer SEMI {
$$.throws = $1.throws;
$$.throwf = $1.throwf;
$$.nexcept = $1.nexcept;
if ($1.qualifier)
Swig_error(cparse_file, cparse_line, "Constructor cannot have a qualifier.\n");
}
| LPAREN parms RPAREN SEMI {
Clear(scanner_ccode);
@ -6685,6 +6794,8 @@ ctor_end : cpp_const ctor_initializer SEMI {
$$.throws = $1.throws;
$$.throwf = $1.throwf;
$$.nexcept = $1.nexcept;
if ($1.qualifier)
Swig_error(cparse_file, cparse_line, "Constructor cannot have a qualifier.\n");
}
;

View file

@ -153,6 +153,7 @@
#define WARN_TYPE_INCOMPLETE 402
#define WARN_TYPE_ABSTRACT 403
#define WARN_TYPE_REDEFINED 404
#define WARN_TYPE_RVALUE_REF_QUALIFIER_IGNORED 405
#define WARN_TYPEMAP_SOURCETARGET 450
#define WARN_TYPEMAP_CHARLEAK 451

View file

@ -38,14 +38,15 @@ int NoExcept = 0;
int SwigRuntime = 0; // 0 = no option, 1 = -runtime, 2 = -noruntime
/* Suppress warning messages for private inheritance, preprocessor evaluation etc...
WARN_PP_EVALUATION 202
WARN_PARSE_PRIVATE_INHERIT 309
WARN_TYPE_ABSTRACT 403
WARN_LANG_OVERLOAD_CONST 512
WARN_PARSE_BUILTIN_NAME 321
WARN_PARSE_REDUNDANT 322
WARN_PP_EVALUATION 202
WARN_PARSE_PRIVATE_INHERIT 309
WARN_PARSE_BUILTIN_NAME 321
WARN_PARSE_REDUNDANT 322
WARN_TYPE_ABSTRACT 403
WARN_TYPE_RVALUE_REF_QUALIFIER_IGNORED 405
WARN_LANG_OVERLOAD_CONST 512
*/
#define EXTRA_WARNINGS "202,309,403,512,321,322"
#define EXTRA_WARNINGS "202,309,403,405,512,321,322"
extern "C" {
extern String *ModuleName;

View file

@ -231,9 +231,21 @@ List *Swig_overload_rank(Node *n, bool script_lang_wrapping) {
}
if (!differ) {
/* See if declarations differ by const only */
String *d1 = Getattr(nodes[i].n, "decl");
String *d2 = Getattr(nodes[j].n, "decl");
if (d1 && d2) {
String *decl1 = Getattr(nodes[i].n, "decl");
String *decl2 = Getattr(nodes[j].n, "decl");
if (decl1 && decl2) {
/* Remove ref-qualifiers. Note that rvalue ref-qualifiers are already ignored and
* it is illegal to overload a function with and without ref-qualifiers. So with
* all the combinations of ref-qualifiers and cv-qualifiers, we just detect
* the cv-qualifier (const) overloading. */
String *d1 = Copy(decl1);
String *d2 = Copy(decl2);
if (SwigType_isreference(d1) || SwigType_isrvalue_reference(d1)) {
Delete(SwigType_pop(d1));
}
if (SwigType_isreference(d2) || SwigType_isrvalue_reference(d2)) {
Delete(SwigType_pop(d2));
}
String *dq1 = Copy(d1);
String *dq2 = Copy(d2);
if (SwigType_isconst(d1)) {

View file

@ -1024,6 +1024,15 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas
}
}
if (!self && SwigType_isrvalue_reference(Getattr(n, "refqualifier"))) {
String *memory_header = NewString("<memory>");
Setfile(memory_header, Getfile(n));
Setline(memory_header, Getline(n));
Swig_fragment_emit(memory_header);
self = NewString("std::move(*this).");
Delete(memory_header);
}
call = Swig_cmethod_call(explicitcall_name ? explicitcall_name : name, p, self, explicit_qualifier, director_type);
cres = Swig_cresult(Getattr(n, "type"), Swig_cresult_name(), call);

View file

@ -1681,6 +1681,7 @@ String *Swig_name_str(Node *n) {
* "MyNameSpace::MyTemplate<MyNameSpace::ABC >::~MyTemplate()"
* "MyNameSpace::ABC::ABC(int,double)"
* "MyNameSpace::ABC::constmethod(int) const"
* "MyNameSpace::ABC::refqualifiermethod(int) const &"
* "MyNameSpace::ABC::variablename"
*
* ----------------------------------------------------------------------------- */
@ -1690,11 +1691,22 @@ String *Swig_name_decl(Node *n) {
String *decl;
qname = Swig_name_str(n);
decl = NewStringf("%s", qname);
if (checkAttribute(n, "kind", "variable"))
decl = NewStringf("%s", qname);
else
decl = NewStringf("%s(%s)%s", qname, ParmList_errorstr(Getattr(n, "parms")), SwigType_isconst(Getattr(n, "decl")) ? " const" : "");
if (!checkAttribute(n, "kind", "variable")) {
String *d = Getattr(n, "decl");
Printv(decl, "(", ParmList_errorstr(Getattr(n, "parms")), ")", NIL);
if (SwigType_isfunction(d)) {
SwigType *decl_temp = Copy(d);
SwigType *qualifiers = SwigType_pop_function_qualifiers(decl_temp);
if (qualifiers) {
String *qualifiers_string = SwigType_str(qualifiers, 0);
Printv(decl, " ", qualifiers_string, NIL);
Delete(qualifiers_string);
}
Delete(decl_temp);
}
}
Delete(qname);

View file

@ -44,7 +44,7 @@
* 'z.' = Rvalue reference (&&)
* 'a(n).' = Array of size n [n]
* 'f(..,..).' = Function with arguments (args)
* 'q(str).' = Qualifier (such as const or volatile) (const, volatile)
* 'q(str).' = Qualifier, such as const or volatile (cv-qualifier)
* 'm(cls).' = Pointer to member (cls::*)
*
* The encoding follows the order that you might describe a type in words.
@ -64,11 +64,19 @@
*
* More examples:
*
* String Encoding C++ Example
* --------------- -----------
* p.f(bool).q(const).long const long (*)(bool)
* m(Funcs).q(const).f(bool).long long (Funcs::*)(bool) const
* r.q(const).m(Funcs).f(int).long long (Funcs::*const &)(int)
* String Encoding C++ Example
* --------------- -----------
* p.f(bool).r.q(const).long const long & (*)(bool)
* m(Funcs).q(const).f(bool).long long (Funcs::*)(bool) const
* r.q(const).m(Funcs).f(int).long long (Funcs::*const &)(int)
* m(Funcs).z.q(const).f(bool).long long (Funcs::*)(bool) const &&
*
* Function decl examples:
*
* f(bool). long a(bool);
* r.f(bool). long b(bool) &;
* z.f(bool). long c(bool) &&;
* z.q(const).f(bool). long d(bool) const &&;
*
* For the most part, this module tries to minimize the use of special
* characters (*, [, <, etc...) in its type encoding. One reason for this
@ -536,10 +544,9 @@ String *SwigType_str(const SwigType *s, const_String_or_char_ptr id) {
String *element = 0;
String *nextelement;
String *forwardelement;
String *member_const_function_element = 0;
SwigType *member_function_qualifiers = 0;
List *elements;
int nelements, i;
int member_const_function = 0;
if (id) {
/* stringify the id expanding templates, for example when the id is a fully qualified templated class name */
@ -570,14 +577,12 @@ String *SwigType_str(const SwigType *s, const_String_or_char_ptr id) {
forwardelement = 0;
}
if (SwigType_isqualifier(element)) {
if (!member_const_function) {
if (!member_function_qualifiers) {
DOH *q = 0;
q = SwigType_parm(element);
Insert(result, 0, " ");
Insert(result, 0, q);
Delete(q);
} else {
member_const_function = 0;
}
} else if (SwigType_ispointer(element)) {
Insert(result, 0, "*");
@ -594,20 +599,28 @@ String *SwigType_str(const SwigType *s, const_String_or_char_ptr id) {
Insert(result, 0, "(");
Append(result, ")");
}
if (SwigType_isqualifier(nextelement)) {
member_const_function_element = nextelement;
member_const_function = 1;
{
String *next3elements = NewStringEmpty();
int j;
for (j = i + 1; j < i + 4 && j < nelements; j++) {
Append(next3elements, Getitem(elements, j));
}
if (SwigType_isfunction(next3elements))
member_function_qualifiers = SwigType_pop_function_qualifiers(next3elements);
Delete(next3elements);
}
Delete(q);
} else if (SwigType_isreference(element)) {
Insert(result, 0, "&");
if (!member_function_qualifiers)
Insert(result, 0, "&");
if ((forwardelement) && ((SwigType_isfunction(forwardelement) || (SwigType_isarray(forwardelement))))) {
Insert(result, 0, "(");
Append(result, ")");
}
} else if (SwigType_isrvalue_reference(element)) {
Insert(result, 0, "&&");
if ((nextelement) && ((SwigType_isfunction(nextelement) || (SwigType_isarray(nextelement))))) {
if (!member_function_qualifiers)
Insert(result, 0, "&&");
if ((forwardelement) && ((SwigType_isfunction(forwardelement) || (SwigType_isarray(forwardelement))))) {
Insert(result, 0, "(");
Append(result, ")");
}
@ -631,12 +644,13 @@ String *SwigType_str(const SwigType *s, const_String_or_char_ptr id) {
Append(result, ",");
}
Append(result, ")");
if (member_const_function_element) {
String *p = SwigType_str(member_const_function_element, 0);
if (member_function_qualifiers) {
String *p = SwigType_str(member_function_qualifiers, 0);
Append(result, " ");
Append(result, p);
Delete(p);
member_const_function_element = 0;
Delete(member_function_qualifiers);
member_function_qualifiers = 0;
}
Delete(parms);
} else {
@ -670,6 +684,7 @@ SwigType *SwigType_ltype(const SwigType *s) {
int nelements, i;
int firstarray = 1;
int notypeconv = 0;
int ignore_member_function_qualifiers = 0;
result = NewStringEmpty();
tc = Copy(s);
@ -696,6 +711,7 @@ SwigType *SwigType_ltype(const SwigType *s) {
tc = td;
}
}
elements = SwigType_split(tc);
nelements = Len(elements);
@ -705,14 +721,33 @@ SwigType *SwigType_ltype(const SwigType *s) {
/* when we see a function, we need to preserve the following types */
if (SwigType_isfunction(element)) {
notypeconv = 1;
ignore_member_function_qualifiers = 0;
}
if (SwigType_isqualifier(element)) {
/* Do nothing. Ignore */
if (ignore_member_function_qualifiers) {
/* cv-qualifiers and ref-qualifiers up until the f() element have already been added */
} else if (SwigType_isqualifier(element)) {
/* swallow cv-qualifiers */
} else if (SwigType_ispointer(element)) {
Append(result, element);
firstarray = 0;
} else if (SwigType_ismemberpointer(element)) {
Append(result, element);
{
String *next3elements = NewStringEmpty();
int j;
for (j = i + 1; j < i + 4 && j < nelements; j++) {
Append(next3elements, Getitem(elements, j));
}
if (SwigType_isfunction(next3elements)) {
SwigType *member_function_qualifiers = SwigType_pop_function_qualifiers(next3elements);
/* compilers won't let us cast from a member function without qualifiers to one with qualifiers, so the qualifiers are kept in the ltype */
if (member_function_qualifiers)
Append(result, member_function_qualifiers);
Delete(member_function_qualifiers);
ignore_member_function_qualifiers = 1;
}
Delete(next3elements);
}
firstarray = 0;
} else if (SwigType_isreference(element)) {
if (notypeconv) {
@ -752,13 +787,14 @@ SwigType *SwigType_ltype(const SwigType *s) {
}
/* -----------------------------------------------------------------------------
* SwigType_lstr(DOH *s, DOH *id)
* SwigType_lstr()
*
* Produces a type-string that is suitable as a lvalue in an expression.
* That is, a type that can be freely assigned a value without violating
* any C assignment rules.
*
* - Qualifiers such as 'const' and 'volatile' are stripped.
* Except for member function cv-qualifiers and ref-qualifiers.
* - Arrays are converted into a *single* pointer (i.e.,
* double [][] becomes double *).
* - References are converted into a pointer.
@ -788,7 +824,7 @@ String *SwigType_rcaststr(const SwigType *s, const_String_or_char_ptr name) {
String *element = 0;
String *nextelement;
String *forwardelement;
String *member_const_function_element = 0;
String *member_function_qualifiers = 0;
SwigType *td, *tc = 0;
const SwigType *rs;
List *elements;
@ -797,7 +833,6 @@ String *SwigType_rcaststr(const SwigType *s, const_String_or_char_ptr name) {
int firstarray = 1;
int isreference = 0;
int isfunction = 0;
int member_const_function = 0;
result = NewStringEmpty();
@ -846,15 +881,13 @@ String *SwigType_rcaststr(const SwigType *s, const_String_or_char_ptr name) {
forwardelement = 0;
}
if (SwigType_isqualifier(element)) {
if (!member_const_function) {
if (!member_function_qualifiers) {
DOH *q = 0;
q = SwigType_parm(element);
Insert(result, 0, " ");
Insert(result, 0, q);
Delete(q);
clear = 0;
} else {
member_const_function = 0;
}
} else if (SwigType_ispointer(element)) {
Insert(result, 0, "*");
@ -868,32 +901,42 @@ String *SwigType_rcaststr(const SwigType *s, const_String_or_char_ptr name) {
Insert(result, 0, "::*");
q = SwigType_parm(element);
Insert(result, 0, q);
Delete(q);
if ((forwardelement) && ((SwigType_isfunction(forwardelement) || (SwigType_isarray(forwardelement))))) {
Insert(result, 0, "(");
Append(result, ")");
}
if (SwigType_isqualifier(nextelement)) {
member_const_function_element = nextelement;
member_const_function = 1;
{
String *next3elements = NewStringEmpty();
int j;
for (j = i + 1; j < i + 4 && j < nelements; j++) {
Append(next3elements, Getitem(elements, j));
}
if (SwigType_isfunction(next3elements))
member_function_qualifiers = SwigType_pop_function_qualifiers(next3elements);
Delete(next3elements);
}
firstarray = 0;
Delete(q);
} else if (SwigType_isreference(element)) {
Insert(result, 0, "&");
if (!member_function_qualifiers) {
Insert(result, 0, "&");
if (!isfunction)
isreference = 1;
}
if ((forwardelement) && ((SwigType_isfunction(forwardelement) || (SwigType_isarray(forwardelement))))) {
Insert(result, 0, "(");
Append(result, ")");
}
if (!isfunction)
isreference = 1;
} else if (SwigType_isrvalue_reference(element)) {
Insert(result, 0, "&&");
if (!member_function_qualifiers) {
Insert(result, 0, "&&");
if (!isfunction)
isreference = 1;
}
if ((forwardelement) && ((SwigType_isfunction(forwardelement) || (SwigType_isarray(forwardelement))))) {
Insert(result, 0, "(");
Append(result, ")");
}
if (!isfunction)
isreference = 1;
clear = 0;
} else if (SwigType_isarray(element)) {
DOH *size;
@ -923,12 +966,13 @@ String *SwigType_rcaststr(const SwigType *s, const_String_or_char_ptr name) {
}
Append(result, ")");
Delete(parms);
if (member_const_function_element) {
String *p = SwigType_str(member_const_function_element, 0);
if (member_function_qualifiers) {
String *p = SwigType_str(member_function_qualifiers, 0);
Append(result, " ");
Append(result, p);
Delete(p);
member_const_function_element = 0;
Delete(member_function_qualifiers);
member_function_qualifiers = 0;
clear = 0;
}
isfunction = 1;

View file

@ -136,6 +136,7 @@ extern "C" {
extern SwigType *SwigType_add_function(SwigType *t, ParmList *parms);
extern SwigType *SwigType_add_template(SwigType *t, ParmList *parms);
extern SwigType *SwigType_pop_function(SwigType *t);
extern SwigType *SwigType_pop_function_qualifiers(SwigType *t);
extern ParmList *SwigType_function_parms(const SwigType *t, Node *file_line_node);
extern List *SwigType_split(const SwigType *t);
extern String *SwigType_pop(SwigType *t);

View file

@ -43,12 +43,12 @@
* All type constructors are denoted by a trailing '.':
*
* 'p.' = Pointer (*)
* 'r.' = Reference (&)
* 'z.' = Rvalue reference (&&)
* 'r.' = Reference or ref-qualifier (&)
* 'z.' = Rvalue reference or ref-qualifier (&&)
* 'a(n).' = Array of size n [n]
* 'f(..,..).' = Function with arguments (args)
* 'q(str).' = Qualifier (such as const or volatile) (const, volatile)
* 'm(qual).' = Pointer to member (qual::*)
* 'q(str).' = Qualifier, such as const or volatile (cv-qualifier)
* 'm(cls).' = Pointer to member (cls::*)
*
* The complete type representation for varargs is:
* 'v(...)'
@ -183,9 +183,10 @@ SwigType *SwigType_del_element(SwigType *t) {
* SwigType_pop()
*
* Pop one type element off the type.
* Example: t in: q(const).p.Integer
* t out: p.Integer
* result: q(const).
* For example:
* t in: q(const).p.Integer
* t out: p.Integer
* result: q(const).
* ----------------------------------------------------------------------------- */
SwigType *SwigType_pop(SwigType *t) {
@ -771,7 +772,6 @@ SwigType *SwigType_array_type(const SwigType *ty) {
* Functions
*
* SwigType_add_function()
* SwigType_del_function()
* SwigType_isfunction()
* SwigType_pop_function()
*
@ -795,14 +795,36 @@ SwigType *SwigType_add_function(SwigType *t, ParmList *parms) {
return t;
}
/* -----------------------------------------------------------------------------
* SwigType_pop_function()
*
* Pop and return the function from the input type leaving the function's return
* type, if any.
* For example:
* t in: q(const).f().p.
* t out: p.
* result: q(const).f().
* ----------------------------------------------------------------------------- */
SwigType *SwigType_pop_function(SwigType *t) {
SwigType *f = 0;
SwigType *g = 0;
char *c = Char(t);
if (strncmp(c, "q(", 2) == 0) {
if (strncmp(c, "r.", 2) == 0 || strncmp(c, "z.", 2) == 0) {
/* Remove ref-qualifier */
f = SwigType_pop(t);
c = Char(t);
}
if (strncmp(c, "q(", 2) == 0) {
/* Remove cv-qualifier */
String *qual = SwigType_pop(t);
if (f) {
SwigType_push(qual, f);
Delete(f);
}
f = qual;
c = Char(t);
}
if (strncmp(c, "f(", 2)) {
printf("Fatal error. SwigType_pop_function applied to non-function.\n");
abort();
@ -814,14 +836,55 @@ SwigType *SwigType_pop_function(SwigType *t) {
return g;
}
/* -----------------------------------------------------------------------------
* SwigType_pop_function_qualifiers()
*
* Pop and return the function qualifiers from the input type leaving the rest of
* function declaration. Returns NULL if no qualifiers.
* For example:
* t in: r.q(const).f().p.
* t out: f().p.
* result: r.q(const)
* ----------------------------------------------------------------------------- */
SwigType *SwigType_pop_function_qualifiers(SwigType *t) {
SwigType *qualifiers = 0;
char *c = Char(t);
if (strncmp(c, "r.", 2) == 0 || strncmp(c, "z.", 2) == 0) {
/* Remove ref-qualifier */
String *qual = SwigType_pop(t);
qualifiers = qual;
c = Char(t);
}
if (strncmp(c, "q(", 2) == 0) {
/* Remove cv-qualifier */
String *qual = SwigType_pop(t);
if (qualifiers) {
SwigType_push(qual, qualifiers);
Delete(qualifiers);
}
qualifiers = qual;
c = Char(t);
}
assert(strncmp(c, "f(", 2) == 0);
return qualifiers;
}
int SwigType_isfunction(const SwigType *t) {
char *c;
if (!t) {
return 0;
}
c = Char(t);
if (strncmp(c, "r.", 2) == 0 || strncmp(c, "z.", 2) == 0) {
/* Might be a function with a ref-qualifier, skip over */
c += 2;
if (!*c)
return 0;
}
if (strncmp(c, "q(", 2) == 0) {
/* Might be a 'const' function. Try to skip over the 'const' */
/* Might be a function with a cv-qualifier, skip over */
c = strchr(c, '.');
if (c)
c++;