diff options
author | Olly Betts <olly@survex.com> | 2022-02-03 15:48:24 +1300 |
---|---|---|
committer | Olly Betts <ojwbetts@gmail.com> | 2022-02-03 17:20:30 +1300 |
commit | ebbf2e607713a15e43b8d40d12fb58823cbb1cf6 (patch) | |
tree | d9e9f0de7fe298f00e04488d1c8347344c6b0675 | |
parent | 20588a4dc712670a240a2adcd47a980d77765e05 (diff) | |
download | swig-ebbf2e607713a15e43b8d40d12fb58823cbb1cf6.tar.gz |
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/
-rw-r--r-- | CHANGES.current | 5 | ||||
-rw-r--r-- | Examples/test-suite/default_arg_expressions.i | 37 | ||||
-rw-r--r-- | Source/CParse/parser.y | 32 |
3 files changed, 73 insertions, 1 deletions
diff --git a/CHANGES.current b/CHANGES.current index 46c567a02..b321377a9 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -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) =========================== +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 [Ruby] https://sourceforge.net/p/swig/bugs/1136/ Fix remove of prefix from method name to only remove it at the start. diff --git a/Examples/test-suite/default_arg_expressions.i b/Examples/test-suite/default_arg_expressions.i index 1d846eaea..99d54c3b9 100644 --- a/Examples/test-suite/default_arg_expressions.i +++ b/Examples/test-suite/default_arg_expressions.i @@ -8,20 +8,29 @@ %warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) UsdGeomTokensPtr; %immutable UsdGeomTokens; +// Don't call our getters get_xxx() as that collides with generated getters in +// some languages (e.g. csharp). + %inline %{ struct Numbers { int val; int *ptr; + const int& g_val() const { return val; } + const int* g_ptr() const { return ptr; } Numbers() : val(), ptr(&val) {} }; struct TfToken { Numbers val; Numbers *ptr; + const Numbers& g_val() const { return val; } + const Numbers* g_ptr() const { return ptr; } TfToken() : val(), ptr(&val) {} }; struct Tokens { const TfToken face; const TfToken *pface; + const TfToken& g_face() const { return face; } + const TfToken* g_pface() const { return pface; } Tokens() : face(), pface(&face) {} }; static Tokens UsdGeomTokens; @@ -31,4 +40,32 @@ void CreateMaterialBindSubset2(int num = UsdGeomTokensPtr->pface->val.val) {} void CreateMaterialBindSubset3(int num = UsdGeomTokensPtr->pface->ptr->val) {} void CreateMaterialBindSubset4(int num = UsdGeomTokensPtr->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()) {} %} diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index c9d24cef0..87f2a7c44 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -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 <bases> base_list inherit raw_inherit; %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> less_valparms_greater; %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 { $$ = $2; if ($2.type == T_ERROR) { @@ -6529,18 +6543,34 @@ exprmem : ID ARROW ID { $$.val = NewStringf("%s->%s", $1, $3); $$.type = 0; } + | ID ARROW ID LPAREN callparms RPAREN { + $$.val = NewStringf("%s->%s(%s)", $1, $3, $5); + $$.type = 0; + } | exprmem ARROW ID { $$ = $1; Printf($$.val, "->%s", $3); } + | exprmem ARROW ID LPAREN callparms RPAREN { + $$ = $1; + Printf($$.val, "->%s(%s)", $3, $5); + } | ID PERIOD ID { $$.val = NewStringf("%s.%s", $1, $3); $$.type = 0; } + | ID PERIOD ID LPAREN callparms RPAREN { + $$.val = NewStringf("%s.%s(%s)", $1, $3, $5); + $$.type = 0; + } | exprmem PERIOD ID { $$ = $1; Printf($$.val, ".%s", $3); } + | exprmem PERIOD ID LPAREN callparms RPAREN { + $$ = $1; + Printf($$.val, ".%s(%s)", $3, $5); + } ; /* Non-compound expression */ |