Fix parser error containing multiple #define statements inside an enum.

The second #define fails to parse:

  enum FooEnum {
    ENUM1 = 0,
    ENUM2 = 1,

  #define MACRO_DEF1 "Hello"
  #define MACRO_DEF2 "World!"

    ENUM3 = 2,
    ENUM4 = 3,
  };

Bug mentioned at https://sourceforge.net/p/swig/patches/333/
This commit is contained in:
William S Fulton 2019-02-16 08:09:56 +00:00
parent 6522afe90a
commit eb7b989c61
6 changed files with 92 additions and 17 deletions

View File

@ -7,6 +7,24 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
Version 4.0.0 (in progress)
===========================
2019-02-16: wsfulton
Fix parser error containing multiple #define statements inside an enum.
The second #define fails to parse:
enum FooEnum {
ENUM1 = 0,
ENUM2 = 1,
#define MACRO_DEF1 "Hello"
#define MACRO_DEF2 "World!"
ENUM3 = 2,
ENUM4 = 3,
};
Bug mentioned at https://sourceforge.net/p/swig/patches/333/
2019-02-14: wsfulton
Add some missing copy constructors into STL containers.

View File

@ -83,7 +83,6 @@ Makefile: $(srcdir)/Makefile.in ../../../config.status
# Broken C++ test cases. (Can be run individually using: make testcase.cpptest)
CPP_TEST_BROKEN += \
constants \
cpp_broken \
director_nested_class \
exception_partial_info \
extend_variable \

View File

@ -1,12 +0,0 @@
%module cpp_broken
// bug #940318
%inline %{
typedef enum {
eZero = 0
#define ONE 1
} EFoo;
%}

View File

@ -97,3 +97,45 @@ enum Greeks13
#define GREEK13 -13
};
/* Multiple macros */
%inline %{
enum Greeks14
{
#define GREEK14a -14
#define GREEK14b -140
theta14,
};
enum Greeks15
{
alpha15 = 150,
beta15 = 151,
#define GREEK15a -150
#define GREEK15b -151
theta15 = 152,
delta15 = 153
};
enum Greeks16
{
alpha16 = 160,
beta16 = 161,
#define GREEK16a -160
#define GREEK16b -161
#define GREEK16c -162
theta16 = 162,
delta16 = 163
};
enum Greeks17
{
alpha17 = 170,
beta17 = 171,
theta17 = 172,
delta17 = 173
#define GREEK17a -170
#define GREEK17b -171
#define GREEK17c -172
};
%}

View File

@ -88,6 +88,30 @@ public class enum_macro_runme {
{
Greeks13 a = null;
}
{
Greeks15 a = Greeks15.alpha15;
a = Greeks15.beta15;
a = Greeks15.theta15;
a = Greeks15.delta15;
if (a.swigValue() != 153)
throw new RuntimeException("Greeks15");
}
{
Greeks16 a = Greeks16.alpha16;
a = Greeks16.beta16;
a = Greeks16.theta16;
a = Greeks16.delta16;
if (a.swigValue() != 163)
throw new RuntimeException("Greeks16");
}
{
Greeks17 a = Greeks17.alpha17;
a = Greeks17.beta17;
a = Greeks17.theta17;
a = Greeks17.delta17;
if (a.swigValue() != 173)
throw new RuntimeException("Greeks17");
}
}
}

View File

@ -6342,8 +6342,12 @@ ename : identifier { $$ = $1; }
| empty { $$ = (char *) 0;}
;
optional_ignored_define
: constant_directive
constant_directives : constant_directive
| constant_directive constant_directives
;
optional_ignored_defines
: constant_directives
| empty
;
@ -6364,7 +6368,7 @@ enumlist : enumlist_item optional_ignored_define_after_comma {
Setattr($2,"_last",NULL);
$$ = $1;
}
| optional_ignored_define {
| optional_ignored_defines {
$$ = 0;
}
;
@ -6380,7 +6384,7 @@ enumlist_tail : COMMA enumlist_item {
}
;
enumlist_item : optional_ignored_define edecl_with_dox optional_ignored_define {
enumlist_item : optional_ignored_defines edecl_with_dox optional_ignored_defines {
$$ = $2;
}
;