From: Iain Buclaw <ibuclaw@gdcproject.org>
To: gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH 2/3] [D] libiberty: Add support for handling function types in dlang_type
Date: Fri, 26 May 2017 16:08:00 -0000 [thread overview]
Message-ID: <CABOHX+dQtWcDYyUG_t5wncf-rHpOM=rLOf7-Z6yRk=Zt2mxJvg@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 280 bytes --]
In the normal case, functions are passed around as a
pointer-to-function type. One place where this is not the case
however is when a function appears in template arguments, here the
function is instead passed by alias.
This patch updates dlang_type() to handle this case.
---
[-- Attachment #2: 02-d-function-types.patch --]
[-- Type: text/x-patch, Size: 3887 bytes --]
commit 43a0c37b48f8365fb34083a8ebbcb6ce8a2da05c
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date: Fri May 26 15:53:53 2017 +0200
libiberty/ChangeLog:
2017-05-26 Iain Buclaw <ibuclaw@gdcproject.org>
* d-demangle.c (dlang_call_convention_p): Move declaration
before dlang_type.
(dlang_type): Handle function types.
* testsuite/d-demangle-expected: Add tests.
diff --git a/libiberty/d-demangle.c b/libiberty/d-demangle.c
index 030cab3333f..829050bc0b8 100644
--- a/libiberty/d-demangle.c
+++ b/libiberty/d-demangle.c
@@ -251,6 +251,22 @@ dlang_hexdigit (const char *mangled, char *ret)
return mangled;
}
+/* Extract the function calling convention from MANGLED and
+ return 1 on success or 0 on failure. */
+static int
+dlang_call_convention_p (const char *mangled)
+{
+ switch (*mangled)
+ {
+ case 'F': case 'U': case 'V':
+ case 'W': case 'R': case 'Y':
+ return 1;
+
+ default:
+ return 0;
+ }
+}
+
/* Demangle the calling convention from MANGLED and append it to DECL.
Return the remaining string on success or NULL on failure. */
static const char *
@@ -600,17 +616,22 @@ dlang_type (string *decl, const char *mangled)
}
case 'P': /* pointer (T*) */
mangled++;
- /* Function pointer types don't include the trailing asterisk. */
- switch (*mangled)
+ if (!dlang_call_convention_p (mangled))
{
- case 'F': case 'U': case 'W':
- case 'V': case 'R': case 'Y':
- mangled = dlang_function_type (decl, mangled);
- string_append (decl, "function");
+ mangled = dlang_type (decl, mangled);
+ string_append (decl, "*");
return mangled;
}
- mangled = dlang_type (decl, mangled);
- string_append (decl, "*");
+ /* Fall through */
+ case 'F': /* function T (D) */
+ case 'U': /* function T (C) */
+ case 'W': /* function T (Windows) */
+ case 'V': /* function T (Pascal) */
+ case 'R': /* function T (C++) */
+ case 'Y': /* function T (Objective-C) */
+ /* Function pointer types don't include the trailing asterisk. */
+ mangled = dlang_function_type (decl, mangled);
+ string_append (decl, "function");
return mangled;
case 'I': /* ident T */
case 'C': /* class T */
@@ -1311,22 +1332,6 @@ dlang_value (string *decl, const char *mangled, const char *name, char type)
return mangled;
}
-/* Extract the function calling convention from MANGLED and
- return 1 on success or 0 on failure. */
-static int
-dlang_call_convention_p (const char *mangled)
-{
- switch (*mangled)
- {
- case 'F': case 'U': case 'V':
- case 'W': case 'R': case 'Y':
- return 1;
-
- default:
- return 0;
- }
-}
-
/* Extract and demangle the symbol in MANGLED and append it to DECL.
Returns the remaining signature on success or NULL on failure. */
static const char *
diff --git a/libiberty/testsuite/d-demangle-expected b/libiberty/testsuite/d-demangle-expected
index 950d4955d8f..7bf8b1725f9 100644
--- a/libiberty/testsuite/d-demangle-expected
+++ b/libiberty/testsuite/d-demangle-expected
@@ -886,6 +886,10 @@ _D8demangle35__T4testVS8demangle1SS2i1a3_616263Zv
demangle.test!(demangle.S(1, "abc"))
#
--format=dlang
+_D8demangle13__T4testTFZaZ6mangleFZv
+demangle.test!(char() function).mangle()
+#
+--format=dlang
_D8demangle4testMxFZv
demangle.test() const
#
@@ -1298,3 +1302,7 @@ std.traits.fqnSym!(std).adjustIdent(immutable(char)[])
--format=dlang
_D2rt8lifetime36__T14_d_newarrayOpTS13_d_newarrayiTZ14_d_newarrayOpTFNaNbxC8TypeInfomPmZAv
rt.lifetime._d_newarrayOpT!(_d_newarrayiT)._d_newarrayOpT(const(TypeInfo), ulong, ulong*)
+#
+--format=dlang
+_D4core8demangle16__T6mangleTFZPvZ6mangleFNaNbNfAxaAaZ11DotSplitter5emptyMxFNaNbNdNiNfZb
+core.demangle.mangle!(void*() function).mangle(const(char)[], char[]).DotSplitter.empty() const
next reply other threads:[~2017-05-26 15:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-26 16:08 Iain Buclaw [this message]
2017-05-26 18:20 ` Ian Lance Taylor via gcc-patches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CABOHX+dQtWcDYyUG_t5wncf-rHpOM=rLOf7-Z6yRk=Zt2mxJvg@mail.gmail.com' \
--to=ibuclaw@gdcproject.org \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).