Commit Graph

254 Commits

Author SHA1 Message Date
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
Olly Betts 967dd4e5c1 Fix dropping of parentheses around < and > expressions
We were dropping parentheses in these cases, which can change the value
of the expression.
2023-11-19 16:28:13 +13:00
Olly Betts 25654e4ad9 Fix deduced result type of bitwise not
This wasn't getting integer promotion applied to it.
2023-11-19 16:27:17 +13:00
Olly Betts 997616e652 Improve type deduction
Create a new T_UNKNOWN type code and use this for the cases where
we previously abused T_INT.  This means we can now reliably deduce
`int` when we see T_INT.

Fix the deduced result types of unary plus and unary minus which weren't
getting integer promotion applied to them.

Fix the deduced result type of the C++ logical not operator which was
`int` but should be `bool`.
2023-11-18 18:27:29 +13:00
Olly Betts 4a85d04793 [PHP] Fix testcase director_finalizer with PHP 8.3
Fixes #2685
2023-10-11 09:16:06 +13:00
Olly Betts 224c56a185 [PHP] Add missing overloading functionality
Implement overloading between different integer types and between double
and float.
2023-08-02 12:02:22 +12:00
Olly Betts 04a60463b3 [php] Fix new template_construct testcase warning 2023-08-01 12:17:28 +12:00
Olly Betts a1409022c5 char_binary_runme.php: Fill in missing parts
These don't currently work so comment them out.
2023-06-14 12:26:57 +12:00
Erez Geva 48dfd63c42 Add 'char_binary' test to Ruby, PHP, Octave 2023-06-14 12:26:46 +12:00
Olly Betts da4a6062bb Fix PHP test suite error reporting
check::fail() and check::warn() now fully support a printf-format
with arguments.
2023-06-12 15:05:38 +12:00
William S Fulton ba2939097f auto without return type warning suppression
Add the ignored declaration to the parse tree so that the explicit warning
features work.
2023-06-10 17:10:45 +01:00
Olly Betts f4fbfa65be Hook up cpp17_director_string_view testcase
Rename from director_string_view (since it requires C++17) and
add it to the list of tests to run which I'd failed to do before.
2023-05-26 17:45:24 +12:00
Olly Betts 427d41b547 Expand std::string_view test coverage
Fill in cases which weren't being tested for some target languages.
2023-05-26 16:19:05 +12:00
Olly Betts 10dc9bb0ce Update preproc_constants_c_runme.php
I only updated preproc_constants_runme.php when I added EXPR_LT and
EXPR_GT to the .i so realign the two again.
2023-05-25 12:52:11 +12:00
Olly Betts 15ace28066 Update preproc_constants* testcases
The changes for supporting more type deduction included a change to
stop treating `long double` and `float` literals as having type
`double`.  This requires updates the preproc_constants_c and
preproc_constants testcases which had a baked in assumption that
float literals were treated as double literals.
2023-05-25 12:47:18 +12:00
Olly Betts 7ba44dc62d Support deducing type of some expressions
This change only supports expressions involving literals of built-in
types, and `int` expressions aren't supported (due to the parser
currently setting .type=T_INT when in situations where that isn't
or may not be the correct type).
2023-05-25 11:50:47 +12:00
Olly Betts 6ad80c25ba Support parsing C++11 auto variables
This uses the existing type deduction code from decltype so has the same
limitations, and such variables will only actually be wrapped when SWIG
can deduce the type.

Fixes #1125
2023-05-25 10:31:22 +12:00
Olly Betts 8a73e25fe2 argcargv.i: NULL terminate argv with empty input
Fixes needed for: C# R
2023-05-23 10:12:49 +12:00
Olly Betts 4ba7e68c28 Test empty array and empty string with argcargv.i
Adding test coverage for target languages where this already works.
2023-05-22 16:08:09 +12:00
Olly Betts 915dc93b0d [octave] Fix argcargv.i bug
The strings from the Octave array are returned in a temporary
std::string object so we need to make a copy of them or else the
final string ends up replicated as all elements.

Unfortunately argcargvtest.i was only checking the final element's
value, so fix it to test both the elements as a regression test for
this, and to catch any similar issues with other target languages.
2023-05-22 13:38:59 +12:00
Olly Betts d8887091fe Support deducing decltype for false and true 2023-05-20 09:09:48 +12:00
Olly Betts 4e4369a4a4 Improve #2446 fix
It seems the parser limitation isn't actually a problem as non of
the cases are valid C++ so drop that from the docs.

Extend test coverage by adding some class methods, including `static` and
`const`.
2023-05-19 14:27:34 +12:00
Olly Betts f215365609 Merge branch 'cpp14-auto-return-type' 2023-05-19 12:02:30 +12:00
Olly Betts 1c309da897 Implement cpp11_decltype_runme.php 2023-05-18 18:48:06 +12:00
Olly Betts 5104040dc9 Partial support for auto without trailing return type
This is a C++14 feature.

SWIG can now parse some cases of this.  The limitation is that there
can either be nothing or `const` between the `)` and the end of the
parameter list and the `{` at the start of the body.

