mirror of https://github.com/swig/swig
Improve parsing of expressions related to functions calls
For example, the following no longer give parse errors: `g().d()`, `g().D`, `(f(1) < g(2))`, `sizeof f(a,b)` Partly addresses #3197
This commit is contained in:
parent
43cc74f85d
commit
3f4ed82945
|
@ -7,6 +7,11 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
|
|||
Version 4.4.0 (in progress)
|
||||
===========================
|
||||
|
||||
2025-06-17: olly
|
||||
#3197 Improve parsing of expressions related to functions calls.
|
||||
For example, the following no longer give parse errors: `g().d()`,
|
||||
`g().D`, `(f(1) < g(2))`, `sizeof f(a,b)`
|
||||
|
||||
2025-06-11: wsfulton
|
||||
[Python] Add support for -builtin and heap types turned on with
|
||||
-DSWIG_HEAPTYPES. This is an important step towards supporting a number of
|
||||
|
@ -42,6 +47,7 @@ Version 4.4.0 (in progress)
|
|||
with Tcl 8.x. Regression introduced in SWIG 4.2.1. As a bonus
|
||||
the generated header no longer requires the user to include tcl.h
|
||||
and various standard C library headers before including it.
|
||||
|
||||
2025-05-28: olly
|
||||
#3186 Fix parse error for C++14 forward declaration of function with
|
||||
auto return type and no trailing return type.
|
||||
|
|
|
@ -75,6 +75,10 @@ const int s8a = sizeof(2.1e-6);
|
|||
const int s8b = sizeof 2.1e-6;
|
||||
const int s9a = sizeof(-s8a);
|
||||
// const int s9b = sizeof -s8a; /* not currently supported */
|
||||
const int s10a = sizeof(xx());
|
||||
// Before 4.4.0 this gave:
|
||||
// Warning 328: Value assigned to s10b not used due to limited parsing implementation.
|
||||
const int s10b = sizeof xx();
|
||||
|
||||
%}
|
||||
|
||||
|
|
|
@ -8,6 +8,9 @@
|
|||
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK) UsdGeomTokensPtr;
|
||||
%immutable UsdGeomTokens;
|
||||
|
||||
// helper() only exists to test we can parse more complex expressions.
|
||||
%ignore helper;
|
||||
|
||||
// Don't call our getters get_xxx() as that collides with generated getters in
|
||||
// some languages (e.g. csharp).
|
||||
|
||||
|
@ -70,4 +73,11 @@ void CreateMaterialBindSubsetw(int num = UsdGeomTokensPtr->g_face().g_val().g_va
|
|||
void CreateMaterialBindSubsetx(int num = UsdGeomTokens.g_face().g_val().g_val()) {}
|
||||
void CreateMaterialBindSubsety(int num = UsdGeomTokens.g_face(1).g_val().g_val()) {}
|
||||
void CreateMaterialBindSubsetz(int num = UsdGeomTokens.g_face(1,2).g_val().g_val()) {}
|
||||
|
||||
// Regression tests for #3197.
|
||||
Tokens& helper(bool = false, bool = false) { return UsdGeomTokens; }
|
||||
void ParseTest1(int num = helper().face.val.val) {}
|
||||
void ParseTest2(int num = helper().g_face().val.val) {}
|
||||
void ParseTestN(bool b = (helper().g_face().val.val < helper().face.val.val)) {}
|
||||
|
||||
%}
|
||||
|
|
|
@ -7,7 +7,7 @@ check::functions(array('xx', 'yy'));
|
|||
// New classes
|
||||
check::classes(array('constant_expr_c'));
|
||||
// New vars
|
||||
check::globals(array('X','d_array','s1a','s2a','s2b','s3a','s3b','s4a','s4b','s5a','s5b','s6a','s6b','s7a','s7b','s8a','s8b','s9a'));
|
||||
check::globals(array('X','d_array','s1a','s2a','s2b','s3a','s3b','s4a','s4b','s5a','s5b','s6a','s6b','s7a','s7b','s8a','s8b','s9a', 's10a', 's10b'));
|
||||
|
||||
check::equal(XX, xx());
|
||||
check::equal(YY, yy());
|
||||
|
|
|
@ -7,7 +7,7 @@ check::functions(array('bar', 'test2', 'xx', 'yy'));
|
|||
// New classes
|
||||
check::classes(array('constant_expr'));
|
||||
// New vars
|
||||
check::globals(array('X','a','d_array','s1a','s2a','s2b','s3a','s3b','s4a','s4b','s5a','s5b','s6a','s6b','s7a','s7b','s8a','s8b', 's9a'));
|
||||
check::globals(array('X','a','d_array','s1a','s2a','s2b','s3a','s3b','s4a','s4b','s5a','s5b','s6a','s6b','s7a','s7b','s8a','s8b', 's9a', 's10a', 's10b'));
|
||||
|
||||
check::equal(XX, xx());
|
||||
check::equal(YY, yy());
|
||||
|
|
|
@ -6759,7 +6759,7 @@ expr : valexpr
|
|||
}
|
||||
;
|
||||
|
||||
/* simple member access expressions */
|
||||
/* member access expressions and function calls */
|
||||
exprmem : ID[lhs] ARROW ID[rhs] {
|
||||
$$ = default_dtype;
|
||||
$$.val = NewStringf("%s->%s", $lhs, $rhs);
|
||||
|
@ -6781,6 +6781,31 @@ exprmem : ID[lhs] ARROW ID[rhs] {
|
|||
$$ = $in;
|
||||
append_expr_from_scanner($$.val);
|
||||
}
|
||||
| type LPAREN {
|
||||
$$ = default_dtype;
|
||||
if (skip_balanced('(', ')') < 0) Exit(EXIT_FAILURE);
|
||||
|
||||
String *qty = Swig_symbol_type_qualify($type, 0);
|
||||
if (SwigType_istemplate(qty)) {
|
||||
String *nstr = SwigType_namestr(qty);
|
||||
Delete(qty);
|
||||
qty = nstr;
|
||||
}
|
||||
/* Try to deduce the type - this could be a C++ "constructor
|
||||
* cast" such as `double(4)` or a function call such as
|
||||
* `some_func()`. In the latter case we get T_USER, but that
|
||||
* is wrong so we map it to T_UNKNOWN until we can actually
|
||||
* deduce the return type of a function call (which is
|
||||
* complicated because the return type can vary between
|
||||
* overloaded forms).
|
||||
*/
|
||||
$$.type = SwigType_type(qty);
|
||||
if ($$.type == T_USER) $$.type = T_UNKNOWN;
|
||||
$$.unary_arg_type = 0;
|
||||
|
||||
$$.val = qty;
|
||||
append_expr_from_scanner($$.val);
|
||||
}
|
||||
;
|
||||
|
||||
/* Non-compound expression */
|
||||
|
@ -7298,31 +7323,6 @@ exprcompound : expr[lhs] PLUS expr[rhs] {
|
|||
$$.val = NewStringf("!%s", $in.val);
|
||||
$$.type = cparse_cplusplus ? T_BOOL : T_INT;
|
||||
}
|
||||
| type LPAREN {
|
||||
$$ = default_dtype;
|
||||
if (skip_balanced('(',')') < 0) Exit(EXIT_FAILURE);
|
||||
|
||||
String *qty = Swig_symbol_type_qualify($type, 0);
|
||||
if (SwigType_istemplate(qty)) {
|
||||
String *nstr = SwigType_namestr(qty);
|
||||
Delete(qty);
|
||||
qty = nstr;
|
||||
}
|
||||
/* Try to deduce the type - this could be a C++ "constructor
|
||||
* cast" such as `double(4)` or a function call such as
|
||||
* `some_func()`. In the latter case we get T_USER, but that
|
||||
* is wrong so we map it to T_UNKNOWN until we can actually
|
||||
* deduce the return type of a function call (which is
|
||||
* complicated because the return type can vary between
|
||||
* overloaded forms).
|
||||
*/
|
||||
$$.type = SwigType_type(qty);
|
||||
if ($$.type == T_USER) $$.type = T_UNKNOWN;
|
||||
$$.unary_arg_type = 0;
|
||||
|
||||
$$.val = qty;
|
||||
append_expr_from_scanner($$.val);
|
||||
}
|
||||
;
|
||||
|
||||
variadic_opt : ELLIPSIS {
|
||||
|
|
Loading…
Reference in New Issue