diff options
author | Kenneth Russel <[email protected]> | 2008-08-17 23:52:29 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2008-08-17 23:52:29 +0000 |
commit | 10032c0115f2794a254cffc2a1cd5e48ca8ff0b8 (patch) | |
tree | 5b599c573265a8744c353e840fb09634ee85b67d /src/java/com/sun/gluegen | |
parent | c4e636dd43da8f327f726a5a508e033197d2ab80 (diff) |
Fixed Issue 7: #define of negative numeric literals are ignored
Applied patch from user tck and adapted to the code structure of the
current branch. Thanks for the patch.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/../svn-server-sync/gluegen/branches/JOGL_2_SANDBOX@108 a78bb65f-1512-4460-ba86-f6dc96a7bf27
Diffstat (limited to 'src/java/com/sun/gluegen')
-rw-r--r-- | src/java/com/sun/gluegen/JavaEmitter.java | 11 | ||||
-rw-r--r-- | src/java/com/sun/gluegen/cgram/GnuCParser.g | 4 | ||||
-rw-r--r-- | src/java/com/sun/gluegen/pcpp/PCPP.java | 2 |
3 files changed, 9 insertions, 8 deletions
diff --git a/src/java/com/sun/gluegen/JavaEmitter.java b/src/java/com/sun/gluegen/JavaEmitter.java index 0bf9702..60daf89 100644 --- a/src/java/com/sun/gluegen/JavaEmitter.java +++ b/src/java/com/sun/gluegen/JavaEmitter.java @@ -229,12 +229,12 @@ public class JavaEmitter implements GlueEmitter { try { // see if it's a double or float double dVal = Double.parseDouble(value); + double absVal = Math.abs(dVal); // if constant is small enough, store it as a float instead of a double - if (dVal > Float.MIN_VALUE && dVal < Float.MAX_VALUE) { - return new Float((float)dVal); + if (absVal < Float.MIN_VALUE || absVal > Float.MAX_VALUE) { + return new Double(dVal); } - return new Double(dVal); - + return new Float((float) dVal); } catch (NumberFormatException e2) { throw new RuntimeException( "Cannot emit define \""+name+"\": value \""+value+ @@ -281,7 +281,8 @@ public class JavaEmitter implements GlueEmitter { if (optionalComment != null && optionalComment.length() != 0) { javaWriter().println(" /** " + optionalComment + " */"); } - javaWriter().println(" public static final " + type + " " + name + " = " + value + ";"); + String suffix = (type.equals("float") ? "f" : ""); + javaWriter().println(" public static final " + type + " " + name + " = " + value + suffix + ";"); } } } diff --git a/src/java/com/sun/gluegen/cgram/GnuCParser.g b/src/java/com/sun/gluegen/cgram/GnuCParser.g index e087a5c..7de057c 100644 --- a/src/java/com/sun/gluegen/cgram/GnuCParser.g +++ b/src/java/com/sun/gluegen/cgram/GnuCParser.g @@ -777,7 +777,7 @@ protected NumberSuffix ; Number - : ( ( Digit )+ ( '.' | 'e' | 'E' ) )=> ( Digit )+ + : ( ('-')? ( Digit )+ ( '.' | 'e' | 'E' ) )=> ('-')? ( Digit )+ ( '.' ( Digit )* ( Exponent )? | Exponent ) @@ -797,7 +797,7 @@ Number ( NumberSuffix )* - | '1'..'9' ( Digit )* + | ('-')? '1'..'9' ( Digit )* ( NumberSuffix )* diff --git a/src/java/com/sun/gluegen/pcpp/PCPP.java b/src/java/com/sun/gluegen/pcpp/PCPP.java index d5d9604..e539cee 100644 --- a/src/java/com/sun/gluegen/pcpp/PCPP.java +++ b/src/java/com/sun/gluegen/pcpp/PCPP.java @@ -71,7 +71,7 @@ public class PCPP { tok.wordChars('A', 'Z'); tok.wordChars('0', '9'); tok.wordChars('_', '_'); - tok.wordChars('.', '.'); + tok.wordChars('-', '.'); tok.wordChars(128 + 32, 255); tok.whitespaceChars(0, ' '); tok.quoteChar('"'); |