[gcjx] Patch: FYI: differentiate abstract methods

Tom Tromey tromey@redhat.com
Tue Mar 22 11:20:00 GMT 2005


I'm checking this in on the gcjx branch.

In a couple of cases, gcjx will create an abstract method that is a
copy of another method, but with a couple of minor changes.  It turns
out that the tree generator wants to be able to find the original
method; it is simpler to do this than it is to figure out how to
handle these methods (e.g., in vtables) some other way.

This patch introduces a new subclass and arranges to create and use it
appropriately.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	* model/method.cc (create_abstract_instance): Create a
	model_abstract_method.
	* aot/aotclass.cc (find_in_vtable): Strip abstract methods.
	* model/invoke.cc (find_method): Create a model_abstract_method.
	* model/method.hh (class model_abstract_method): New class.

Index: aot/aotclass.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/aot/Attic/aotclass.cc,v
retrieving revision 1.1.2.7
diff -u -r1.1.2.7 aotclass.cc
--- aot/aotclass.cc 9 Mar 2005 01:49:36 -0000 1.1.2.7
+++ aot/aotclass.cc 21 Mar 2005 21:41:29 -0000
@@ -212,6 +212,15 @@
 {
   lay_out_vtable ();
 
+  // An abstract method can itself be derived from an abstract method.
+  // We strip them all off to get the method as actually declared.
+  while (dynamic_cast<model_abstract_method *> (method))
+    {
+      model_abstract_method *mam
+	= assert_cast<model_abstract_method *> (method);
+      method = mam->get_original ();
+    }
+
   int index = 0;
   for (std::vector<model_method *>::const_iterator i = vtable.begin ();
        i != vtable.end ();
Index: model/invoke.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/model/Attic/invoke.cc,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 invoke.cc
--- model/invoke.cc 12 Mar 2005 20:51:07 -0000 1.1.2.2
+++ model/invoke.cc 21 Mar 2005 21:41:32 -0000
@@ -245,8 +245,7 @@
 			      ? non_interface
 			      : *(maximal.begin ()));
 
-      phony = new model_method (chosen->get_location (),
-				chosen->get_declaring_class ());
+      phony = new model_abstract_method (chosen);
       phony->set_name (chosen->get_name ());
       phony->set_modifiers (chosen->get_modifiers ());
       // FIXME
Index: model/method.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/model/Attic/method.cc,v
retrieving revision 1.1.2.3
diff -u -r1.1.2.3 method.cc
--- model/method.cc 13 Feb 2005 03:46:45 -0000 1.1.2.3
+++ model/method.cc 21 Mar 2005 21:41:32 -0000
@@ -77,8 +77,7 @@
   assert (! static_p ());
   assert (type_parameters.empty ());
 
-  ref_method result = new model_method (get_location (),
-					get_declaring_class ());
+  ref_method result = new model_abstract_method (this);
   result->set_modifiers ((get_modifiers () | ACC_ABSTRACT) & ~ACC_FINAL);
   result->set_name (name);
   result->set_parameters (parameters);
Index: model/method.hh
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/model/Attic/method.hh,v
retrieving revision 1.1.2.3
diff -u -r1.1.2.3 method.hh
--- model/method.hh 12 Mar 2005 20:51:07 -0000 1.1.2.3
+++ model/method.hh 21 Mar 2005 21:41:32 -0000
@@ -350,6 +350,27 @@
   }
 };
 
+/// This represents a method that is the result of merging multiple
+/// abstract methods together.  
+class model_abstract_method : public model_method
+{
+  /// The original method which served as our template.
+  model_method *original;
+
+public:
+
+  model_abstract_method (model_method *m)
+    : model_method (m->get_location (), m->get_declaring_class ()),
+      original (m)
+  {
+  }
+
+  model_method *get_original () const
+  {
+    return original;
+  }
+};
+
 const format &operator% (const format &, model_method *);
 
 #endif // GCJX_MODEL_METHOD_HH



More information about the Java-patches mailing list