This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Excise CHAR_TYPE from Java
- From: Nathan Sidwell <nathan at codesourcery dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: aph at redhat dot com
- Date: Thu, 09 Dec 2004 16:08:38 +0000
- Subject: Excise CHAR_TYPE from Java
- Organization: Codesourcery LLC
I noticed that tree.def said this
/* CHAR in Pascal; not used in C.
No special fields needed. */
about CHAR_TYPE. Well, it is used in Java too, but only just. Rather
than fix the comment to reflect reality, I decided to fix reality (much more
satisfying :)
This patch removes the Java FE's use of CHAR_TYPE, by adding explicit
checks for char_type_node as appropriate -- that is what the C++ FE does
when it needs to distinguish identically laid out wchar_t from short or int
(or whatever it's identical to).
Obviously, if this goes in, the next step will be to nuke the uses of
CHAR_TYPE from the middle end.
booted & tested on i686-pc-linux-gnu, ok?
Let me know if you don't think this is an appropriate cleanup for now.
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk
2004-12-09 Nathan Sidwell <nathan@codesourcery.com>
* decl.c (java_init_decl_processing): Make char_type_node an
INTEGER_TYPE.
* jcf-write.c (adjusted_typed_op): Move CHAR_TYPE processing into
INTEGER_TYPE and adjust.
* mangle.c (mangle_type): Likewise.
* typeck.c (convert, promote_type, build_java_signature): Likewise.
* verify.c (verify_jvm_instructions): Remove CHAR_TYPE check.
* parse.h (JINTERGAL_TYPE_P): Likewise.
Index: java/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/decl.c,v
retrieving revision 1.206
diff -c -3 -p -r1.206 decl.c
*** java/decl.c 27 Nov 2004 20:48:16 -0000 1.206
--- java/decl.c 9 Dec 2004 15:50:22 -0000
*************** java_init_decl_processing (void)
*** 656,662 ****
initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
short_array_type_node = build_prim_array_type (short_type_node, 200);
#endif
! char_type_node = make_node (CHAR_TYPE);
TYPE_PRECISION (char_type_node) = 16;
fixup_unsigned_type (char_type_node);
pushdecl (build_decl (TYPE_DECL, get_identifier ("char"), char_type_node));
--- 656,662 ----
initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
short_array_type_node = build_prim_array_type (short_type_node, 200);
#endif
! char_type_node = make_node (INTEGER_TYPE);
TYPE_PRECISION (char_type_node) = 16;
fixup_unsigned_type (char_type_node);
pushdecl (build_decl (TYPE_DECL, get_identifier ("char"), char_type_node));
Index: java/jcf-write.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/jcf-write.c,v
retrieving revision 1.158
diff -c -3 -p -r1.158 jcf-write.c
*** java/jcf-write.c 24 Nov 2004 11:41:38 -0000 1.158
--- java/jcf-write.c 9 Dec 2004 15:50:28 -0000
*************** adjust_typed_op (tree type, int max)
*** 881,893 ****
case RECORD_TYPE: return 4;
case BOOLEAN_TYPE:
return TYPE_PRECISION (type) == 32 || max < 5 ? 0 : 5;
- case CHAR_TYPE:
- return TYPE_PRECISION (type) == 32 || max < 6 ? 0 : 6;
case INTEGER_TYPE:
switch (TYPE_PRECISION (type))
{
! case 8: return max < 5 ? 0 : 5;
! case 16: return max < 7 ? 0 : 7;
case 32: return 0;
case 64: return 1;
}
--- 881,899 ----
case RECORD_TYPE: return 4;
case BOOLEAN_TYPE:
return TYPE_PRECISION (type) == 32 || max < 5 ? 0 : 5;
case INTEGER_TYPE:
switch (TYPE_PRECISION (type))
{
! case 8:
! {
! int special_val = 5 + (type == char_type_node);
! return max < special_val ? 0 : special_val;
! }
! case 16:
! {
! int special_val = 7 - (type == char_type_node);
! return max < special_val ? 0 : special_val;
! }
case 32: return 0;
case 64: return 1;
}
Index: java/mangle.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/mangle.c,v
retrieving revision 1.32
diff -c -3 -p -r1.32 mangle.c
*** java/mangle.c 22 Oct 2003 18:00:06 -0000 1.32
--- java/mangle.c 9 Dec 2004 15:50:29 -0000
*************** mangle_type (tree type)
*** 191,202 ****
{
char code;
case BOOLEAN_TYPE: code = 'b'; goto primitive;
- case CHAR_TYPE: code = 'w'; goto primitive;
case VOID_TYPE: code = 'v'; goto primitive;
case INTEGER_TYPE:
/* Get the original type instead of the arguments promoted type.
Avoid symbol name clashes. Should call a function to do that.
FIXME. */
if (type == promoted_short_type_node)
type = short_type_node;
if (type == promoted_byte_type_node)
--- 191,208 ----
{
char code;
case BOOLEAN_TYPE: code = 'b'; goto primitive;
case VOID_TYPE: code = 'v'; goto primitive;
case INTEGER_TYPE:
/* Get the original type instead of the arguments promoted type.
Avoid symbol name clashes. Should call a function to do that.
FIXME. */
+ if (type == char_type_node
+ || type == promoted_char_type_node)
+ {
+ code = 'w';
+ goto primitive;
+ }
+
if (type == promoted_short_type_node)
type = short_type_node;
if (type == promoted_byte_type_node)
Index: java/parse.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.h,v
retrieving revision 1.103
diff -c -3 -p -r1.103 parse.h
*** java/parse.h 15 Oct 2004 18:43:10 -0000 1.103
--- java/parse.h 9 Dec 2004 15:50:31 -0000
*************** extern tree stabilize_reference (tree);
*** 192,199 ****
/* Types classification, according to the JLS, section 4.2 */
#define JFLOAT_TYPE_P(TYPE) (TYPE && TREE_CODE ((TYPE)) == REAL_TYPE)
#define JINTEGRAL_TYPE_P(TYPE) ((TYPE) \
! && (TREE_CODE ((TYPE)) == INTEGER_TYPE \
! || TREE_CODE ((TYPE)) == CHAR_TYPE))
#define JNUMERIC_TYPE_P(TYPE) ((TYPE) \
&& (JFLOAT_TYPE_P ((TYPE)) \
|| JINTEGRAL_TYPE_P ((TYPE))))
--- 192,198 ----
/* Types classification, according to the JLS, section 4.2 */
#define JFLOAT_TYPE_P(TYPE) (TYPE && TREE_CODE ((TYPE)) == REAL_TYPE)
#define JINTEGRAL_TYPE_P(TYPE) ((TYPE) \
! && (TREE_CODE ((TYPE)) == INTEGER_TYPE))
#define JNUMERIC_TYPE_P(TYPE) ((TYPE) \
&& (JFLOAT_TYPE_P ((TYPE)) \
|| JINTEGRAL_TYPE_P ((TYPE))))
Index: java/typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/typeck.c,v
retrieving revision 1.73
diff -c -3 -p -r1.73 typeck.c
*** java/typeck.c 25 Nov 2004 03:46:41 -0000 1.73
--- java/typeck.c 9 Dec 2004 15:50:33 -0000
*************** convert (tree type, tree expr)
*** 133,139 ****
return fold (convert_to_boolean (type, expr));
if (code == INTEGER_TYPE)
{
! if ((really_constant_p (expr)
|| (! flag_unsafe_math_optimizations
&& ! flag_emit_class_files))
&& TREE_CODE (TREE_TYPE (expr)) == REAL_TYPE
--- 133,142 ----
return fold (convert_to_boolean (type, expr));
if (code == INTEGER_TYPE)
{
! if (type == char_type_node
! || type == promoted_char_type_node)
! return fold (convert_to_char (type, expr));
! else if ((really_constant_p (expr)
|| (! flag_unsafe_math_optimizations
&& ! flag_emit_class_files))
&& TREE_CODE (TREE_TYPE (expr)) == REAL_TYPE
*************** convert (tree type, tree expr)
*** 151,158 ****
}
if (code == REAL_TYPE)
return fold (convert_to_real (type, expr));
- if (code == CHAR_TYPE)
- return fold (convert_to_char (type, expr));
if (code == POINTER_TYPE)
return fold (convert_to_pointer (type, expr));
error ("conversion to non-scalar type requested");
--- 154,159 ----
*************** promote_type (tree type)
*** 447,457 ****
if (type == boolean_type_node)
return promoted_boolean_type_node;
goto handle_int;
! case CHAR_TYPE:
if (type == char_type_node)
return promoted_char_type_node;
- goto handle_int;
- case INTEGER_TYPE:
handle_int:
if (TYPE_PRECISION (type) < TYPE_PRECISION (int_type_node))
{
--- 448,456 ----
if (type == boolean_type_node)
return promoted_boolean_type_node;
goto handle_int;
! case INTEGER_TYPE:
if (type == char_type_node)
return promoted_char_type_node;
handle_int:
if (TYPE_PRECISION (type) < TYPE_PRECISION (int_type_node))
{
*************** build_java_signature (tree type)
*** 621,629 ****
switch (TREE_CODE (type))
{
case BOOLEAN_TYPE: sg[0] = 'Z'; goto native;
- case CHAR_TYPE: sg[0] = 'C'; goto native;
case VOID_TYPE: sg[0] = 'V'; goto native;
case INTEGER_TYPE:
switch (TYPE_PRECISION (type))
{
case 8: sg[0] = 'B'; goto native;
--- 620,634 ----
switch (TREE_CODE (type))
{
case BOOLEAN_TYPE: sg[0] = 'Z'; goto native;
case VOID_TYPE: sg[0] = 'V'; goto native;
case INTEGER_TYPE:
+ if (type == char_type_node
+ || type == promoted_char_type_node)
+ {
+ sg[0] = 'C';
+ goto native;
+ }
+
switch (TYPE_PRECISION (type))
{
case 8: sg[0] = 'B'; goto native;
Index: java/verify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/verify.c,v
retrieving revision 1.68
diff -c -3 -p -r1.68 verify.c
*** java/verify.c 25 Nov 2004 07:03:55 -0000 1.68
--- java/verify.c 9 Dec 2004 15:50:36 -0000
*************** verify_jvm_instructions (JCF* jcf, const
*** 952,958 ****
case OPCODE_return: type = void_type_node; goto ret;
case OPCODE_ireturn:
if ((TREE_CODE (return_type) == BOOLEAN_TYPE
- || TREE_CODE (return_type) == CHAR_TYPE
|| TREE_CODE (return_type) == INTEGER_TYPE)
&& TYPE_PRECISION (return_type) <= 32)
type = return_type;
--- 952,957 ----