Commit Graph

117 Commits

Author SHA1 Message Date
William S Fulton 64649df343 Don't show incorrect warning SWIGWARN_LANG_SMARTPTR_MISSING (520)
Was showing for an ignored derived class.

Closes #2879
2024-09-21 13:28:03 +01:00
William S Fulton 54916f150e Improved namespace validity checks for the nspace feature 2024-06-01 13:41:59 +01:00
William S Fulton e4795e9af0 Validate scopename in nspace feature 2024-06-01 08:04:14 +01:00
William S Fulton 59827e7191 Fix %nspace and %nspacemove for nested classes and enums in a class
For example:

  %nspace Space::OuterClass80;
  namespace Space {
    struct OuterClass80 {
      struct InnerClass80 {
        struct BottomClass80 {};
      };
      enum InnerEnum80 { ie80a, ie80b };
    };
  }

Previously the following were additionally required for some languages:

  %nspace Space::OuterClass80::InnerClass80;
  %nspace Space::OuterClass80::InnerClass80::Bottom80;

Now the appropriate nspace setting is taken from the outer class.

A new warning has also been introduced to check and correct conflicting
nspace usage, for example if the following is additionally added:

  %nspacemove(AnotherSpace) Space::OuterClass80::InnerClass80;

The following warning appears as an inner class can't be moved outside
of the outer class:

  Warning 406: Ignoring nspace setting (AnotherSpace) for 'Space::OuterClass80::InnerClass80',
  Warning 406: as it conflicts with the nspace setting (Space) for outer class 'Space::OuterClass80'.

This really helps with %nspacemove as now one can simply move an outer
class to another namespace, like this:

  %nspacemove(AnotherSpace) Space::OuterClass80;

and all the nested classes will automatically also be moved
into the appropriate namespace.
2024-06-01 08:04:08 +01:00
William S Fulton 5035473e9b Enhance %nspace with %nspacemove for moving symbols into a different target language namespace
%nspacemove moves a class or enum into a different target language 'namespace'.

This builds on top of %nspace and so is currently only implemented in
C#, D, Java, Javascript and Lua.

Javascript also supports %nspace for functions and variables in a
namespace with a non-standard implementation; %nspacemove is not
fully working yet for Javascript.

Issue #2782
2024-06-01 08:02:49 +01:00
William S Fulton ce911f8ae3 Fix incomplete ignoring of duplicating %template instantiations
When template parameter typedefs are involved, a duplicate %template
instantiation was not properly ignoring the duplicate instantiation,
resulting in compile time errors.

Closes #2814
2024-02-23 22:08:10 +00:00
William S Fulton 3be670e8db Fix assertion handling upcasting when using %shared_ptr on some templates.
A different approach is taken for supporting casting smart pointers up the
inheritance hierarchy. We no longer try to replace the underlying pointer type,
provided in the 'feature:smartptr', with the base class type. Such as morphing
'std::shared_ptr<(Derived)>' into 'std::shared_ptr<(Base)>'. Instead, we simply
use 'feature:smartptr' from the base class. This is more reliable than trying to
pattern match the pointer type in the feature. The base class must of course
also have the 'feature:smartptr' set, and this is still checked for as before.
The feature is now parsed in one place and stored in the parse tree in the
new 'smart' attribute for handling by the target languages.

Fix also improves the handling of the type parsed in 'feature:smartptr' in that
the type is now normalized and resolved in the scope of the class it is attached
to.

Closes #2768
2024-01-30 22:24:42 +00:00
William S Fulton 34e25241e7 Comment correction since recent code refactor 2023-08-05 19:46:16 +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 655d43769e Move adding members due to using declaration from Allocate to TypePass
Adding using declarations to the parse tree is done in this later
TypePass stage of processing the parse tree as the implicitly defined
constructors in the base class have already been added. The implicitly
defined constructors are also added in TypePass and are added during
processing of a base class, which is always before a derived class.
These constructors are thus available for a derived class to use when
TypePass::usingDeclaration is looking for base class constructors to add
to the parse tree.

This is a another step towards supporting C++11 using declarations for
inheriting base class constructors that are implicitly defined, both
template and non-template classes.
2023-07-14 08:39:27 +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 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 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 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 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
Olly Betts 631b41ae7b Use https for swig.org links 2022-10-06 13:16:39 +13:00
William S Fulton 469f694ae6 Fix using declaration in derived class bugs
Problem when all the base class's overloaded methods were
overridden in the derived class - fixes "multiply defined" errors.

Linked lists of the overloaded methods were not set up correctly
when handling the using declaration.

Closes #2244
2022-03-24 20:52:58 +00: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 e53f51b89d Add missing symtab for functions added by using declarations
Fixes fully qualified names for functions added by using declarations:
- Error messages show fully qualified names in Lua
- Overload warning messages show fully qualified names
- Error messages calling dispatch functions for handling overloaded methods in OCaml, Python and Tcl
2022-03-10 22:18:23 +00:00
William S Fulton bd5ffe86e4 Using declarations in derived class parameters scoping fix
Fix using declaration in derived class incorrectly introducing a method
from a base class when the using declaration is declared before the method
declaration. Problem occurred when within a namespace and the parameter types
in the method signatures were not fully qualified.

