jcf-dump.c (flag_print_constant_pool): Default to off.
authorPer Bothner <per@bothner.com>
Tue, 16 Mar 2004 22:36:43 +0000 (14:36 -0800)
committerPer Bothner <bothner@gcc.gnu.org>
Tue, 16 Mar 2004 22:36:43 +0000 (14:36 -0800)
* 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.

From-SVN: r79555

gcc/java/ChangeLog
gcc/java/jcf-dump.c

index 2657d62f870d083565366f2438fe08920c2e9561..0ea4ce1247bcb9b449169730c992826ac3ac9da7 100644 (file)
@@ -1,3 +1,11 @@
+2004-03-16  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.
+
 2004-03-15  Andrew Haley  <aph@redhat.com>
 
        PR java/14581
index 0776629a81e57eaf2d182e620eafbe68102c66de..c28a3f43c4cb092c3502b24a69b309e3218a6a43 100644 (file)
@@ -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, const char * value)
       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, const char * value)
 
 #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, const char * value)
     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, const char * value)
                                                                            \
       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, const char * value)
 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 *jcf, int index, int expected)
     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 unsigned char *entries, int count)
          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);
        }
     }
@@ -976,6 +991,9 @@ main (int argc, char** argv)
        }
     }
 
+  if (verbose && ! flag_javap_compatible)
+    flag_print_constant_pool = 1;
+
   if (optind == argc)
     {
       fprintf (stderr, _("jcf-dump: no classes specified\n"));