Commit graph

440 commits

Author SHA1 Message Date
William S Fulton
e8ebadcded Add director shared_ptr typemaps for Java
Correct testcase to test T*const& rather than T*& typemaps
2017-10-16 18:21:31 +01:00
William S Fulton
d6077129e4 Testcase changes to satisfy pep8 E742 and E743 checks
Closes #1110
2017-10-09 07:27:38 +01:00
William S Fulton
e27a606335 Allow an instantiated template to have the same name as the C++ template name
For example, this is now possible:
  template<typename T> struct X { ... };
  %template(X) X<int>;
Closes #1100.
2017-09-29 23:28:04 +01:00
William S Fulton
ed4b84f4d3 Fix overloading of shared_ptr method overloading
Add 'equivalent' attribute to typecheck typemap.
Closes #1098.
2017-09-23 15:19:34 +01:00
William S Fulton
f5e1856650 Expand std::shared_ptr testing to C# D Java Python 2017-09-22 20:03:47 +01:00
William S Fulton
c4e280024f Add support for %typemap and member function pointers with qualifiers 2017-09-09 23:46:14 +01:00
William S Fulton
950edc1c00 Add support for conversion operators with ref-qualifiers 2017-08-30 18:17:05 +01:00
William S Fulton
8a40327aa8 Add unignore for rvalue ref-qualifiers
Use std::move on this pointer as the default approach to supporting
rvalue ref-qualifiers if a user really wants to wrap.

std::move requires <memory> headers so add swigfragments.swg for all
languages to use common fragments. Just header file fragments for now.
2017-08-30 18:17:04 +01:00
William S Fulton
1cf599bccb Improve ref-qualifier implementation
Internally, handle function ref-qualifiers in the function decl type string.
Needed for a whole host of things to work like %feature and %rename.
Add %feature %rename and %ignore testing for ref-qualifiers.
2017-08-30 18:17:04 +01:00
William S Fulton
9e19fe7868 C++11 ref-qualifier support added
Fixes #1059

Methods with rvalue ref-qualifiers are ignored by default as it is not
possible to have an rvalue temporary from the target language (which is
needed to call the rvalue ref-qualified method).
A warning 405 is shown mentioning the ignored rvalue ref-qualifier method
which can be seen with the -Wextra option.

  cpp_refqualifier.i:15: Warning 405: Method with rvalue ref-qualifier ignored h() const &&.

Usually rvalue and lvalue ref-qualifier overloaded methods are written - the
lvalue method will then be wrapped.
2017-08-19 01:02:34 +01:00
William S Fulton
96e99416d7 Add using declarations to templates into typedef table.
Fixes #1051. Using declarations to templates were missing in SWIG's internal typedef tables.
This led to a few problems, such as, templates that did not instantiate and generated
C++ code that did not compile as SWIG did not know what scope the template was
in. This happened mostly when a using declaration was used on a template type in a
completely unrelated namespace.
2017-08-16 00:24:25 +01:00
William S Fulton
bf98c5304f Fix type lookup in the presence of using directives and using declarations
Fix some cases of type lookup failure via a combination of both using directives and
using declarations resulting in C++ code that did not compile as the generated type was
not fully qualified for use in the global namespace. Example below:

    namespace Space5 {
      namespace SubSpace5 {
        namespace SubSubSpace5 {
          struct F {};
        }
      }
      using namespace SubSpace5;
      using SubSubSpace5::F;
      void func(SubSubSpace5::F f);
    }
2017-08-16 00:24:25 +01:00
William S Fulton
959e627208 %template scope enforcement and class definition fixes
The scoping rules around %template have been specified and enforced.
The %template directive for a class template is the equivalent to an
explicit instantiation of a C++ class template. The scope for a valid
%template instantiation is now the same as the scope required for a
valid explicit instantiation of a C++ template. A definition of the
template for the explicit instantiation must be in scope where the
instantiation is declared and must not be enclosed within a different
namespace.

