From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2449 invoked by alias); 11 Dec 2005 01:33:00 -0000 Received: (qmail 2434 invoked by uid 22791); 11 Dec 2005 01:32:58 -0000 X-Spam-Check-By: sourceware.org Received: from zproxy.gmail.com (HELO zproxy.gmail.com) (64.233.162.207) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sun, 11 Dec 2005 01:32:56 +0000 Received: by zproxy.gmail.com with SMTP id i11so1198106nzi for ; Sat, 10 Dec 2005 17:32:54 -0800 (PST) Received: by 10.64.210.7 with SMTP id i7mr5050314qbg; Sat, 10 Dec 2005 17:32:54 -0800 (PST) Received: by 10.65.35.8 with HTTP; Sat, 10 Dec 2005 17:32:53 -0800 (PST) Message-ID: <5652dcd50512101732w776d3301u72c8a132a71b4870@mail.gmail.com> Date: Sun, 11 Dec 2005 01:33:00 -0000 From: TJ Laurenzo Reply-To: tj@laurenzo.org To: java-patches@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: PATCH: Fix for java/PR9861 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_220_9724257.1134264773857" X-IsSubscribed: yes Mailing-List: contact java-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: java-patches-owner@gcc.gnu.org X-SW-Source: 2005-q4/txt/msg00314.txt.bz2 ------=_Part_220_9724257.1134264773857 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Content-length: 744 This patch has been discussed extensively on the mailing lists: http://gcc.gnu.org/ml/gcc-patches/2005-09/msg01716.html Modifications have been made to formatting per Ian Taylor and I am commiting the patch now. The remainder of the patch was approved by Andrew Haley. The test suite looked good when bootstrapped on i686-pc-linux-gnu. Note that this patch changes the name mangling behavior for Java methods (as defined by gcj and g++ when compiling CNI classes) so as to allow return type mangling. Existing Java libraries will need to be rebuilt to account for the change. In addition, existing binutils/gdb will not be able to properly decode the names until rebuilt with the libiberty changes commited as part of this patch. TJ ------=_Part_220_9724257.1134264773857 Content-Type: text/x-patch; name=pr9861.diff; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="pr9861.diff" Content-length: 14574 Index: libiberty/ChangeLog =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- libiberty/ChangeLog (revision 108355) +++ libiberty/ChangeLog (working copy) @@ -1,3 +1,17 @@ +2005-12-10 Terry Laurenzo + + PR java/9861 + * cp-demangle.c (d_bare_function_type): Recognize new 'J' qualifer + and include return type when found. + (d_print_comp)[DEMANGLE_COMPONENT_FUNCTION_TYPE]: Add + conditional logic to change printing order of return type.when + the DMGL_RET_POSTFIX option is present. + (java_demangle_v3): Add DMGL_RET_POSTFIX option to d_demangle + call. + * testsuite/test-demangle.c (main): Recognize option --ret-postfix + * testsuite/demangle-expected: Test cases to verify extended encoding. + Updated comment to document --ret-postfix option. +=09 2005-11-06 Richard Guenther =20 * splay-tree.c (rotate_left): New function. Index: include/ChangeLog =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- include/ChangeLog (revision 108355) +++ include/ChangeLog (working copy) @@ -1,3 +1,9 @@ +2005-12-10 Terry Laurenzo + + PR java/9861 + * demangle.h : Add DMGL_RET_POSTFIX define to enable alternative + output format for return types + 2005-10-31 Mark Kettenis =20 * floatformat.h (enum floatformat_byteorders): Add Index: libiberty/cp-demangle.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- libiberty/cp-demangle.c (revision 108355) +++ libiberty/cp-demangle.c (working copy) @@ -1939,7 +1939,7 @@ return ret; } =20 -/* ::=3D + */ +/* ::=3D [J]+ */ =20 static struct demangle_component * d_bare_function_type (struct d_info *di, int has_return_type) @@ -1947,13 +1947,22 @@ struct demangle_component *return_type; struct demangle_component *tl; struct demangle_component **ptl; + char peek; =20 + /* Detect special qualifier indicating that the first argument + is the return type. */ + peek =3D d_peek_char (di); + if (peek =3D=3D 'J') + { + d_advance (di, 1); + has_return_type =3D 1; + } + return_type =3D NULL; tl =3D NULL; ptl =3D &tl; while (1) { - char peek; struct demangle_component *type; =20 peek =3D d_peek_char (di); @@ -3025,13 +3034,16 @@ =20 case DEMANGLE_COMPONENT_FUNCTION_TYPE: { + if ((dpi->options & DMGL_RET_POSTFIX) !=3D 0) + d_print_function_type (dpi, dc, dpi->modifiers); + + /* Print return type if present */ if (d_left (dc) !=3D NULL) { struct d_print_mod dpm; =20 /* We must pass this type down as a modifier in order to print it in the right location. */ - dpm.next =3D dpi->modifiers; dpi->modifiers =3D &dpm; dpm.mod =3D dc; @@ -3045,10 +3057,14 @@ if (dpm.printed) return; =20 - d_append_char (dpi, ' '); + /* In standard prefix notation, there is a space between the + return type and the function signature. */ + if ((dpi->options & DMGL_RET_POSTFIX) =3D=3D 0) + d_append_char (dpi, ' '); } =20 - d_print_function_type (dpi, dc, dpi->modifiers); + if ((dpi->options & DMGL_RET_POSTFIX) =3D=3D 0)=20 + d_print_function_type (dpi, dc, dpi->modifiers); =20 return; } @@ -4003,7 +4019,8 @@ char *from; char *to; =20 - demangled =3D d_demangle (mangled, DMGL_JAVA | DMGL_PARAMS, &alc); + demangled =3D d_demangle (mangled, DMGL_JAVA | DMGL_PARAMS | DMGL_RET_PO= STFIX,=20 + &alc); =20 if (demangled =3D=3D NULL) return NULL; Index: libiberty/testsuite/test-demangle.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- libiberty/testsuite/test-demangle.c (revision 108355) +++ libiberty/testsuite/test-demangle.c (working copy) @@ -114,6 +114,7 @@ --is-v3-ctor Calls is_gnu_v3_mangled_ctor on input; expected output is an integer representing ctor_kind. --is-v3-dtor Likewise, but for dtors. + --ret-postfix Passes the DMGL_RET_POSTFIX option =20 For compatibility, just in case it matters, the options line may be empty, to mean --format=3Dauto. If it doesn't start with --, then it @@ -129,6 +130,7 @@ int no_params; int is_v3_ctor; int is_v3_dtor; + int ret_postfix; struct line format; struct line input; struct line expect; @@ -158,6 +160,7 @@ tests++; =20 no_params =3D 0; + ret_postfix =3D 0; is_v3_ctor =3D 0; is_v3_dtor =3D 0; if (format.data[0] =3D=3D '\0') @@ -212,6 +215,8 @@ is_v3_ctor =3D 1; else if (strcmp (opt, "--is-v3-dtor") =3D=3D 0) is_v3_dtor =3D 1; + else if (strcmp (opt, "--ret-postfix") =3D=3D 0) + ret_postfix =3D 1; else { printf ("FAIL at line %d: unrecognized option %s\n", @@ -255,7 +260,8 @@ cplus_demangle_set_style (style); =20 result =3D cplus_demangle (input.data, - DMGL_PARAMS|DMGL_ANSI|DMGL_TYPES); + DMGL_PARAMS|DMGL_ANSI|DMGL_TYPES + |(ret_postfix ? DMGL_RET_POSTFIX : 0)); =20 if (result ? strcmp (result, expect.data) Index: libiberty/testsuite/demangle-expected =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- libiberty/testsuite/demangle-expected (revision 108355) +++ libiberty/testsuite/demangle-expected (working copy) @@ -11,6 +11,7 @@ # --is-v3-ctor Calls is_gnu_v3_mangled_ctor on input; expected # output is an integer representing ctor_kind. # --is-v3-dtor Likewise, but for dtors. +# --ret-postfix Passes the DMGL_RET_POSTFIX option # # For compatibility, just in case it matters, the options line may be # empty, to mean --format=3Dauto. If it doesn't start with --, then it @@ -3781,3 +3782,26 @@ --format=3Djava _ZGAN4java4lang5Class7forNameEPNS0_6StringE hidden alias for java.lang.Class.forName(java.lang.String) +# +# Test cases to verify encoding that determines if a return type is present +# Related to PR9861 +--format=3Djava +_ZN4java4lang4Math4acosEJdd +java.lang.Math.acos(double)double +# +--format=3Dauto +_ZN4java4lang4Math4acosEJdd +double java::lang::Math::acos(double) +# +--format=3Dauto +_ZN4java4lang4Math4acosEJvd +void java::lang::Math::acos(double) +# +--format=3Dauto --ret-postfix +_ZN4java4lang4Math4acosEJdd +java::lang::Math::acos(double)double +# +--format=3Dgnu-v3 --no-params --ret-postfix +_Z4makeI7FactoryiET_IT0_Ev +make()Factory +make Index: include/demangle.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- include/demangle.h (revision 108355) +++ include/demangle.h (working copy) @@ -35,6 +35,8 @@ #define DMGL_JAVA (1 << 2) /* Demangle as Java rather than C++. */ #define DMGL_VERBOSE (1 << 3) /* Include implementation details. */ #define DMGL_TYPES (1 << 4) /* Also try to demangle type encodings. */ +#define DMGL_RET_POSTFIX (1 << 5) /* Print function return types (wh= en + present) after function signatu= re */ =20 #define DMGL_AUTO (1 << 8) #define DMGL_GNU (1 << 9) Index: gcc/cp/mangle.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- gcc/cp/mangle.c (revision 108355) +++ gcc/cp/mangle.c (working copy) @@ -1858,16 +1858,38 @@ is mangled before the parameter types. If non-NULL, DECL is FUNCTION_DECL for the function whose type is being emitted. =20 - ::=3D + */ + If DECL is a member of a Java type, then a literal 'J' + is output and the return type is mangled as if INCLUDE_RETURN_TYPE + were nonzero. =20 + ::=3D [J]+ */ + static void write_bare_function_type (const tree type, const int include_return_type_p, const tree decl) { + int java_method_p; + MANGLE_TRACE_TREE ("bare-function-type", type); =20 + /* Detect Java methods and emit special encoding. */ + if (decl !=3D NULL + && DECL_FUNCTION_MEMBER_P (decl) + && TYPE_FOR_JAVA (DECL_CONTEXT (decl)) + && !DECL_CONSTRUCTOR_P (decl) + && !DECL_DESTRUCTOR_P (decl) + && !DECL_CONV_FN_P (decl)) + { + java_method_p =3D 1; + write_char ('J'); + } + else + { + java_method_p =3D 0; + } + /* Mangle the return type, if requested. */ - if (include_return_type_p) + if (include_return_type_p || java_method_p) write_type (TREE_TYPE (type)); =20 /* Now mangle the types of the arguments. */ Index: gcc/cp/ChangeLog =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- gcc/cp/ChangeLog (revision 108355) +++ gcc/cp/ChangeLog (working copy) @@ -1,3 +1,9 @@ +2005-12-10 Terry Laurenzo + + PR java/9861 + * mangle.c (write_bare_function_type): Mangle return type for + methods of Java classes + 2005-12-08 Th=E9odore Papadopoulo =20=09 * call.c (build_conditional_expr): Print types in error messages. Index: gcc/java/mangle.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- gcc/java/mangle.c (revision 108355) +++ gcc/java/mangle.c (working copy) @@ -188,6 +188,14 @@ if (TREE_CODE (TREE_TYPE (mdecl)) =3D=3D METHOD_TYPE) arglist =3D TREE_CHAIN (arglist); =20=20=20 + /* Output literal 'J' and mangle the return type IF not a=20 + constructor. */ + if (!ID_INIT_P (method_name)) + { + obstack_1grow (mangle_obstack, 'J'); + mangle_type(TREE_TYPE(TREE_TYPE(mdecl))); + } +=20=20 /* No arguments is easy. We shortcut it. */ if (arglist =3D=3D end_params_node) obstack_1grow (mangle_obstack, 'v'); Index: gcc/java/ChangeLog =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- gcc/java/ChangeLog (revision 108355) +++ gcc/java/ChangeLog (working copy) @@ -1,3 +1,11 @@ +2005-12-10 Terry Laurenzo + + PR java/9861 + * mangle.c (mangle_method_decl): Mangle Java methods by prepending 'J' + to bare_function_type and including the return type + * builtins.c (initialize_builtins) : Change builtin mangled name + constants to conform to new mangling scheme + 2005-12-08 Andrew Haley =20 PR libgcj/25265 Index: gcc/java/builtins.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- gcc/java/builtins.c (revision 108355) +++ gcc/java/builtins.c (working copy) @@ -194,43 +194,43 @@ float_ftype_float_float, "fmodf", BUILTIN_CONST); =20 define_builtin (BUILT_IN_ACOS, "__builtin_acos", - double_ftype_double, "_ZN4java4lang4Math4acosEd", + double_ftype_double, "_ZN4java4lang4Math4acosEJdd", BUILTIN_CONST); define_builtin (BUILT_IN_ASIN, "__builtin_asin", - double_ftype_double, "_ZN4java4lang4Math4asinEd", + double_ftype_double, "_ZN4java4lang4Math4asinEJdd", BUILTIN_CONST); define_builtin (BUILT_IN_ATAN, "__builtin_atan", - double_ftype_double, "_ZN4java4lang4Math4atanEd", + double_ftype_double, "_ZN4java4lang4Math4atanEJdd", BUILTIN_CONST); define_builtin (BUILT_IN_ATAN2, "__builtin_atan2", - double_ftype_double_double, "_ZN4java4lang4Math5atan2Edd", + double_ftype_double_double, "_ZN4java4lang4Math5atan2EJddd", BUILTIN_CONST); define_builtin (BUILT_IN_CEIL, "__builtin_ceil", - double_ftype_double, "_ZN4java4lang4Math4ceilEd", + double_ftype_double, "_ZN4java4lang4Math4ceilEJdd", BUILTIN_CONST); define_builtin (BUILT_IN_COS, "__builtin_cos", - double_ftype_double, "_ZN4java4lang4Math3cosEd", + double_ftype_double, "_ZN4java4lang4Math3cosEJdd", BUILTIN_CONST); define_builtin (BUILT_IN_EXP, "__builtin_exp", - double_ftype_double, "_ZN4java4lang4Math3expEd", + double_ftype_double, "_ZN4java4lang4Math3expEJdd", BUILTIN_CONST); define_builtin (BUILT_IN_FLOOR, "__builtin_floor", - double_ftype_double, "_ZN4java4lang4Math5floorEd", + double_ftype_double, "_ZN4java4lang4Math5floorEJdd", BUILTIN_CONST); define_builtin (BUILT_IN_LOG, "__builtin_log", - double_ftype_double, "_ZN4java4lang4Math3logEd", + double_ftype_double, "_ZN4java4lang4Math3logEJdd", BUILTIN_CONST); define_builtin (BUILT_IN_POW, "__builtin_pow", - double_ftype_double_double, "_ZN4java4lang4Math3powEdd", + double_ftype_double_double, "_ZN4java4lang4Math3powEJddd", BUILTIN_CONST); define_builtin (BUILT_IN_SIN, "__builtin_sin", - double_ftype_double, "_ZN4java4lang4Math3sinEd", + double_ftype_double, "_ZN4java4lang4Math3sinEJdd", BUILTIN_CONST); define_builtin (BUILT_IN_SQRT, "__builtin_sqrt", - double_ftype_double, "_ZN4java4lang4Math4sqrtEd", + double_ftype_double, "_ZN4java4lang4Math4sqrtEJdd", BUILTIN_CONST); define_builtin (BUILT_IN_TAN, "__builtin_tan", - double_ftype_double, "_ZN4java4lang4Math3tanEd", + double_ftype_double, "_ZN4java4lang4Math3tanEJdd", BUILTIN_CONST); =20=20=20 t =3D tree_cons (NULL_TREE, boolean_type_node, end_params_node); ------=_Part_220_9724257.1134264773857--