Commit Graph

16 Commits

Author SHA1 Message Date
William S Fulton a28b8cfed4 Redundant code removal in nested.cxx
c96c04c5ae
Replicate changes in this commit to add_symbols() for add_symbols_c().
Setting feature:immutable is now done in Allocate:cDeclaration.
Setting hasconsttype for static const variables (or constexpr) doesn't
look possible in this situation (C code for anonymous structs) - no
valid C syntax that I can figure out.

Anonymous nested structs are necessarily read-only (and set as
immutable in Swig_nested_name_unnamed_c_structs).

From https://sourceforge.net/p/swig/bugs/793/ ...

The union variable intRep below has a named type IntRepType.

typedef struct Object {
  int objtype;
  union IntRepType {
    double dvalue;
  } intRep;
} Object;

void tester() {
  /* approach (1) */
  obj.intRep.dvalue = 1.23;

  /* approach (2) */
  union IntRepType irt;
  irt.dvalue = 2.34;
  obj.intRep = irt;
}

Using C code there are two approaches to setting a value in intRep. Equivalents in perl are:

my $obj = example::Object->new();

 # approach (1)
$obj->{intRep}->{dvalue} = 3.45;

 # approach (2)
my $irt = example::IntRepType->new();
$irt->{dvalue} = 4.56;
$obj->{intRep} = $irt;

An Object_intRep_set wrapper is generated which takes type IntRepType as desired.

However, with an anonymous union:

typedef struct Object {
  int objtype;
  union IntRepType {
    double dvalue;
  } intRep;
} Object;

intRep does not have any named type name and is anonymous. It is thus not possible to create a type outside of Object to assign to intRep.
Only approach (1) is available in C and so SWIG can only provide approach (1) via wrappers too.
There is no Object_intRep_set wrapper, intRep is immutable.
2023-09-10 12:51:42 +01:00
William S Fulton a3e8e1fe50 Warnings 302 and 322 code refactor 2023-07-28 07:16:49 +01:00
William S Fulton 526bc33376 More redefinition/redeclaration warning message improvements
Replicate redefinition/redeclaration warning message improvements
in previous commit to nested classes.

Adding the symtab to all nodes in Swig_symbol_add() has also fixed some
warning displays with %extend 302 warnings, which were completely
missing before (extend_placement.i testcase).
2023-07-28 07:15:41 +01:00
Olly Betts 631b41ae7b Use https for swig.org links 2022-10-06 13:16:39 +13:00
Olly Betts b127e11f1e Fix typos in docs and comments 2022-02-27 18:15:46 +13:00
Olly Betts de1cae9319 Fix segmentation fault when top==NULL
Introduced by nested class handling (reported in issue#346 by Paweł Tomulik).
2015-02-26 14:57:19 +13:00
Vladimir Kalinin 665c4f581b %extend symbols for nested structs get into a wrong C symbol table 2014-05-28 22:15:50 +04:00
William S Fulton 71e72c45ed Create separate extetnd.c file for handling extensions / %extend
This is just a simple code refactor, moving and function renaming to
remove the %extend code out of the parser into its own file now
 that it isn't just used in the parser.
2014-05-21 19:16:15 +01:00
Vladimir Kalinin 3692e175bc global unnamed structures ignored 2014-05-15 03:13:25 +04:00
Vladimir Kalinin 5d78f14b1c test added for nested unnamed C struct %extend 2014-05-14 00:56:39 +04:00
Vladimir Kalinin 2aa540b9c0 %extend for nested unnamed C structs 2014-05-14 00:51:36 +04: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
William S Fulton 2121e1217e Ensure -c++out is not used with -c++
Error checking for this combination implemented as well as correcting
Octave

Also refactor, replacing CPlusPlusOut variable with cparse_cplusplusout
for an implementation which more closely resembles cparse_cplusplus which
is also required in both .c and .cxx files.
2013-12-12 20:52:44 +00:00
William S Fulton 3b4d331310 Add missing header to new source file 2013-12-12 09:00:23 +00: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