This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[gcjx] Patch: FYI: annotation reading and writing
- From: Tom Tromey <tromey at redhat dot com>
- To: Java Patch List <java-patches at gcc dot gnu dot org>
- Date: 18 Jan 2005 16:54:55 -0700
- Subject: [gcjx] Patch: FYI: annotation reading and writing
- Reply-to: tromey at redhat dot com
I'm checking this in on the gcjx branch.
This fixes a few bugs in annotation reading and writing.
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
* bytecode/attribute.cc (emit_annotation_value): Put annotation
class as utf8.
(emit_annotation): Likewise. Number of pairs takes two bytes.
(emit_annotation_value): Correctly write arrays. Handle nested
annotations.
* bytecode/classreader.cc (parse_annotation): Class is stored as
a Utf8Const.
(parse_parameter_annotations): Only one byte for number of
parameters.
(parse_annotation): Read two bytes for number of elements.
(parse_attributes): Fixed assertions.
Index: bytecode/attribute.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/bytecode/Attic/attribute.cc,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 attribute.cc
--- bytecode/attribute.cc 16 Jan 2005 04:36:41 -0000 1.1.2.2
+++ bytecode/attribute.cc 18 Jan 2005 23:58:25 -0000
@@ -26,6 +26,13 @@
#include "bytecode/attribute.hh"
#include "bytecode/generate.hh"
+static int emit_annotation_value (bytecode_stream *writer,
+ output_constant_pool *pool,
+ model_expression *expr);
+static int emit_annotation (bytecode_stream *writer,
+ output_constant_pool *pool,
+ model_annotation *anno);
+
bytecode_attribute::bytecode_attribute (output_constant_pool *p,
const std::string &n)
: pool (p),
@@ -248,7 +255,7 @@
else if (type == global->get_compiler ()->java_lang_Class ())
{
model_class_ref *ref = assert_cast<model_class_ref *> (expr);
- int index = pool->add (ref->get_class ());
+ int index = pool->add_utf (ref->get_class ()->get_descriptor ());
if (writer)
{
writer->put ('c');
@@ -263,17 +270,30 @@
std::list<ref_expression> array = init->get_initializers ();
if (writer)
- writer->put2 (array.size ());
- result += 2;
+ {
+ writer->put ('[');
+ writer->put2 (array.size ());
+ }
+ result += 3;
for (std::list<ref_expression>::const_iterator i = array.begin ();
i != array.end ();
++i)
result += emit_annotation_value (writer, pool, (*i).get ());
}
+ else if (type->annotation_p ())
+ {
+ model_annotation *annot = assert_cast<model_annotation *> (expr);
+ if (writer)
+ writer->put ('@');
+ ++result;
+
+ result += emit_annotation (writer, pool, annot);
+ }
else
{
- // FIXME: handle enum constant or attribute.
+ // The only remaining case is an enum constant.
+ // FIXME: unwrap the member ref and write it.
abort ();
}
@@ -288,15 +308,15 @@
{
int result = 0;
- int val = pool->add (anno->type ());
+ int val = pool->add_utf (anno->type ()->get_descriptor ());
if (writer)
writer->put2 (val);
result += 2;
std::list<ref_annotation_value> vals = anno->get_arguments ();
if (writer)
- writer->put (vals.size ());
- ++result;
+ writer->put2 (vals.size ());
+ result += 2;
for (std::list<ref_annotation_value>::const_iterator i = vals.begin ();
i != vals.end ();
Index: bytecode/classreader.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/bytecode/Attic/classreader.cc,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 classreader.cc
--- bytecode/classreader.cc 13 Jan 2005 03:18:34 -0000 1.1.2.1
+++ bytecode/classreader.cc 18 Jan 2005 23:58:25 -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.
//
@@ -202,11 +202,11 @@
class_reader::parse_annotation ()
{
uint16 index = read_u2 ();
- std::string anno_type_name = pool->get_class (index);
+ std::string anno_type_name = pool->get_utf8 (index);
- uint8 count = read_u1 ();
+ uint16 count = read_u2 ();
std::list<ref_annotation_value> values;
- for (uint8 i = 0; i < count; ++i)
+ for (uint16 i = 0; i < count; ++i)
{
index = read_u2 ();
std::string name = pool->get_utf8 (index);
@@ -233,7 +233,7 @@
assert (current_method);
std::list<ref_variable_decl> params = current_method->get_parameters ();
- uint8 count = read_u2 ();
+ uint8 count = read_u1 ();
if (count != params.size ())
throw error ("expected %1 parameter annotations, but found %2")
% params.size () % count;
@@ -600,8 +600,6 @@
int count = read_u2 ();
int seen = 0;
- assert (current_annotations.empty ());
-
for (int i = 0; i < count; ++i)
{
uint16 name_index = read_u2 ();
@@ -640,11 +638,15 @@
case ATTR_RUNTIMEVISIBLEPARAMETERANNOTATIONS:
case ATTR_RUNTIMEINVISIBLEPARAMETERANNOTATIONS:
+ // Note: can't be called for Code attribute.
+ assert (current_annotations.empty ());
parse_parameter_annotations ();
break;
case ATTR_RUNTIMEVISIBLEANNOTATIONS:
case ATTR_RUNTIMEINVISIBLEANNOTATIONS:
+ // Note: can't be called for Code attribute.
+ assert (current_annotations.empty ());
parse_annotations ();
break;