Index: java/gjavah.c =================================================================== RCS file: /cvsroot/gcc/gcc/gcc/java/gjavah.c,v retrieving revision 1.135 diff -c -3 -r1.135 gjavah.c *** java/gjavah.c 25 Jun 2005 00:33:00 -0000 1.135 --- java/gjavah.c 4 Sep 2005 19:51:23 -0000 *************** *** 145,151 **** static void print_c_decl (FILE*, JCF*, int, int, int, const char *, int); static void print_stub_or_jni (FILE*, JCF*, int, int, int, const char *, int); static void print_full_cxx_name (FILE*, JCF*, int, int, int, const char *, int); - static void decompile_method (FILE*, JCF*, int); static void add_class_decl (FILE*, JCF*, JCF_u2); static void print_name (FILE *, JCF *, int); --- 145,150 ---- *************** *** 173,179 **** static void jni_print_char (FILE *, int); static void jni_print_float (FILE *, jfloat); static void jni_print_double (FILE *, jdouble); - static void decompile_return_statement (FILE *, JCF *, int, int, int); static void handle_inner_classes (int); --- 172,177 ---- *************** *** 250,257 **** } \ } ! #define HANDLE_CODE_ATTRIBUTE(MAX_STACK, MAX_LOCALS, CODE_LENGTH) \ ! if (out && method_declared) decompile_method (out, jcf, CODE_LENGTH); static int decompiled = 0; #define HANDLE_END_METHOD() \ --- 248,255 ---- } \ } ! #define HANDLE_CODE_ATTRIBUTE(MAX_STACK, MAX_LOCALS, CODE_LENGTH) ! static int decompiled = 0; #define HANDLE_END_METHOD() \ *************** *** 986,1183 **** free (override); } - /* A helper for the decompiler which prints a `return' statement where - the type is a reference type. If METHODTYPE and OBJECTTYPE are not - identical, we emit a cast. We do this because the C++ compiler - doesn't know that a reference can be cast to the type of an - interface it implements. METHODTYPE is the index of the method's - signature. NAMEINDEX is the index of the field name; -1 for - `this'. OBJECTTYPE is the index of the object's type. */ - static void - decompile_return_statement (FILE *out, JCF *jcf, int methodtype, - int nameindex, int objecttype) - { - int cast = 0; - int obj_name_len, method_name_len; - const unsigned char *obj_data, *method_data; - - obj_name_len = JPOOL_UTF_LENGTH (jcf, objecttype); - obj_data = JPOOL_UTF_DATA (jcf, objecttype); - - method_name_len = JPOOL_UTF_LENGTH (jcf, methodtype); - method_data = JPOOL_UTF_DATA (jcf, methodtype); - - /* Skip forward to return type part of method. */ - while (*method_data != ')') - { - ++method_data; - --method_name_len; - } - /* Skip past `)'. */ - ++method_data; - --method_name_len; - - /* If we see an `L', skip it and the trailing `;'. */ - if (method_data[0] == 'L' && method_data[method_name_len - 1] == ';') - { - ++method_data; - method_name_len -= 2; - } - if (obj_data[0] == 'L' && obj_data[obj_name_len - 1] == ';') - { - ++obj_data; - obj_name_len -= 2; - } - - /* FIXME: if METHODTYPE is a superclass of OBJECTTYPE then we don't - need a cast. Right now there is no way to determine if this is - the case. */ - if (method_name_len != obj_name_len) - cast = 1; - else - { - int i; - for (i = 0; i < method_name_len; ++i) - { - if (method_data[i] != obj_data[i]) - { - cast = 1; - break; - } - } - } - - fputs (" { return ", out); - - if (cast) - { - int array_depth = 0; - const unsigned char *limit; - - fputs ("reinterpret_cast<", out); - - while (*method_data == '[') - { - ++method_data; - ++array_depth; - --method_name_len; - fputs ("JArray<", out); - } - - /* Leading space to avoid C++ digraphs. */ - fputs (" ::", out); - - /* If we see an `L', skip it and the trailing `;'. Only do this - if we've seen an array specification. If we don't have an - array then the `L' was stripped earlier. */ - if (array_depth && method_data[0] == 'L' - && method_data[method_name_len - 1] == ';') - { - ++method_data; - method_name_len -= 2; - } - - limit = method_data + method_name_len; - while (method_data < limit) - { - int ch = UTF8_GET (method_data, limit); - if (ch == '/') - fputs ("::", out); - else - jcf_print_char (out, ch); - } - fputs (" *", out); - - /* Close each array. */ - while (array_depth > 0) - { - fputs ("> *", out); - --array_depth; - } - - /* Close the cast. */ - fputs ("> (", out); - } - - if (nameindex == -1) - fputs ("this", out); - else - print_field_name (out, jcf, nameindex, 0); - - if (cast) - fputs (")", out); - - fputs ("; }", out); - } - - - /* Try to decompile a method body. Right now we just try to handle a - simple case that we can do. Expand as desired. */ - static void - decompile_method (FILE *out, JCF *jcf, int code_len) - { - const unsigned char *codes = jcf->read_ptr; - int index; - uint16 name_and_type, name; - - /* If the method is synchronized, don't touch it. */ - if ((method_access & ACC_SYNCHRONIZED)) - return; - - if (code_len == 5 - && codes[0] == OPCODE_aload_0 - && codes[1] == OPCODE_getfield - && (codes[4] == OPCODE_areturn - || codes[4] == OPCODE_dreturn - || codes[4] == OPCODE_freturn - || codes[4] == OPCODE_ireturn - || codes[4] == OPCODE_lreturn)) - { - /* Found code like `return FIELD'. */ - index = (codes[2] << 8) | codes[3]; - /* FIXME: ensure that tag is CONSTANT_Fieldref. */ - name_and_type = JPOOL_USHORT2 (jcf, index); - /* FIXME: ensure that tag is CONSTANT_NameAndType. */ - name = JPOOL_USHORT1 (jcf, name_and_type); - if (codes[4] == OPCODE_areturn) - decompile_return_statement (out, jcf, method_signature, - name, JPOOL_USHORT2 (jcf, name_and_type)); - else - { - fputs (" { return ", out); - /* FIXME: flags. */ - print_field_name (out, jcf, name, 0); - fputs ("; }", out); - } - decompiled = 1; - } - else if (code_len == 2 - && codes[0] == OPCODE_aload_0 - && codes[1] == OPCODE_areturn - /* We're going to generate `return this'. This only makes - sense for non-static methods. */ - && ! (method_access & ACC_STATIC)) - { - decompile_return_statement (out, jcf, method_signature, -1, - JPOOL_USHORT1 (jcf, jcf->this_class)); - decompiled = 1; - } - else if (code_len == 1 && codes[0] == OPCODE_return) - { - /* Found plain `return'. */ - fputs (" { }", out); - decompiled = 1; - } - else if (code_len == 2 - && codes[0] == OPCODE_aconst_null - && codes[1] == OPCODE_areturn) - { - /* Found `return null'. We don't want to depend on NULL being - defined. */ - fputs (" { return 0; }", out); - decompiled = 1; - } - } /* Like strcmp, but invert the return result for the hash table. This should probably be in hashtab.c to complement the existing string --- 984,989 ----