This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gcjx] Patch: FYI: handle static field refs


I'm checking this in on the gcjx branch.

The tree-lowering code was not properly handling references to
constant fields.  The fix is appended.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>
	* tree.cc (visit_field_ref): Handle constant expressions.

Index: tree.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/tree.cc,v
retrieving revision 1.1.2.50
diff -u -r1.1.2.50 tree.cc
--- tree.cc 4 Oct 2005 02:08:31 -0000 1.1.2.50
+++ tree.cc 4 Oct 2005 22:14:29 -0000
@@ -1922,6 +1922,8 @@
 				 const ref_expression &expr,
 				 const model_field *field)
 {
+  bool should_inline = const_cast<model_field *> (field)->inlineable_p ();
+
   // Note that we don't need any special handling for 'array.length'
   // -- the generic code here works fine.
   tree expr_tree = NULL_TREE;
@@ -1929,25 +1931,45 @@
     {
       expr->visit (this);
       expr_tree = current;
+
+      // A very obscure case: if we have 'foo.bar', and bar is
+      // inlineable, we must inline it but we must also null-check
+      // 'foo'.
+      if (should_inline && ! field->static_p ())
+	expr_tree = gcc_builtins->check_reference (expr_tree, true);
     }
 
-#if 0
-  // FIXME: where should this go?  [ In the ABI ]
-  if (expr->type () != field->get_declaring_class ())
-    // FIXME: is this right?
-    emit_type_assertion (field->get_declaring_class (), expr->type ());
-#endif
+  if (should_inline)
+    {
+      model_expression *init = field->get_initializer ().get ();
+      // This assertion should be true due to constant folding when
+      // resolving the field.
+      assert (dynamic_cast<model_literal_base *> (init));
+      init->visit (this);
+
+      if (expr_tree != NULL_TREE)
+	current = build2 (COMPOUND_EXPR, TREE_TYPE (current),
+			  expr_tree, current);
 
-  // FIXME: handle inlining constant fields here (this is not
-  // abi-specific)
+      // FIXME: should annotate() here if possible.
+    }
+  else
+    {
+      // FIXME: Note that map_field_ref does not handle the case of a
+      // non-static reference to a static field.
 
-  // FIXME: Note that map_field_ref does not handle the case of a
-  // non-static reference to a static field.
+#if 0
+      // FIXME: where should this go?  [ In the ABI ]
+      if (expr->type () != field->get_declaring_class ())
+	// FIXME: is this right?
+	emit_type_assertion (field->get_declaring_class (), expr->type ());
+#endif
 
-  gcc_builtins->lay_out_class (field->get_declaring_class ());
-  current = gcc_builtins->map_field_ref (class_wrapper, expr_tree,
-					 const_cast<model_field *> (field));
-  annotate (current, elt);
+      gcc_builtins->lay_out_class (field->get_declaring_class ());
+      current = gcc_builtins->map_field_ref (class_wrapper, expr_tree,
+					     const_cast<model_field *> (field));
+      annotate (current, elt);
+    }
 }
 
 void


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]