This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Patch: PR 6382 fix (not for 3.1)
- From: Tom Tromey <tromey at redhat dot com>
- To: Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Cc: Java Patch List <java-patches at gcc dot gnu dot org>
- Date: 24 Apr 2002 11:26:00 -0600
- Subject: Patch: PR 6382 fix (not for 3.1)
- Reply-to: tromey at redhat dot com
This patch fixes PR 6382.
In Java, String conversion of integral types always prints in decimal.
Alex tells me that print_int_node() was intended for debugging only.
So this patch introduces a new function which formats a number as a
decimal string. It does this using shifting and masking -- long
division in binary. Perhaps there's a more efficient way (though this
method really isn't that bad).
This code does have an ASCII assumption in it. I've marked it with a
FIXME, but perhaps I ought to remove it, on the theory that in Java
all internal string information is in UTF-8 -- so this assumption is
valid.
Tested on x86 Red Hat Linux 6.2. It fixes the test case in the PR
(I'll check that in separately).
Ok to commit? This is something I would commit to the trunk, and then
later to the branch for 3.1.1 (not 3.1).
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
For PR java/6382:
* parse.y (string_convert_int_cst): New function.
(merge_string_cste): Use it.
Index: parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.372
diff -u -r1.372 parse.y
--- parse.y 15 Apr 2002 09:25:29 -0000 1.372
+++ parse.y 24 Apr 2002 17:11:46 -0000
@@ -337,6 +337,8 @@
PTR));
static bool emit_test_initialization PARAMS ((struct hash_entry *, PTR));
+static char *string_convert_int_cst PARAMS ((tree));
+
/* Number of error found so far. */
int java_error_count;
/* Number of warning found so far. */
@@ -12552,8 +12554,82 @@
return assignment;
}
-/* Print an INTEGER_CST node in a static buffer, and return the buffer. */
+/* Print an INTEGER_CST node as decimal in a static buffer, and return
+ the buffer. This is used only for string conversion. */
+static char *
+string_convert_int_cst (node)
+ tree node;
+{
+ static char buffer[80];
+
+ unsigned HOST_WIDE_INT lo = TREE_INT_CST_LOW (node);
+ unsigned HOST_WIDE_INT hi = TREE_INT_CST_HIGH (node);
+ char *p = buffer + sizeof (buffer) - 1;
+ int neg = 0;
+
+ unsigned HOST_WIDE_INT hibit = (((unsigned HOST_WIDE_INT) 1)
+ << (HOST_BITS_PER_WIDE_INT - 1));
+
+ *p-- = '\0';
+
+ /* If negative, note the fact and negate the value. */
+ if ((hi & hibit))
+ {
+ lo = ~lo;
+ hi = ~hi;
+ if (++lo == 0)
+ ++hi;
+ neg = 1;
+ }
+
+ /* Divide by 10 until there are no bits left. */
+ while (hi || lo)
+ {
+ unsigned HOST_WIDE_INT acc = 0;
+ unsigned HOST_WIDE_INT outhi = 0, outlo = 0;
+ unsigned int i;
+
+ /* Use long division to compute the result and the remainder. */
+ for (i = 0; i < 2 * HOST_BITS_PER_WIDE_INT; ++i)
+ {
+ /* Shift a bit into accumulator. */
+ acc <<= 1;
+ if ((hi & hibit))
+ acc |= 1;
+ /* Shift the value. */
+ hi <<= 1;
+ if ((lo & hibit))
+ hi |= 1;
+ lo <<= 1;
+
+ /* Shift the correct bit into the result. */
+ outhi <<= 1;
+ if ((outlo & hibit))
+ outhi |= 1;
+ outlo <<= 1;
+ if (acc >= 10)
+ {
+ acc -= 10;
+ outlo |= 1;
+ }
+ }
+
+ /* FIXME: ASCII assumption. */
+ *p-- = '0' + acc;
+
+ hi = outhi;
+ lo = outlo;
+ }
+
+ if (neg)
+ *p-- = '-';
+
+ return p + 1;
+}
+
+/* Print an INTEGER_CST node in a static buffer, and return the
+ buffer. This is used only for error handling. */
char *
print_int_node (node)
tree node;
@@ -13676,8 +13752,8 @@
string = ch;
}
else
- string = print_int_node (op2);
-
+ string = string_convert_int_cst (op2);
+
return do_merge_string_cste (op1, string, strlen (string), after);
}
return NULL_TREE;