For example, a few %template and explicit instantiations of std::vector
are shown below:

  // valid
  namespace std {
    %template(vin) vector<int>;
    template class vector<int>;
  }

  // valid
  using namespace std;
  %template(vin) vector<int>;
  template class vector<int>;

  // valid
  using std::vector;
  %template(vin) vector<int>;
  template class vector<int>;

  // ill-formed
  namespace unrelated {
    using std::vector;
    %template(vin) vector<int>;
    template class vector<int>;
  }

  // ill-formed
  namespace unrelated {
    using namespace std;
    %template(vin) vector<int>;
    template class vector<int>;
  }

  // ill-formed
  namespace unrelated {
    namespace std {
      %template(vin) vector<int>;
      template class vector<int>;
    }
  }

  // ill-formed
  namespace unrelated {
    %template(vin) std::vector<int>;
    template class std::vector<int>;
  }

When the scope is incorrect, an error now occurs such as:

cpp_template_scope.i:34: Error: 'vector' resolves to 'std::vector' and
was incorrectly instantiated in scope 'unrelated' instead of within scope 'std'.

Previously SWIG accepted the ill-formed examples above but this led to
numerous subtle template scope problems especially in the presence of
using declarations and using directives as well as with %feature and %typemap.

Actually, a valid instantiation is one which conforms to the C++03
standard as C++11 made a change to disallow using declarations and
using directives to find a template.

  // valid C++03, ill-formed C++11
  using std::vector;
  template class vector<int>;

Similar fixes for defining classes using forward class references have
also been put in place. For example:

namespace Space1 {
  struct A;
}
namespace Space2 {
  struct Space1::A {
    void x();
  }
}

will now error out with:

cpp_class_definition.i:5: Error: 'Space1::A' resolves to 'Space1::A' and
was incorrectly instantiated in scope 'Space2' instead of within scope 'Space1'.
2017-08-16 00:24:25 +01:00
William S Fulton
26e14c4f18 Fix scope lookup for template parameters containing unary scope operators
Fixes cases like:

namespace Alloc {
  template<typename T> struct Rebind {
    typedef int Integer;
  };
}
%template(RebindBucket) Alloc::Rebind< Bucket >;
OR
%template(RebindBucket) Alloc::Rebind< ::Bucket >;

Alloc::Rebind< Bucket >::Integer Bucket1() { return 1; }
Alloc::Rebind< ::Bucket >::Integer Bucket2() { return 2; }
Alloc::Rebind<::template TemplateBucket<double>>::Integer Bucket3() { return 3; };
2017-08-16 00:24:24 +01:00
William S Fulton
f5cb0420f3 Merge branch 'fflexo-javalist'
* fflexo-javalist:
  Java std::vector minor improvement
  Fix Java container tests for change in vector constructor declaration
  Add in missing Java std::list listIterator index range checking
  Minor correction in C# std::list doNextIndex
  Add missing typedefs to Java std::vector
  Consistent destructor declarations
  Remove Java std::list::max_size
  Java std::list std::vector - test addAll and subList
  Handle length_error exceptions in Java std::vector::reserve
  Remove Java std::list::assign
  Additional add/remove methods added to Java std::list wrappers
  More efficient add implementation for Java std::list
  Java std::vector std::list: add missing exception handling
  Java std::vector std::list enhancements
  Modify std::list declarations to match the C++ standard
  Fix removing elements from std::list Java wrapper
  Improve Java std::list std::vector runtime tests and wrap std::list::clear
  Wrap std::list::empty as isEmpty in Java
  javabase typemap improvement for std::list
  Java std::list - fully qualifiy Java class name to avoid potential name ambiguity
  cosmetics
  Remove redundant code
  Java std::list rework to be consistent with std::vector wrappers
  li_std_list testcase not working for most languages
  re-enabled li_std_list test
  Switched from autobox to jboxtype per #842
  Document autobox.i
  Made the conversion from long->int for size_type mapping onto Java interfaces cleaner.
  Be consistent in semantics of %extend on std::list::iterator
  Comment on consideration of making iterator non-static.
  Java style fix: iterator->Iterator
  Moving iterator functionality into nested Java class now.
  Removed typedef from li_std_list test as it's not expected to work properly in templated code
  Added a best case workaround for std::list::size_type vs jint problem. There's a bit of commentry added around it too for clarity.
  Drop non-const reference from autobox typemap macro to be consistent.
  just use a forward declaration for C++ iterator types to fix enum errors
  Added enum to li_std_list tests
  Added li_std_list to the Java test-suit makefile
  added more comments in a few places
  Base _runme.java for li_std_list off li_std_vector_runme.java
  Expose more types from li_std_list.i
  Don't expose sort() to avoid adding dependencies on all std::list users
  Target each method specificly for setting modifiers
  Don't expose remove() method from std::list to avoid confusing it with Java's remove() in List
  - added std_list.i implemenatation that extends Java's AbstractSequentialList base class - added autobox.i that provides supporting typemaps for generics in containers
