Skip to content

Commit 4fcf6aa

Browse files
committed
Parse mangling for template parameter pack
1 parent 40962cc commit 4fcf6aa

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

msvc-demangler.mjs

+10-8
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,13 @@ export class Demangler {
420420
default: () => ({}),
421421
});
422422
}
423+
parse_template_parameter_index() {
424+
const num = this.parse_integer();
425+
const parm_index = num & ~(-1n << 12n);
426+
const parm_nesting = (num >> 12n) & ~(-1n << 8n);
427+
const parm_cumulative_parent_number = (num >> 20n) & ~(-1n << 10n);
428+
return { parm_index, parm_nesting, parm_cumulative_parent_number };
429+
}
423430
parse_template_argument() {
424431
return this.parse("non-type template argument")({
425432
'A': () => {
@@ -470,15 +477,9 @@ export class Demangler {
470477
'O': error,
471478
'P': todo,
472479
'Q': todo,
473-
'R': () => {
474-
const num = this.parse_integer();
475-
const parm_index = num & ~(-1n << 12n);
476-
const parm_nesting = (num >> 12n) & ~(-1n << 8n);
477-
const parm_cumulative_parent_number = (num >> 20n) & ~(-1n << 10n);
478-
return { typekind: 'template argument', argkind: 'parameter', parm_index, parm_nesting, parm_cumulative_parent_number };
479-
},
480+
'R': () => ({ typekind: 'template argument', argkind: 'parameter', ...this.parse_template_parameter_index() }),
480481
'S': () => ({ typekind: 'template argument', argkind: 'empty non-type' }),
481-
'T': todo,
482+
'T': () => ({ typekind: 'template argument', argkind: 'parameter pack', ...this.parse_template_parameter_index() }),
482483
'0': () => ({ typekind: 'template argument', argkind: 'integral', value: this.parse_integer() }),
483484
'1': () => ({ typekind: 'template argument', argkind: 'entity', entity: this.parse_mangled() }),
484485
'2': () => this.parse_class_non_type_template_argument(),
@@ -846,6 +847,7 @@ function print_template_argument(ast) {
846847
case 'alias':
847848
return print_qualified_name(ast.typename);
848849
case 'parameter':
850+
case 'parameter pack':
849851
if (ast.parm_nesting > 1)
850852
return quoted(`T-${ast.parm_nesting}-${ast.parm_index}`);
851853
return quoted(`T${ast.parm_index}`);

test.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ async function get_all_testcases() {
8585
["??$g@$M$$CBUA@@1??__N2UA@@H0CK@@@$$Z$$CBU1@@@YAHABUA@@@Z", "int g<(const A)&A{(int)42}, const A>(const A &)"],
8686
["??$g@$MPBUA@@1??__N2UA@@H0CK@@@$$Z$$CBU1@@@YAHABUA@@@Z", "int g<(const A *)&A{(int)42}, const A>(const A &)"],
8787
["??$f@$$W$RBAAB@@@9", "f<'T1'...>"],
88+
["??$f@$$W$TBAAB@@@9", "f<'T1'...>"],
8889
["?f@@$$hYAXXZ", "void f()"],
8990
];
9091
const testfiles = await readdir('tests').then(files => files.filter(name => name.endsWith('.cpp')));

0 commit comments

Comments
 (0)