aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenneth Russel <[email protected]>2008-08-17 23:52:29 +0000
committerKenneth Russel <[email protected]>2008-08-17 23:52:29 +0000
commit10032c0115f2794a254cffc2a1cd5e48ca8ff0b8 (patch)
tree5b599c573265a8744c353e840fb09634ee85b67d
parentc4e636dd43da8f327f726a5a508e033197d2ab80 (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
-rw-r--r--src/java/com/sun/gluegen/JavaEmitter.java11
-rw-r--r--src/java/com/sun/gluegen/cgram/GnuCParser.g4
-rw-r--r--src/java/com/sun/gluegen/pcpp/PCPP.java2
-rw-r--r--test/issue7.cfg5
-rwxr-xr-xtest/issue7.h19
5 files changed, 33 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('"');
diff --git a/test/issue7.cfg b/test/issue7.cfg
new file mode 100644
index 0000000..d7afc83
--- /dev/null
+++ b/test/issue7.cfg
@@ -0,0 +1,5 @@
+Style AllStatic
+Package issue7
+JavaClass Issue7
+JavaOutputDir ./
+NativeOutputDir ./
diff --git a/test/issue7.h b/test/issue7.h
new file mode 100755
index 0000000..ba2d3f5
--- /dev/null
+++ b/test/issue7.h
@@ -0,0 +1,19 @@
+#define inttest0 100
+#define inttest1 -100
+
+#define longtest0 10000000000
+#define longtest1 -10000000000
+
+#define floattest0 100.0
+#define floattest1 -100.0
+#define floattest2 0.01
+#define floattest3 -0.01
+#define floattest4 1e2
+#define floattest5 -1e2
+#define floattest6 1e-2
+#define floattest7 -1e-2
+
+#define doubletest0 2e150
+#define doubletest1 -2e150
+#define doubletest2 2e-150
+#define doubletest3 -2e-150