From 173474fa26823a6a508344430ec0f4443e0bc8b9 Mon Sep 17 00:00:00 2001 From: Kenneth Russel Date: Tue, 27 Feb 2007 22:56:30 +0000 Subject: Incorporated fixes from Krishna Gadepalli in handling of enums git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/../svn-server-sync/gluegen/trunk@57 a78bb65f-1512-4460-ba86-f6dc96a7bf27 --- src/java/com/sun/gluegen/cgram/HeaderParser.g | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'src/java') diff --git a/src/java/com/sun/gluegen/cgram/HeaderParser.g b/src/java/com/sun/gluegen/cgram/HeaderParser.g index abb3de4..f91f146 100644 --- a/src/java/com/sun/gluegen/cgram/HeaderParser.g +++ b/src/java/com/sun/gluegen/cgram/HeaderParser.g @@ -594,13 +594,29 @@ enumList[EnumType enumeration] { enumerator[EnumType enumeration, long defaultValue] returns [long newDefaultValue] { newDefaultValue = defaultValue; } - : eName:ID ( ASSIGN eVal:expr )? { - // FIXME! Integer.parseInt() will throw if its argument is in octal or hex format. - long value = (eVal == null) ? defaultValue : Long.parseLong(eVal.getText()); + : eName:ID ( ASSIGN eVal:expr )? { + long value = 0; + if (eVal != null) { + String vTxt = eVal.getText(); + if (enumHash.containsKey(vTxt)) { + EnumType oldEnumType = (EnumType) enumHash.get(vTxt); + value = oldEnumType.getEnumValue(vTxt); + } else { + try { + value = Long.decode(vTxt).longValue(); + } catch (NumberFormatException e) { + System.err.println("NumberFormatException: " + enumerator_AST_in); + throw e; + } + } + } else { + value = defaultValue; + } + newDefaultValue = value+1; String eTxt = eName.getText(); if (enumHash.containsKey(eTxt)) { - EnumType oldEnumType = ((EnumType)enumHash.get(eTxt)); + EnumType oldEnumType = (EnumType) enumHash.get(eTxt); long oldValue = oldEnumType.getEnumValue(eTxt); System.err.println("WARNING: redefinition of enumerated value '" + eTxt + "';" + " existing definition is in enumeration '" + oldEnumType.getName() + -- cgit v1.2.3