diff --git a/gcc/java/ChangeLog b/gcc/java/ChangeLog index 760502d872e..2abb8d04d90 100644 --- a/gcc/java/ChangeLog +++ b/gcc/java/ChangeLog @@ -1,3 +1,20 @@ +2002-12-23 Jeff Sturm + + * class.c (build_static_field_ref): Check FIELD_FINAL. + + * constants.c (alloc_class_constant): Use TYPE_CPOOL_DATA_REF + instead of current_constant_pool_data_ref. + * java-tree.h (current_constant_pool_data_ref): Undefine. + (JTI_CURRENT_CONSTANT_POOL_DATA_REF): Remove. + * jcf-parse.c (init_outgoing_cpool): Don't initialize + current_constant_pool_data_ref. + + * except.c (prepare_eh_table_type ): Use DECL_NAME of class type, + not build_internal_class_name. + + * parse.y (patch_incomplete_class_ref): Always emit `class$' method. + Use it when class ref isn't certain to be compiled. + 2002-12-23 Joseph S. Myers * gcj.texi: Include gcc-common.texi. diff --git a/gcc/java/class.c b/gcc/java/class.c index f833888367c..5e5a66eb279 100644 --- a/gcc/java/class.c +++ b/gcc/java/class.c @@ -1076,7 +1076,9 @@ build_static_field_ref (fdecl) { tree fclass = DECL_CONTEXT (fdecl); int is_compiled = is_compiled_class (fclass); - if (is_compiled) + + /* Allow static final fields to fold to a constant. */ + if (is_compiled || FIELD_FINAL (fdecl)) { if (!DECL_RTL_SET_P (fdecl)) { diff --git a/gcc/java/constants.c b/gcc/java/constants.c index 977a7bdfece..ca8c8600232 100644 --- a/gcc/java/constants.c +++ b/gcc/java/constants.c @@ -388,10 +388,12 @@ alloc_class_constant (clas) static tree build_constant_data_ref () { - if (TYPE_CPOOL_DATA_REF (current_class)) - current_constant_pool_data_ref = TYPE_CPOOL_DATA_REF (current_class); + tree cpool_data_ref = NULL_TREE; - else if (current_constant_pool_data_ref == NULL_TREE) + if (TYPE_CPOOL_DATA_REF (current_class)) + cpool_data_ref = TYPE_CPOOL_DATA_REF (current_class); + + if (cpool_data_ref == NULL_TREE) { tree decl; tree decl_name = mangled_classname ("_CD_", current_class); @@ -400,10 +402,10 @@ build_constant_data_ref () one_elt_array_domain_type)); TREE_STATIC (decl) = 1; make_decl_rtl (decl, NULL); - TYPE_CPOOL_DATA_REF (current_class) = current_constant_pool_data_ref + TYPE_CPOOL_DATA_REF (current_class) = cpool_data_ref = build1 (ADDR_EXPR, ptr_type_node, decl); } - return current_constant_pool_data_ref; + return cpool_data_ref; } /* Get the pointer value at the INDEX'th element of the constant pool. */ diff --git a/gcc/java/except.c b/gcc/java/except.c index 4e662b94c5b..0c7a4742293 100644 --- a/gcc/java/except.c +++ b/gcc/java/except.c @@ -336,7 +336,7 @@ prepare_eh_table_type (type) else exp = fold (build (PLUS_EXPR, ptr_type_node, - build_utf8_ref (build_internal_class_name (type)), + build_utf8_ref (DECL_NAME (TYPE_NAME (type))), size_one_node)); return exp; } diff --git a/gcc/java/java-tree.h b/gcc/java/java-tree.h index 046cb9dfa68..41b6297948f 100644 --- a/gcc/java/java-tree.h +++ b/gcc/java/java-tree.h @@ -399,7 +399,6 @@ enum java_tree_index JTI_NATIVECODE_PTR_ARRAY_TYPE_NODE, JTI_WFL_OPERATOR, - JTI_CURRENT_CONSTANT_POOL_DATA_REF, JTI_MAIN_CLASS, JTI_CURRENT_CLASS, @@ -685,10 +684,6 @@ extern GTY(()) tree java_global_trees[JTI_MAX]; /* They need to be reset before processing each class */ extern struct CPool *outgoing_cpool; -/* If non-NULL, an ADDR_EXPR referencing a VAR_DECL containing - the constant data array for the current class. */ -#define current_constant_pool_data_ref \ - java_global_trees[JTI_CURRENT_CONSTANT_POOL_DATA_REF] #define wfl_operator \ java_global_trees[JTI_WFL_OPERATOR] diff --git a/gcc/java/jcf-parse.c b/gcc/java/jcf-parse.c index 4d6b8b7092a..6853f2ff943 100644 --- a/gcc/java/jcf-parse.c +++ b/gcc/java/jcf-parse.c @@ -709,7 +709,6 @@ load_inner_classes (cur_class) void init_outgoing_cpool () { - current_constant_pool_data_ref = NULL_TREE; outgoing_cpool = xmalloc (sizeof (struct CPool)); memset (outgoing_cpool, 0, sizeof (struct CPool)); } diff --git a/gcc/java/parse.y b/gcc/java/parse.y index b68eb158ab6..f22863095bd 100644 --- a/gcc/java/parse.y +++ b/gcc/java/parse.y @@ -14073,7 +14073,16 @@ patch_incomplete_class_ref (node) if (!(ref_type = resolve_type_during_patch (type))) return error_mark_node; - if (!flag_emit_class_files || JPRIMITIVE_TYPE_P (ref_type) + /* Generate the synthetic static method `class$'. (Previously we + deferred this, causing different method tables to be emitted + for native code and bytecode.) */ + if (!TYPE_DOT_CLASS (current_class)) + build_dot_class_method (current_class); + + /* If we're not emitting class files and we know ref_type is a + compiled class, build a direct reference. */ + if ((! flag_emit_class_files && is_compiled_class (ref_type)) + || JPRIMITIVE_TYPE_P (ref_type) || TREE_CODE (ref_type) == VOID_TYPE) { tree dot = build_class_ref (ref_type); @@ -14084,10 +14093,7 @@ patch_incomplete_class_ref (node) } /* If we're emitting class files and we have to deal with non - primitive types, we invoke (and consider generating) the - synthetic static method `class$'. */ - if (!TYPE_DOT_CLASS (current_class)) - build_dot_class_method (current_class); + primitive types, we invoke the synthetic static method `class$'. */ ref_type = build_dot_class_method_invocation (ref_type); return java_complete_tree (ref_type); }