Commit Graph

380 Commits

Author SHA1 Message Date
William S Fulton f91a9cb8e4 Use SWIG_NOEXCEPT for deprecated dynamic exception specifications
SWIG_NOEXCEPT is generated instead of throw() which is deprecated in
c++11. If c++11 or later is being used, then this macro expands to
noexcept instead of throw().

Affects director code only.

Also fix up some testcase to not use throw() when using c++11 or later.
Tested with clang and -Wdeprecated-dynamic-exception-spec as gcc
doesn't seem to warn for this deprecation.

Closes #3027
2025-04-29 22:41:09 +01: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 494a782714 Fix some source comments 2024-07-19 09:28:33 +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
William S Fulton feaabb0d2a template templated static methods support
Fix compilation errors in generated code when instantiating a templated
static method within a template (non-static methods and constructors were
always okay). For example:

  template <typename T> class X {
    template <class InputIterator>
      static void fn(InputIterator first, InputIterator last) { ... }
  };
  class SimpleIterator { ... };

  %extend X<int> {
    %template(fn) fn<SimpleIterator>;
  }

The problem being fixed here is an extended method was generated when it
should not have been as for other %template instantiations within a
template - the template can be called directly.

Test includes variadic static method templates in a template, including
method overloading..
2024-02-28 22:32:04 +00:00
William S Fulton 71b0073ff7 Improve language symbols error reporting
Old...
example.i:8: Error: 'Type' is multiply defined in the generated target language module.
:EOF: Error: Previous declaration of 'Type'

New...
example.i:8: Error: 'Type' is multiply defined in the generated target language module.
example.i:7: Error: Previous declaration of 'Type'

Fixes many cases, but the language symbols need more work in order for
deeper scopes to report the file/line numbering correctly.

Example from issue #1897
2024-02-03 14:29:01 +00:00
William S Fulton a742321f11 Fix missing line/file info in error message 'Recursive typedef detected...' 2024-02-03 14:27:37 +00: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 9a691f44c7 Correct initialization order in Language 2023-10-19 08:47:45 +01:00
Rose c4a4717a28 Remove redundant initialization code
Some of this code is redundant and taken care of by the initializer.
2023-10-16 16:48:04 -04:00
William S Fulton d4abe14f7e Non-assignable detection fixes when wrapping const 2D arrays
Const member variables such as the following are non-assignable by
by default:

  const int x[2][2];

Variable setters are not generated when wrapping these non-assignable
variables and classes containing such non-assignable variables.
2023-09-09 12:31:33 +01:00
William S Fulton c96c04c5ae Non-assignable detection fixes when wrapping const member variables
Const member variables such as the following are non-assignable by
by default:

  char * const x;
  const int x;
  const int x[1];

but not:

  const char * x;

Variable setters are not generated when wrapping these non-assignable
variables and classes containing such non-assignable variables.
2023-09-09 06:24:14 +01:00
William S Fulton c0b36721a3 Replace Language::is_assignable with Language::is_immutable
Avoids confusion with newly created Allocate::is_assignable.
Language::is_immutable is just a wrapper around the
"feature:immutable" flag since previous commit.

is_mutable rename wip
2023-09-07 07:01:37 +01:00
William S Fulton e07957ad4c Implicit assignment operator detection fixes.
A class that does not have an explicit assignment operator does not
have an implicit assignment operator if a member variable is not
assignable. Similarly should one of the base classes also not be
assignable. Detection of these scenarios has been fixed so that when
wrapping a variable that is not assignable, a variable setter is not
generated in order to avoid a compiler error.

Template instantiation via %template is required in order for this to
work for templates that are not assignable.

Closes #1416
2023-09-07 04:41:52 +01:00
William S Fulton f11bffcb19 Variable setters for non-assignable types
Fix incorrect variable setters being generated when the type of the
variable is not assignable, due to variable type inheriting a private
assignment operator further up the inheritance chain (further up than
the immediate base).
2023-09-04 07:34:06 +01:00
William S Fulton e69f77f2e1 Remove unused "has_constructor" internal attribute 2023-09-02 17:16:12 +01:00
William S Fulton b9f1515514 Corrected type returned from calling nodeType 2023-08-05 19:46:15 +01:00
Olly Betts 31c73a2b85 Fix comments to match actual function return value 2023-08-01 12:03:46 +12:00
William S Fulton eb18619178 More refactoring for internal destructor and constructor names
Further removal of template parameters from the "name" attribute for
constructors and destructors.

Add test case for templated constructor instantiations - based on the
Python and Octave only li_std_pair_extra.i test which caused problems
making this change.
2023-07-22 18:21:32 +01:00
William S Fulton 6bcf612c92 C++11 using declarations for inheriting constructors
Support extended to directors.

Go protected constructors fix required for new testcase:
- Emit wrappers if director class is abstract
- If called, errors out with: accessing abstract class or protected constructor
- Now consistent with other target languages
2023-07-15 12:41:12 +01:00
William S Fulton d387ea21d6 Move addCopyConstructor, addDefaultConstructor, addDestructor from Language to Allocate
This is one more step in the direction of supporting C++11 using
declarations for inheriting constructors that are implied/non-explicit
in a base class.

This step now adds the default constructor/destructors to the parse tree
in the earlier Allocate stage of processing the parse tree instead of
the language specific stage.

Doing this in the Allocate stage is much more sensible as this is the
stage that is primarily analysing the classes that require implied default
constructors and destructors.

Only minor complication is that the Language class controls most of the
director code generation and requires the previous commit to move director
enablement detection into Swig_directors_enabled() which is callable from
the Allocate class.
2023-07-14 08:39:27 +01:00
William S Fulton 84542f6b59 Replace Language::directorsEnabled() with Swig_directors_enabled()
For use outside of the target languages for forthcoming commits
which move adding default constructors/destructors from Language
to Allocate.
2023-07-12 18:44:42 +01:00
William S Fulton e138b0bae1 Internal destructor name no longer contains template parameters
This is for consistency with other members.

Notable side effects:
    - When $name is replaced in a constructor it no longer includes any
      template parameters, so similar to member functions which also
      don't include template parameters (li_boost_shared_ptr testcase)
2023-07-08 10:30:33 +01:00
William S Fulton 9cf049186b Internal constructor name no longer contains template parameters
This is for consistency with other members.
Fixes csymbol table name for the constructor.

Notable side effects:

- When $name is replaced in a constructor it no longer includes any
  template parameters, so similar to member functions which also
  don't include template parameters (li_boost_shared_ptr testcase)
- Fixes mangled C constructor name when using nested templates
  (nested_in_template, template_nested testcases)
- Fixes some typedef look up when generating templates that have
  default template parameters, to improve generated code so that
  the default parameters are no longer explicitly generated when
  the template type is used (template_default_class_parms_typedef
  testcase)
- For Ruby, better error messages when calling constructors,
  old:
    runme.rb:5:in `initialize': Expected argument 0 of type int, but got String "hi" (TypeError)
	in SWIG method 'Temply<(int)>'
  new:
    runme.rb:5:in `initialize': Expected argument 0 of type int, but got String "hi" (TypeError)
	in SWIG method 'Temply'
- Feature matching of parameters that are template types is now
  consistent for parameters in constructors and methods
  (features testcase)
  Potential incompatibility though:
  old:
    %exception Template<int>::Template(const Template&) "..."
  new:
    %exception Template<int>::Template(const Template<int>&) "..."
2023-07-08 10:30:33 +01:00
William S Fulton 1d1aab2925 Refactor accessDeclaration methods 2023-07-04 12:13:23 +01:00
William S Fulton 61e60271fe Add support for C++11 using declarations for inheriting constructors
Closes #2641
2023-07-04 12:07:16 +01:00
William S Fulton 49e60c7d56 Fix directors and allprotected mode and using declarations.
Fixes recently introduced seg fault, but this has never worked properly.

Closes #2616
2023-06-24 12:29:59 +01:00
Olly Betts af7099432c Remove deprecated -make_default, -no_default, etc 2023-06-15 15:06:04 +12:00
Olly Betts 736c052d7d Remove long deprecated features
These features were all deprecated in 1.3.26 (October 9, 2005)
or before (many long before), so all more than 17 years and 3 new major
versions ago which seems more than enough time for users to have stopped
using them, especially as most emit a deprecation warning if used.
2023-06-15 15:05:15 +12:00
Olly Betts b1388bcbf9 Parse storage class more flexibly
Previously we had a hard-coded list of allowed combinations in the
grammar, but this suffers from combinatorial explosion, and results
in a vague `Syntax error in input` error for invalid (and missing)
combinations.

This means we now support a number of cases which are valid C++
but weren't supported.

Fixes #302
Fixes #2079 (friend constexpr)
Fixes #2474 (virtual explicit)
2023-05-11 13:54:30 +12:00
William S Fulton 7dccbf8694 Duplicate parameter name handling improvements
When a method with duplicate parameter names is wrapped such as:

  void fn_3parms(int p_a, int p_a, double p_c);

Previously all duplicate parameter names were changed in order to
provide unique parameter names:
  void fn_3parms(int arg0, int arg1, double p_c)
Now the parameter names changed are just the 2nd and subsequent duplicate
parameter names:
  void fn_3parms(int p_a, int arg1, double p_c)
