Commit Graph

1049 Commits

Author SHA1 Message Date
William S Fulton 26b0911a74 Add support for $n special variable expansion in the names of typemap local variables
For example:

  %typemap(in) int MYINT (int $1_temp) { ... }

$1_temp is typically expanded to arg1_temp, arg2_temp etc depending on
which argument the typemap is applied to.
2025-02-19 20:44:40 +00:00
William S Fulton e8787615a7 Regression fix when using -keyword, kwargs or compactdefaultargs option
Restore generating a non-const cast to the default value when
wrapping const pointer default arguments.

Fixes #3075.
2025-02-05 08:09:44 +00:00
William S Fulton d9edb22d1c %apply and typedefs improvement
Perform repeated typedef lookups instead of a single typedef
lookup on the type being applied in %apply when looking for a family
of typemaps to apply.

Closes #3064
2024-11-09 13:30:19 +00:00
William S Fulton 40b6cc684f Use exact type for temporary variable wrapping parameters with default args and compactdefaultargs
When wrapping a default argument such as 'const bool& x = true'
a variable with the exact same type, such as:

  bool const &arg2_defvalue = true;

is now used in the generated code instead of a dereferenced type:

  bool arg2_defvalue = true;

This can still be used for the wrapped argument without any other
changes:

  bool *arg2 = (bool *) &arg2_defrvalue;

and the lifetimes are still the same for the temporary variable.

Works around some typedef issues for enum classes introduced in the
previous commit in the cpp11_strongly_typed_enumerations testcase,
when wrapping a parameter 'const PRINT_SETUP& e = PRINT_SETUP::TO_CONSOLE'
The temporary variable being generated became:

  enum MyClass::PRINT_SETUP arg2_defvalue = MyClass::PRINT_SETUP::TO_CONSOLE ;

The enum in the type is wrong for an enum class. Now the original type
is used:

  MyClass::PRINT_SETUP const &arg2_defvalue = MyClass::PRINT_SETUP::TO_CONSOLE ;
2024-11-04 23:21:25 +00:00
William S Fulton 5c2e83dd1a Typedefs to references fix for the compactdefaultargs feature
Fixes error: SwigType_del_reference applied to non-reference type
2024-11-04 23:21:25 +00:00
William S Fulton 936767da8e Few error message improvements and consistency tweaks 2024-11-04 23:21:25 +00:00
William S Fulton 3cda507e57 Fix initializer lists used with -keyword or compactdefaultargs option
Remove casts to local variables that have initial values taken from the
default arguments being wrapped. This is for the default case, that is,
for all types, except references.

This fixes handling of parameters with default arguments that are initializer
lists by removing a cast to the initializer.

For wrapping parameter X x = {}, the generated code previously would have
contained:
  X arg2 = (X) {};
Now it is:
  X arg2 = {};

Closes #1851
2024-11-04 23:21:25 +00:00
Olly Betts ce6d2dd11e Drop support for raw type strings in interface files
This is described in CHANGES as a "Secret developer feature" and
a "SICK HACK".  It was only documented in developer documentation, and
had no test coverage.

It allowed specifying an SWIG internal syntax type string, e.g.

  `p.a(10).p.f(int, p.f(int).int)` foo(int, int (*x)(int));

However there seems to be no good reason to support this - it's
better to use the C/C++ syntax:

  (*(*foo(int, int (*)(int)))[10])(int, int (*)(int));

Fixes #2998
Closes #3034
2024-10-22 09:05:54 +13:00
Olly Betts 4be9274c82 Fix bug handling 0xff after #
We were treating byte 0xff as EOF after a `#` which wasn't handled by
the preprocessor on platforms with signed char, while EOF was treated as
byte 0xff on platforms with unsigned char.
2024-10-09 08:25:08 +13:00
Olly Betts c61da55db4 Remove unused field in struct Scanner
This was being initialized to NULL but never actually used.  The
filename gets tracked via the String objects being scanned.
2024-10-06 08:07:26 +13: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 9cba248bec Straighten out handling of integer constants
This provides a generic framework to aid converting C/C++ integer and
boolean literals to target language literals, replacing custom code in
several target language backends (and fixing some bugs in that code).
2024-09-16 16:10:02 +12:00
Olly Betts 4ea006c4f4 Merge branch 'master' into C 2024-09-13 12:31:14 +12:00
Olly Betts 06cb7a122c Fix qualify of "enum class" enumerator names
Fix incorrect inclusion of "enum " when qualifying C++11 "enum class"
enumerator names.

Fixes #197
Fixes #675
Fixes #1677
Fixes #2047
Closes #3013
2024-09-11 17:42:34 +12:00
Olly Betts eff3d2225e Merge branch 'master' into C 2024-09-11 16:26:07 +12:00
William S Fulton 61dffc06d1 %interface regression fix for multiple inheritance and common bases
Regressio introduced in 7592722.

Closes #2875
2024-09-07 20:07:17 +01:00
William S Fulton 3935fee467 Warning fix: conversion from 'size_t' to 'int', possible loss of data 2024-09-04 19:36:38 +01:00
Olly Betts 30030583da Improve handling of zero bytes in input files
This is certainly a corner case, but GCC and clang both accept zero
bytes at least in comments, and SWIG's current handling is to ignore
the zero byte and all following characters up to and including the next
newline, so for example if a // comment contains a zero byte SWIG would
quietly ignore the next line.

Closes #3010
2024-09-03 10:14:01 +12:00
Olly Betts 0ae9bb987e Add comment noting %(escape)s limitation 2024-08-17 16:17:24 +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 8513f24ec6 Add comment noting \e is a non-standard string escape 2024-08-15 14:39:21 +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 16680f59da Improve handling of bad octal and binary numbers
SWIG now gives an error for digits 8 and 9 in octal constants -
previously these were quietly accepted resulting in a bogus value.

C++11 binary constants are now treated similarly - only digits 0
and 1 were allowed before, but trying to use other digits now gives
a clearer error.
2024-08-15 13:47:47 +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 6eb2560e8d Stop removing `f` and `F` suffixes from float literals
This was resulting in incorrect generated C# and Java code.  For
some cases such as `#define CONSTANT 1.0f` this was a regression
introduced in 4.2.0 when we started more correctly wrapping these
as `float` rather than `double`.

Fixes #1917
2024-07-18 16:03:31 +12:00
Olly Betts 5dcb37310e Merge branch 'master' into C 2024-07-18 09:25:24 +12:00
William S Fulton 1e2b0b8079 Warning fix for redefined friend declarations that are also constexpr 2024-06-16 22:23:20 +01:00
Vadim Zeitlin 19c0b351e6 Merge branch 'master' into C
Perform only minimum conflict resolution, C backend tests don't pass
yet.
2024-06-16 16:24:15 +02:00
William S Fulton a3682dd3e5 Merge branch 'nspacemove'
* nspacemove:
  Improved namespace validity checks for the nspace feature
  Add docs for %nspacemove
  Add nspacemove example for STL types
  Validate scopename in nspace feature
  Fix %nspace and %nspacemove for nested classes and enums in a class
  Enhance %nspace with %nspacemove for moving symbols into a different target language namespace
  nspacemove testcase
  Correct code in javascript testcase for jsc

Conflicts:
	CHANGES.current
2024-06-01 13:45:48 +01:00
William S Fulton e4795e9af0 Validate scopename in nspace feature 2024-06-01 08:04:14 +01: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 f81fd4bf3e Fix function name in comment 2024-05-21 10:20:27 +12:00
Olly Betts f5daf83d47 Make a load of internal functions static
None of these are prototyped, used outside of the file they are
declared in, or documented aside from comments above the function.
2024-03-28 08:53:22 +13:00
Olly Betts 9a5dd880e8 Merge branch 'master' into C 2024-03-18 09:09:51 +13:00
William S Fulton 9441c9513c Add missing use of move constructor
instead of copy constructor when passing movable types by value.
Additional enhancement when passing movable types to constructors.

Enhancement to e777b054d5.
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
William S Fulton 5eac7bdaa8 Improve -debug-module option for template parameters
Show the template parameters as a string
2024-02-28 08:37:48 +00:00
Olly Betts ceafa131de Warn and ignore %constant with unsupported implicit type
SWIG 4.2.0 reported an assertion failure.  SWIG 4.1.1 generated
C/C++ code which failed to compile.
2024-02-14 18:00:51 +13:00
Olly Betts f04d424d46 Update example warning ignore comment
Replace a warning number which is no longer used.
2024-02-12 09:55:08 +13:00
William S Fulton dc11837c64 Command encoder error message improvement
Show the actual command to help diagnose as the line number info is missing
2024-02-03 14:29:01 +00:00
William S Fulton 6064dd8519 Remove redundant Clear call 2024-02-03 14:21:46 +00:00
Olly Betts e5af5dcadb Handle T_FLTCPLX in NewSwigType()
This fixes an assertion failure and segfault trying to use %constant
to deduce the type of a "float _Complex" constant.
2024-01-31 14:51:50 +13:00
Olly Betts 3de7c6723e Remove dead code
This "currently unimplemented" alternate universe version of
NewSwigType() has been disabled by a preprocessor conditional
for over 20 years.
2024-01-31 14:18:25 +13:00
William S Fulton 3be670e8db Fix assertion handling upcasting when using %shared_ptr on some templates.
A different approach is taken for supporting casting smart pointers up the
inheritance hierarchy. We no longer try to replace the underlying pointer type,
provided in the 'feature:smartptr', with the base class type. Such as morphing
'std::shared_ptr<(Derived)>' into 'std::shared_ptr<(Base)>'. Instead, we simply
use 'feature:smartptr' from the base class. This is more reliable than trying to
pattern match the pointer type in the feature. The base class must of course
also have the 'feature:smartptr' set, and this is still checked for as before.
The feature is now parsed in one place and stored in the parse tree in the
new 'smart' attribute for handling by the target languages.

Fix also improves the handling of the type parsed in 'feature:smartptr' in that
the type is now normalized and resolved in the scope of the class it is attached
to.

Closes #2768
2024-01-30 22:24:42 +00:00
Olly Betts 02b716ee29 Pass NULL instead of "" for name to SwigType_str()
Both have the same effect but "" takes a much more complicated code
path to achieve it.
2024-01-31 10:31:24 +13:00
William S Fulton fe6c096dcb gcc-4.8 warning fixes 2024-01-15 23:06:13 +00:00
William S Fulton cf996fcb41 Fix maybe uninitialized warnings 2023-12-21 01:13:24 +00:00
Olly Betts ab6397a891 Removed unused T_ENUM code
As best I can make out T_ENUM has never been used since it was added by
an apparently unrelated commit in 2000:
bcc6cbfb16
2023-12-01 08:59:30 +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
William S Fulton 68b0fd809f $typemap() fix for handling variable overrides
Fix when variable override contains a pointer dereference ->.
This enables use of $1.x as a variable override value as SWIG
replaces $1.x with a pointer dereference expression, such as
(&arg1)->x.

Added a testcase showing how Python typemaps could alternatively
be written using $typemap() instead of using C++ templates as used in
the UTL. I'm not convinced this is fully reliable or even a good idea,
so the variable replacements in $typemap() remain undocumented.
2023-11-03 09:07:51 +00:00