Allow method calls in expressions
This allows default parameter values containing method calls to be parsed and handled - e.g. `x->foo(3,4)` and `y.z()`. Fixes #660 and https://sourceforge.net/p/swig/bugs/1081/
This commit is contained in:
parent
20588a4dc7
commit
ebbf2e6077
3 changed files with 73 additions and 1 deletions
|
|
@ -7,6 +7,11 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
|
||||||
Version 4.1.0 (in progress)
|
Version 4.1.0 (in progress)
|
||||||
===========================
|
===========================
|
||||||
|
|
||||||
|
2022-02-03: olly
|
||||||
|
#660 https://sourceforge.net/p/swig/bugs/1081/
|
||||||
|
Default parameter values containing method calls are now parsed and
|
||||||
|
handled - e.g. `x->foo(3,4)` and `y.z()`.
|
||||||
|
|
||||||
2022-02-02: olly
|
2022-02-02: olly
|
||||||
[Ruby] https://sourceforge.net/p/swig/bugs/1136/ Fix remove of prefix
|
[Ruby] https://sourceforge.net/p/swig/bugs/1136/ Fix remove of prefix
|
||||||
from method name to only remove it at the start.
|
from method name to only remove it at the start.
|
||||||
|
|
|
||||||
|
|
@ -8,20 +8,29 @@
|
||||||
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) UsdGeomTokensPtr;
|
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) UsdGeomTokensPtr;
|
||||||
%immutable UsdGeomTokens;
|
%immutable UsdGeomTokens;
|
||||||
|
|
||||||
|
// Don't call our getters get_xxx() as that collides with generated getters in
|
||||||
|
// some languages (e.g. csharp).
|
||||||
|
|
||||||
%inline %{
|
%inline %{
|
||||||
struct Numbers {
|
struct Numbers {
|
||||||
int val;
|
int val;
|
||||||
int *ptr;
|
int *ptr;
|
||||||
|
const int& g_val() const { return val; }
|
||||||
|
const int* g_ptr() const { return ptr; }
|
||||||
Numbers() : val(), ptr(&val) {}
|
Numbers() : val(), ptr(&val) {}
|
||||||
};
|
};
|
||||||
struct TfToken {
|
struct TfToken {
|
||||||
Numbers val;
|
Numbers val;
|
||||||
Numbers *ptr;
|
Numbers *ptr;
|
||||||
|
const Numbers& g_val() const { return val; }
|
||||||
|
const Numbers* g_ptr() const { return ptr; }
|
||||||
TfToken() : val(), ptr(&val) {}
|
TfToken() : val(), ptr(&val) {}
|
||||||
};
|
};
|
||||||
struct Tokens {
|
struct Tokens {
|
||||||
const TfToken face;
|
const TfToken face;
|
||||||
const TfToken *pface;
|
const TfToken *pface;
|
||||||
|
const TfToken& g_face() const { return face; }
|
||||||
|
const TfToken* g_pface() const { return pface; }
|
||||||
Tokens() : face(), pface(&face) {}
|
Tokens() : face(), pface(&face) {}
|
||||||
};
|
};
|
||||||
static Tokens UsdGeomTokens;
|
static Tokens UsdGeomTokens;
|
||||||
|
|
@ -31,4 +40,32 @@ void CreateMaterialBindSubset2(int num = UsdGeomTokensPtr->pface->val.val) {}
|
||||||
void CreateMaterialBindSubset3(int num = UsdGeomTokensPtr->pface->ptr->val) {}
|
void CreateMaterialBindSubset3(int num = UsdGeomTokensPtr->pface->ptr->val) {}
|
||||||
void CreateMaterialBindSubset4(int num = UsdGeomTokensPtr->face.val.val) {}
|
void CreateMaterialBindSubset4(int num = UsdGeomTokensPtr->face.val.val) {}
|
||||||
void CreateMaterialBindSubset5(int num = UsdGeomTokens.face.val.val) {}
|
void CreateMaterialBindSubset5(int num = UsdGeomTokens.face.val.val) {}
|
||||||
|
void CreateMaterialBindSubset6(int num = UsdGeomTokensPtr->pface->val.g_val()) {}
|
||||||
|
void CreateMaterialBindSubset7(int num = UsdGeomTokensPtr->pface->ptr->g_val()) {}
|
||||||
|
void CreateMaterialBindSubset8(int num = UsdGeomTokensPtr->face.val.g_val()) {}
|
||||||
|
void CreateMaterialBindSubset9(int num = UsdGeomTokens.face.val.g_val()) {}
|
||||||
|
void CreateMaterialBindSubseta(int num = UsdGeomTokensPtr->pface->g_val().val) {}
|
||||||
|
void CreateMaterialBindSubsetb(int num = UsdGeomTokensPtr->pface->g_ptr()->val) {}
|
||||||
|
void CreateMaterialBindSubsetc(int num = UsdGeomTokensPtr->face.g_val().val) {}
|
||||||
|
void CreateMaterialBindSubsetd(int num = UsdGeomTokens.face.g_val().val) {}
|
||||||
|
void CreateMaterialBindSubsete(int num = UsdGeomTokensPtr->pface->g_val().g_val()) {}
|
||||||
|
void CreateMaterialBindSubsetf(int num = UsdGeomTokensPtr->pface->g_ptr()->g_val()) {}
|
||||||
|
void CreateMaterialBindSubsetg(int num = UsdGeomTokensPtr->face.g_val().g_val()) {}
|
||||||
|
void CreateMaterialBindSubseth(int num = UsdGeomTokens.face.g_val().g_val()) {}
|
||||||
|
void CreateMaterialBindSubseti(int num = UsdGeomTokensPtr->g_pface()->val.val) {}
|
||||||
|
void CreateMaterialBindSubsetj(int num = UsdGeomTokensPtr->g_pface()->ptr->val) {}
|
||||||
|
void CreateMaterialBindSubsetk(int num = UsdGeomTokensPtr->g_face().val.val) {}
|
||||||
|
void CreateMaterialBindSubsetl(int num = UsdGeomTokens.g_face().val.val) {}
|
||||||
|
void CreateMaterialBindSubsetm(int num = UsdGeomTokensPtr->g_pface()->val.g_val()) {}
|
||||||
|
void CreateMaterialBindSubsetn(int num = UsdGeomTokensPtr->g_pface()->ptr->g_val()) {}
|
||||||
|
void CreateMaterialBindSubseto(int num = UsdGeomTokensPtr->g_face().val.g_val()) {}
|
||||||
|
void CreateMaterialBindSubsetp(int num = UsdGeomTokens.g_face().val.g_val()) {}
|
||||||
|
void CreateMaterialBindSubsetq(int num = UsdGeomTokensPtr->g_pface()->g_val().val) {}
|
||||||
|
void CreateMaterialBindSubsetr(int num = UsdGeomTokensPtr->g_pface()->g_ptr()->val) {}
|
||||||
|
void CreateMaterialBindSubsets(int num = UsdGeomTokensPtr->g_face().g_val().val) {}
|
||||||
|
void CreateMaterialBindSubsett(int num = UsdGeomTokens.g_face().g_val().val) {}
|
||||||
|
void CreateMaterialBindSubsetu(int num = UsdGeomTokensPtr->g_pface()->g_val().g_val()) {}
|
||||||
|
void CreateMaterialBindSubsetv(int num = UsdGeomTokensPtr->g_pface()->g_ptr()->g_val()) {}
|
||||||
|
void CreateMaterialBindSubsetw(int num = UsdGeomTokensPtr->g_face().g_val().g_val()) {}
|
||||||
|
void CreateMaterialBindSubsetx(int num = UsdGeomTokens.g_face().g_val().g_val()) {}
|
||||||
%}
|
%}
|
||||||
|
|
|
||||||
|
|
@ -1678,7 +1678,7 @@ static String *add_qualifier_to_declarator(SwigType *type, SwigType *qualifier)
|
||||||
%type <type> type rawtype type_right anon_bitfield_type decltype ;
|
%type <type> type rawtype type_right anon_bitfield_type decltype ;
|
||||||
%type <bases> base_list inherit raw_inherit;
|
%type <bases> base_list inherit raw_inherit;
|
||||||
%type <dtype> definetype def_args etype default_delete deleted_definition explicit_default;
|
%type <dtype> definetype def_args etype default_delete deleted_definition explicit_default;
|
||||||
%type <dtype> expr exprnum exprsimple exprcompound valexpr exprmem;
|
%type <dtype> expr exprnum exprsimple exprcompound valexpr exprmem callparms callptail;
|
||||||
%type <id> ename ;
|
%type <id> ename ;
|
||||||
%type <id> less_valparms_greater;
|
%type <id> less_valparms_greater;
|
||||||
%type <str> type_qualifier;
|
%type <str> type_qualifier;
|
||||||
|
|
@ -5254,6 +5254,20 @@ valparm : parm {
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
callparms : valexpr callptail {
|
||||||
|
$$ = $1;
|
||||||
|
Printf($$.val, "%s", $2);
|
||||||
|
}
|
||||||
|
| empty { $$.val = NewStringEmpty(); }
|
||||||
|
;
|
||||||
|
|
||||||
|
callptail : COMMA valexpr callptail {
|
||||||
|
$$.val = NewStringf(",%s%s", $2, $3);
|
||||||
|
$$.type = 0;
|
||||||
|
}
|
||||||
|
| empty { $$.val = NewStringEmpty(); }
|
||||||
|
;
|
||||||
|
|
||||||
def_args : EQUAL definetype {
|
def_args : EQUAL definetype {
|
||||||
$$ = $2;
|
$$ = $2;
|
||||||
if ($2.type == T_ERROR) {
|
if ($2.type == T_ERROR) {
|
||||||
|
|
@ -6529,18 +6543,34 @@ exprmem : ID ARROW ID {
|
||||||
$$.val = NewStringf("%s->%s", $1, $3);
|
$$.val = NewStringf("%s->%s", $1, $3);
|
||||||
$$.type = 0;
|
$$.type = 0;
|
||||||
}
|
}
|
||||||
|
| ID ARROW ID LPAREN callparms RPAREN {
|
||||||
|
$$.val = NewStringf("%s->%s(%s)", $1, $3, $5);
|
||||||
|
$$.type = 0;
|
||||||
|
}
|
||||||
| exprmem ARROW ID {
|
| exprmem ARROW ID {
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
Printf($$.val, "->%s", $3);
|
Printf($$.val, "->%s", $3);
|
||||||
}
|
}
|
||||||
|
| exprmem ARROW ID LPAREN callparms RPAREN {
|
||||||
|
$$ = $1;
|
||||||
|
Printf($$.val, "->%s(%s)", $3, $5);
|
||||||
|
}
|
||||||
| ID PERIOD ID {
|
| ID PERIOD ID {
|
||||||
$$.val = NewStringf("%s.%s", $1, $3);
|
$$.val = NewStringf("%s.%s", $1, $3);
|
||||||
$$.type = 0;
|
$$.type = 0;
|
||||||
}
|
}
|
||||||
|
| ID PERIOD ID LPAREN callparms RPAREN {
|
||||||
|
$$.val = NewStringf("%s.%s(%s)", $1, $3, $5);
|
||||||
|
$$.type = 0;
|
||||||
|
}
|
||||||
| exprmem PERIOD ID {
|
| exprmem PERIOD ID {
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
Printf($$.val, ".%s", $3);
|
Printf($$.val, ".%s", $3);
|
||||||
}
|
}
|
||||||
|
| exprmem PERIOD ID LPAREN callparms RPAREN {
|
||||||
|
$$ = $1;
|
||||||
|
Printf($$.val, ".%s(%s)", $3, $5);
|
||||||
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
/* Non-compound expression */
|
/* Non-compound expression */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue