Commit graph

5,431 commits

Author SHA1 Message Date
William S Fulton
004af63f3c Syntax error fixes parsing more elaborate parameter pack arguments
that are function pointers and member function pointers.

  template <typename... V> struct VariadicParms {
    void ParmsFuncPtrPtr(int (*)(V*...)) {}
    void ParmsFuncPtrPtrRef(int (*)(V*&...)) {}
    void ParmsFuncPtrPtrRValueRef(int (*)(V*&&...)) {}
    void ParmsFuncPtrRef(int (*)(V&...)) {}
    void ParmsFuncPtrRValueRef(int (*)(V&&...)) {}

    void ParmsMemFuncPtrPtr(int (KlassMemFuncs::*)(V*...)) {}
    void ParmsMemFuncPtrPtrRef(int (KlassMemFuncs::*)(V*&...)) {}
    void ParmsMemFuncPtrPtrRValueRef(int (KlassMemFuncs::*)(V*&&...)) {}
    void ParmsMemFuncPtrRef(int (KlassMemFuncs::*)(V&...)) {}
    void ParmsMemFuncPtrRValueRef(int (KlassMemFuncs::*)(V&&...)) {}
  };

  %template(VariadicParms0) VariadicParms<>;
  %template(VariadicParms1) VariadicParms<A>;

  Also in various other places such as within noexcept specifiers:

    template<typename T, typename... Args>
    void emplace(Args &&... args) noexcept(
        std::is_nothrow_constructible<T, Args &&...>::value);

Issue #1863
2022-12-30 00:19:02 +00:00
William S Fulton
674abaddbf Fix instantiation of variadic class templates
containing parameter pack arguments that are function pointers.

  template <typename... V> struct VariadicParms {
    void ParmsFuncPtrVal(int (*)(V...)) {}
  };

  %template(VariadicParms0) VariadicParms<>;
  %template(VariadicParms1) VariadicParms<A>;
2022-12-29 23:38:17 +00:00
William S Fulton
70837bbc26 Fix syntax error parsing variadic template parameter pack arguments
that are function pointers

Issue #1863
2022-12-23 16:25:50 +00:00
William S Fulton
91af6cba27 Parser code refactor around variadic types 2022-12-22 21:23:44 +00:00
William S Fulton
f648e58cb1 Extend variadic template support to various type combinations 2022-12-22 21:23:44 +00:00
William S Fulton
67c4c2186c Support multiple arguments in variadic templates.
Remove warning SWIGWARN_CPP11_VARIADIC_TEMPLATE which was issued if more
than one argument was used for a variadic template.

SwigType enhancement: 'v.' now represents a variadic argument.
2022-12-22 21:23:39 +00:00
William S Fulton
1e73045da8 Refactor Swig_cparse_template_parms_expand()
Break up functionality in Swig_cparse_template_parms_expand() to make it
more readable / maintainable.
2022-12-21 20:15:47 +00:00
William S Fulton
9e8a0daf9e Refactor %template parameters handling
Move code from %template parsing in parser.y into new function
Swig_cparse_template_parms_expand
2022-12-09 19:23:57 +00:00
William S Fulton
8a24c19d26 Fix syntax error for misplaced Doxygen comment after struct/class member.
Fix syntax error using Doxygen member groups syntax, "///*}", when used after
final struct/class member.

Issue #1636
2022-12-06 21:31:38 +00:00
William S Fulton
dc04564023 Improved handling of Doxygen comments in parameter lists
Fix garbled Doxygen post comments in parameter lists.
Fix syntax error parsing a trailing Doxygen comment in parameter lists.

Closes #2023
2022-12-05 19:47:59 +00:00
William S Fulton
f7b4127310 Fix syntax error parsing of Doxygen comments after last enum item
It is unconventional to have a doxygen comment after an enum item. It is
attached to the previous, that is, the enum item to match Doxygen behaviour.

Closes #1609
2022-12-03 10:09:37 +00:00
William S Fulton
24f75aa481 Fix parsing of unconventional Doxygen post comments for enum items.
Closes #1715
2022-12-03 09:49:42 +00:00
William S Fulton
7bdc708e5f Template parameters handling tidy up
Technical correction on how template parameters are stored in a Parm*.
Doesn't actually make any change, but they are now displayed correctly
when using debug options such as -debug-module.
2022-12-02 19:44:59 +00:00
William S Fulton
05b93b1f06 Improved template template parameters support.
Previously, specifying more than one simple template template parameter
resulted in a parse error. Now multiple template template parameters are
working including instantiation with %template. Example:

  template <template<template<class> class, class> class Op, template<class> class X, class Y>
    class C { ... };

Closes #624
Closes #1021
2022-12-02 19:16:02 +00:00
William S Fulton
c5e02bf327 Ocaml name mangling fix
Fixes testcase template_expr which was resulting in OCaml syntax errors.
2022-11-29 08:04:37 +00:00
William S Fulton
2a1711e436 Slightly better decltype() support for expressions
decltype now accepts C++ expressions instead of just an ID, such as:

  int i,j;
  ...  decltype(i+j) ...
  ...  decltype(&i) ...

These result in a warning for non-trivial expressions which SWIG cannot evaluate:

  Warning 344: Unable to deduce decltype for 'i+j'.

See 'Type Inference' in CPlusPlus.html for workarounds.

Issue #1589
Issue #1590
2022-11-26 01:16:20 +00:00
William S Fulton
9b91b24d6b Fix syntax error parsing unnamed template parameters with a default.
Closes #961
2022-11-25 08:37:39 +00:00
Olly Betts
081d44d45e Follow-on fix for previous change
These cases don't trigger ubsan warnings and seem to work locally
for me, but CI was failing on a number of builds.

See #2447
2022-11-25 12:29:52 +13:00
Olly Betts
81c6a63898 Fix undefined behaviour in parser
Fix undefined behaviour in swig's parser when handling default parameter
expressions containing method calls.

Fixes #2447
2022-11-25 09:51:58 +13:00
William S Fulton
d3095144e1 Optimise SwigType_base implementation
Also fixes assumption that templates start '<' instead of '<('.
Checked java and python test-suite - no changes in output.
2022-11-23 20:22:40 +00:00
William S Fulton
ca5c68e544 Fix seg fault handling template parameter expressions containing '>='
Similar to previous commit

Issue #1037
2022-11-22 21:40:38 +00:00
William S Fulton
0341258af7 Fix seg fault handling template parameter expressions containing '<='
Recent commits ensure types are correctly stored in SwigType *. In
particular template parameters are enclosed within '<(' and ')>'.
Now we can confidently handle template parameters as really being
delimited as such to fix an infinite loop handling template expressions
containing '<' or '>'. The previous implementation only assumed
template parameters were delimited by '<' and '>'.

Issue #1037
2022-11-22 08:37:35 +00:00
William S Fulton
29bc7492a2 SwigType * handling corrections - Python builtin 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 *.

The previous commit is a pre-requisite in order to prevent duplicate
symbols from being generated in the C++ wrappers.
2022-11-18 19:44:00 +00:00
William S Fulton
4729cf2b1f Duplicate class template instantiations via %template changes
Named duplicate class template instantiations now issue a warning and are ignored.
Duplicate empty class template instantiations are quietly ignored.

The test cases are fixed for this new behaviour.

This commit is a pre-requisite for the near future so that the Python
builtin wrappers can correctly use the SwigType_namestr function without
generating duplicate symbol names.
2022-11-18 19:35:47 +00:00
William S Fulton
777fd2c280 Minor refactor of D, C#, Java director code
for overloaded methods. Fixes regression (crash) in director_ignore D
testcase since string mangling names change.
2022-11-12 16:30:25 +00:00
William S Fulton
e3ccabbd4d Simpler names when using SwigType_manglestr for templates
The default template name is generated instead of one with the default
template parameter.

Used in various places such as the type system.
2022-11-12 11:46:52 +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
3364c18d06 Remove unused code in mzscheme.cxx 2022-11-12 09:06:26 +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
William S Fulton
2acdfd77e9 SwigType * handling corrections
Further corrections to pass SwigType * to methods expecting types
instead of passing readable type strings.

Required reworking code that adds a fake inheritance for smart pointers
using the smartptr feature. Swig_smartptr_upcast() added as a support
function for this.
2022-11-09 22:11:27 +00:00
William S Fulton
ea3f043920 SwigValueWrapper and SwigType * correction
Modifying the type by adding in SwigValueWrapper needs to follow the
normal SwigType conventions for correct and proper type handling.
2022-11-08 09:11:35 +00:00
William S Fulton
52edda64c1 Fix infinite loop handling non-type template parameters
Fixes infinite loop due to () brackets in a non-type template
parameter containing an expression

Fixes #2418

