Skip to content

Commit

Permalink
fix delegate/function syntax
Browse files Browse the repository at this point in the history
show function attributes with DMGL_VERBOSE
  • Loading branch information
rainers committed Apr 17, 2017
1 parent 959b9c8 commit ba049f9
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions libiberty/d-demangle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -1359,6 +1363,7 @@ dlang_parse_mangle (string *decl, const char *mangled,
{
string mods;
string type;
string attr;
int saved;

/* Skip over 'this' parameter. */
Expand All @@ -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. */
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit ba049f9

Please sign in to comment.