From: tromey Date: Mon, 18 Nov 2002 18:13:36 +0000 (+0000) Subject: Fix for PR java/7912: X-Git-Tag: upstream/4.9.2~83369 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ecb1637cc30e93ed3e12567baf26f7a1697d289d;p=platform%2Fupstream%2Flinaro-gcc.git Fix for PR java/7912: * expr.c (can_widen_reference_to): Allow cast of array to Cloneable or Serializable. * java-tree.h (java_lang_cloneable_identifier_node): Declare. (java_io_serializable_identifier_node): Likewise. * parse.y (java_lang_cloneable, java_io_serializable): Removed. (valid_ref_assignconv_cast_p): Use new identifier nodes. * lex.c (java_init_lex): Don't initialize java_lang_cloneable and java_io_serializable. * decl.c (java_init_decl_processing): Initialize java_lang_cloneable_identifier_node and java_io_serializable_identifier_node. (java_lang_cloneable_identifier_node): New global. (java_io_serializable_identifier_node): Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@59227 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/java/ChangeLog b/gcc/java/ChangeLog index d0dd068..e8c9d51 100644 --- a/gcc/java/ChangeLog +++ b/gcc/java/ChangeLog @@ -1,3 +1,20 @@ +2002-11-18 Tom Tromey + + Fix for PR java/7912: + * expr.c (can_widen_reference_to): Allow cast of array to + Cloneable or Serializable. + * java-tree.h (java_lang_cloneable_identifier_node): Declare. + (java_io_serializable_identifier_node): Likewise. + * parse.y (java_lang_cloneable, java_io_serializable): Removed. + (valid_ref_assignconv_cast_p): Use new identifier nodes. + * lex.c (java_init_lex): Don't initialize java_lang_cloneable and + java_io_serializable. + * decl.c (java_init_decl_processing): Initialize + java_lang_cloneable_identifier_node and + java_io_serializable_identifier_node. + (java_lang_cloneable_identifier_node): New global. + (java_io_serializable_identifier_node): Likewise. + 2002-11-14 Jens-Michael Hoffmann * buffer.c: Remove unnecessary casts. diff --git a/gcc/java/decl.c b/gcc/java/decl.c index bcf30b3..9e8efef 100644 --- a/gcc/java/decl.c +++ b/gcc/java/decl.c @@ -57,6 +57,12 @@ static tree check_local_named_variable PARAMS ((tree, tree, int, int *)); static tree check_local_unnamed_variable PARAMS ((tree, tree, tree)); static void dump_function PARAMS ((enum tree_dump_index, tree)); +/* Name of the Cloneable class. */ +tree java_lang_cloneable_identifier_node; + +/* Name of the Serializable class. */ +tree java_io_serializable_identifier_node; + /* Set to nonzero value in order to emit class initilization code before static field references. */ extern int always_initialize_class_p; @@ -601,6 +607,10 @@ java_init_decl_processing () access0_identifier_node = get_identifier ("access$0"); classdollar_identifier_node = get_identifier ("class$"); + java_lang_cloneable_identifier_node = get_identifier ("java.lang.Cloneable"); + java_io_serializable_identifier_node = + get_identifier ("java.io.Serializable"); + /* for lack of a better place to put this stub call */ init_expr_processing(); diff --git a/gcc/java/expr.c b/gcc/java/expr.c index 0c434e9..8db2670 100644 --- a/gcc/java/expr.c +++ b/gcc/java/expr.c @@ -1,5 +1,5 @@ /* Process expressions for the GNU compiler for the Java(TM) language. - Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001 + Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. This file is part of GNU CC. @@ -391,7 +391,12 @@ can_widen_reference_to (source_type, target_type) { HOST_WIDE_INT source_length, target_length; if (TYPE_ARRAY_P (source_type) != TYPE_ARRAY_P (target_type)) - return 0; + { + /* An array implements Cloneable and Serializable. */ + tree name = DECL_NAME (TYPE_NAME (target_type)); + return (name == java_lang_cloneable_identifier_node + || name == java_io_serializable_identifier_node); + } target_length = java_array_type_length (target_type); if (target_length >= 0) { diff --git a/gcc/java/java-tree.h b/gcc/java/java-tree.h index 051e41b..046cb9d 100644 --- a/gcc/java/java-tree.h +++ b/gcc/java/java-tree.h @@ -258,6 +258,9 @@ typedef struct CPool constant_pool; #define COMPONENT_REF_SIGNATURE(CPOOL, IDX) \ NAME_AND_TYPE_SIGNATURE (CPOOL, COMPONENT_REF_NAME_AND_TYPE(CPOOL, IDX)) +extern GTY(()) tree java_lang_cloneable_identifier_node; +extern GTY(()) tree java_io_serializable_identifier_node; + enum java_tree_index { JTI_PROMOTED_BYTE_TYPE_NODE, diff --git a/gcc/java/lex.c b/gcc/java/lex.c index f1589db..eecbcff 100644 --- a/gcc/java/lex.c +++ b/gcc/java/lex.c @@ -91,10 +91,6 @@ java_init_lex (finput, encoding) if (!java_lang_id) java_lang_id = get_identifier ("java.lang"); - if (!java_lang_cloneable) - java_lang_cloneable = get_identifier ("java.lang.Cloneable"); - if (!java_io_serializable) - java_io_serializable = get_identifier ("java.io.Serializable"); if (!inst_id) inst_id = get_identifier ("inst$"); if (!wpv_id) diff --git a/gcc/java/parse.y b/gcc/java/parse.y index 61595b8..2a77235 100644 --- a/gcc/java/parse.y +++ b/gcc/java/parse.y @@ -391,12 +391,6 @@ static GTY(()) tree java_lang_id; instance/field access functions. */ static GTY(()) tree inst_id; -/* The "java.lang.Cloneable" qualified name. */ -static GTY(()) tree java_lang_cloneable; - -/* The "java.io.Serializable" qualified name. */ -static GTY(()) tree java_io_serializable; - /* Context and flag for static blocks */ static GTY(()) tree current_static_block; @@ -13071,9 +13065,10 @@ valid_ref_assignconv_cast_p (source, dest, cast) { /* Array */ return (cast - && (DECL_NAME (TYPE_NAME (source)) == java_lang_cloneable + && (DECL_NAME (TYPE_NAME (source)) + == java_lang_cloneable_identifier_node || (DECL_NAME (TYPE_NAME (source)) - == java_io_serializable))); + == java_io_serializable_identifier_node))); } } if (TYPE_ARRAY_P (source)) @@ -13083,8 +13078,10 @@ valid_ref_assignconv_cast_p (source, dest, cast) /* Can't cast an array to an interface unless the interface is java.lang.Cloneable or java.io.Serializable. */ if (TYPE_INTERFACE_P (dest)) - return (DECL_NAME (TYPE_NAME (dest)) == java_lang_cloneable - || DECL_NAME (TYPE_NAME (dest)) == java_io_serializable); + return (DECL_NAME (TYPE_NAME (dest)) + == java_lang_cloneable_identifier_node + || (DECL_NAME (TYPE_NAME (dest)) + == java_io_serializable_identifier_node)); else /* Arrays */ { tree source_element_type = TYPE_ARRAY_ELEMENT (source);