2017-06-29 20:20:40 +01:00
William S Fulton
44cd658a53 Add in missing Java std::list listIterator index range checking 2017-06-29 19:32:34 +01:00
William S Fulton
90d2ba884c Java std::list std::vector - test addAll and subList 2017-06-26 13:42:19 +01:00
William S Fulton
ecebbdd0df Additional add/remove methods added to Java std::list wrappers
Add functions similar to java.util.LinkedList<E>:
  addFirst
  addLast
  removeFirst
  removeLast
2017-06-25 00:10:06 +01:00
William S Fulton
c686045f55 More efficient add implementation for Java std::list
The default implementation in AbstractSequentialList<E>
calls add(size(), e) and size() might be expensive.
2017-06-24 23:33:31 +01:00
William S Fulton
ea55c5bba0 Java std::vector std::list enhancements
- Add missing vector copy constructor
- Add constructor to initialize the containers. Note that Java's
  equivalent constructor for ArrayList just sets the capacity, whereas
  the wrappers behave like the C++ constructor and set the size. I've
  done this mainly because there has been a vector(size_type) constructor
  in the Java wrappers for many years, so best to keep this unchanged.
2017-06-24 14:30:03 +01:00
William S Fulton
2d99027935 Fix removing elements from std::list Java wrapper
Add missing remove method on Java side (without it elements aren't
removed).
2017-06-23 16:17:00 +01:00
William S Fulton
428b332e68 Improve Java std::list std::vector runtime tests and wrap std::list::clear 2017-06-23 15:42:59 +01:00
William S Fulton
990c597365 Wrap std::list::empty as isEmpty in Java 2017-06-23 15:26:53 +01:00
William S Fulton
95e8643d70 Rename func to funk in tests to avoid Go keyword problems 2017-06-16 19:24:48 +01:00
Alan Woodland
4db1300622 Merge branch 'master' into javalist 2017-06-05 21:55:12 +01:00
William S Fulton
bc7c80b862 More Java vector runtime tests 2017-06-05 19:33:45 +01:00
William S Fulton
65abd9558d Merge branch 'java-vector-test'
* java-vector-test:
  Java std_vector runtime test

Conflicts:
	Examples/test-suite/java/li_std_vector_runme.java
2017-06-05 19:23:31 +01:00
William S Fulton
30b7424f8e Java std_vector runtime test
From Volker Diels-Grabsch in SF patch https://sourceforge.net/p/swig/patches/278/
2017-06-05 19:15:32 +01:00
William S Fulton
338acfabeb Merge branch 'vadz-java-vector'
* vadz-java-vector:
  Fix potential STL std::vector wrappers <: digraphs problems.
  Add runtime checks for vector size in Java
  Make std::vector<> wrappers conform to List interface in Java
  Add helper macro to avoid duplication in Java vector typemaps

Conflicts:
	CHANGES.current
2017-05-26 19:15:12 +01:00
William S Fulton
a4d01cddeb Missing smart pointer handling in Java director extra methods
- Add CHANGES file entry
- Add testcase
2017-05-25 20:35:18 +01:00
William S Fulton
4bf607589f Fix Java shared_ptr and directors for derived classes java compilation error.
For shared_ptr proxy proxy classes, add a protected method swigSetCMemOwn for modifying
the swigCMemOwn and swigCMemOwnDerived member variables which are used by various other
methods for controlling memory ownership.

