Improved member function pointer parsing
Add support for parsing member function pointers with qualifiers, references and pointers, eg short (Funcs::* const parm)(bool)
This commit is contained in:
parent
8e86aaf2c3
commit
4f235027f4
3 changed files with 120 additions and 6 deletions
|
|
@ -101,3 +101,65 @@ int call3(int & (FunkSpace::Funktions::*d)(const int &, int), int a, int b) { Fu
|
||||||
int unreal1(double (Space::Shape::*memptr)(Space::Shape &, int & (FunkSpace::Funktions::*)(const int &, int))) { return 0; }
|
int unreal1(double (Space::Shape::*memptr)(Space::Shape &, int & (FunkSpace::Funktions::*)(const int &, int))) { return 0; }
|
||||||
int unreal2(double (Space::Shape::*memptr)(Thing<short>)) { return 0; }
|
int unreal2(double (Space::Shape::*memptr)(Thing<short>)) { return 0; }
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
||||||
|
%inline %{
|
||||||
|
struct Funcs {
|
||||||
|
short FF(bool) {}
|
||||||
|
short CC(bool) const {}
|
||||||
|
};
|
||||||
|
|
||||||
|
class MemberFuncPtrs
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// member const function pointers, unnamed parameters
|
||||||
|
int aaa1(short (Funcs::* )(bool) const) const;
|
||||||
|
int aaa2(short (Funcs::* const *&)(bool) const) const;
|
||||||
|
int aaa3(short (Funcs::* *& )(bool) const) const;
|
||||||
|
int aaa4(short (Funcs::* *const& )(bool) const) const;
|
||||||
|
int aaa5(short (Funcs::* & )(bool) const) const;
|
||||||
|
int aaa6(short (Funcs::* const)(bool) const) const;
|
||||||
|
int aaa7(short (Funcs::* const&)(bool) const) const;
|
||||||
|
|
||||||
|
// member non-const function pointers, unnamed parameters
|
||||||
|
int bbb1(short (Funcs::* )(bool)) const;
|
||||||
|
int bbb2(short (Funcs::* const *&)(bool)) const;
|
||||||
|
int bbb3(short (Funcs::* *& )(bool)) const;
|
||||||
|
int bbb4(short (Funcs::* *const& )(bool)) const;
|
||||||
|
int bbb5(short (Funcs::* & )(bool)) const;
|
||||||
|
int bbb6(short (Funcs::* const)(bool)) const;
|
||||||
|
int bbb7(short (Funcs::* const&)(bool)) const;
|
||||||
|
|
||||||
|
// member const function pointers, named parameters
|
||||||
|
int ppp1(short (Funcs::* pp1)(bool) const) const;
|
||||||
|
int ppp2(short (Funcs::* const *& pp2)(bool) const) const;
|
||||||
|
int ppp3(short (Funcs::* *& pp3)(bool) const) const;
|
||||||
|
int ppp4(short (Funcs::* *const& pp4)(bool) const) const;
|
||||||
|
int ppp5(short (Funcs::* & pp5)(bool) const) const;
|
||||||
|
int ppp6(short (Funcs::* const pp6)(bool) const) const;
|
||||||
|
int ppp7(short (Funcs::* const& pp7)(bool) const) const;
|
||||||
|
|
||||||
|
// member non-const 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;
|
||||||
|
};
|
||||||
|
|
||||||
|
// member function pointer variables
|
||||||
|
short (Funcs::* pp1)(bool) = &Funcs::FF;
|
||||||
|
|
||||||
|
short (Funcs::* const * extra2)(bool) = &pp1;
|
||||||
|
short (Funcs::* * extra3)(bool) = &pp1;
|
||||||
|
short (Funcs::* *const extra4)(bool) = &pp1;
|
||||||
|
|
||||||
|
short (Funcs::* const *& pp2)(bool) = extra2;
|
||||||
|
short (Funcs::* *& pp3)(bool) = extra3;
|
||||||
|
short (Funcs::* *const& pp4)(bool) = extra4;
|
||||||
|
short (Funcs::* & pp5)(bool) = pp1;
|
||||||
|
short (Funcs::* const pp6)(bool) = &Funcs::FF;
|
||||||
|
short (Funcs::* const& pp7)(bool) = pp1;
|
||||||
|
%}
|
||||||
|
|
|
||||||
|
|
@ -5433,7 +5433,7 @@ direct_declarator : idcolon {
|
||||||
}
|
}
|
||||||
SwigType_add_rvalue_reference($$.type);
|
SwigType_add_rvalue_reference($$.type);
|
||||||
}
|
}
|
||||||
| LPAREN idcolon DSTAR direct_declarator RPAREN {
|
| LPAREN idcolon DSTAR declarator RPAREN {
|
||||||
SwigType *t;
|
SwigType *t;
|
||||||
$$ = $4;
|
$$ = $4;
|
||||||
t = NewStringEmpty();
|
t = NewStringEmpty();
|
||||||
|
|
@ -5443,7 +5443,42 @@ direct_declarator : idcolon {
|
||||||
Delete($$.type);
|
Delete($$.type);
|
||||||
}
|
}
|
||||||
$$.type = t;
|
$$.type = t;
|
||||||
|
}
|
||||||
|
| LPAREN idcolon DSTAR type_qualifier declarator RPAREN {
|
||||||
|
SwigType *t;
|
||||||
|
$$ = $5;
|
||||||
|
t = NewStringEmpty();
|
||||||
|
SwigType_add_memberpointer(t, $2);
|
||||||
|
SwigType_push(t, $4);
|
||||||
|
if ($$.type) {
|
||||||
|
SwigType_push(t, $$.type);
|
||||||
|
Delete($$.type);
|
||||||
}
|
}
|
||||||
|
$$.type = t;
|
||||||
|
}
|
||||||
|
| LPAREN idcolon DSTAR abstract_declarator RPAREN {
|
||||||
|
SwigType *t;
|
||||||
|
$$ = $4;
|
||||||
|
t = NewStringEmpty();
|
||||||
|
SwigType_add_memberpointer(t, $2);
|
||||||
|
if ($$.type) {
|
||||||
|
SwigType_push(t, $$.type);
|
||||||
|
Delete($$.type);
|
||||||
|
}
|
||||||
|
$$.type = t;
|
||||||
|
}
|
||||||
|
| LPAREN idcolon DSTAR type_qualifier abstract_declarator RPAREN {
|
||||||
|
SwigType *t;
|
||||||
|
$$ = $5;
|
||||||
|
t = NewStringEmpty();
|
||||||
|
SwigType_add_memberpointer(t, $2);
|
||||||
|
SwigType_push(t, $4);
|
||||||
|
if ($$.type) {
|
||||||
|
SwigType_push(t, $$.type);
|
||||||
|
Delete($$.type);
|
||||||
|
}
|
||||||
|
$$.type = t;
|
||||||
|
}
|
||||||
| direct_declarator LBRACKET RBRACKET {
|
| direct_declarator LBRACKET RBRACKET {
|
||||||
SwigType *t;
|
SwigType *t;
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
|
|
@ -5593,6 +5628,14 @@ abstract_declarator : pointer {
|
||||||
$$.parms = 0;
|
$$.parms = 0;
|
||||||
$$.have_parms = 0;
|
$$.have_parms = 0;
|
||||||
}
|
}
|
||||||
|
| idcolon DSTAR type_qualifier {
|
||||||
|
$$.type = NewStringEmpty();
|
||||||
|
SwigType_add_memberpointer($$.type, $1);
|
||||||
|
SwigType_push($$.type, $3);
|
||||||
|
$$.id = 0;
|
||||||
|
$$.parms = 0;
|
||||||
|
$$.have_parms = 0;
|
||||||
|
}
|
||||||
| pointer idcolon DSTAR {
|
| pointer idcolon DSTAR {
|
||||||
SwigType *t = NewStringEmpty();
|
SwigType *t = NewStringEmpty();
|
||||||
$$.type = $1;
|
$$.type = $1;
|
||||||
|
|
|
||||||
|
|
@ -64,10 +64,11 @@
|
||||||
*
|
*
|
||||||
* More examples:
|
* More examples:
|
||||||
*
|
*
|
||||||
* String Encoding C Example
|
* String Encoding C++ Example
|
||||||
* --------------- ---------
|
* --------------- -----------
|
||||||
* p.f(bool).q(const).long const long (*)(bool)
|
* p.f(bool).q(const).long const long (*)(bool)
|
||||||
* m(Funcs).q(const).f(bool).long long (Funcs::*)(bool) const
|
* m(Funcs).q(const).f(bool).long long (Funcs::*)(bool) const
|
||||||
|
* r.q(const).m(Funcs).f(int).long long (Funcs::*const &)(int)
|
||||||
*
|
*
|
||||||
* For the most part, this module tries to minimize the use of special
|
* For the most part, this module tries to minimize the use of special
|
||||||
* characters (*, [, <, etc...) in its type encoding. One reason for this
|
* characters (*, [, <, etc...) in its type encoding. One reason for this
|
||||||
|
|
@ -438,8 +439,13 @@ SwigType *SwigType_default_deduce(const SwigType *t) {
|
||||||
Setitem(l, numitems-2, deduced_subtype);
|
Setitem(l, numitems-2, deduced_subtype);
|
||||||
}
|
}
|
||||||
} else if (SwigType_ismemberpointer(subtype)) {
|
} else if (SwigType_ismemberpointer(subtype)) {
|
||||||
/* member pointer deduction, m(CLASS). => p. */
|
if (numitems >= 3) {
|
||||||
Setitem(l, numitems-2, NewString("p."));
|
/* member pointer deduction, eg, r.p.m(CLASS) => r.m(CLASS) */
|
||||||
|
Delitem(l, numitems-3);
|
||||||
|
} else {
|
||||||
|
/* member pointer deduction, m(CLASS). => p. */
|
||||||
|
Setitem(l, numitems-2, NewString("p."));
|
||||||
|
}
|
||||||
} else if (is_enum && !SwigType_isqualifier(subtype)) {
|
} else if (is_enum && !SwigType_isqualifier(subtype)) {
|
||||||
/* enum deduction, enum SWIGTYPE => SWIGTYPE */
|
/* enum deduction, enum SWIGTYPE => SWIGTYPE */
|
||||||
Setitem(l, numitems-1, NewString("SWIGTYPE"));
|
Setitem(l, numitems-1, NewString("SWIGTYPE"));
|
||||||
|
|
@ -803,7 +809,10 @@ String *SwigType_rcaststr(const SwigType *s, const_String_or_char_ptr name) {
|
||||||
if (SwigType_isconst(s)) {
|
if (SwigType_isconst(s)) {
|
||||||
tc = Copy(s);
|
tc = Copy(s);
|
||||||
Delete(SwigType_pop(tc));
|
Delete(SwigType_pop(tc));
|
||||||
rs = tc;
|
if (SwigType_ismemberpointer(tc))
|
||||||
|
rs = s;
|
||||||
|
else
|
||||||
|
rs = tc;
|
||||||
} else {
|
} else {
|
||||||
rs = s;
|
rs = s;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue