Fix parsing of enum declaration and initialization

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11752 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2009-11-17 19:31:13 +00:00
commit 7cb4e902d5
5 changed files with 58 additions and 5 deletions

View file

@ -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:

View file

@ -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};
%}

View file

@ -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

View file

@ -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

View file

@ -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);