Commit 1b9ee723 by Per Bothner Committed by Per Bothner

jcf-write.c (generate_classfile): Don't write ConstantValue attribute if field is not final...


	* jcf-write.c (generate_classfile):  Don't write ConstantValue
	attribute if field is not final, for compatibility with jdk.

	* jcf-write.c (generate_classfile):  Convert ConstantValue values
	to correct type.  Work-around for front-end bug.
	* class.c (set_constant_value):  Error if constant has wrong type.

From-SVN: r45298
parent b8ec5764
2001-08-30 Per Bothner <per@bothner.com> 2001-08-30 Per Bothner <per@bothner.com>
* jcf-write.c (generate_classfile): Don't write ConstantValue
attribute if field is not final, for compatibility with jdk.
* jcf-write.c (generate_classfile): Convert ConstantValue values
to correct type. Work-around for front-end bug.
* class.c (set_constant_value): Error if constant has wrong type.
2001-08-30 Per Bothner <per@bothner.com>
* jcf-dump.c (print_constant): Fix fencepost error so "Float" and * jcf-dump.c (print_constant): Fix fencepost error so "Float" and
"Double" are printed at verbosity 1. "Double" are printed at verbosity 1.
......
...@@ -777,6 +777,12 @@ set_constant_value (field, constant) ...@@ -777,6 +777,12 @@ set_constant_value (field, constant)
else else
{ {
DECL_INITIAL (field) = constant; DECL_INITIAL (field) = constant;
if (TREE_TYPE (constant) != TREE_TYPE (field)
&& ! (TREE_TYPE (constant) == int_type_node
&& INTEGRAL_TYPE_P (TREE_TYPE (field))
&& TYPE_PRECISION (TREE_TYPE (field)) <= 32))
error ("ConstantValue attribute of field '%s' has wrong type",
IDENTIFIER_POINTER (DECL_NAME (field)));
if (FIELD_FINAL (field)) if (FIELD_FINAL (field))
DECL_FIELD_FINAL_IUD (field) = 1; DECL_FIELD_FINAL_IUD (field) = 1;
} }
......
...@@ -2884,7 +2884,8 @@ generate_classfile (clas, state) ...@@ -2884,7 +2884,8 @@ generate_classfile (clas, state)
build_java_signature (TREE_TYPE (part))); build_java_signature (TREE_TYPE (part)));
PUT2(i); PUT2(i);
have_value = DECL_INITIAL (part) != NULL_TREE have_value = DECL_INITIAL (part) != NULL_TREE
&& FIELD_STATIC (part) && CONSTANT_VALUE_P (DECL_INITIAL (part)); && FIELD_STATIC (part) && CONSTANT_VALUE_P (DECL_INITIAL (part))
&& FIELD_FINAL (part);
if (have_value) if (have_value)
attr_count++; attr_count++;
...@@ -2896,6 +2897,8 @@ generate_classfile (clas, state) ...@@ -2896,6 +2897,8 @@ generate_classfile (clas, state)
{ {
tree init = DECL_INITIAL (part); tree init = DECL_INITIAL (part);
static tree ConstantValue_node = NULL_TREE; static tree ConstantValue_node = NULL_TREE;
// This conversion is a work-around for front-end bug.
init = convert (TREE_TYPE (part), init);
ptr = append_chunk (NULL, 8, state); ptr = append_chunk (NULL, 8, state);
if (ConstantValue_node == NULL_TREE) if (ConstantValue_node == NULL_TREE)
ConstantValue_node = get_identifier ("ConstantValue"); ConstantValue_node = get_identifier ("ConstantValue");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment