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:
William S Fulton 2017-03-10 18:39:23 +00:00
commit 4f235027f4
3 changed files with 120 additions and 6 deletions

View file

@ -5433,7 +5433,7 @@ direct_declarator : idcolon {
}
SwigType_add_rvalue_reference($$.type);
}
| LPAREN idcolon DSTAR direct_declarator RPAREN {
| LPAREN idcolon DSTAR declarator RPAREN {
SwigType *t;
$$ = $4;
t = NewStringEmpty();
@ -5443,7 +5443,42 @@ direct_declarator : idcolon {
Delete($$.type);
}
$$.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 {
SwigType *t;
$$ = $1;
@ -5593,6 +5628,14 @@ abstract_declarator : pointer {
$$.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 {
SwigType *t = NewStringEmpty();
$$.type = $1;

View file

@ -64,10 +64,11 @@
*
* More examples:
*
* String Encoding C Example
* --------------- ---------
* 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)
*
* For the most part, this module tries to minimize the use of special
* 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);
}
} else if (SwigType_ismemberpointer(subtype)) {
/* member pointer deduction, m(CLASS). => p. */
Setitem(l, numitems-2, NewString("p."));
if (numitems >= 3) {
/* 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)) {
/* enum deduction, enum SWIGTYPE => 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)) {
tc = Copy(s);
Delete(SwigType_pop(tc));
rs = tc;
if (SwigType_ismemberpointer(tc))
rs = s;
else
rs = tc;
} else {
rs = s;
}