From eb7b989c6173fd22911d69636e64f2e4a044c1d6 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 16 Feb 2019 08:09:56 +0000 Subject: [PATCH] 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/ --- CHANGES.current | 18 ++++++++ Examples/test-suite/common.mk | 1 - Examples/test-suite/cpp_broken.i | 12 ------ Examples/test-suite/enum_macro.i | 42 +++++++++++++++++++ .../test-suite/java/enum_macro_runme.java | 24 +++++++++++ Source/CParse/parser.y | 12 ++++-- 6 files changed, 92 insertions(+), 17 deletions(-) delete mode 100644 Examples/test-suite/cpp_broken.i diff --git a/CHANGES.current b/CHANGES.current index 5c1f00f3f..d3e84c86d 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -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. diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 04b39e75f..6794c2e8b 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -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 \ diff --git a/Examples/test-suite/cpp_broken.i b/Examples/test-suite/cpp_broken.i deleted file mode 100644 index 84d6122e5..000000000 --- a/Examples/test-suite/cpp_broken.i +++ /dev/null @@ -1,12 +0,0 @@ -%module cpp_broken - - -// bug #940318 -%inline %{ -typedef enum { -eZero = 0 -#define ONE 1 -} EFoo; -%} - - diff --git a/Examples/test-suite/enum_macro.i b/Examples/test-suite/enum_macro.i index c058cdf72..a5e8a2461 100644 --- a/Examples/test-suite/enum_macro.i +++ b/Examples/test-suite/enum_macro.i @@ -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 +}; +%} diff --git a/Examples/test-suite/java/enum_macro_runme.java b/Examples/test-suite/java/enum_macro_runme.java index 4ac7409ee..c05793347 100644 --- a/Examples/test-suite/java/enum_macro_runme.java +++ b/Examples/test-suite/java/enum_macro_runme.java @@ -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"); + } } } diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 29e5705bf..f20f1db2f 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -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; } ;