Commit Graph

300 Commits

Author SHA1 Message Date
Olly Betts 3f4ed82945 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
2025-06-17 14:59:54 +12:00
Olly Betts 31668d98e1 Fix warnings from cpp11_auto_variable_runme.php 2025-06-08 09:58:30 +12:00
Olly Betts 6dbf867d23 Fix handling of corner cases by previous change
Don't collapse runs of whitespace to a single space, instead replace
each whitespace with one space.

Leave the expression as-is if it contains one or more double quotes
as we don't want to change the value of string literals, and any
expression containing double quotes won't currently work in the context
where we need to replace newlines anyway.

Fixes #3127 better
2025-03-03 11:22:37 +13:00
Olly Betts 0b4496a735 Fix testsuite SWIG warnings; enable SWIG -Werror
SWIG/mzscheme (aka racket) is excluded for now as it currently has a lot
of testsuite warnings and is slated for removal in 4.4.0 anyway.

Closes #3034
2024-10-22 10:30:52 +13:00
William S Fulton 60a476982a Run inout testcase for all languages except D 2024-10-05 23:29:34 +01:00
Olly Betts d80ce85819 Handle arbitrary expressions as a subscript
We don't actually need to parse expressions in this context so we can
just skip to the matching closing square bracket.
2024-09-30 09:25:00 +13:00
Olly Betts a111df5650 Enable part of testcase which now works
Looks like handling of this was fixed by
3ef3f39516.
2024-09-28 15:35:40 +12:00
Olly Betts 0f7278ea92 Fix PHP testsuite warning 2024-09-26 11:12:40 +12:00
Olly Betts 6567c5d186 Add support for C99 _Bool
SWIG now treats _Bool as an alias for the bool keyword when in C mode.
2024-09-25 06:23:48 +12:00
Olly Betts 2c4ff2f4d6 [php] Fix warning from string_constants testcase 2024-09-22 08:12:45 +12:00
Olly Betts 9f685e03f0 Add regression test for old bug fix
We don't seem to have anything in the testsuite which exercises this
case.

There's some special handling of casts applied to string literals in the
parser which was committed as part of the fix for this, but removing it
doesn't seem to cause anything to fail (not even this testcase which
it reportedly fixed), and a wide character version seems to work without
any equivalent special handling.  Maybe other things have changed since
which fixed this case without needing special cast handling.  Deserves
further investigation.
2024-09-21 09:04:27 +12:00
William S Fulton 9bf4842002 C++ reference errors when passing in a 'NULL' change of behaviour.
Most languages now use "NullReferenceError" in the error message
where they previously used "ValueError". Also exception changes:

Guile:    "swig-null-reference-error" instead of "swig-value-error"
MzScheme: "swig-null-reference-error" instead of "swig-value-error"
PHP:      zend_ce_type_error instead of zend_ce_value_error
Python:   Consistently raises TypeError instead of a mix of ValueError
          and TypeError.
Ruby:     Consistently raises NullReferenceError instead of a mix of
          ArgumentError and NullReferenceErrorError.

The consistent raising of a TypeError instead of ValueError for Python
ensures that incorrectly passing 'None' into a C++ reference argument
will correctly convert the error into a NotImplemented error for
the rich comparisons implementations per PEP 207. Fixes #2987

Note that the li_constraints checking implementation for the NONNULL
typemap for pointers also makes the same error change from
SWIG_ValueError to SWIG_NullReferenceError.

The D typemaps use SWIG_DNullReferenceException instead of
SWIG_DIllegalArgumentException, although this ultimately has no change
as the same D Exception is still thrown.
2024-09-14 13:03:36 +01:00
Olly Betts 61e54ab054 Improve handling of zero bytes in string literals
Many of the target languages don't handle this currently.  Those
that don't support this in their strings never will, but others
can probably be fixed.

