Skip to content

Commit 526474e

Browse files
mstangekhuey
authored andcommitted
Add no_return_type to DemangleOptions.
1 parent 255703c commit 526474e

File tree

6 files changed

+78
-6
lines changed

6 files changed

+78
-6
lines changed

c_api/include/cpp_demangle.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ extern "C" {
88
struct DemangleOptions {
99
// Do not display function arguments.
1010
bool no_params;
11+
// Do not display the function return type.
12+
bool no_return_type;
1113
};
1214

1315
extern char *demangle(const char *buffer, struct DemangleOptions options);

c_api/test/cxxfilt.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
static const struct option long_options[] = {
99
{"help", no_argument, NULL, 'h'},
1010
{"no-params", no_argument, NULL, 'p'},
11+
{"no-return-type", no_argument, NULL, 'r'},
1112
{NULL, no_argument, NULL, 0}};
1213

1314
// Prints the help message of the program.
@@ -19,6 +20,9 @@ static void usage() {
1920
fprintf(stdout, "\
2021
[-p|--no-params]\t Do not display function arguments\n");
2122

23+
fprintf(stdout, "\
24+
[-r|--no-return-type]\t Do not display function return types\n");
25+
2226
fprintf(stdout, "]\n");
2327

2428
fprintf(stdout, "\
@@ -45,6 +49,7 @@ void demangle_name(char *mangled_name, bool no_params) {
4549
int main(int argc, char **argv) {
4650
int c = 0;
4751
bool no_params = false;
52+
bool no_return_type = false;
4853

4954
// This is where all the options/flags for this example should be handled.
5055
while ((c = getopt_long(argc, argv, "_hp", long_options, (int *)0)) != EOF) {
@@ -56,6 +61,9 @@ int main(int argc, char **argv) {
5661
case 'p':
5762
no_params = true;
5863
break;
64+
case 'r':
65+
no_return_type = true;
66+
break;
5967
}
6068
}
6169

examples/cppfilt.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ fn main() {
104104

105105
let options = DemangleOptions {
106106
no_params: matches.is_present("noparams"),
107+
no_return_type: matches.is_present("noreturntype"),
107108
};
108109

109110
let demangle_result = if let Some(names) = matches.values_of("mangled_names") {

src/ast.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,11 +538,16 @@ where
538538
// argument pack.
539539
is_template_argument_pack: bool,
540540

541-
// Whether to show function parameters and (if applicable) return types.
541+
// Whether to show function parameters.
542542
// This must be set to true before calling `demangle` on `Encoding`
543543
// unless that call is via the toplevel call to `MangledName::demangle`.
544544
show_params: bool,
545545

546+
// Whether to show function return types.
547+
// This must be set to true before calling `demangle` on `Encoding`
548+
// unless that call is via the toplevel call to `MangledName::demangle`.
549+
show_return_type: bool,
550+
546551
// recursion protection.
547552
state: Cell<DemangleState>,
548553
}
@@ -590,6 +595,7 @@ where
590595
is_template_prefix_in_nested_name: false,
591596
is_template_argument_pack: false,
592597
show_params: !options.no_params,
598+
show_return_type: !options.no_return_type,
593599
state: Cell::new(DemangleState {
594600
recursion_level: 0,
595601
}),
@@ -1483,7 +1489,7 @@ where
14831489
// http://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangle.function-type
14841490
let scope = if let Some(template_args) = name.get_template_args(ctx.subs) {
14851491
let scope = scope.push(template_args);
1486-
if ctx.show_params && !name.is_ctor_dtor_conversion(ctx.subs) {
1492+
if ctx.show_return_type && !name.is_ctor_dtor_conversion(ctx.subs) {
14871493
fun_ty.0[0].demangle(ctx, scope)?;
14881494
write!(ctx, " ")?;
14891495
}

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ use std::fmt;
8888
pub struct DemangleOptions {
8989
/// Do not display function arguments.
9090
pub no_params: bool,
91+
/// Do not display the function return type.
92+
pub no_return_type: bool,
9193
}
9294

9395
/// A `Symbol` which owns the underlying storage for the mangled name.

tests/tests.rs

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,40 @@ macro_rules! demangles {
8080
};
8181
}
8282

83+
macro_rules! demangles_no_param_and_no_return_type {
84+
( $mangled:ident , $demangled:expr ) => {
85+
demangles_no_param_and_no_return_type!($mangled, stringify!($mangled), $demangled);
86+
};
87+
( $name:ident , $mangled:expr , $demangled:expr ) => {
88+
#[test]
89+
fn $name() {
90+
let options = DemangleOptions { no_params: true, no_return_type: true };
91+
assert_demangles_as($mangled, $demangled, Some(options));
92+
}
93+
};
94+
}
95+
96+
macro_rules! demangles_no_return_type {
97+
( $mangled:ident , $demangled:expr ) => {
98+
demangles_no_return_type!($mangled, stringify!($mangled), $demangled);
99+
};
100+
( $name:ident , $mangled:expr , $demangled:expr ) => {
101+
#[test]
102+
fn $name() {
103+
let options = DemangleOptions { no_params: false, no_return_type: true };
104+
assert_demangles_as($mangled, $demangled, Some(options));
105+
}
106+
};
107+
}
108+
83109
macro_rules! demangles_no_param {
84110
( $mangled:ident , $demangled:expr ) => {
85111
demangles_no_param!($mangled, stringify!($mangled), $demangled);
86112
};
87113
( $name:ident , $mangled:expr , $demangled:expr ) => {
88114
#[test]
89115
fn $name() {
90-
let options = DemangleOptions { no_params: true };
116+
let options = DemangleOptions { no_params: true, no_return_type: false };
91117
assert_demangles_as($mangled, $demangled, Some(options));
92118
}
93119
};
@@ -458,18 +484,45 @@ demangles!(
458484
_ZNSt6vectorIN3xxx6xxxxxx15xxxxxxxxxxxxxxxESaIS2_EE12emplace_backIIS2_EEEvDpOT_,
459485
"void std::vector<xxx::xxxxxx::xxxxxxxxxxxxxxx, std::allocator<xxx::xxxxxx::xxxxxxxxxxxxxxx> >::emplace_back<xxx::xxxxxx::xxxxxxxxxxxxxxx>(xxx::xxxxxx::xxxxxxxxxxxxxxx&&)"
460486
);
461-
demangles_no_param!(
487+
demangles_no_param_and_no_return_type!(
462488
_ZN2js9LifoAlloc21newArrayUninitializedI17OffsetAndDefIndexEEPT_m,
463489
"js::LifoAlloc::newArrayUninitialized<OffsetAndDefIndex>"
464490
);
465-
demangles_no_param!(
491+
demangles_no_param_and_no_return_type!(
466492
_Z4callIXadL_Z5helloiEEEvi,
467493
"call<&hello(int)>"
468494
);
469-
demangles_no_param!(
495+
demangles_no_param_and_no_return_type!(
470496
_ZNK5Hello6methodEv,
471497
"Hello::method"
472498
);
499+
500+
demangles_no_return_type!(
501+
_ZL15draw_quad_spansIjEviPN4glsl11vec2_scalarEtPDv16_fR7TextureiS6_RK8ClipRect,
502+
"draw_quad_spans<unsigned int>(int, glsl::vec2_scalar*, unsigned short, float __vector(16)*, Texture&, int, Texture&, ClipRect const&)"
503+
);
504+
505+
demangles_no_return_type!(
506+
_ZL13draw_elementsItEviiR6BuffermR11VertexArrayR7TextureiS5_,
507+
"draw_elements<unsigned short>(int, int, Buffer&, unsigned long, VertexArray&, Texture&, int, Texture&)"
508+
);
509+
510+
demangles_no_return_type!(
511+
_ZL12check_depth8ILi515ELb0EEitPtRDv8_s,
512+
"check_depth8<515, false>(unsigned short, unsigned short*, short __vector(8)&)"
513+
);
514+
515+
demangles_no_return_type!(
516+
_ZN7mozilla6detail23RunnableMethodArgumentsIJNS_2wr10WrWindowIdEbEE5applyINS2_12RenderThreadEMS6_FvS3_bEEEDTcl9applyImplfp_fp0_dtdefpT10mArgumentstlNSt3__116integer_sequenceImJLm0ELm1EEEEEEEPT_T0_,
517+
"mozilla::detail::RunnableMethodArguments<mozilla::wr::WrWindowId, bool>::apply<mozilla::wr::RenderThread, void (mozilla::wr::RenderThread::*)(mozilla::wr::WrWindowId, bool)>(mozilla::wr::RenderThread*, void (mozilla::wr::RenderThread::*)(mozilla::wr::WrWindowId, bool))"
518+
);
519+
520+
demangles_no_param!(
521+
_ZN7mozilla6detail23RunnableMethodArgumentsIJNS_2wr10WrWindowIdEbEE5applyINS2_12RonderThroudEMS6_FvS3_bEEEDTcl9applyImplfp_fp0_dtdefpT10mArgumentstlNSt3__116integer_sequenceImJLm0ELm1EEEEEEEPT_T0_,
522+
"decltype ((applyImpl)({parm#1}, {parm#2}, (*this).mArguments, std::__1::integer_sequence<unsigned long, (unsigned long)0, (unsigned long)1>{})) mozilla::detail::RunnableMethodArguments<mozilla::wr::WrWindowId, bool>::apply<mozilla::wr::RonderThroud, void (mozilla::wr::RonderThroud::*)(mozilla::wr::WrWindowId, bool)>"
523+
);
524+
525+
473526
demangles!(
474527
_ZZN17TestLargestRegion18TestNonRectangularEvENUt_D2Ev,
475528
"TestLargestRegion::TestNonRectangular()::{unnamed type#1}::~TestNonRectangular()"

0 commit comments

Comments
 (0)