Issue #1441
2022-03-10 22:18:23 +00:00
Olly Betts 55377bdc08 Add DOH Exit() and SetExitHandler()
Exit() is a wrapper for exit() by default, but SetExitHandler() allows
specifying a function to call instead.

This means that failures within DOH (e.g. Malloc() failing due to lack
of memory) will now perform cleanup such as removing output files.

This commit also cleans up exit statuses so SWIG should now reliably
exit with status 0 if the run was successful and status 1 if there was
an error (or a warning and -Werror was in effect).

Previously in some situations SWIG would try to exit with the status set
to the number of errors encountered, but that's problematic - for
example if there were 256 errors this would result in exit status 0 on
most platforms.  Also some error statuses have special meanings e.g.
those defined by <sysexits.h>.

Also SWIG/Javascript tried to exit with status -1 in a few places (which
typically results in exit status 255).
2022-03-06 12:33:54 +13:00
William S Fulton 961424a986 Fix line/file info for methods added by using declarations 2022-02-26 20:07:58 +00:00
William S Fulton 79a1bbee8b Using declarations in inheritance hierarchy improvements.
- Improved documentation for using declarations.
- Issue new warning WARN_LANG_USING_NAME_DIFFERENT when there
  is a conflict in the target language name to be used when
  introducing a method via a using declaration. Previously
  the method was silently ignored. Issue #1840. Issue #655.
2022-02-26 12:46:06 +00:00
William S Fulton b3da344765 Add some comments about shared_ptr upcast code 2020-01-24 19:46:39 +00:00
William S Fulton 2cf075558c Replace all exit() with SWIG_exit()
For consistent cleanup on error
2019-07-31 00:08:49 +01:00
William S Fulton 32a454cfef Merge branch 'templates-scope-enforcement'
* templates-scope-enforcement:
  Test a few %template errors
  Add using declarations to templates into typedef table.
  Fix type lookup in the presence of using directives and using declarations
  More docs on %template
  Testcase fix for nameclash in php
  %template scope enforcement and class definition fixes
  Template documentation tweaks
  More consistent formatting of examples in documentation
  More consistent formatting of examples in documentation
  Documentation corrections to use targetlang formatting
  More consistent formatting of examples in documentation
  More consistent formatting of examples in documentation
  More consistent formatting of examples in documentation
  Namespace documentation minor corrections
  Improve description of template_parameters_resolve
  Minor code optimisation in template_parameters_resolve
  Fix scope lookup for template parameters containing unary scope operators
  Typemap change for templates
2017-08-16 21:44:51 +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 2165f27f5d Fix incorrectly shown warning for empty template instantiation used as a base class. 2017-08-13 21:32:44 +01:00
Lior Goldberg d0fc5b7b5b Add C++11 alias templates 2016-07-06 00:31:04 +03:00
William S Fulton 38cda92938 smartptr inheritance fix when using templates and typedefs
Fixes SF bug 3333549 - %shared_ptr fixes when the type is a template using
template parameters that are typedef'd to another type.

Also fixes python -O optimization where the smart pointer conversion to the
base class needs to work because of the virtual methods that have been
optimized away.
2016-06-21 07:00:56 +01: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
William S Fulton 3efdbc8f2e Don't issue unnecessary base class ignored message
Don't warn about base class being ignored when the derived class is
itself ignored.

Closes #669
2016-05-02 22:50:09 +01:00
William S Fulton fc2205e64d %shared_ptr support improvements for classes in an inheritance chain
Fix %shared_ptr support for private and protected inheritance.
- Remove unnecessary Warning 520: Derived class 'Derived' of 'Base'
  is not similarly marked as a smart pointer
- Do not generate code that attempts to cast up the inheritance chain in the
  type system runtime in such cases as it doesn't compile and can't be used.
Remove unnecessary warning 520 for %shared_ptr when the base class is ignored.
2015-10-01 22:36:01 +01:00
William S Fulton faeaacf112 smartptr feature support - factor out common code 2015-09-25 22:57:59 +01:00
Vladimir Kalinin d2ab75f907 obscure case workaround in std::set wrapper, where ignored type still need to be processed 2014-05-19 02:05:23 +04:00
Vladimir Kalinin 3692e175bc global unnamed structures ignored 2014-05-15 03:13:25 +04:00
Olly Betts 2f3bf144c6 Fix assorted comment and documentation typos 2014-02-23 17:15:22 +13:00
Vladimir Kalinin 2f3d93e93a Nested classes support is diversified, depending on the language capability. If the language cannot support nested classes, they will be unconditionally moved to the global namespace. If language module does not override Language::nestedClassesSupport() function, nested classes will be ignored, unless "feature:flatnested" is used. 2014-02-02 22:38:13 +04:00
Vladimir Kalinin b4fef06c42 fixed %template within %extend, test added
fixed language symbol table nested classes name separator, test added
fixed %feature "flatnested" working with %extend
fixed Swig_offset_string for empty string
added simple template to save/restore values in current scope (readability reasons)
2013-12-19 02:11:22 +04:00
Vladimir Kalinin b0afa8a95c nested private classes are discarded while parsing
nested relate functions are moved to nested.cxx and renamed accordingly
2013-12-05 20:41:22 +04:00
William S Fulton 44a883a057 Cosmetics/code beautification of nested class support 2013-11-29 07:29:58 +00:00
Vladimir Kalinin b63c4839fe Nested classes support
Closes #89
Squash merge branch 'master' of https://github.com/wkalinin/swig into wkalinin-nested