Fixes #2996
Fixes #2997
2024-08-30 11:07:15 +12:00
Olly Betts 7a8c9fdfa8 Straighten out handling of char and string constants
Fixes #904
Fixes #1907
Fixes #2579
Fixes #2990
2024-08-17 16:12:45 +12:00
Olly Betts 4299e893da Fix parsing of octal string escapes
We now stop when the next character is digit 8 or 9, and stop after 3
octal digits even if the next character is an octal digit.
2024-08-15 14:38:52 +12:00
Olly Betts 8d1ac40dc6 Fix wrapping of string with control characters
Fix wrapping of string constants containing bytes 0-8, 11, 12 or 14-31
followed by a digit '0' to '7'.  We were emitting these bytes as a one
or two character octal escape sequence which when interpreted would
include the following character.
2024-08-01 14:36:43 +12:00
Olly Betts 3452d08cd8 Support parsing `noexcept(X)` in expressions
Missing C++11 feature.
2024-07-26 12:31:44 +12:00
William S Fulton ba9b0a35ab Merge branch 'char_binary_java_fix-tidyup'
* char_binary_java_fix-tidyup:
  Move SWIGStringWithLengthHelper to csharphead.swg
  cdata whitespace/cosmetic fixups
  cdata doc updates
  Rename `typemaps/cdata_struct.swg` to `typemaps/cdata_begin.swg`. And `typemaps/cdata.swg` to `typemaps/cdata.swg`. Move `cdata_apply.swg` content to `typemaps/cdata.swg`.
  Group the C# marshalling of STRING-LENGTH typemap  into C# class named SWIGStringWithLengthHelper.
  Leave Length & string reverse order typemap in typemaps/strings.swg
  Support old C# as "LPUTF8Str" was add in 2017.
  Improve documentation. Follow @wsfulton reviews.
  Use a dummy for MzScheme and untested OCaml cdate. To prevent compilation error.
  Further fixing follow reviews.
  Reorganise raw data typemap,  so typemaps folder contain only common part. Improve document.
  Inline SWIG_string_to_utf8_bytes SWIG_utf8_bytes_to_string code
  Fixes of STRING/BYTES LENGTH typemaps.

 Conflicts:
	CHANGES.current
2024-06-13 10:53:19 +01:00
Olly Betts a5de191402 Improve support for C++11 alignof(T)
Support alignof(T) for arbitrary type T, and deduce the type of
alignof(T) as size_t.
2024-06-06 12:44:46 +12:00
Olly Betts 57ed628035 Improve parsing of sizeof(X)
Support parsing `sizeof(X)` for any expression or type X by skipping
balanced parentheses.  We don't need to actually parse X since the type
of sizeof is always size_t.

Fixes #2919
2024-06-06 10:36:12 +12:00
Olly Betts 0ce05c33e9 Improve alternative operator names support
Handle alternative operator names in C++ preprocessor expressions.
Handle full set of alternative operator names in C++ expressions
(previously only "and", "or" and "not" were understood).

Fixes #2914
2024-05-30 11:38:32 +12:00
Olly Betts a7eca8b415 Support __VA_OPT__
Fixes #1574
2024-03-28 12:46:58 +13:00
Olly Betts f037a5994e Fix typo in recent preproc testcase change 2024-03-28 10:50:55 +13:00
William S Fulton 24a66e6125 Add const std::unique_ptr & input typemaps 2024-03-06 21:46:58 +00:00
William S Fulton 846b40793e Add non-const std::unique_ptr & input typemaps 2024-03-06 21:46:58 +00:00
William S Fulton 5712ce6464 std::unique_ptr return by reference typemaps added 2024-03-06 21:46:58 +00:00
William S Fulton 3f1e40d2f4 Add std::unique_ptr && output typemaps
Move semantics are not supported by default.
They behave as if a lvalue reference was returned.
2024-03-06 21:46:58 +00:00
William S Fulton ae22a97f1b Movable std::unique_ptr - add std::unique_ptr && typemaps
Closes #2650
2024-03-06 21:46:58 +00:00
William S Fulton dcc1471dd3 Add missing use of move constructor
instead of copy constructor when passing movable types. This was
previously implemented only for parameters passed to a global function
or static member function and is now extended to member methods.

