[gcjx] Patch: FYI: remove .class-specific test

Tom Tromey tromey@redhat.com
Sat Jan 22 08:35:00 GMT 2005


I'm checking this in on the gcjx branch.

I prefer not to have tests for whether a given class came from a
.class file in them model.  It isn't always possible to avoid this,
but in the case of the 'implements' clause for an annotation class,
it is.  This patch changes things so that this case is handled in the
class file reader.

Tom

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

	* model/annotype.cc (resolve_hook): Don't special case class
	files.
	* bytecode/classreader.cc (parse): Specially handle interfaces of
	annotation types.
	* model/fwdtype.hh (model_forwarding_full::get_name): New method.

Index: bytecode/classreader.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/bytecode/Attic/classreader.cc,v
retrieving revision 1.1.2.6
diff -u -r1.1.2.6 classreader.cc
--- bytecode/classreader.cc 22 Jan 2005 07:56:24 -0000 1.1.2.6
+++ bytecode/classreader.cc 22 Jan 2005 08:33:50 -0000
@@ -1004,6 +1004,20 @@
       result->set_modifiers (access_flags);
     }
 
+  if (result->annotation_p ())
+    {
+      // Internally we add interfaces to an annotation when resolving.
+      // So, here we just check to make sure the class file is
+      // correct, and then we let the model do its thing later.
+      if (interfaces.size () != 1)
+	throw error ("annotation type must implement just one interface, %<java.lang.annotation.Annotation%>");
+      ref_forwarding_type t = interfaces.front ();
+      if (dynamic_cast<model_forwarding_full *> (t.get ()) == NULL
+	  || (assert_cast<model_forwarding_full *> (t.get ())->get_name ()
+	      != "java/lang/annotation/Annotation"))
+	throw error ("annotation type must implement just one interface, %<java.lang.annotation.Annotation%>");
+      interfaces.clear ();
+    }
   result->set_implements (interfaces);
 
   ref_unit unit (new model_unit_class (where, inner_infos, pool));
Index: model/annotype.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/model/Attic/annotype.cc,v
retrieving revision 1.1.2.3
diff -u -r1.1.2.3 annotype.cc
--- model/annotype.cc 22 Jan 2005 07:56:24 -0000 1.1.2.3
+++ model/annotype.cc 22 Jan 2005 08:33:51 -0000
@@ -53,22 +53,13 @@
 {
   model_class *annot
     = global->get_compiler ()->java_lang_annotation_Annotation ();
-  if (from_class)
-    {
-      if (interfaces.size () != 1)
-	throw error ("annotation implements wrong number of interfaces");
-      // FIXME: check that we have just Annotation here.
-    }
-  else
-    {
-      // When parsing we don't add the interface.
-      assert (interfaces.empty ());
 
-      location w = get_location ();
-      ref_forwarding_type anno = new model_forwarding_resolved (w, annot);
-      std::list<ref_forwarding_type> ifaces;
-      set_implements (ifaces);
-    }
+  assert (interfaces.empty ());
+
+  location w = get_location ();
+  ref_forwarding_type anno = new model_forwarding_resolved (w, annot);
+  std::list<ref_forwarding_type> ifaces;
+  set_implements (ifaces);
 
   for (member_type::const_iterator i = anno_members.begin ();
        i != anno_members.end ();
Index: model/fwdtype.hh
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/model/Attic/fwdtype.hh,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 fwdtype.hh
--- model/fwdtype.hh 13 Jan 2005 03:18:36 -0000 1.1.2.1
+++ model/fwdtype.hh 22 Jan 2005 08:33:51 -0000
@@ -1,6 +1,6 @@
 // Type forwarding.
 
-// Copyright (C) 2004 Free Software Foundation, Inc.
+// Copyright (C) 2004, 2005 Free Software Foundation, Inc.
 //
 // This file is part of GCC.
 //
@@ -191,6 +191,11 @@
   }
 
   void resolve (resolution_scope *);
+
+  std::string get_name () const
+  {
+    return name;
+  }
 };
 
 /// This is a forwarding type which finds its argument as a member of



More information about the Java-patches mailing list