Closes #230
Closes #759
2017-05-23 21:36:08 +01:00
William S Fulton
dcc5911839 Fix handling of typedef'd function pointers for Go
Add equivalent runtime tests for Python and Java
2017-03-17 07:49:21 +00:00
William S Fulton
2a5068bcf2 Add some tests for typedef to member function pointers 2017-03-10 23:25:31 +00:00
William S Fulton
5aff26fcb5 Add support for parsing and wrapping member const function pointers 2017-03-10 23:25:31 +00:00
William S Fulton
8a4ab380a1 Java director typemaps and test tweak
- Fix java_director_typemaps test name clash ensuring parallel tests work
- Replace assert with code that is guaranteed to run
- Nicer generated code from directorargout typemap
2017-01-24 23:47:30 +00:00
William S Fulton
2abdb50f60 Merge branch 'andrey-starodubtsev-directorargout_and_java_typemaps'
* andrey-starodubtsev-directorargout_and_java_typemaps:
  WIP: #704 (java directorargout + java/typemaps.i fixes)
  WIP: #704 (java directorargout + java/typemaps.i fixes)
  WIP: #704 (java directorargout + java/typemaps.i fixes)
  WIP: #704 (java directorargout + java/typemaps.i fixes)
  WIP: #704 (java directorargout + java/typemaps.i fixes)
  a lot of memory leak (local refs) fixed
  java directorargout + java/typemaps.i fixes
2017-01-24 19:04:35 +00:00
William S Fulton
d6d7afb755 Enhance %extend to extend a class with template constructors 2017-01-24 19:01:43 +00:00
William S Fulton
481ebfab45 Enhance %extend to extend a class with static template methods 2017-01-24 19:01:43 +00:00
Andrey Starodubtsev
cdbab138a8 WIP: #704 (java directorargout + java/typemaps.i fixes)
- added virtual function with omitted arg names
2017-01-22 13:41:53 +03:00
William S Fulton
b538070016 Enhance %extend to extend a class with template methods 2017-01-22 10:36:46 +00:00
Andrey Starodubtsev
4ba9de370e Merge branch 'master' into directorargout_and_java_typemaps 2017-01-21 17:41:31 +03:00
William S Fulton
4c1152efcd Merge branch 'fschlimb-templ_def_cache'
* fschlimb-templ_def_cache:
  Add template_default_cache runtime tests
  Fix template_default_cache testcase
  template_default_cache is a multi-module test
  using 2-level caching as suggested by @wsfulton
  account for explicitly qualified scopes
  adding test
  restricting chaching template default types
2017-01-16 07:50:13 +00:00
William S Fulton
6db71c690a Add template_default_cache runtime tests
Also correct illegal C++ namespace names
2017-01-16 07:46:03 +00:00
William S Fulton
3d2e57b0f2 Add %proxycode directive for adding code into proxy classes for C#, D and Java 2017-01-13 20:43:50 +00:00
Vadim Zeitlin
c79dd9d420 Make std::vector<> wrappers conform to List interface in Java
Derive the class wrapping std::vector<> in Java from java.util.AbstractList<>.
This makes it possible to use it with various algorithms working with Java
collections and, maybe even more importantly, makes it possible to iterate
over the wrapped vectors using for-each loops.

This commit is based on the original patch by Volker Diels-Grabsch from
https://sourceforge.net/p/swig/patches/278/
2016-11-29 17:46:38 +01:00
William S Fulton
7268f58c4c Fix %rename override of wildcard %rename for templates
%rename(GlobalIntOperator) *::operator bool; // wildcard %rename
%rename(XIntOperator) X::operator bool; // fix now overrides first %rename above
OR
%rename(XIntOperator) X<int>::operator bool; // fix now overrides first %rename above

template<typename T> struct X {
  operator bool();
  ...
};
%template(Xint) X<int>;
2016-11-28 22:50:52 +00:00
Andrey Starodubtsev
3e449ea05f Merge branch 'master' into directorargout_and_java_typemaps 2016-11-02 18:12:38 +03:00
William S Fulton
5df10e380e Fix some test-suite warnings 2016-10-16 19:10:35 +01:00
Andrey Starodubtsev
b2bcf040c0 java directorargout + java/typemaps.i fixes
- directorargout didn't work - it used string "jresult" instead of
  argument name
- java/typemaps.i didn't work with directors
- test for using java/typemaps.i in directors added
2016-06-08 15:04:47 +03:00
William S Fulton
b9ca9f5efc Smart pointer to %ignored class doesn't expose inherited methods fix.
Regression introduced in swig-3.0.9 by 3efdbc8
Closes #690
2016-05-31 22:10:37 +01:00