Enhancement to e777b054d5.
2024-03-06 21:46:58 +00:00
Erez Geva 1bf59e0bbc Fixes of STRING/BYTES LENGTH typemaps.
Fix Java STRING LENGTH typemap.
Use string type in static typed languages (Java, C#, D and Go).

Add BYTES LENGTH typemap and apply it for binary data.
Use byte type in static typed languages.

Add li_cdata_cpp, li_cdata and char_binary
 tests for most of languages(apart from R and experimental).

Fix the director_binary_string test and add it to C#, D, Go,
 Perl, PHP, Python, Ruby and octave.

Update documents.

Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
2024-02-29 02:09:09 +01:00
Olly Betts ed30a80d7f [php] Add runme for testcase constant_expr 2024-02-26 12:45:45 +13:00
Olly Betts 4b433543fc [php] Add runme for li_stdint testcase 2024-02-26 12:05:14 +13:00
Olly Betts 4bebdf4430 Improve type deduction for enum value in expression 2024-02-15 21:29:05 +13:00
Olly Betts 4dc621d804 Fix type deduction for certain cases
Fix type deduction for certain cases involving C-style casts, or
which are syntactically like a C-style cast applied to an unary
operator, such as: (7)*6

See #2796
2024-02-13 17:05:55 +13:00
Olly Betts 39e8508dfc Fix handling of enum initialised by typedef-ed cast
Regression introduced in 4.2.0.

Fixes #2796
2024-02-13 10:56:09 +13:00
Olly Betts 1cf7ef4c5d Update expected functions for overload_simple testcase 2024-01-31 10:23:40 +13:00
William S Fulton 0a16044a27 Wrap friend functions that are defined or declared within a namespace
Previously unqualified friend definitions/declarations in a namespace were
ignored.
2024-01-15 19:18:13 +00:00
William S Fulton 158fbdc760 Improve friend function documentation
Add unqualified friend example in docs as a testcase
2024-01-15 18:52:05 +00:00
William S Fulton c7ab6a01c6 Fix seg fault handling friend constructor/destructor declarations
Closes #2749
2024-01-15 18:52:05 +00:00
William S Fulton 33dd5cfe3f Merge branch 'python_cast_mode_2'
* python_cast_mode_2:
  python/cast_mode: Add tests for min/max of double -> int convertions.
  python/cast_mode: Fix integer overflow of LONG_MAX+1.
2023-12-24 18:08:28 +00:00
Olly Betts 32adf4b3c9 [PHP] Fix %feature(php:allowdynamicproperties, 0)
The handling of this feature now matches other boolean features.
Previously any value set was treated as on.
2023-12-22 09:37:42 +13:00
Olly Betts ccaf46262a Expand director_string_runme.*
Fill in parts which were missing for some target languages.
2023-12-21 10:59:44 +13:00
Olly Betts ccf4f6ec72 Sort out directorout typemaps for std::string_view
With Perl the returned string is still being corrupted (the testcase
flags this as "TODO" for Perl's test harness).

Warnings aren't currently emitted for Perl, Ruby or Tcl as I'm not
seeing where in the UTL maze the directorout typemap actually gets
defined.
2023-12-21 10:59:44 +13:00
Markus Wick 2e138a5146 python/cast_mode: Add tests for min/max of double -> int convertions.
Test min/max values of all implicit PyLong + PyFloat -> C u?l?l convertions.

Also check all off-by-one for throwing errors.
2023-12-06 22:11:23 +01:00
Olly Betts 3a6d124751 Extend type deduction
SWIG can now deduce the type of an expression including variables, and
the deduced type for unary & is now correct (it was the type of the
subexpression & was applied to).
2023-12-04 17:10:30 +13:00
Olly Betts c5c843e14c Fix deduced type of unary *
Previously we incorrectly used the type of the expression that * was
applied to.
2023-12-04 16:18:59 +13:00
Olly Betts da018ed6f7 Support type deduction of enums
Fixes #2715
2023-12-01 08:57:41 +13:00
Olly Betts b5ca500b40 Deduce type of TYPE(EXPRESSION)
This is actually an easy case - e.g. the type of `double(4)` is
`double`.
2023-11-19 22:08:25 +13:00
Olly Betts 5f8b9135cc Fix director_classes testcase failures on x86
Adjust the floating point constants to be 1.125 and 2.25 (which
can be exactly represented in base-2 floating point) instead of
1.1 and 2.2 (which can't).  This avoids problems on platforms where
floating point calculations suffer from excess precision, the most
commonly used of which is x86 when using 387 FP instructions.
2023-11-19 21:45:30 +13:00
Olly Betts d506235a6d Fix testcase addition in previous commit 2023-11-19 21:15:46 +13:00