Fixes #2446
2023-05-18 15:19:23 +12:00
Olly Betts 5b709dd163 Merge branch 'JS-check-fix' 2023-05-12 16:18:46 +12:00
Olly Betts a44a7de348 Expand li_std_string_runme.*
Add testing of the empty and null cases for all languages which
already have a runme.
2023-05-12 16:05:48 +12:00
Erez Geva b6eaee8d12 Add li_constraints test, testing 'constraints.i'.
For: JavaScript, C#, go, Java, Lua, Perl, PHP, python, Ruby, TCL and Octave.

Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
2023-05-12 01:23:31 +02:00
Olly Betts 6085a9661e Initial support for std::string_view
So far C#, Java, Lua and PHP are supported.

Closes: #2540
See #1567
2023-05-08 15:56:37 +12:00
Olly Betts 15b739d60e [PHP] Wrap method with both static and non-static overloads
We now wrap this as a non-static method in PHP, which means the static
form only callable via an object.

Previously this case could end up wrapped as static or non-static
in PHP.  If it was wrapped as static, attempting to call non-static
overloaded forms would crash with a segmentation fault.

See #2544
2023-05-08 15:44:24 +12:00
Olly Betts d9aeb01306 catches_strings_runme.php: Check exact exception message
There's no need to do a substring check here.
2023-04-24 15:15:44 +12:00
Olly Betts d45884bab5 [php] Add throws typemaps for string* + const string* 2023-04-24 12:18:52 +12:00
Olly Betts 6cd19ba926 [php] Support INPUT,INOUT,OUTPUT for std::string&
By default SWIG/PHP wraps std::string& as a pass-by-reference PHP
string parameter, but sometimes such a parameter is only for input
or only for output, so add support for the named typemaps that other
target languages support.
2023-04-21 17:50:25 +12:00
Olly Betts 3275331886 Add regression test for << in array size bug
Go is happy with the testcase if the type is changed from int to
char, so just go with that.

See https://sourceforge.net/p/swig/bugs/983/
2023-04-20 14:55:09 +12:00
Olly Betts 9873ff107a Remove remaining traces of PHP7 support
The bulk of this was already removed in
e3b112c69c.
2023-04-20 13:45:30 +12:00
Olly Betts e3b112c69c Remove support for PHP7
PHP7 security support ended 2022-11-28 so it doesn't make sense to
include support for it in the SWIG 4.2.x release series.
2023-04-14 17:38:01 +12:00
Olly Betts 747a6a264f [php] Fix handling of multi-module cases
Look up unknown base classes using SWIG_MangledTypeQueryModule().

Revert to using SWIG_TypeCheck() instead of SWIG_TypeCheckStruct()
as the latter doesn't seem to work for this case (at least for PHP
right now).

Add mod_runme.php as a regression test for this.

Adjust the PHP test harness not to set up reflection for the module
unless it's actually needed for a testcase.  Currently the approach
to find the module name doesn't work for multi-module testcases.

See #2126
2022-10-18 10:28:17 +13:00
Olly Betts fefb231bd8 [php] Update exception_memory_leak_runme.php
Test the new "return by value" case too.
2022-10-14 14:44:19 +13:00
Olly Betts 3dd7e93c77 Fix issues with exception_memory_leak testcase
The out typemap uses a function name which doesn't match the name of the
function we want it to apply to, so this testcase wasn't actually
triggering an exception so wasn't actually testing anything!

With that fixed, the testcase fails to compile for PHP due to use of
SWIG_exception_fail() (which not all target languages implement), and
with that fixed, the _runme.php needs a try ... catch adding to handle
the raised exception.
2022-10-14 12:12:21 +13:00
Olly Betts 91887a10cd [php] Avoid creating dynamic properties in testsuite
This gives a deprecation warning with PHP 8.2.
2022-09-28 18:53:04 +13:00
Olly Betts e789c9e799 [php] Avoid deprecated interpolation syntax
Avoid syntax deprecated in PHP 8.2.
2022-09-28 18:51:53 +13:00
William S Fulton ed333b6b97 std::string throws typemaps
Go, Guile, Racket, Scilab: Add throws typemaps for std::string so that
thrown string exception messages can be seen.

Test all language for std::string throws typemaps
2022-09-19 09:09:29 +01:00
William S Fulton 4a29229bab Add catches_strings test to test throws char * typemap 2022-09-19 09:09:29 +01:00
William S Fulton e97181ebc0 Add missing typecheck typemaps for std::auto_ptr and std::unique_ptr
To fix overloading when using these types.
2022-09-17 10:23:51 +01:00
William S Fulton dad7c93ca0 Provide SWIGTYPE MOVE typemaps in swigmove.i
For implementing full move semantics when passing parameters by value.
Based on SWIGTYPE && and std::unique_ptr typemaps which implement move
semantics.

Added for all languages, but untested for: Go, Ocaml, R, Scilab (and
unlikely to be fully functional for same reasons as for std::unique_ptr
support).

Issue #999
2022-09-16 08:36:25 +01:00
Olly Betts adc2fa9664 Fix default_args_runme.php for 32-bit platforms
On 32-bit platforms -2147483648 is a PHP float (rather than PHP int on
64-bit platforms) so only check equivalence rather than strict equality.

Fixes #2360
2022-09-14 11:30:28 +12:00
William S Fulton 2212af3f4f rvalue reference outputs
Document rvalue reference outputs behaviour
Test rvalue reference outputs
2022-09-08 08:46:32 +01:00