By Vladimir Kalinin
* 'master' of https://github.com/wkalinin/swig:
  CPlusPlusOut mode for Octave
  nested class illustration
  fixed "Abstract" flag for nested classes added an example enabled anonymous nested structs runtime test
  porting
  warnings disabled
  porting fixes
  java runtime tests ported
  nested class closing bracket offset fixed
  removed double nested template (not supported by %template parsing)
  template_nested test extended
  parent field made public
  property access fixed
  replaced tabs with spaces
  warning W-reorder
  deprecated warnings removed, derived_nested runtime test added
  optimized string indenting
  Nested classes indenting
  nested classes docs
  fixed the order in which flattened inner classes are added after the outer
  Private nested classes were getting into the type table.
  Java getProxyName() fix for nested classes fixes the case when nested classes is forward declared
  Fix for a case when a nested class inherits from the same base as the outer. (Base class constructor declaration is found first in this case)
  merge fix
  nested C struct first immediate declaration incorrectly renamed sample fixed
  tests updated to reflect nested classes support
  Java nested classes support (1)
  flattening should remove the link to the outer class
  access mode correctly set/restored for nested classes
  nested templates should be skipped while flattening (template nodes themselves, not expanded versions) also non-public nested classes should be ignored
  If nested classes are not supported, default behaviour is flattening, not ignoring flag "nested" is preserved, so, the nested classes can be ignored by user
  nested workaround test updated
  template instantiated within a class is marked as nested for ignoring purposes
  %ignore not applied to the nested classed, because "nested" flag is set too late
  typedef name takes precedence over the real name (reason?)
  unnamed structs should be processed for all the languages
  nested C struct instances are wrapped as "immutable"
  tree building
  typedef declaration for unnamed C structures fixed
  nested classes "flattening"
  fixed %ignoring nested classes
  renamed "nested" attribute to "nested:outer" added "nested" flag, to be used with $ignore (it is not removed while flattening) added nestedClassesSupported() function to the Language interface
  renamed "nested" attribute to "nested:outer" added "nested" flag, to be used with $ignore (it is not removed while flattening) added nestedClassesSupported() function to the Language interface
  tree iteration fix
  dirclassname variable names unified memory issue fixed
  merge error
  ignore unnamed structs for C++
  unnamed nested C structs naming & unnesting
  class added to classes hash under typedef name
  private nested classes skipped
  test updated due to nested templates support
  anonymous structs with inheritance fixed nested_class test to allow anonymous structs w/o declarator
  tests updated: nested workaround removed from namespace_class.i propagated nested template declaration to the C++ file
  injected members scope
  nested tempplates fixes, nested structures in "C" mode parsing added utility function "appendSibling" (like "appendChild")
  nested unnamed structures parsing fixes, access mode restored on nested class end, tdname is properly patched with outer class name prefix
  memory management fixes
  nested templates (1)
  Nested unnamed structs
  Nested class support (1)
  Nested class support (1)
2013-11-29 07:02:34 +00:00
William S Fulton b725625e6f Add support for thread_local when specified with other legitimate storage class specifiers - extern and static 2013-02-08 06:36:39 +00:00
William S Fulton 6399428a62 Add lambda functions to the symbol tables and add ability to suppress lambda warnings. 2013-02-04 20:05:34 +00:00
William S Fulton e805d5f925 Merge branch 'master' into gsoc2009-matevz
parser.y still to be fixed up

Conflicts:
	Doc/Devel/engineering.html
	Examples/Makefile.in
	Lib/allegrocl/allegrocl.swg
	Lib/csharp/csharp.swg
	Lib/csharp/enums.swg
	Lib/csharp/enumsimple.swg
	Lib/csharp/enumtypesafe.swg
	Lib/java/java.swg
	Lib/python/pydocs.swg
	Lib/r/rtype.swg
	Source/Include/swigwarn.h
	Source/Modules/octave.cxx
	Source/Modules/python.cxx
	Source/Modules/ruby.cxx
	Source/Swig/scanner.c
	Source/Swig/stype.c
	Source/Swig/swig.h
	configure.ac
2013-01-28 07:01:37 +00:00
William S Fulton 7841a0d097 Remove cvs/svn Id strings 2013-01-12 01:21:16 +00:00
William S Fulton 7d610dbd62 Remove unnecessary null check
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13926 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-11-22 23:20:57 +00:00