Add support for parsing and wrapping member const function pointers
This commit is contained in:
parent
67edda3bf5
commit
5aff26fcb5
6 changed files with 383 additions and 21 deletions
|
|
@ -1351,6 +1351,37 @@ static void mark_nodes_as_extend(Node *n) {
|
|||
}
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* add_qualifier_to_declarator
|
||||
*
|
||||
* Adding a qualifier to a pointer to member function is a special case.
|
||||
* For example : typedef double (Cls::*pmf)(void) const;
|
||||
* The declarator is : m(Cls).f(void).
|
||||
* We need : m(Cls).q(const).f(void).
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static String *add_qualifier_to_declarator(SwigType *type, SwigType *qualifier) {
|
||||
int is_pointer_to_member_function = 0;
|
||||
String *decl = Copy(type);
|
||||
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;
|
||||
} else {
|
||||
Delete(decl);
|
||||
decl = Copy(type);
|
||||
}
|
||||
Delete(memberptr);
|
||||
}
|
||||
if (!is_pointer_to_member_function)
|
||||
SwigType_push(decl, qualifier);
|
||||
return decl;
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
%union {
|
||||
|
|
@ -1751,7 +1782,6 @@ constant_directive : CONSTANT identifier EQUAL definetype SEMI {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
| CONSTANT type declarator def_args SEMI {
|
||||
if (($4.type != T_ERROR) && ($4.type != T_SYMBOL)) {
|
||||
SwigType_push($2,$3.type);
|
||||
|
|
@ -1768,12 +1798,38 @@ constant_directive : CONSTANT identifier EQUAL definetype SEMI {
|
|||
SetFlag($$,"feature:immutable");
|
||||
add_symbols($$);
|
||||
} else {
|
||||
if ($4.type == T_ERROR) {
|
||||
Swig_warning(WARN_PARSE_UNSUPPORTED_VALUE,cparse_file,cparse_line,"Unsupported constant value\n");
|
||||
}
|
||||
if ($4.type == T_ERROR) {
|
||||
Swig_warning(WARN_PARSE_UNSUPPORTED_VALUE,cparse_file,cparse_line, "Unsupported constant value\n");
|
||||
}
|
||||
$$ = 0;
|
||||
}
|
||||
}
|
||||
/* Member const function pointers . eg.
|
||||
%constant short (Funcs::*pmf)(bool) const = &Funcs::F; */
|
||||
| CONSTANT type direct_declarator LPAREN parms RPAREN CONST_QUAL 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, $3.type);
|
||||
/* Sneaky callback function trick */
|
||||
if (SwigType_isfunction($2)) {
|
||||
SwigType_add_pointer($2);
|
||||
}
|
||||
$$ = new_node("constant");
|
||||
Setattr($$, "name", $3.id);
|
||||
Setattr($$, "type", $2);
|
||||
Setattr($$, "value", $8.val);
|
||||
if ($8.rawval) Setattr($$, "rawval", $8.rawval);
|
||||
Setattr($$, "storage", "%constant");
|
||||
SetFlag($$, "feature:immutable");
|
||||
add_symbols($$);
|
||||
} else {
|
||||
if ($8.type == T_ERROR) {
|
||||
Swig_warning(WARN_PARSE_UNSUPPORTED_VALUE,cparse_file,cparse_line, "Unsupported constant value\n");
|
||||
}
|
||||
$$ = 0;
|
||||
}
|
||||
}
|
||||
| CONSTANT error SEMI {
|
||||
Swig_warning(WARN_PARSE_BAD_VALUE,cparse_file,cparse_line,"Bad constant value (ignored).\n");
|
||||
$$ = 0;
|
||||
|
|
@ -2942,12 +2998,14 @@ c_declaration : c_decl {
|
|||
------------------------------------------------------------ */
|
||||
|
||||
c_decl : storage_class type declarator initializer c_decl_tail {
|
||||
String *decl = $3.type;
|
||||
$$ = new_node("cdecl");
|
||||
if ($4.qualifier) SwigType_push($3.type,$4.qualifier);
|
||||
if ($4.qualifier)
|
||||
decl = add_qualifier_to_declarator($3.type, $4.qualifier);
|
||||
Setattr($$,"type",$2);
|
||||
Setattr($$,"storage",$1);
|
||||
Setattr($$,"name",$3.id);
|
||||
Setattr($$,"decl",$3.type);
|
||||
Setattr($$,"decl",decl);
|
||||
Setattr($$,"parms",$3.parms);
|
||||
Setattr($$,"value",$4.val);
|
||||
Setattr($$,"throws",$4.throws);
|
||||
|
|
@ -4959,6 +5017,27 @@ parameter_declarator : declarator def_args {
|
|||
$$.id = 0;
|
||||
$$.defarg = $1.rawval ? $1.rawval : $1.val;
|
||||
}
|
||||
/* Member const function pointer parameters. eg.
|
||||
int f(short (Funcs::*parm)(bool) const); */
|
||||
| direct_declarator LPAREN parms RPAREN CONST_QUAL {
|
||||
SwigType *t;
|
||||
$$ = $1;
|
||||
t = NewStringEmpty();
|
||||
SwigType_add_function(t,$3);
|
||||
SwigType_add_qualifier(t, "const");
|
||||
if (!$$.have_parms) {
|
||||
$$.parms = $3;
|
||||
$$.have_parms = 1;
|
||||
}
|
||||
if (!$$.type) {
|
||||
$$.type = t;
|
||||
} else {
|
||||
SwigType_push(t, $$.type);
|
||||
Delete($$.type);
|
||||
$$.type = t;
|
||||
}
|
||||
$$.defarg = 0;
|
||||
}
|
||||
;
|
||||
|
||||
plain_declarator : declarator {
|
||||
|
|
@ -5002,7 +5081,6 @@ plain_declarator : declarator {
|
|||
}
|
||||
;
|
||||
|
||||
|
||||
declarator : pointer notso_direct_declarator {
|
||||
$$ = $2;
|
||||
if ($$.type) {
|
||||
|
|
@ -5404,7 +5482,7 @@ direct_declarator : idcolon {
|
|||
Delete($$.type);
|
||||
$$.type = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* User-defined string literals. eg.
|
||||
int operator"" _mySuffix(const char* val, int length) {...} */
|
||||
/* This produces one S/R conflict. */
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@
|
|||
* '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::*)
|
||||
* 'm(cls).' = Pointer to member (cls::*)
|
||||
*
|
||||
* The encoding follows the order that you might describe a type in words.
|
||||
* For example "p.a(200).int" is "A pointer to array of int's" and
|
||||
|
|
@ -62,6 +62,13 @@
|
|||
*
|
||||
* Replace(t,"q(const).","",DOH_REPLACE_ANY)
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* For the most part, this module tries to minimize the use of special
|
||||
* characters (*, [, <, etc...) in its type encoding. One reason for this
|
||||
* is that SWIG might be extended to encode data in formats such as XML
|
||||
|
|
@ -372,7 +379,7 @@ SwigType *SwigType_default_create(const SwigType *ty) {
|
|||
* and is very close to the type deduction used in partial template class
|
||||
* specialization matching in that the most specialized type is always chosen.
|
||||
* SWIGTYPE is used as the generic type. The basic idea is to repeatedly call
|
||||
* this function to find a deduced type unless until nothing matches.
|
||||
* this function to find a deduced type until nothing matches.
|
||||
*
|
||||
* The type t must have already been converted to the default type via a call to
|
||||
* SwigType_default_create() before calling this function.
|
||||
|
|
@ -528,8 +535,10 @@ 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;
|
||||
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 */
|
||||
|
|
@ -560,11 +569,15 @@ String *SwigType_str(const SwigType *s, const_String_or_char_ptr id) {
|
|||
forwardelement = 0;
|
||||
}
|
||||
if (SwigType_isqualifier(element)) {
|
||||
DOH *q = 0;
|
||||
q = SwigType_parm(element);
|
||||
Insert(result, 0, " ");
|
||||
Insert(result, 0, q);
|
||||
Delete(q);
|
||||
if (!member_const_function) {
|
||||
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, "*");
|
||||
if ((forwardelement) && ((SwigType_isfunction(forwardelement) || (SwigType_isarray(forwardelement))))) {
|
||||
|
|
@ -580,6 +593,10 @@ 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;
|
||||
}
|
||||
Delete(q);
|
||||
} else if (SwigType_isreference(element)) {
|
||||
Insert(result, 0, "&");
|
||||
|
|
@ -613,6 +630,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);
|
||||
Append(result, " ");
|
||||
Append(result, p);
|
||||
Delete(p);
|
||||
member_const_function_element = 0;
|
||||
}
|
||||
Delete(parms);
|
||||
} else {
|
||||
if (strcmp(Char(element), "v(...)") == 0) {
|
||||
|
|
@ -763,6 +787,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;
|
||||
SwigType *td, *tc = 0;
|
||||
const SwigType *rs;
|
||||
List *elements;
|
||||
|
|
@ -771,6 +796,7 @@ 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();
|
||||
|
||||
|
|
@ -816,12 +842,16 @@ String *SwigType_rcaststr(const SwigType *s, const_String_or_char_ptr name) {
|
|||
forwardelement = 0;
|
||||
}
|
||||
if (SwigType_isqualifier(element)) {
|
||||
DOH *q = 0;
|
||||
q = SwigType_parm(element);
|
||||
Insert(result, 0, " ");
|
||||
Insert(result, 0, q);
|
||||
Delete(q);
|
||||
clear = 0;
|
||||
if (!member_const_function) {
|
||||
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, "*");
|
||||
if ((forwardelement) && ((SwigType_isfunction(forwardelement) || (SwigType_isarray(forwardelement))))) {
|
||||
|
|
@ -839,6 +869,10 @@ String *SwigType_rcaststr(const SwigType *s, const_String_or_char_ptr name) {
|
|||
Insert(result, 0, "(");
|
||||
Append(result, ")");
|
||||
}
|
||||
if (SwigType_isqualifier(nextelement)) {
|
||||
member_const_function_element = nextelement;
|
||||
member_const_function = 1;
|
||||
}
|
||||
firstarray = 0;
|
||||
} else if (SwigType_isreference(element)) {
|
||||
Insert(result, 0, "&");
|
||||
|
|
@ -885,6 +919,14 @@ 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);
|
||||
Append(result, " ");
|
||||
Append(result, p);
|
||||
Delete(p);
|
||||
member_const_function_element = 0;
|
||||
clear = 0;
|
||||
}
|
||||
isfunction = 1;
|
||||
} else {
|
||||
String *bs = SwigType_namestr(element);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue