Commit Graph

692 Commits

Author SHA1 Message Date
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 3ce0174a0c Fix random doubled spaces in code 2023-11-17 09:49:36 +13:00
William S Fulton e8d3c74590 Improvements to $typemap() special variable replacement overrides
In $typemap(), the $n special variables are replaced by the appropriate
value for the type associated with the typemap calling $typemap().
The (undocumented) special variable overrides now also support
controlling what the $n special variables are replaced with from the
calling typemap, for example:

  %typemap(in) std::pair<std::string, int> {
    int& input_value_second = $1.second;
    $typemap(in, int, 1=input_value_second);
    ...
  }

replaces $1 in the int typemap with input_value_second instead of
whatever is the default for the target language (a variable that holds
the int value after marshalling from the target language).

This additional functionality might make it possible to replace the C++
templates used in the UTL with a much simpler system of typemaps utilising
$typemap(). See follow on commit to typemaps.c.
2023-11-03 09:07:51 +00:00
William S Fulton 791d0a5e17 Further using declarations fix for inheritance hierarchies
more than two deep and the using declarations are overloaded.
Using declarations from a base class' base were not available for use
in the target language when the using declaration was before a method
declaration.

Closes #2687
2023-10-16 20:05:34 +01:00
William S Fulton 7bba06b03e Java - SWIGWORDSIZE64 for long type
Defining SWIGWORDSIZE64 now applies the (unsigned) long long
typemaps to (unsigned) long for a better match on systems
where long is 64-bits.

Although size_t typemaps are now applied from the int typemaps instead
of the long typemaps, identical code is generated and the mapping is
still to the Java signed long type.

Closes #646
Closes #649

Running the test-suite as follows on a 64-bit long system:

  env SWIG_FEATURES=-DSWIGWORDSIZE64 make check-java-test-suite

passes, except for a few tests which fail where they expect the
default Java type to be int or long instead of long or BigInteger
respectively.

Also arrays_java.i results in:
  invalid conversion from ‘long int*’ to ‘long long int*’ [-fpermissive]
  invalid conversion from ‘long int**’ to ‘long long int**’ [-fpermissive]
2023-10-05 21:30:30 +01:00
William S Fulton 650aad82ed Fix incorrect variable setters being generated when wrapping arrays
A setter is no longer generated if the type of the array members
are non-assignable.
2023-09-09 19:15:15 +01: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 ec53b06b8a Restore missing variable setters for types containing non-assignable static members
A struct/class that contains a non-assignable member variable is
actually assignable itself. Only non-static members, not static members,
contribute to the containing class being non-assignable.

Recent regression fix from a few commits back.
2023-09-08 07:49:01 +01:00
William S Fulton 275764c7bb Non-assignable detection fixes when wrapping rvalue reference variables
Rvalue reference variables such as the following are non-assignable by
by default:

  X &&v;

Variable setters are not generated when wrapping these non-assignable
variables and classes containing such non-assignable variables.
2023-09-07 07:02:35 +01:00
William S Fulton 912c535add Non-assignable detection fixes when wrapping reference variables
Reference variables such as the following are non-assignable by
by default:

  int &v;

Variable setters are not generated when wrapping these non-assignable
variables and classes containing such non-assignable variables.
2023-09-07 07:02:35 +01:00
William S Fulton f3e12fbd47 Assignment operator detection fixes when wrapping static member variables
Also add tests for global variables are immutable via assignment.
2023-09-07 07:02:35 +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 5284999bde Add tests for C++11 deleted assignment operators and member variables
Check that setters are not generated if the member variable is not
assignable.
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 bf330ba524 C++11 deleted destructors fixes
Fix problems wrapping deleted destructors. Derived classes are not
constructible, so don't attempt to generate default constructor or
copy constructor wrappers.

  struct StackOnly1 {
    // Only constructible on the stack
    ~StackOnly1() = delete;
  };
  struct StackOnlyDerived1 : StackOnly1 {
    // this class is not constructible due to deleted base destructor
  };
2023-09-02 22:55:58 +01:00
William S Fulton 33d45f0428 Fix %copyctor feature and C++11 deleted copy constructors
A default constructor wrapper was sometimes incorrectly generated.
2023-09-02 16:55:01 +01:00
William S Fulton fb7e0ef069 C++11 single default deleted constructor fix
Fix for when a class has a default deleted constructor and does
not have any other constructors (except implicit or explicit copy
constructors).

Closes #1644
2023-09-02 14:07:47 +01:00
William S Fulton 605e5a1abb C++11 default deleted constructors fix
SwigValueWrapper was not being used when the default constructor is
deleted for a type passed around by value.

Fix is only for when other constructors declarations are present,
deleted, defaulted or not.

Issue #1644
2023-09-02 12:35:39 +01:00
William S Fulton 2e1506c189 Add support for using declarations to introduce templated members
Add support for using declarations to introduce templated member
methods and for inheriting templated constructors, such as:

  struct Base {
    // templated constructor
    template <typename T> Base(const T &t, const char *s) {}
    // templated member method
    template <typename T> void template_method(const T &t, const char *s) {}
  };

  %template(Base) Base::Base<int>;
  %template(template_method) Base::template_method<double>;

  struct Derived : Base {
    using Base::Base;
    using Base::template_method;
  };

Previously the templated methods and constructors were ignored and
not introduced into the Derived class.
2023-08-07 07:37:28 +01:00
William S Fulton 93732bb195 Fix using declarations for deep inheritance hierarchies
Fixes inheritance hierarchies more than two deep and the using
declarations are overloaded. Using declarations
from a base class' base were not available for use in the target
language. For example in the code below, Using1::usingmethod(int i)
was not wrapped for use in Using3:

  struct Using1 {
  protected:
    void usingmethod(int i) {}
  };
  struct Using2 : Using1 {
  protected:
    void usingmethod(int i, int j) {}
    using Using1::usingmethod;
  };
  struct Using3 : Using2 {
    void usingmethod(int i, int j, int k) {}
    using Using2::usingmethod;
  };

Similarly for C++11 using declarations for inheriting constructors.
2023-08-05 19:47:17 +01:00
William S Fulton 69d5373131 Fix missing constructor generation due to abstract class test failure
when a method is declared in the class along with a
using declaration and the using declaration is declared before
the method that implemented the pure virtual method, such as:

  struct ConcreteDerived : AbstractBase {
    ConcreteDerived() {} // was not wrapped
    using AbstractBase::f;
    virtual void f(int n) override {}
  };

SourceForge bug: https://sourceforge.net/p/swig/bugs/932/

check_implemented in allocate.cxx was correctly finding a
non-abstract method, however, Swig_symbol_clookup_local_check, was
using the using declaration node instead of using the node returned
by check_implemented. The checkfunc is now given more control by
returning the node to use rather than Swig_symbol_clookup_local_check
always using the head of the csym linked list.
2023-08-05 19:47:17 +01:00
William S Fulton 74e1deef6b Fix %copyctor used on class hierarchies with non-const copy constructor
Previously SWIG always attempted to call a copy constructor
taking a const reference parameter instead of a non-const
reference parameter.
2023-07-29 18:16:40 +01:00
William S Fulton 5e1a37c6c5 Fix duplicate sym:overname values using %copyctor
The sym:overname attribute was not being updated when templates were
included in the list of overloaded methods/constructors, leading to
duplicate target language symbols in some language like java/csharp.

Closes #2541
2023-07-29 00:28:28 +01:00
William S Fulton 94ab699075 Consistency in warnings for ambiguous/redefined templated constructors
Constructors used to warn with:
  Warning 302: Identifier 'Json' redefined (ignored)
But now warn with:
  Warning 322: Redundant redeclaration of 'Json'

Note that 320 is a warning that is shown by default and 322 is a
hidden warning by default.

The warning is now consistent for both templated methods and constructors
that are deemed redefined. See cpp11_template_parameters_decltype
testcase. This testcase has been enhanced with a runtime test to check
that the workarounds for overloaded templated constructors/methods do
work.
2023-07-25 20:04:49 +01: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 525426911c C++11 using declarations for inheriting implicit base templated constructors
Testcase - compiles given previous commit, but needs more work!
2023-07-21 19:28:27 +01:00
William S Fulton 2ff9da0ce6 Constructors and destructors declared with template parameters
Recent commits for internal constructor and destructor names resulted
in destructors declared with template parameters being ignored
with warnings like:
  Illegal destructor name TemplPublicBase6< int >::~TemplPublicBase6(). Ignored.

Although declaring constructors and destructors with template parameters
are rejected by modern compilers and C++20, SWIG continues to support it.

Make sure the name stored in the parse tree is the C++20 compliant name
name, that is, without the template parameters.

Fixes using declarations for templated constructors declared with
template parameters, was warning with:
  Nothing known about 'TemplPublicBase6< int >::TemplPublicBase6'.
2023-07-18 19:29:40 +01:00
William S Fulton 0830c96e1b More director protected constructor tests 2023-07-15 15:17:15 +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 feb8e2e641 Fix C++11 using declarations for inheriting implicit base constructors
Parser no longer checks for a declared constructor when handling a
using declaration in order to correct the name as it won't find
implicitly declared constructors. Now it checks that a using
declaration is for something that looks like a constructor instead
by checking the immediate base classes for allowed constructors.
2023-07-14 08:39:27 +01:00
William S Fulton b7332ce8ca Fix using declarations and templates with explicitly declared constructors
Corner case problem fix for when the base template class was
instantiated with %template including the default arguments and
the base class had an explicitly declared constructor.

Swig_symbol_template_deftype() was sometimes incorrectly finding
a constructor instead of a template and thus failing to correctly
expand the template default args. Problem noticed since
9cf049186b where constructors are
stored simply by their name instead of name plus template args.

Probably fixes a few other subtle template problems when a template
class contains default args.
2023-07-12 18:44:42 +01:00
William S Fulton 30e68625af Add testcase for using declarations and templates 2023-07-09 15:56:20 +01:00
William S Fulton a0bde3f319 C++11 using declarations for inheriting constructors - template classes with template base classes
Internal using name no longer contains template parameters.
Fixes symbol table lookup for non-instantiated template constructor.
Builds on previous few commits where the internal name no longer
contains the template parameters for constructors and destructors.
2023-07-08 20:01:39 +01:00
William S Fulton 5b9179ea7e C++11 using declarations for template classes with non-template base classes 2023-07-07 12:05:09 +01:00
William S Fulton e73a1b91a3 C++11 using declarations for inheriting overloaded constructors
Fixes for C++11 using declarations for inheriting constructors
when the constructors are overloaded.
2023-07-05 00:10:47 +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 3ef3f39516 Fix syntax error parsing an expression
which calls a function with no parameters within additional brackets.

This is more of a hack than a fix as attempts to parse properly
failed, see issue #2640.

Closes #2640
2023-06-30 08:54:23 +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 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 8a73e25fe2 argcargv.i: NULL terminate argv with empty input
Fixes needed for: C# R
2023-05-23 10:12:49 +12:00
Olly Betts 1594a89afa [Java] Handle empty Java array 2023-05-22 14:08:13 +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
Erez Geva bdc2190cde Add argc and argv multi-argument typemap to Java, Guile, JavaScript, Scilab and C#
Fixes #2552

Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
2023-05-20 16:17:00 +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
William S Fulton 4a6f6283aa Fix duplicate const in generated code wrapping templates
Fix duplicate const in generated code when template instantiation type is const
and use of template parameter is also explicitly const, such as:

  template <typename T> struct Conster {
    void cccc1(T const& t) {}
  };
  %template(ConsterInt) Conster<const int>;

Above previously led to generated code:
  (arg1)->cccc1((int const const &)*arg2);
instead of
  (arg1)->cccc1((int const &)*arg2);
2023-03-08 19:45:17 +00:00