This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[gcjx] Patch: FYI: more annotation class fixes
- From: Tom Tromey <tromey at redhat dot com>
- To: Java Patch List <java-patches at gcc dot gnu dot org>
- Date: 19 Jan 2005 12:43:57 -0700
- Subject: [gcjx] Patch: FYI: more annotation class fixes
- Reply-to: tromey at redhat dot com
I'm checking this in on the gcjx branch.
This fixes a few more buglets in the code to read annotations from a
.class file. (FWIW annotations still have a serious bug in
resolution, namely a meta-annotation which is applied to itself, like
@Documented, causes an erroneous circularity error.)
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
* model/annotype.cc (resolve_hook): Allow one interface when read
from .class.
* bytecode/classreader.hh (class_reader::parse_field_descriptor):
Declare.
* bytecode/classreader.cc (parse_field_descriptor): New method.
(parse_field): Use it.
(parse_annotation): Use it.
(parse_annotation_value): Use it when parsing class constants and
enum constants.
Index: bytecode/classreader.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/bytecode/Attic/classreader.cc,v
retrieving revision 1.1.2.4
diff -u -r1.1.2.4 classreader.cc
--- bytecode/classreader.cc 19 Jan 2005 03:09:43 -0000 1.1.2.4
+++ bytecode/classreader.cc 19 Jan 2005 19:45:44 -0000
@@ -155,13 +155,11 @@
case 'e':
{
- std::string class_name;
std::string field_name;
- std::string descriptor;
uint16 index = read_u2 ();
- pool->get_fieldref (index, class_name, field_name, descriptor);
- ref_forwarding_type base = new model_forwarding_full (where,
- descriptor);
+ ref_forwarding_type base = parse_field_descriptor (index);
+ uint16 fn_index = read_u2 ();
+ field_name = pool->get_utf8 (fn_index);
// FIXME.
// val = new model_enum_field_ref (where, base, field_name);
}
@@ -170,8 +168,7 @@
case 'c':
{
uint16 index = read_u2 ();
- std::string cname = pool->get_class (index);
- ref_forwarding_type t = new model_forwarding_full (cname);
+ ref_forwarding_type t = parse_field_descriptor (index);
val = new model_class_ref (where, t);
}
break;
@@ -202,7 +199,7 @@
class_reader::parse_annotation ()
{
uint16 index = read_u2 ();
- std::string anno_type_name = pool->get_utf8 (index);
+ ref_forwarding_type anno_type = parse_field_descriptor (index);
uint16 count = read_u2 ();
std::list<ref_annotation_value> values;
@@ -214,9 +211,7 @@
values.push_back (new model_annotation_value (where, name, expr));
}
- return new model_annotation (where,
- new model_forwarding_full (anno_type_name),
- values);
+ return new model_annotation (where, anno_type, values);
}
void
@@ -789,6 +784,17 @@
}
}
+ref_forwarding_type
+class_reader::parse_field_descriptor (uint16 name_index)
+{
+ std::string name = pool->get_utf8 (name_index);
+ unsigned int off = 0;
+ ref_forwarding_type t = one_type (name, off);
+ if (off != name.length ())
+ throw error ("malformed type descriptor %1") % name;
+ return t;
+}
+
void
class_reader::parse_field ()
{
@@ -797,12 +803,7 @@
uint16 descriptor_index = read_u2 ();
std::string name = pool->get_utf8 (name_index);
- std::string sig = pool->get_utf8 (descriptor_index);
- unsigned int off = 0;
- ref_forwarding_type vtype = one_type (sig, off);
- if (off != sig.length ())
- throw error ("malformed descriptor while parsing field %1")
- % name;
+ ref_forwarding_type vtype = parse_field_descriptor (descriptor_index);
current_field = new model_field (where, name, vtype, result.get ());
current_field->set_from_class ();
Index: bytecode/classreader.hh
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/bytecode/Attic/classreader.hh,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 classreader.hh
--- bytecode/classreader.hh 13 Jan 2005 03:18:34 -0000 1.1.2.1
+++ bytecode/classreader.hh 19 Jan 2005 19:45:44 -0000
@@ -1,6 +1,6 @@
// Read a class and put it in the model.
-// Copyright (C) 2004 Free Software Foundation, Inc.
+// Copyright (C) 2004, 2005 Free Software Foundation, Inc.
//
// This file is part of GCC.
//
@@ -143,6 +143,7 @@
class_file_error error (const char *) const;
class_known_attribute find_attribute_type (const std::string &);
+ ref_forwarding_type parse_field_descriptor (uint16);
ref_forwarding_type one_type (const std::string &, unsigned int &);
ref_forwarding_type parse_method_descriptor (const std::string &,
std::list<ref_forwarding_type> &);
Index: model/annotype.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/model/Attic/annotype.cc,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 annotype.cc
--- model/annotype.cc 13 Jan 2005 03:18:35 -0000 1.1.2.1
+++ model/annotype.cc 19 Jan 2005 19:45:44 -0000
@@ -1,6 +1,6 @@
// Represent an annotation type.
-// Copyright (C) 2004 Free Software Foundation, Inc.
+// Copyright (C) 2004, 2005 Free Software Foundation, Inc.
//
// This file is part of GCC.
//
@@ -51,14 +51,24 @@
void
model_annotation_type::resolve_hook (resolution_scope *scope)
{
- assert (interfaces.empty ());
+ 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,
- global->get_compiler ()->java_lang_annotation_Annotation ());
- std::list<ref_forwarding_type> ifaces;
- set_implements (ifaces);
+ 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 ();