From ba049f94b300e8624076061aeab1f5b0206d23f2 Mon Sep 17 00:00:00 2001 From: Rainer Schuetze Date: Mon, 17 Apr 2017 15:41:51 +0200 Subject: [PATCH] fix delegate/function syntax show function attributes with DMGL_VERBOSE --- libiberty/d-demangle.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/libiberty/d-demangle.c b/libiberty/d-demangle.c index 8f614d0873..70602e69a3 100644 --- a/libiberty/d-demangle.c +++ b/libiberty/d-demangle.c @@ -401,7 +401,7 @@ dlang_attributes (string *decl, const char *mangled) /* Demangle the function type from MANGLED and append it to DECL. Return the remaining string on success or NULL on failure. */ static const char * -dlang_function_type (string *decl, const char *mangled, int options) +dlang_function_type (string *decl, const char *mangled, int options, const char* fntype) { string attr, args, type; size_t szattr, szargs, sztype; @@ -436,10 +436,16 @@ dlang_function_type (string *decl, const char *mangled, int options) /* Append to decl in order. */ string_appendn (decl, type.b, sztype); + string_appendn (decl, " ", 1); + string_append(decl, fntype); string_append (decl, "("); string_appendn (decl, args.b, szargs); - string_append (decl, ") "); - string_appendn (decl, attr.b, szattr); + string_append (decl, ")"); + if (szattr) + { + string_appendn(decl, " ", 1); + string_appendn (decl, attr.b, szattr); + } string_delete (&attr); string_delete (&args); @@ -605,8 +611,7 @@ dlang_type (string *decl, const char *mangled, int options) { case 'F': case 'U': case 'W': case 'V': case 'R': case 'Y': - mangled = dlang_function_type (decl, mangled, options); - string_append (decl, "function"); + mangled = dlang_function_type (decl, mangled, options, "function"); return mangled; } mangled = dlang_type (decl, mangled, options); @@ -629,8 +634,7 @@ dlang_type (string *decl, const char *mangled, int options) mangled = dlang_type_modifiers (&mods, mangled); szmods = string_length (&mods); - mangled = dlang_function_type (decl, mangled, options); - string_append (decl, "delegate"); + mangled = dlang_function_type (decl, mangled, options, "delegate"); string_appendn (decl, mods.b, szmods); string_delete (&mods); @@ -1359,6 +1363,7 @@ dlang_parse_mangle (string *decl, const char *mangled, { string mods; string type; + string attr; int saved; /* Skip over 'this' parameter. */ @@ -1369,15 +1374,14 @@ dlang_parse_mangle (string *decl, const char *mangled, string_init (&mods); mangled = dlang_type_modifiers (&mods, mangled); + string_init(&attr); if (mangled && dlang_call_convention_p (mangled)) { string args; /* Skip over calling convention and attributes. */ - saved = string_length (decl); - mangled = dlang_call_convention (decl, mangled); - mangled = dlang_attributes (decl, mangled); - string_setlength (decl, saved); + mangled = dlang_call_convention (&attr, mangled); + mangled = dlang_attributes (&attr, mangled); /* Save the function arguments, and append it to the demangled result if requested. */ @@ -1408,8 +1412,12 @@ dlang_parse_mangle (string *decl, const char *mangled, string_prepend (decl, " "); string_prependn (decl, type.b, string_length (&type)); } + if (options & DMGL_VERBOSE) + string_prependn (decl, attr.b, string_length (&attr)); string_delete (&type); + string_delete (&attr); + string_delete (&mods); } }