2023-02-18 16:28:33 +00:00
William S Fulton 46f2778412 Consolidate name mangling functions
Swig_string_mangle      => Swig_name_mangle_string
Swig_name_mangle        => Swig_name_mangle_string
Swig_string_mangle_type => Swig_name_mangle_type
2022-11-12 09:18:19 +00:00
William S Fulton 6a9be797e1 SwigType * handling corrections - mangling
Further corrections to pass SwigType * to methods expecting types
instead of passing readable type strings.

Swig_string_mangle() takes a generic String *, but it was calling
functions that require SwigType *. Swig_string_mangle_type() is
now provided for SwigType *r. The special template handling
on types now occurs in this function.
2022-11-12 06:42:36 +00:00
Olly Betts 631b41ae7b Use https for swig.org links 2022-10-06 13:16:39 +13:00
Vadim Zeitlin b9fa8c23bb Make method wrappers suffix optional and disabled by default
Unfortunately the changes of 26bf86322 (Use SWIG-specific for
non-overloaded synthesized functions too, 2021-11-09) did break some
existing code bases using SWIG as they hardcoded the old wrapper
function names.

So turn this off by default and add a global variable allowing to enable
this, which can be done for a specific language only. This is ugly but,
unfortunately, there is no way to use the Language object from the C
function Swig_MethodToFunction(), so the only alternative would be to
add another parameter to it, but it already has 6 of them, so it
wouldn't really be that much better.

See #2366, #2368, #2370.
2022-09-19 12:40:03 +12:00
Olly Betts b2c58115d7 Fix previous commit
Revert changes inadvertently included, and fix `=` to `==`.
2022-03-20 19:44:23 +13:00
Olly Betts 029ddab8b5 [ci] Try to fix failing appveyor python builds 2022-03-20 18:42:50 +13:00
William S Fulton 50518d4e77 Using declarations, directors and overloaded methods
Language::unrollVirtualMethods was assuming that the using
declaration would only introduce one method. Fix this by adding
in all the overloaded methods from a base class.

Affects code generation in C# and Java, but I was not able
to construct a test that failed before this commit.
2022-03-10 22:18:23 +00:00
William S Fulton 8a8532d823 Refactor code out of Language::unrollVirtualMethods
Move code in main loop into new function to handle one method at a time.
In preparation for next commit for using declaration fix.
Remove unused default_director variable.
2022-03-10 22:18:23 +00:00
William S Fulton fe27e3d2ba Language::unrollVirtualMethods variable initialisation refactor 2022-03-10 22:18:23 +00:00
Vadim Zeitlin 26bf86322b Use SWIG-specific for non-overloaded synthesized functions too
This avoids conflicts between such functions, which are generated when
using %extend to add static methods to an existing class, and the actual
wrapper functions generated by the backend.

This shouldn't result in any user-visible changes.
2021-11-09 23:35:30 +01:00
Vadim Zeitlin 119222be77 Refactor code in Language::staticmemberfunctionHandler()
No real changes, just move the test for "code" to the outer scope to
facilitate the upcoming changes.

This commit is best viewed ignoring whitespace-only changes.
2021-11-09 23:35:28 +01:00
Olly Betts 9ddc9dceb7 Remove support for $source and $target
These were officially deprecated in 2001, and attempts to use them have
resulted in a warning (including a pointer to what to update them to)
for most if not all of that time.

Fixes #1984
2021-04-30 10:20:14 +12:00
William S Fulton 39b44a377a Warning tweaks for destructors that are final in director classes 2019-03-03 15:12:29 +00:00
William S Fulton 3b07cba740 Fixes for final destructors in director classes
A class marked as a director with a final destructor should not be a
wrapped as a director class. Fix seg faults in this case.
2019-03-03 14:52:52 +00:00
William S Fulton b9c4a84780 Warning fix for final destructor in directors
Fix suppression of final destructors used in director classes.
Add testcase for final destructors in director classes.
2019-03-02 19:02:35 +00:00
Zackery Spytz c3d652c785 Fix the handling of director classes with final methods
Generated SwigDirector_* classes were attempting to override
methods marked as final.

In addition, give a warning if the destructor of a director class is
final.

Closes #564.
2019-02-22 06:28:53 -07:00
Alec Woods 86e08c8e34 Fixes so that fastproxy and autodoc work correctly with both low-level C API and high-level Python Shadow API 2019-01-26 09:30:26 -05:00
Alec Woods 591a70378e Fixing python docstring handling for -fastproxy 2019-01-26 09:30:26 -05:00
Vadim Zeitlin 3f5c17824c Improve handling parameters clashing with language keywords
Previously, only Python tried to preserve the original parameter name
(by prepending or appending an underscore to it, but otherwise keeping
the original name) if it conflicted with one of the language keywords,
while all the other languages replaced the parameter name with a
meaningless "argN" in this case.

Now do this for all languages as this results in more readable generated
code and there doesn't seem to be any reason to restrict this to Python
only.
2019-01-16 04:16:59 +01:00