From 7cb4e902d59aa73009cd4f928d5470fa68803f36 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 17 Nov 2009 19:31:13 +0000 Subject: [PATCH] Fix parsing of enum declaration and initialization git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11752 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 9 +++++++++ Examples/test-suite/enums.i | 20 ++++++++++++++++++-- Examples/test-suite/octave/enums_runme.m | 16 ++++++++++++++++ Examples/test-suite/python/enums_runme.py | 12 ++++++++++++ Source/CParse/parser.y | 6 +++--- 5 files changed, 58 insertions(+), 5 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index e97bbc58a..bc28d8fc1 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,15 @@ Version 1.3.41 (in progress) ============================ +2009-11-17: wsfulton + Fix parsing of enum declaration and initialization, for example: + + enum ABC { + a, + b, + c + } A = a, *pC = &C, array[3] = {a, b, c}; + 2009-11-17: wsfulton Fix parsing of struct declaration and initialization, for example: diff --git a/Examples/test-suite/enums.i b/Examples/test-suite/enums.i index 00499f800..40be28e94 100644 --- a/Examples/test-suite/enums.i +++ b/Examples/test-suite/enums.i @@ -8,6 +8,7 @@ %warnfilter(SWIGWARN_RUBY_WRONG_NAME) globalinstance1; %warnfilter(SWIGWARN_RUBY_WRONG_NAME) globalinstance2; %warnfilter(SWIGWARN_RUBY_WRONG_NAME) globalinstance3; +%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK); %inline %{ @@ -64,7 +65,7 @@ typedef struct _iFoo enum { Phoo = +50, Char = 'a' - } e; + } e; } iFoo; %} #else @@ -77,5 +78,20 @@ struct iFoo }; }; %} - #endif + +// enum declaration and initialization +%inline %{ +enum Exclamation { + goodness, + gracious, + me +} enumInstance = me; + +enum ContainYourself { + slap = 10, + my, + thigh +} Slap = slap, My = my, Thigh = thigh, *pThigh = &Thigh, arrayContainYourself[3] = {slap, my, thigh}; +%} + diff --git a/Examples/test-suite/octave/enums_runme.m b/Examples/test-suite/octave/enums_runme.m index 91f2ce2bf..789f7c9e4 100644 --- a/Examples/test-suite/octave/enums_runme.m +++ b/Examples/test-suite/octave/enums_runme.m @@ -5,3 +5,19 @@ enums.bar2(1) enums.bar3(1) enums.bar1(1) +if (enums.cvar.enumInstance != 2) + error +endif + +if (enums.cvar.Slap != 10) + error +endif + +if (enums.cvar.My != 11) + error +endif + +if (enums.cvar.Thigh != 12) + error +endif + diff --git a/Examples/test-suite/python/enums_runme.py b/Examples/test-suite/python/enums_runme.py index 59a982974..e8dbe6942 100644 --- a/Examples/test-suite/python/enums_runme.py +++ b/Examples/test-suite/python/enums_runme.py @@ -5,3 +5,15 @@ _enums.bar2(1) _enums.bar3(1) _enums.bar1(1) +if _enums.cvar.enumInstance != 2: + raise RuntimeError + +if _enums.cvar.Slap != 10: + raise RuntimeError + +if _enums.cvar.My != 11: + raise RuntimeError + +if _enums.cvar.Thigh != 12: + raise RuntimeError + diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 0da3666f8..8b4521ef1 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -3132,7 +3132,7 @@ c_enum_decl : storage_class ENUM ename LBRACE enumlist RBRACE SEMI { add_symbols($$); /* Add to tag space */ add_symbols($5); /* Add enum values to id space */ } - | storage_class ENUM ename LBRACE enumlist RBRACE declarator c_decl_tail { + | storage_class ENUM ename LBRACE enumlist RBRACE declarator initializer c_decl_tail { Node *n; SwigType *ty = 0; String *unnamed = 0; @@ -3174,8 +3174,8 @@ c_enum_decl : storage_class ENUM ename LBRACE enumlist RBRACE SEMI { SetFlag(n,"unnamedinstance"); Delete(cty); } - if ($8) { - Node *p = $8; + if ($9) { + Node *p = $9; set_nextSibling(n,p); while (p) { SwigType *cty = Copy(ty);