public inbox for java-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [gcjx] Patch: FYI: handle static field refs
@ 2005-10-04 22:15 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2005-10-04 22:15 UTC (permalink / raw)
  To: Java Patch List

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-10-04 22:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-10-04 22:15 [gcjx] Patch: FYI: handle static field refs Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).