This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
PATCH to java/jcf-dump.c
- From: Per Bothner <per at bothner dot com>
- To: gcc-patches at gcc dot gnu dot org, java at gcc dot gnu dot org
- Date: Fri, 12 Mar 2004 13:01:40 -0800
- Subject: PATCH to java/jcf-dump.c
The attached patch does the following:
(1) Fixes a buglet in the display of anonymous inner classes.
(2) Check flag_print_constant_pool in more places to determine
whether to emit constant pool indexes.
(3) Changed the default for flag_print_constant_pool, but the
verbose (-v) flag turns it on.
The latter may be a matter for discussion. It may be reasonable
to add a separate option to control flag_print_constant_pool. If so,
what should it be?
There may also be documentation implications. I'll look at that
after people have had a chance to comment on the preferred behavior.
Tested on mainline on Fedora1; I'll check it in as is in a few days
unless there is support for different behavior.
--
--Per Bothner
per@bothner.com http://per.bothner.com/
2004-03-12 Per Bothner <per@bothner.com>
* jcf-dump.c (flag_print_constant_pool): Default to off.
(print_constant_terse_with_index): New helper function.
(various places): Check flag_print_constant_pool where missing.
(main): If verbose set flag_print_constant_pool.
(HANDLE_INNERCLASSES_ATTRIBUTE): Null inner class name is anonymous.
Index: jcf-dump.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/jcf-dump.c,v
retrieving revision 1.58
diff -u -p -r1.58 jcf-dump.c
--- jcf-dump.c 10 Feb 2004 19:12:34 -0000 1.58
+++ jcf-dump.c 12 Mar 2004 20:51:53 -0000
@@ -74,7 +74,7 @@ int verbose = 0;
int flag_disassemble_methods = 0;
int flag_print_class_info = 1;
-int flag_print_constant_pool = 1;
+int flag_print_constant_pool = 0;
int flag_print_fields = 1;
int flag_print_methods = 1;
int flag_print_attributes = 1;
@@ -152,9 +152,7 @@ utf8_equal_string (JCF *jcf, int index,
print_access_flags (out, ACCESS_FLAGS, 'c'); \
fputc ('\n', out); \
fprintf (out, "This class: "); \
- if (flag_print_constant_pool) \
- fprintf (out, "%d=", THIS); \
- print_constant_terse (out, jcf, THIS, CONSTANT_Class); \
+ print_constant_terse_with_index (out, jcf, THIS, CONSTANT_Class); \
if (flag_print_constant_pool || SUPER != 0) \
fprintf (out, ", super: "); \
if (flag_print_constant_pool) \
@@ -173,8 +171,8 @@ utf8_equal_string (JCF *jcf, int index,
#define HANDLE_CLASS_INTERFACE(INDEX) \
if (flag_print_class_info) \
- { fprintf (out, "- Implements: %d=", INDEX); \
- print_constant_terse (out, jcf, INDEX, CONSTANT_Class); \
+ { fprintf (out, "- Implements: "); \
+ print_constant_terse_with_index (out, jcf, INDEX, CONSTANT_Class); \
fputc ('\n', out); }
#define HANDLE_START_FIELDS(FIELDS_COUNT) \
@@ -287,9 +285,13 @@ utf8_equal_string (JCF *jcf, int index,
int name_index = JCF_readu2 (jcf); \
int signature_index = JCF_readu2 (jcf); \
int slot = JCF_readu2 (jcf); \
- fprintf (out, " slot#%d: name: %d=", slot, name_index); \
+ 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: %d=", signature_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); }}
@@ -317,19 +319,22 @@ utf8_equal_string (JCF *jcf, int index,
\
if (flag_print_class_info) \
{ \
- fprintf (out, "\n class: "); \
- if (flag_print_constant_pool) \
- fprintf (out, "%d=", inner_class_info_index); \
- print_constant_terse (out, jcf, \
+ fprintf (out, "\n inner: "); \
+ print_constant_terse_with_index (out, jcf, \
inner_class_info_index, CONSTANT_Class); \
- fprintf (out, " (%d=", inner_name_index); \
- print_constant_terse (out, jcf, inner_name_index, CONSTANT_Utf8); \
- fprintf (out, "), access flags: 0x%x", inner_class_access_flags); \
+ if (inner_name_index == 0) \
+ fprintf (out, " (anonymous)"); \
+ else if (verbose || flag_print_constant_pool) \
+ { \
+ fprintf (out, " ("); \
+ print_constant_terse_with_index (out, jcf, inner_name_index, \
+ CONSTANT_Utf8); \
+ fputc (')', out); \
+ } \
+ fprintf (out, ", access flags: 0x%x", inner_class_access_flags); \
print_access_flags (out, inner_class_access_flags, 'c'); \
fprintf (out, ", outer class: "); \
- if (flag_print_constant_pool) \
- fprintf (out, "%d=", outer_class_info_index); \
- print_constant_terse (out, jcf, \
+ print_constant_terse_with_index (out, jcf, \
outer_class_info_index, CONSTANT_Class); \
} \
} \
@@ -350,12 +355,16 @@ utf8_equal_string (JCF *jcf, int index,
static void
print_constant_ref (FILE *stream, JCF *jcf, int index)
{
- fprintf (stream, "#%d=<", index);
if (index <= 0 || index >= JPOOL_SIZE(jcf))
- fprintf (stream, "out of range");
+ fprintf (stream, "<out of range>");
else
- print_constant (stream, jcf, index, 1);
- fprintf (stream, ">");
+ {
+ if (flag_print_constant_pool)
+ fprintf (stream, "#%d=", index);
+ fputc ('<', stream);
+ print_constant (stream, jcf, index, 1);
+ fputc ('>', stream);
+ }
}
/* Print the access flags given by FLAGS.
@@ -414,6 +423,14 @@ print_constant_terse (FILE *out, JCF *jc
print_constant (out, jcf, index, 0);
}
+static void
+print_constant_terse_with_index (FILE *out, JCF *jcf, int index, int expected)
+{
+ if (flag_print_constant_pool)
+ fprintf (out, "%d=", index);
+ print_constant_terse (out, jcf, index, expected);
+}
+
/* Print the constant at INDEX in JCF's constant pool.
If verbosity==0, print very tersely (no extraneous text).
If verbosity==1, prefix the type of the constant.
@@ -775,15 +792,13 @@ print_exception_table (JCF *jcf, const u
int end_pc = GET_u2 (ptr+2);
int handler_pc = GET_u2 (ptr+4);
int catch_type = GET_u2 (ptr+6);
- fprintf (out, " start: %d, end: %d, handler: %d, type: %d",
- start_pc, end_pc, handler_pc, catch_type);
+ fprintf (out, " start: %d, end: %d, handler: %d, type: ",
+ start_pc, end_pc, handler_pc);
if (catch_type == 0)
- fputs (" /* finally */", out);
+ fputs ("0 /* finally */", out);
else
- {
- fputc('=', out);
- print_constant_terse (out, jcf, catch_type, CONSTANT_Class);
- }
+ print_constant_terse_with_index (out, jcf,
+ catch_type, CONSTANT_Class);
fputc ('\n', out);
}
}
@@ -975,6 +990,9 @@ main (int argc, char** argv)
usage ();
}
}
+
+ if (verbose && ! flag_javap_compatible)
+ flag_print_constant_pool = 1;
if (optind == argc)
{