Non-trivial expressions are still not qualified properly though.
2022-11-05 08:41:10 +00:00
William S Fulton
973590ff91 R rtypecheck typemaps
Further switch to use rtypecheck typemaps instead of hard coded logic.
The full switch to typemaps is deferred until swig-4.2 as it can't be fully
backwards compatible. For now a warning is provided to help the
transition. It provides the full typemap that should be placed into
a user's interface file, for example:

%typemap("rtype") int32_t * "integer"
void testmethod(int32_t * i);
void testmethod();

If there is no rtypecheck typemap for int32_t *, the warning shown is:

example.i:7: Warning 750: Optional rtypecheck code is deprecated. Add the
following typemap to fix as the next version of SWIG will not work without it:
%typemap("rtypecheck") int32_t * %{ (is.integer($arg) || is.numeric($arg)) %}

The warning is shown for any code that previously used "numeric", "integer" or
"character" for the rtype typemap. Copying the rtypecheck typemap as
shown into the user interface file will provide the appropriate fix and
the warning will disappear. This is important to do as swig-4.2 will
not be able to provide this helpful warning.
2022-11-05 08:40:26 +00:00
William S Fulton
d6d83f4df4 Overloading fixes for R and rtypecheck typemap
- Fix for special variable $argtype expansion in rtypecheck typemap.
- Remove unnecessary () brackets when using rtypecheck typemap for
  single parameter functions.
- Add rtypecheck typemaps for shared_ptr so that NULL can be used
  in overloaded functions taking shared_ptr.
2022-11-05 08:40:26 +00:00
William S Fulton
f2da4f2ade Improve R wrapper error message calling overloaded methods
when incorrect types passed are passed to the overloaded methods.

Old unhelpful error message:
  Error in f(...) : could not find function "f"

Example of new improved error message:
  Error in use_count(k) :
    cannot find overloaded function for use_count with argtypes (NULL)
2022-11-05 08:40:19 +00:00
Olly Betts
df716b8f00 Document that -php7 is for PHP 7 *or later*
This was already in the manual, but not in -help output.

Fixes #2420
2022-10-31 13:41:10 +13:00
William S Fulton
a5b4a4389c Merge branch 'rfix-cleaned-up'
* rfix-cleaned-up:
  Whitespace cleanup in R testcase
  R shared_ptr fixes
  align implementation of smartname to r class name
  enable test for pointerreftest fixed by 752b7e8
  switched implementation reference from java to python
  fixes from code review
  enable li_boost_shared_ptr in r-test-suite
  typo in comment
  fix naming of RClass when template of a shared_ptr
2022-10-24 19:39:34 +01:00
William S Fulton
6c4dcbb8fe R shared_ptr fixes
Fix problems in shared_ptr wrappers where the class names were
not consistent when using the shared_ptr template or the actual
underlying type. Move $R_class substitution to typemaps.

Issue #2386
2022-10-24 19:37:56 +01:00
William S Fulton
4a8f7a9c46 Visual C++ warning fixes 2022-10-24 18:43:31 +01:00
AndLLA
0fec14ba34 align implementation of smartname to r class name 2022-10-24 18:20:10 +01:00
AndLLA
b885c22f11 fixes from code review 2022-10-24 18:20:10 +01:00
AndLLA
b15e058a27 typo in comment 2022-10-24 18:20:10 +01:00
AndLLA
a71bb2bc6e fix naming of RClass when template of a shared_ptr 2022-10-24 18:20:10 +01:00
William S Fulton
38c2c15e61 Merge branch 'MSB8027'
* MSB8027:
  CMake: Avoid including parser.c twice
  Fix -Wunused-variable warning
2022-10-24 16:28:29 +01:00
William S Fulton
6370fab025 R - fix $typemap() for R specific typemaps
Add support for special variable replacement in the $typemap()
special variable macro for R specific typemaps (rtype, rtypecheck,
scoercein, scoereout).
2022-10-24 16:27:54 +01:00
William S Fulton
1d73341aa4 Polymorphism in R wrappers fixed for C++ structs 2022-10-24 08:56:55 +01:00
Julien Schueller
0d523d337d Fix -Wunused-variable warning 2022-10-24 09:34:10 +02: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
William S Fulton
15c433c5f9 C89 fixes 2022-10-14 22:34:18 +01:00
Olly Betts
5f96d15943 [R] Run destructors of local C++ objects on SWIG_fail
Arrange that destructors of local C++ objects in the wrapper function
get run on SWIG_fail (which calls Rf_error() which calls longjmp()).

We achieve this by putting almost everything in the function in its
own block, and end that right before Rf_error() at which point those
destructors will get called.
2022-10-14 14:44:19 +13:00