This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[ecj] Patch: FYI: update jcf-dump for 1.5
- From: Tom Tromey <tromey at redhat dot com>
- To: Java Patch List <java-patches at gcc dot gnu dot org>
- Cc: Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Date: 27 Jun 2006 18:41:28 -0600
- Subject: [ecj] Patch: FYI: update jcf-dump for 1.5
- Reply-to: tromey at redhat dot com
I'm checking this in on the gcj-eclipse branch.
This updates jcf-dump for the new 1.5 features:
* Handle Signature attribute. (I renamed "signature" to "descriptor"
elsewhere for clarify and better conformance to the new JVM spec.)
The signature handling is pretty lame -- we just print it as a
string, rather than trying to decode it.
* Handle EnclosingMethod
* Handle LocalVariableTypeTable
* Handle all annotation-related attributes
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
* jcf-reader.c (get_attribute): Handle EnclosingMethod,
Signature, LocalVariableTypeTable, annotation attributes.
* jcf-dump.c (HANDLE_ENCLOSINGMETHOD_ATTRIBUTE): New macro.
(HANDLE_SIGNATURE_ATTRIBUTE): Likewise.
(HANDLE_START_FIELD): Mention 'descriptor', not 'signature'.
(HANDLE_METHOD): Likewise.
(HANDLE_LOCALVARIABLETYPETABLE_ATTRIBUTE): New macro.
(print_annotation): New function.
(print_element_value): Likewise.
(indent): Likewise.
(HANDLE_RUNTIMEVISIBLEANNOTATIONS_ATTRIBUTE): New macro.
(HANDLE_RUNTIMEINVISIBLEANNOTATIONS_ATTRIBUTE): Likewise.
(print_parameter_annotations): New function.
(HANDLE_RUNTIMEVISIBLEPARAMETERANNOTATIONS_ATTRIBUTE): New macro.
(HANDLE_RUNTIMEINVISIBLEPARAMETERANNOTATIONS_ATTRIBUTE):
Likewise.
(HANDLE_ANNOTATIONDEFAULT_ATTRIBUTE): Likewise.
(print_annotations): New function.
Index: jcf-dump.c
===================================================================
--- jcf-dump.c (revision 114870)
+++ jcf-dump.c (working copy)
@@ -96,6 +96,7 @@
static void print_access_flags (FILE *, uint16, char);
static void print_constant_terse (FILE*, JCF*, int, int);
+static void print_constant_terse_with_index (FILE *, JCF *, int, int);
static void print_constant (FILE *, JCF *, int, int);
static void print_constant_ref (FILE *, JCF *, int);
static void disassemble_method (JCF*, const unsigned char *, int);
@@ -109,6 +110,11 @@
static void print_constant_pool (struct JCF *);
static void print_exception_table (struct JCF *, const unsigned char *entries,
int);
+static void indent (FILE *, int);
+static void print_element_value (FILE *, JCF *, int);
+static void print_annotation (FILE *, JCF *, int);
+static void print_annotations (FILE *, JCF *, int);
+static void print_parameter_annotations (FILE *, JCF *, int);
#define PRINT_SIGNATURE_RESULT_ONLY 1
#define PRINT_SIGNATURE_ARGS_ONLY 2
@@ -184,7 +190,7 @@
{ fprintf (out, "Field name:"); \
print_constant_terse (out, jcf, NAME, CONSTANT_Utf8); \
print_access_flags (out, ACCESS_FLAGS, 'f'); \
- fprintf (out, " Signature: "); \
+ fprintf (out, " Descriptor: "); \
if (flag_print_constant_pool) \
fprintf (out, "%d=", SIGNATURE); \
print_signature (out, jcf, SIGNATURE, 0); \
@@ -227,7 +233,7 @@
fprintf (out, "\nMethod name:"); \
print_constant_terse (out, jcf, NAME, CONSTANT_Utf8); \
print_access_flags (out, ACCESS_FLAGS, 'm'); \
- fprintf (out, " Signature: "); \
+ fprintf (out, " Descriptor: "); \
if (flag_print_constant_pool) \
fprintf (out, "%d=", SIGNATURE); \
print_signature (out, jcf, SIGNATURE, 0); \
@@ -295,6 +301,26 @@
print_signature (out, jcf, signature_index, 0); \
fprintf (out, " (pc: %d length: %d)\n", start_pc, length); }}
+#define HANDLE_LOCALVARIABLETYPETABLE_ATTRIBUTE(COUNT) \
+{ int n = (COUNT); int i; \
+ COMMON_HANDLE_ATTRIBUTE(JCF, attribute_name, attribute_length); \
+ fprintf (out, ", count: %d\n", n); \
+ for (i = 0; i < n; i++) { \
+ int start_pc = JCF_readu2 (jcf); \
+ int length = JCF_readu2 (jcf); \
+ int name_index = JCF_readu2 (jcf); \
+ int signature_index = JCF_readu2 (jcf); \
+ int slot = JCF_readu2 (jcf); \
+ fprintf (out, " slot#%d: name: ", slot); \
+ if (flag_print_constant_pool) \
+ fprintf (out, "%d=", name_index); \
+ print_name (out, jcf, name_index); \
+ fprintf (out, ", type: "); \
+ if (flag_print_constant_pool) \
+ fprintf (out, "%d=", signature_index); \
+ print_signature (out, jcf, signature_index, 0); \
+ fprintf (out, " (pc: %d length: %d)\n", start_pc, length); }}
+
#define HANDLE_LINENUMBERTABLE_ATTRIBUTE(COUNT) \
{ int n = (COUNT); int i; \
COMMON_HANDLE_ATTRIBUTE(jcf, attribute_name, attribute_length); \
@@ -357,6 +383,58 @@
for (i = 0; i < n; i++) { c = JCF_readu(jcf); fputc(c, out); } \
if (c != '\r' && c != '\n') fputc('\n', out); }
+#define HANDLE_ENCLOSINGMETHOD_ATTRIBUTE() \
+{ COMMON_HANDLE_ATTRIBUTE(jcf, attribute_name, attribute_length); \
+ uint16 class_index = JCF_readu2 (jcf); \
+ uint16 method_index = JCF_readu2 (jcf); \
+ fprintf (out, "\n Class: "); \
+ print_constant_terse_with_index (out, jcf, class_index, CONSTANT_Class); \
+ fprintf (out, "\n Method: "); \
+ print_constant_terse_with_index (out, jcf, method_index, \
+ CONSTANT_NameAndType); \
+ fputc ('\n', out); \
+}
+
+#define HANDLE_SIGNATURE_ATTRIBUTE() \
+{ \
+ COMMON_HANDLE_ATTRIBUTE(jcf, attribute_name, attribute_length); \
+ uint16 signature = JCF_readu2 (jcf); \
+ fprintf (out, "\n Value: "); \
+ print_constant_terse_with_index (out, jcf, signature, CONSTANT_Utf8); \
+ fputc ('\n', out); \
+}
+
+#define HANDLE_RUNTIMEVISIBLEANNOTATIONS_ATTRIBUTE() \
+{ \
+ COMMON_HANDLE_ATTRIBUTE(jcf, attribute_name, attribute_length); \
+ print_annotations (out, jcf, 1); \
+}
+
+#define HANDLE_RUNTIMEINVISIBLEANNOTATIONS_ATTRIBUTE() \
+{ \
+ COMMON_HANDLE_ATTRIBUTE(jcf, attribute_name, attribute_length); \
+ print_annotations (out, jcf, 1); \
+}
+
+#define HANDLE_RUNTIMEVISIBLEPARAMETERANNOTATIONS_ATTRIBUTE() \
+{ \
+ COMMON_HANDLE_ATTRIBUTE(jcf, attribute_name, attribute_length); \
+ print_parameter_annotations (out, jcf, 1); \
+}
+
+#define HANDLE_RUNTIMEINVISIBLEPARAMETERANNOTATIONS_ATTRIBUTE() \
+{ \
+ COMMON_HANDLE_ATTRIBUTE(jcf, attribute_name, attribute_length); \
+ print_parameter_annotations (out, jcf, 1); \
+}
+
+#define HANDLE_ANNOTATIONDEFAULT_ATTRIBUTE() \
+{ \
+ COMMON_HANDLE_ATTRIBUTE(jcf, attribute_name, attribute_length); \
+ print_element_value (out, jcf, 1); \
+}
+
+
#define PROCESS_OTHER_ATTRIBUTE(JCF, INDEX, LENGTH) \
{ COMMON_HANDLE_ATTRIBUTE(JCF, INDEX, LENGTH); \
fputc ('\n', out); JCF_SKIP (JCF, LENGTH); }
@@ -367,7 +445,157 @@
#include "javaop.h"
+
+
static void
+indent (FILE *stream, int level)
+{
+ int i;
+ for (i = 0; i < level; ++i)
+ fprintf (stream, " ");
+}
+
+static void
+print_element_value (FILE *stream, JCF *jcf, int level)
+{
+ uint8 tag = JCF_readu (jcf);
+ indent (stream, level);
+ switch (tag)
+ {
+ case 'B':
+ case 'C':
+ case 'S':
+ case 'Z':
+ case 'I':
+ {
+ uint16 cindex = JCF_readu2 (jcf);
+ print_constant_terse_with_index (stream, jcf, cindex,
+ CONSTANT_Integer);
+ }
+ break;
+ case 'D':
+ {
+ uint16 cindex = JCF_readu2 (jcf);
+ print_constant_terse_with_index (stream, jcf, cindex,
+ CONSTANT_Double);
+ }
+ break;
+ case 'F':
+ {
+ uint16 cindex = JCF_readu2 (jcf);
+ print_constant_terse_with_index (stream, jcf, cindex,
+ CONSTANT_Float);
+ }
+ break;
+ case 'J':
+ {
+ uint16 cindex = JCF_readu2 (jcf);
+ print_constant_terse_with_index (stream, jcf, cindex,
+ CONSTANT_Long);
+ }
+ break;
+ case 's':
+ {
+ uint16 cindex = JCF_readu2 (jcf);
+ print_constant_terse_with_index (stream, jcf, cindex,
+ CONSTANT_String);
+ }
+ break;
+
+ case 'e':
+ {
+ uint16 type_name_index = JCF_readu2 (jcf);
+ uint16 const_name_index = JCF_readu2 (jcf);
+ fprintf (stream, "enum class: ");
+ print_constant_terse_with_index (stream, jcf, type_name_index,
+ CONSTANT_Utf8);
+ fprintf (stream, "\n");
+ indent (stream, level);
+ fprintf (stream, "Field: ");
+ print_constant_terse_with_index (stream, jcf, const_name_index,
+ CONSTANT_Utf8);
+ }
+ break;
+ case 'c':
+ {
+ uint16 class_info_index = JCF_readu2 (jcf);
+ print_constant_terse_with_index (stream, jcf, class_info_index,
+ CONSTANT_Utf8);
+ }
+ break;
+ case '@':
+ {
+ fprintf (stream, "Annotation:\n");
+ print_annotation (stream, jcf, level + 1);
+ }
+ break;
+ case '[':
+ {
+ uint16 n_array_elts = JCF_readu2 (jcf);
+ fprintf (stream, "array[%d]: [\n", (int) n_array_elts);
+ while (n_array_elts--)
+ print_element_value (stream, jcf, level + 1);
+ indent (stream, level);
+ fprintf (stream, "]");
+ }
+ break;
+ default:
+ fprintf (stream, "Unexpected tag value: %d", (int) tag);
+ break;
+ }
+ fputc ('\n', stream);
+}
+
+static void
+print_annotation (FILE *stream, JCF *jcf, int level)
+{
+ uint16 type_index = JCF_readu2 (jcf);
+ uint16 npairs = JCF_readu2 (jcf);
+ fprintf (stream, "\n");
+ indent (stream, level);
+ fprintf (stream, "Annotation name: ");
+ print_constant_terse_with_index (stream, jcf, type_index,
+ CONSTANT_Utf8);
+ if (npairs)
+ {
+ fprintf (stream, "\n");
+ while (npairs--)
+ {
+ uint16 name_index = JCF_readu2 (jcf);
+ indent (stream, level + 1);
+ fprintf (stream, "Name: ");
+ print_constant_terse_with_index (stream, jcf, name_index,
+ CONSTANT_Utf8);
+ fprintf (stream, "\n");
+ print_element_value (stream, jcf, level + 2);
+ }
+ }
+}
+
+static void
+print_annotations (FILE *stream, JCF *jcf, int level)
+{
+ uint16 num = JCF_readu2 (jcf);
+ while (num--)
+ print_annotation (stream, jcf, level);
+}
+
+static void
+print_parameter_annotations (FILE *stream, JCF *jcf, int level)
+{
+ uint8 nparams = JCF_readu (jcf);
+ uint8 i;
+ for (i = 0; i < nparams; ++i)
+ {
+ indent (stream, level);
+ fprintf (stream, "Parameter annotations (%d):\n", (int) i);
+ print_annotations (stream, jcf, level + 1);
+ }
+}
+
+
+
+static void
print_constant_ref (FILE *stream, JCF *jcf, int index)
{
if (index <= 0 || index >= JPOOL_SIZE(jcf))
Index: jcf-reader.c
===================================================================
--- jcf-reader.c (revision 114870)
+++ jcf-reader.c (working copy)
@@ -1,7 +1,7 @@
/* This file read a Java(TM) .class file.
It is not stand-alone: It depends on tons of macros, and the
intent is you #include this file after you've defined the macros.
- Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005
+ Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2006
Free Software Foundation, Inc.
This file is part of GCC.
@@ -199,6 +199,14 @@
}
else
#endif
+#ifdef HANDLE_LOCALVARIABLETYPETABLE_ATTRIBUTE
+ if (MATCH_ATTRIBUTE ("LocalVariableTypeTable"))
+ {
+ uint16 count = JCF_readu2 (jcf);
+ HANDLE_LOCALVARIABLETYPETABLE_ATTRIBUTE (count);
+ }
+ else
+#endif
#ifdef HANDLE_INNERCLASSES_ATTRIBUTE
if (MATCH_ATTRIBUTE ("InnerClasses"))
{
@@ -235,7 +243,56 @@
}
else
#endif
+#ifdef HANDLE_ENCLOSINGMETHOD_ATTRIBUTE
+ if (MATCH_ATTRIBUTE ("EnclosingMethod"))
{
+ HANDLE_ENCLOSINGMETHOD_ATTRIBUTE ();
+ }
+ else
+#endif
+#ifdef HANDLE_SIGNATURE_ATTRIBUTE
+ if (MATCH_ATTRIBUTE ("Signature"))
+ {
+ HANDLE_SIGNATURE_ATTRIBUTE ();
+ }
+ else
+#endif
+#ifdef HANDLE_RUNTIMEVISIBLEANNOTATIONS_ATTRIBUTE
+ if (MATCH_ATTRIBUTE ("RuntimeVisibleAnnotations"))
+ {
+ HANDLE_RUNTIMEVISIBLEANNOTATIONS_ATTRIBUTE ();
+ }
+ else
+#endif
+#ifdef HANDLE_RUNTIMEINVISIBLEANNOTATIONS_ATTRIBUTE
+ if (MATCH_ATTRIBUTE ("RuntimeInvisibleAnnotations"))
+ {
+ HANDLE_RUNTIMEINVISIBLEANNOTATIONS_ATTRIBUTE ();
+ }
+ else
+#endif
+#ifdef HANDLE_RUNTIMEVISIBLEPARAMETERANNOTATIONS_ATTRIBUTE
+ if (MATCH_ATTRIBUTE ("RuntimeVisibleParameterAnnotations"))
+ {
+ HANDLE_RUNTIMEVISIBLEPARAMETERANNOTATIONS_ATTRIBUTE ();
+ }
+ else
+#endif
+#ifdef HANDLE_RUNTIMEINVISIBLEPARAMETERANNOTATIONS_ATTRIBUTE
+ if (MATCH_ATTRIBUTE ("RuntimeInvisibleParameterAnnotations"))
+ {
+ HANDLE_RUNTIMEINVISIBLEPARAMETERANNOTATIONS_ATTRIBUTE ();
+ }
+ else
+#endif
+#ifdef HANDLE_ANNOTATIONDEFAULT_ATTRIBUTE
+ if (MATCH_ATTRIBUTE ("AnnotationDefault"))
+ {
+ HANDLE_ANNOTATIONDEFAULT_ATTRIBUTE ();
+ }
+ else
+#endif
+ {
#ifdef PROCESS_OTHER_ATTRIBUTE
PROCESS_OTHER_ATTRIBUTE(jcf, attribute_name, attribute_length);
#else