* demangler: C++ modules support
@ 2022-05-23 13:07 Nathan Sidwell
0 siblings, 0 replies; only message in thread
From: Nathan Sidwell @ 2022-05-23 13:07 UTC (permalink / raw)
To: GCC Patches
[-- Attachment #1: Type: text/plain, Size: 667 bytes --]
This adds demangling support for C++ modules. A new 'W' component
along with augmented behaviour of 'S' components.
I guess I should go actually fix the ABI document itself now ...
include/
* demangle.h (enum demangle_component_type): Add module components.
libiberty/
* cp-demangle.c (d_make_comp): Adjust.
(d_name, d_prefix): Adjust subst handling. Add module handling.
(d_maybe_module_name): New.
(d_unqualified_name): Add incoming module parm. Handle it. Adjust all
callers.
(d_special_name): Add 'GI' support.
(d_count_template_scopes): Adjust.
(d_print_comp_inner): Print module.
* testsuite/demangle-expected: New test cases
--
Nathan Sidwell
[-- Attachment #2: 0001-demangler-C-modules-support.patch --]
[-- Type: text/x-patch, Size: 13296 bytes --]
From b7feb71d45e4cd894d7706c21a21a3871070d098 Mon Sep 17 00:00:00 2001
From: Nathan Sidwell <nathan@acm.org>
Date: Tue, 8 Mar 2022 12:54:03 -0800
Subject: [PATCH] demangler: C++ modules support
This adds demangling support for C++ modules. A new 'W' component
along with augmented behaviour of 'S' components.
include/
* demangle.h (enum demangle_component_type): Add module components.
libiberty/
* cp-demangle.c (d_make_comp): Adjust.
(d_name, d_prefix): Adjust subst handling. Add module handling.
(d_maybe_module_name): New.
(d_unqualified_name): Add incoming module parm. Handle it. Adjust all callers.
(d_special_name): Add 'GI' support.
(d_count_template_scopes): Adjust.
(d_print_comp_inner): Print module.
* testsuite/demangle-expected: New test cases
---
include/demangle.h | 7 +-
libiberty/cp-demangle.c | 142 +++++++++++++++++++++-----
libiberty/testsuite/demangle-expected | 67 ++++++++++++
3 files changed, 188 insertions(+), 28 deletions(-)
diff --git a/include/demangle.h b/include/demangle.h
index 44a27374d4f..e2aa4a971ff 100644
--- a/include/demangle.h
+++ b/include/demangle.h
@@ -451,7 +451,12 @@ enum demangle_component_type
DEMANGLE_COMPONENT_NOEXCEPT,
DEMANGLE_COMPONENT_THROW_SPEC,
- DEMANGLE_COMPONENT_STRUCTURED_BINDING
+ DEMANGLE_COMPONENT_STRUCTURED_BINDING,
+
+ DEMANGLE_COMPONENT_MODULE_NAME,
+ DEMANGLE_COMPONENT_MODULE_PARTITION,
+ DEMANGLE_COMPONENT_MODULE_ENTITY,
+ DEMANGLE_COMPONENT_MODULE_INIT,
};
/* Types which are only used internally. */
diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c
index cf451c5aff2..d06d80d1fee 100644
--- a/libiberty/cp-demangle.c
+++ b/libiberty/cp-demangle.c
@@ -429,10 +429,12 @@ static struct demangle_component *d_name (struct d_info *, int substable);
static struct demangle_component *d_nested_name (struct d_info *);
+static int d_maybe_module_name (struct d_info *, struct demangle_component **);
+
static struct demangle_component *d_prefix (struct d_info *, int);
static struct demangle_component *d_unqualified_name (struct d_info *,
- struct demangle_component *scope);
+ struct demangle_component *scope, struct demangle_component *module);
static struct demangle_component *d_source_name (struct d_info *);
@@ -984,6 +986,7 @@ d_make_comp (struct d_info *di, enum demangle_component_type type,
case DEMANGLE_COMPONENT_COMPOUND_NAME:
case DEMANGLE_COMPONENT_VECTOR_TYPE:
case DEMANGLE_COMPONENT_CLONE:
+ case DEMANGLE_COMPONENT_MODULE_ENTITY:
if (left == NULL || right == NULL)
return NULL;
break;
@@ -1022,6 +1025,7 @@ d_make_comp (struct d_info *di, enum demangle_component_type type,
case DEMANGLE_COMPONENT_TRINARY_ARG2:
case DEMANGLE_COMPONENT_TPARM_OBJ:
case DEMANGLE_COMPONENT_STRUCTURED_BINDING:
+ case DEMANGLE_COMPONENT_MODULE_INIT:
if (left == NULL)
return NULL;
break;
@@ -1030,6 +1034,8 @@ d_make_comp (struct d_info *di, enum demangle_component_type type,
empty. */
case DEMANGLE_COMPONENT_ARRAY_TYPE:
case DEMANGLE_COMPONENT_INITIALIZER_LIST:
+ case DEMANGLE_COMPONENT_MODULE_NAME:
+ case DEMANGLE_COMPONENT_MODULE_PARTITION:
if (right == NULL)
return NULL;
break;
@@ -1422,6 +1428,7 @@ d_name (struct d_info *di, int substable)
{
char peek = d_peek_char (di);
struct demangle_component *dc = NULL;
+ struct demangle_component *module = NULL;
int subst = 0;
switch (peek)
@@ -1435,7 +1442,7 @@ d_name (struct d_info *di, int substable)
break;
case 'U':
- dc = d_unqualified_name (di, NULL);
+ dc = d_unqualified_name (di, NULL, NULL);
break;
case 'S':
@@ -1446,12 +1453,21 @@ d_name (struct d_info *di, int substable)
dc = d_make_name (di, "std", 3);
di->expansion += 3;
}
- else
+
+ if (d_peek_char (di) == 'S')
{
- dc = d_substitution (di, 0);
- if (!dc)
+ module = d_substitution (di, 0);
+ if (!module)
return NULL;
- subst = 1;
+ if (!(module->type == DEMANGLE_COMPONENT_MODULE_NAME
+ || module->type == DEMANGLE_COMPONENT_MODULE_PARTITION))
+ {
+ if (dc)
+ return NULL;
+ subst = 1;
+ dc = module;
+ module = NULL;
+ }
}
}
/* FALLTHROUGH */
@@ -1459,7 +1475,7 @@ d_name (struct d_info *di, int substable)
case 'L':
default:
if (!subst)
- dc = d_unqualified_name (di, dc);
+ dc = d_unqualified_name (di, dc, module);
if (d_peek_char (di) == 'I')
{
/* This is <template-args>, which means that we just saw
@@ -1552,15 +1568,6 @@ d_prefix (struct d_info *di, int substable)
return NULL;
ret = cplus_demangle_type (di);
}
- else if (peek == 'S')
- {
- if (ret)
- return NULL;
- ret = d_substitution (di, 1);
- if (!ret)
- return NULL;
- continue;
- }
else if (peek == 'I')
{
if (ret == NULL)
@@ -1586,7 +1593,24 @@ d_prefix (struct d_info *di, int substable)
d_advance (di, 1);
}
else
- ret = d_unqualified_name (di, ret);
+ {
+ struct demangle_component *module = NULL;
+ if (peek == 'S')
+ {
+ module = d_substitution (di, 1);
+ if (!module)
+ return NULL;
+ if (!(module->type == DEMANGLE_COMPONENT_MODULE_NAME
+ || module->type == DEMANGLE_COMPONENT_MODULE_PARTITION))
+ {
+ if (ret)
+ return NULL;
+ ret = module;
+ continue;
+ }
+ }
+ ret = d_unqualified_name (di, ret, module);
+ }
if (!ret)
break;
@@ -1601,20 +1625,46 @@ d_prefix (struct d_info *di, int substable)
return ret;
}
-/* <unqualified-name> ::= <operator-name> [<abi-tags>]
- ::= <ctor-dtor-name> [<abi-tags>]
- ::= <source-name> [<abi-tags>]
- ::= <local-source-name> [<abi-tags>]
- ::= DC <source-name>+ E [<abi-tags>]
+static int
+d_maybe_module_name (struct d_info *di, struct demangle_component **name)
+{
+ while (d_peek_char (di) == 'W')
+ {
+ d_advance (di, 1);
+ enum demangle_component_type code = DEMANGLE_COMPONENT_MODULE_NAME;
+ if (d_peek_char (di) == 'P')
+ {
+ code = DEMANGLE_COMPONENT_MODULE_PARTITION;
+ d_advance (di, 1);
+ }
+
+ *name = d_make_comp (di, code, *name, d_source_name (di));
+ if (!*name)
+ return 0;
+ if (!d_add_substitution (di, *name))
+ return 0;
+ }
+ return 1;
+}
+
+/* <unqualified-name> ::= [<module-name>] <operator-name> [<abi-tags>]
+ ::= [<module-name>] <ctor-dtor-name> [<abi-tags>]
+ ::= [<module-name>] <source-name> [<abi-tags>]
+ ::= [<module-name>] <local-source-name> [<abi-tags>]
+ ::= [<module-name>] DC <source-name>+ E [<abi-tags>]
<local-source-name> ::= L <source-name> <discriminator> [<abi-tags>]
*/
static struct demangle_component *
-d_unqualified_name (struct d_info *di, struct demangle_component *scope)
+d_unqualified_name (struct d_info *di, struct demangle_component *scope,
+ struct demangle_component *module)
{
struct demangle_component *ret;
char peek;
+ if (!d_maybe_module_name (di, &module))
+ return NULL;
+
peek = d_peek_char (di);
if (IS_DIGIT (peek))
ret = d_source_name (di);
@@ -1688,6 +1738,8 @@ d_unqualified_name (struct d_info *di, struct demangle_component *scope)
else
return NULL;
+ if (module)
+ ret = d_make_comp (di, DEMANGLE_COMPONENT_MODULE_ENTITY, ret, module);
if (d_peek_char (di) == 'B')
ret = d_abi_tags (di, ret);
if (scope)
@@ -2166,6 +2218,14 @@ d_special_name (struct d_info *di)
return d_make_comp (di, DEMANGLE_COMPONENT_HIDDEN_ALIAS,
d_encoding (di, 0), NULL);
+ case 'I':
+ {
+ struct demangle_component *module = NULL;
+ if (!d_maybe_module_name (di, &module) || !module)
+ return NULL;
+ return d_make_comp (di, DEMANGLE_COMPONENT_MODULE_INIT,
+ module, NULL);
+ }
case 'T':
switch (d_next_char (di))
{
@@ -3302,7 +3362,7 @@ d_unresolved_name (struct d_info *di)
}
else
type = cplus_demangle_type (di);
- name = d_unqualified_name (di, type);
+ name = d_unqualified_name (di, type, NULL);
if (d_peek_char (di) == 'I')
name = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, name,
d_template_args (di));
@@ -3375,7 +3435,7 @@ d_expression_1 (struct d_info *di)
/* operator-function-id, i.e. operator+(t). */
d_advance (di, 2);
- name = d_unqualified_name (di, NULL);
+ name = d_unqualified_name (di, NULL, NULL);
if (name == NULL)
return NULL;
if (d_peek_char (di) == 'I')
@@ -3483,7 +3543,7 @@ d_expression_1 (struct d_info *di)
/* fold-expression. */
left = d_operator_name (di);
else if (!strcmp (code, "di"))
- left = d_unqualified_name (di, NULL);
+ left = d_unqualified_name (di, NULL, NULL);
else
left = d_expression_1 (di);
if (!strcmp (code, "cl"))
@@ -3501,7 +3561,7 @@ d_expression_1 (struct d_info *di)
d_unqualified_name rather than d_expression_1 here for
old mangled names that didn't add 'on' before operator
names. */
- right = d_unqualified_name (di, NULL);
+ right = d_unqualified_name (di, NULL, NULL);
if (d_peek_char (di) == 'I')
right = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE,
right, d_template_args (di));
@@ -4147,6 +4207,9 @@ d_count_templates_scopes (struct d_print_info *dpi,
case DEMANGLE_COMPONENT_NUMBER:
case DEMANGLE_COMPONENT_UNNAMED_TYPE:
case DEMANGLE_COMPONENT_STRUCTURED_BINDING:
+ case DEMANGLE_COMPONENT_MODULE_NAME:
+ case DEMANGLE_COMPONENT_MODULE_PARTITION:
+ case DEMANGLE_COMPONENT_MODULE_INIT:
break;
case DEMANGLE_COMPONENT_TEMPLATE:
@@ -4252,6 +4315,7 @@ d_count_templates_scopes (struct d_print_info *dpi,
case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS:
case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS:
+ case DEMANGLE_COMPONENT_MODULE_ENTITY:
d_count_templates_scopes (dpi, d_left (dc));
break;
@@ -4831,6 +4895,25 @@ d_print_comp_inner (struct d_print_info *dpi, int options,
d_append_char (dpi, ']');
return;
+ case DEMANGLE_COMPONENT_MODULE_ENTITY:
+ d_print_comp (dpi, options, d_left (dc));
+ d_append_char (dpi, '@');
+ d_print_comp (dpi, options, d_right (dc));
+ return;
+
+ case DEMANGLE_COMPONENT_MODULE_NAME:
+ case DEMANGLE_COMPONENT_MODULE_PARTITION:
+ {
+ if (d_left (dc))
+ d_print_comp (dpi, options, d_left (dc));
+ char c = dc->type == DEMANGLE_COMPONENT_MODULE_PARTITION
+ ? ':' : d_left (dc) ? '.' : 0;
+ if (c)
+ d_append_char (dpi, c);
+ d_print_comp (dpi, options, d_right (dc));
+ }
+ return;
+
case DEMANGLE_COMPONENT_QUAL_NAME:
case DEMANGLE_COMPONENT_LOCAL_NAME:
d_print_comp (dpi, options, d_left (dc));
@@ -5062,6 +5145,11 @@ d_print_comp_inner (struct d_print_info *dpi, int options,
d_print_comp (dpi, options, dc->u.s_dtor.name);
return;
+ case DEMANGLE_COMPONENT_MODULE_INIT:
+ d_append_string (dpi, "initializer for module ");
+ d_print_comp (dpi, options, d_left (dc));
+ return;
+
case DEMANGLE_COMPONENT_VTABLE:
d_append_string (dpi, "vtable for ");
d_print_comp (dpi, options, d_left (dc));
diff --git a/libiberty/testsuite/demangle-expected b/libiberty/testsuite/demangle-expected
index 2b0b531d4bf..351af349219 100644
--- a/libiberty/testsuite/demangle-expected
+++ b/libiberty/testsuite/demangle-expected
@@ -1503,3 +1503,70 @@ std::[a]
_ZN3NMSDC1aEE
NMS::[a]
+
+# Modules
+_ZN5Outer5InnerW3FOO2FnERNS0_1XE
+Outer::Inner::Fn@FOO(Outer::Inner::X&)
+
+_ZN5OuterW3FOO5Inner2FnERNS1_1XE
+Outer::Inner@FOO::Fn(Outer::Inner@FOO::X&)
+
+_ZN4Quux4TotoW3FooW3Bar3BazEPNS0_S2_5PlughE
+Quux::Toto::Baz@Foo.Bar(Quux::Toto::Plugh@Foo.Bar*)
+
+_ZW6Module1fNS_1a1bENS0_1cE
+f@Module(a@Module::b, a@Module::c)
+
+_ZN3BobW3FOOW3BAR3BarEPS1_1APNS_S1_1BE
+Bob::Bar@FOO.BAR(A@FOO.BAR*, Bob::B@FOO.BAR*)
+
+_ZW3FOOW3BAR3FooPS0_1APN3BobS0_1BE
+Foo@FOO.BAR(A@FOO.BAR*, Bob::B@FOO.BAR*)
+
+_ZN3BobW3FOOW3BAZ3FooEPS0_W3BAR1APNS_S2_1BE
+Bob::Foo@FOO.BAZ(A@FOO.BAR*, Bob::B@FOO.BAR*)
+
+_ZW3FOOW3BAZ3BarPS_W3BAR1APN3BobS1_1BE
+Bar@FOO.BAZ(A@FOO.BAR*, Bob::B@FOO.BAR*)
+
+_ZNW3FOO3TPLIS_3OneE1MEPS1_
+TPL@FOO<One@FOO>::M(One@FOO*)
+
+_ZNW3FOO3TPLIS_3OneE1NIS_3TwoEEvPS1_PT_
+void TPL@FOO<One@FOO>::N<Two@FOO>(One@FOO*, Two@FOO*)
+
+_ZN3NMSW3FOO3TPLINS_S0_3OneEE1MEPS2_
+NMS::TPL@FOO<NMS::One@FOO>::M(NMS::One@FOO*)
+
+_ZN3NMSW3FOO3TPLINS_S0_3OneEE1NINS_S0_3TwoEEEvPS2_PT_
+void NMS::TPL@FOO<NMS::One@FOO>::N<NMS::Two@FOO>(NMS::One@FOO*, NMS::Two@FOO*)
+
+_ZNStW3STD9allocatorIiE1MEPi
+std::allocator@STD<int>::M(int*)
+
+_ZNStW3STD9allocatorIiE1NIfEEPT_Pi
+float* std::allocator@STD<int>::N<float>(int*)
+
+_ZNStW3STD9allocatorI4PoohE1MEPS1_
+std::allocator@STD<Pooh>::M(Pooh*)
+
+_ZNStW3STD9allocatorI4PoohE1NI6PigletEEPT_PS1_
+Piglet* std::allocator@STD<Pooh>::N<Piglet>(Pooh*)
+
+_ZW3FooDC1a1bE
+[a, b]@Foo
+
+_ZN1NW3FooDC1a1bEE
+N::[a, b]@Foo
+
+_ZN3NMSW3MOD3FooB3ABIEv
+NMS::Foo@MOD[abi:ABI]()
+
+_ZGIW3Foo
+initializer for module Foo
+
+_ZGIW3FooW3Bar
+initializer for module Foo.Bar
+
+_ZGIW3FooWP3BarW3Baz
+initializer for module Foo:Bar.Baz
--
2.30.2
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-05-23 13:07 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-23 13:07 demangler: C++ modules support Nathan Sidwell
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).