aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTerry Laurenzo <tlaurenzo@gmail.com>2005-12-11 01:34:02 +0000
committerTerry Laurenzo <tlaurenzo@gmail.com>2005-12-11 01:34:02 +0000
commit4862933170b4b399879a86208651fa0ee70ce58d (patch)
treed3a6af3b149154654e7557325e0a2d26a3b83556
parentba164a58978a2b193e9bcfc8e9ab7a7395a10a7a (diff)
Fixes java/PR9861
git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@108374 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/mangle.c26
-rw-r--r--gcc/java/ChangeLog8
-rw-r--r--gcc/java/builtins.c26
-rw-r--r--gcc/java/mangle.c8
-rw-r--r--include/ChangeLog6
-rw-r--r--include/demangle.h2
-rw-r--r--libiberty/ChangeLog14
-rw-r--r--libiberty/cp-demangle.c29
-rw-r--r--libiberty/testsuite/demangle-expected24
-rw-r--r--libiberty/testsuite/test-demangle.c8
11 files changed, 135 insertions, 22 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 633e4d8ca0e..13b075bb9d7 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2005-12-10 Terry Laurenzo <tlaurenzo@gmail.com>
+
+ PR java/9861
+ * mangle.c (write_bare_function_type): Mangle return type for
+ methods of Java classes
+
2005-12-08 Théodore Papadopoulo <Theodore.Papadopoulo@sophia.inria.fr>
* call.c (build_conditional_expr): Print types in error messages.
diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
index c654d764bbd..3b844b5addf 100644
--- a/gcc/cp/mangle.c
+++ b/gcc/cp/mangle.c
@@ -1858,16 +1858,38 @@ write_function_type (const tree type)
is mangled before the parameter types. If non-NULL, DECL is
FUNCTION_DECL for the function whose type is being emitted.
- <bare-function-type> ::= </signature/ type>+ */
+ 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.
+
+ <bare-function-type> ::= [J]</signature/ type>+ */
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);
+ /* Detect Java methods and emit special encoding. */
+ if (decl != 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 = 1;
+ write_char ('J');
+ }
+ else
+ {
+ java_method_p = 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));
/* Now mangle the types of the arguments. */
diff --git a/gcc/java/ChangeLog b/gcc/java/ChangeLog
index 0dc39ad8047..43859b71bbd 100644
--- a/gcc/java/ChangeLog
+++ b/gcc/java/ChangeLog
@@ -1,3 +1,11 @@
+2005-12-10 Terry Laurenzo <tlaurenzo@gmail.com>
+
+ 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 <aph@redhat.com>
PR libgcj/25265
diff --git a/gcc/java/builtins.c b/gcc/java/builtins.c
index 2ea9e578784..ff6da981a0e 100644
--- a/gcc/java/builtins.c
+++ b/gcc/java/builtins.c
@@ -194,43 +194,43 @@ initialize_builtins (void)
float_ftype_float_float, "fmodf", BUILTIN_CONST);
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);
t = tree_cons (NULL_TREE, boolean_type_node, end_params_node);
diff --git a/gcc/java/mangle.c b/gcc/java/mangle.c
index e8df917e423..372c9466c63 100644
--- a/gcc/java/mangle.c
+++ b/gcc/java/mangle.c
@@ -188,6 +188,14 @@ mangle_method_decl (tree mdecl)
if (TREE_CODE (TREE_TYPE (mdecl)) == METHOD_TYPE)
arglist = TREE_CHAIN (arglist);
+ /* Output literal 'J' and mangle the return type IF not a
+ constructor. */
+ if (!ID_INIT_P (method_name))
+ {
+ obstack_1grow (mangle_obstack, 'J');
+ mangle_type(TREE_TYPE(TREE_TYPE(mdecl)));
+ }
+
/* No arguments is easy. We shortcut it. */
if (arglist == end_params_node)
obstack_1grow (mangle_obstack, 'v');
diff --git a/include/ChangeLog b/include/ChangeLog
index 575bcf73db7..71fe4253afa 100644
--- a/include/ChangeLog
+++ b/include/ChangeLog
@@ -1,3 +1,9 @@
+2005-12-10 Terry Laurenzo <tlaurenzo@gmail.com>
+
+ PR java/9861
+ * demangle.h : Add DMGL_RET_POSTFIX define to enable alternative
+ output format for return types
+
2005-10-31 Mark Kettenis <kettenis@gnu.org>
* floatformat.h (enum floatformat_byteorders): Add
diff --git a/include/demangle.h b/include/demangle.h
index 304a4c4e472..af294672736 100644
--- a/include/demangle.h
+++ b/include/demangle.h
@@ -35,6 +35,8 @@ extern "C" {
#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 (when
+ present) after function signature */
#define DMGL_AUTO (1 << 8)
#define DMGL_GNU (1 << 9)
diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog
index 6fdeba3e852..85e96bad04b 100644
--- a/libiberty/ChangeLog
+++ b/libiberty/ChangeLog
@@ -1,3 +1,17 @@
+2005-12-10 Terry Laurenzo <tlaurenzo@gmail.com>
+
+ 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.
+
2005-11-06 Richard Guenther <rguenther@suse.de>
* splay-tree.c (rotate_left): New function.
diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c
index 8f1cfb17f87..109d533b524 100644
--- a/libiberty/cp-demangle.c
+++ b/libiberty/cp-demangle.c
@@ -1939,7 +1939,7 @@ d_function_type (struct d_info *di)
return ret;
}
-/* <bare-function-type> ::= <type>+ */
+/* <bare-function-type> ::= [J]<type>+ */
static struct demangle_component *
d_bare_function_type (struct d_info *di, int has_return_type)
@@ -1947,13 +1947,22 @@ d_bare_function_type (struct d_info *di, int has_return_type)
struct demangle_component *return_type;
struct demangle_component *tl;
struct demangle_component **ptl;
+ char peek;
+
+ /* Detect special qualifier indicating that the first argument
+ is the return type. */
+ peek = d_peek_char (di);
+ if (peek == 'J')
+ {
+ d_advance (di, 1);
+ has_return_type = 1;
+ }
return_type = NULL;
tl = NULL;
ptl = &tl;
while (1)
{
- char peek;
struct demangle_component *type;
peek = d_peek_char (di);
@@ -3025,13 +3034,16 @@ d_print_comp (struct d_print_info *dpi,
case DEMANGLE_COMPONENT_FUNCTION_TYPE:
{
+ if ((dpi->options & DMGL_RET_POSTFIX) != 0)
+ d_print_function_type (dpi, dc, dpi->modifiers);
+
+ /* Print return type if present */
if (d_left (dc) != NULL)
{
struct d_print_mod dpm;
/* We must pass this type down as a modifier in order to
print it in the right location. */
-
dpm.next = dpi->modifiers;
dpi->modifiers = &dpm;
dpm.mod = dc;
@@ -3045,10 +3057,14 @@ d_print_comp (struct d_print_info *dpi,
if (dpm.printed)
return;
- 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) == 0)
+ d_append_char (dpi, ' ');
}
- d_print_function_type (dpi, dc, dpi->modifiers);
+ if ((dpi->options & DMGL_RET_POSTFIX) == 0)
+ d_print_function_type (dpi, dc, dpi->modifiers);
return;
}
@@ -4003,7 +4019,8 @@ java_demangle_v3 (const char* mangled)
char *from;
char *to;
- demangled = d_demangle (mangled, DMGL_JAVA | DMGL_PARAMS, &alc);
+ demangled = d_demangle (mangled, DMGL_JAVA | DMGL_PARAMS | DMGL_RET_POSTFIX,
+ &alc);
if (demangled == NULL)
return NULL;
diff --git a/libiberty/testsuite/demangle-expected b/libiberty/testsuite/demangle-expected
index 4526773a780..fa2a2fed245 100644
--- a/libiberty/testsuite/demangle-expected
+++ b/libiberty/testsuite/demangle-expected
@@ -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=auto. If it doesn't start with --, then it
@@ -3781,3 +3782,26 @@ _test_array__L_1__B23b___clean.6
--format=java
_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=java
+_ZN4java4lang4Math4acosEJdd
+java.lang.Math.acos(double)double
+#
+--format=auto
+_ZN4java4lang4Math4acosEJdd
+double java::lang::Math::acos(double)
+#
+--format=auto
+_ZN4java4lang4Math4acosEJvd
+void java::lang::Math::acos(double)
+#
+--format=auto --ret-postfix
+_ZN4java4lang4Math4acosEJdd
+java::lang::Math::acos(double)double
+#
+--format=gnu-v3 --no-params --ret-postfix
+_Z4makeI7FactoryiET_IT0_Ev
+make<Factory, int>()Factory<int>
+make<Factory, int>
diff --git a/libiberty/testsuite/test-demangle.c b/libiberty/testsuite/test-demangle.c
index dcb27d259d4..93793996fe0 100644
--- a/libiberty/testsuite/test-demangle.c
+++ b/libiberty/testsuite/test-demangle.c
@@ -114,6 +114,7 @@ exp: %s\n",
--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=auto. If it doesn't start with --, then it
@@ -129,6 +130,7 @@ main(argc, argv)
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 @@ main(argc, argv)
tests++;
no_params = 0;
+ ret_postfix = 0;
is_v3_ctor = 0;
is_v3_dtor = 0;
if (format.data[0] == '\0')
@@ -212,6 +215,8 @@ main(argc, argv)
is_v3_ctor = 1;
else if (strcmp (opt, "--is-v3-dtor") == 0)
is_v3_dtor = 1;
+ else if (strcmp (opt, "--ret-postfix") == 0)
+ ret_postfix = 1;
else
{
printf ("FAIL at line %d: unrecognized option %s\n",
@@ -255,7 +260,8 @@ main(argc, argv)
cplus_demangle_set_style (style);
result = cplus_demangle (input.data,
- DMGL_PARAMS|DMGL_ANSI|DMGL_TYPES);
+ DMGL_PARAMS|DMGL_ANSI|DMGL_TYPES
+ |(ret_postfix ? DMGL_RET_POSTFIX : 0));
if (result
? strcmp (result, expect.data)