Commit graph

19,965 commits

Author SHA1 Message Date
William S Fulton
8bf81b8718 More docs on %template 2017-08-16 00:24:25 +01:00
William S Fulton
1434449041 Testcase fix for nameclash in php 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
97ae9d66bc Template documentation tweaks
Add subsections to the template documentation
Rewrite some of the template introduction
2017-08-16 00:24:25 +01:00
William S Fulton
5779aa8d79 More consistent formatting of examples in documentation 2017-08-16 00:24:25 +01:00
William S Fulton
04131a988f More consistent formatting of examples in documentation 2017-08-16 00:24:25 +01:00
William S Fulton
c454f2ce2f Documentation corrections to use targetlang formatting 2017-08-16 00:24:25 +01:00
William S Fulton
ba45861b46 More consistent formatting of examples in documentation 2017-08-16 00:24:25 +01:00
William S Fulton
8052211ac5 More consistent formatting of examples in documentation 2017-08-16 00:24:25 +01:00
William S Fulton
7ee76f93f9 More consistent formatting of examples in documentation 2017-08-16 00:24:25 +01:00
William S Fulton
8753f9652c Namespace documentation minor corrections 2017-08-16 00:24:24 +01:00
William S Fulton
2681bbad36 Improve description of template_parameters_resolve 2017-08-16 00:24:24 +01:00
William S Fulton
8bf3a342c2 Minor code optimisation in template_parameters_resolve 2017-08-16 00:24:24 +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
aa2932f409 Typemap change for templates
For templates only, the template parameters are fully resolved when
handling typemaps. Without this, it is too hard to have decent rules
to apply typemaps when parameter types are typedef'd and template
parameters have default values.

Fixes %clear for typedefs in templates, eg:

  %typemap("in") XXX<int>::Long "..."
  template typename<T> struct XXX {
    typedef long Long;
  };
  %clear XXX<int>::Long;

as the typemap was previously incorrectly stored as a typemap for long
instead of XXX<int>::Long.
2017-08-16 00:24:06 +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
abe53e39a9 Java std::vector minor improvement 2017-06-29 20:19:59 +01:00
William S Fulton
0b390a5473 Fix Java container tests for change in vector constructor declaration 2017-06-29 19:59:19 +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
fccf5c29b4 Minor correction in C# std::list doNextIndex 2017-06-29 15:34:05 +01:00
William S Fulton
f4aa8b3321 Add missing typedefs to Java std::vector 2017-06-26 15:28:43 +01:00
William S Fulton
d04eb88742 Consistent destructor declarations 2017-06-26 13:53:49 +01:00
William S Fulton
d92faa7f7f Remove Java std::list::max_size
Not in any Java equivalent containers nor std::vector wrapper.
2017-06-26 13:43:57 +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
3af40e7423 Handle length_error exceptions in Java std::vector::reserve 2017-06-26 12:46:22 +01:00
William S Fulton
6daed2cea1 Remove Java std::list::assign
This doesn't exist in equivalent Java containers. If we put it back, the
full set of overloaded assign wrappers ought to be added.
2017-06-26 12:28:02 +01:00
Nihal
74fa7d00e2 Fix indentation in PHP7 and PHP5 variables example 2017-06-26 15:36:55 +12: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
a8e948e96d Java std::vector std::list: add missing exception handling 2017-06-24 22:53:11 +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
b40b9aee83 Modify std::list declarations to match the C++ standard 2017-06-23 20:10:26 +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
c6bff3731e Add Python 3 C++11 Travis testing 2017-06-23 14:51:25 +01:00
William S Fulton
005ff93dbd Fix construction from dict for std::multimap std::unordered_multimap (Python 3) 2017-06-23 14:38:26 +01:00
William S Fulton
a2267a8152 Memory leak fixes in Python default argument handling 2017-06-23 14:19:12 +01:00
Olly Betts
ad7dcb2c87 Merge branch 'm7thon-python23-octal-arguments' 2017-06-23 14:57:05 +12:00
Olly Betts
2425c8d6d8 Don't handle cases like -1U as Python constants 2017-06-23 14:54:50 +12:00
Michael Thon
80ffb169c1 [Python] fix and improve default argument handling
1. Fix negative octals. Currently not handled correctly by `-py3`
   (unusual case, but incorrect).
2. Fix arguments of type "octal + something" (e.g. `0640 | 04`).
   Currently drops everything after the first octal. Nasty!
3. Fix bool arguments "0 + something" (e.g. `0 | 1`) are always
   "False" (unusual case, but incorrect).
4. Remove special handling of "TRUE" and "FALSE" from
   `convertValue` since there's no reason these have to match
   "true" and "false".
5. Remove the Python 2 vs. Python 3 distinction based on the
   `-py3` flag. Now the same python code is produced for default
   arguments for Python 2 and Python 3. For this, octal default
   arguments, e.g. 0644, are now wrapped as `int('644', 8)`. This
   is required, as Python 2 and Python 3 have incompatible syntax
   for octal literals.

Fixes #707
2017-06-23 13:38:49 +12:00
William S Fulton
109a60add6 javabase typemap improvement for std::list 2017-06-22 22:17:59 +01:00
William S Fulton
430376e115 Java std::list - fully qualifiy Java class name to avoid potential name ambiguity 2017-06-22 22:11:02 +01:00
William S Fulton
7b7f921ccb cosmetics 2017-06-22 20:38:19 +01:00
William S Fulton
02a00db9f5 Remove redundant code 2017-06-22 20:33:16 +01:00
William S Fulton
dd25f5b722 Java std::list rework to be consistent with std::vector wrappers 2017-06-22 20:33:09 +01:00
William S Fulton
fa416e4d40 li_std_list testcase not working for most languages 2017-06-21 15:51:52 +01:00
William S Fulton
2a47918a3f Add changes entry for ccache-swig configure fix 2017-06-21 15:35:35 +01:00
William S Fulton
a90cc8f447 Merge branch 'futatuki-ccache-configure-care-for-rename'
* futatuki-ccache-configure-care-for-rename:
  Apply changes requested for this pull request
  fix typo
  Embed fixed string '.exe' to CCache/config_win32.h even if EXEEXT is empty.
  Add header file in CCache for _WIN32 environment
  CCache: take care of program prefix/suffix on configure
2017-06-21 15:15:24 +01:00
FUTATSUKI YASUHITO
7be53b7692 Apply changes requested for this pull request 2017-06-21 11:54:06 +09:00