@@ -236,7 +236,24 @@ private final class CppMangleVisitor : Visitor
236
236
}
237
237
}
238
238
239
- bool substitute (RootObject p)
239
+ /**
240
+ * Attempt to perform substitution on `p`
241
+ *
242
+ * If `p` already appeared in the mangling, it is stored as
243
+ * a 'part', and short references in the form of `SX_` can be used.
244
+ * Note that `p` can be anything: template declaration, struct declaration,
245
+ * class declaration, namespace...
246
+ *
247
+ * Params:
248
+ * p = The object to attempt to substitute
249
+ * nested = Whether or not `p` is to be considered nested.
250
+ * When `true`, `N` will be prepended before the substitution.
251
+ *
252
+ * Returns:
253
+ * Whether `p` already appeared in the mangling,
254
+ * and substitution has been written to `this.buf`.
255
+ */
256
+ bool substitute (RootObject p, bool nested = false )
240
257
{
241
258
// printf("substitute %s\n", p ? p.toChars() : null);
242
259
auto i = find(p);
@@ -245,6 +262,8 @@ private final class CppMangleVisitor : Visitor
245
262
// printf("\tmatch\n");
246
263
/* Sequence is S_, S0_, .., S9_, SA_, ..., SZ_, S10_, ...
247
264
*/
265
+ if (nested)
266
+ buf.writeByte(' N' );
248
267
buf.writeByte(' S' );
249
268
writeSequenceFromIndex(i);
250
269
buf.writeByte(' _' );
@@ -550,19 +569,24 @@ private final class CppMangleVisitor : Visitor
550
569
if (TemplateInstance ti = s.isTemplateInstance())
551
570
{
552
571
bool needsTa = false ;
553
- if (substitute(ti.tempdecl))
572
+ const isNested = !! ti.tempdecl.namespace || !! getQualifier(ti.tempdecl);
573
+ if (substitute(ti.tempdecl, ! haveNE && isNested))
574
+ {
554
575
template_args(ti);
576
+ if (! haveNE && isNested)
577
+ buf.writeByte(' E' );
578
+ }
555
579
else if (this .writeStdSubstitution(ti, needsTa))
556
580
{
557
581
if (needsTa)
558
582
template_args(ti);
559
583
}
560
584
else
561
585
{
562
- append(ti.tempdecl);
563
586
this .writeNamespace(
564
587
s.namespace, () {
565
588
this .writeIdentifier(ti.tempdecl.toAlias().ident);
589
+ append(ti.tempdecl);
566
590
template_args(ti);
567
591
}, haveNE);
568
592
}
@@ -811,7 +835,6 @@ private final class CppMangleVisitor : Visitor
811
835
isChar((* ti.tiargs)[0 ]) &&
812
836
isChar_traits_char((* ti.tiargs)[1 ]) &&
813
837
isAllocator_char((* ti.tiargs)[2 ]))
814
-
815
838
{
816
839
buf.writestring(" Ss" );
817
840
return ;
0 commit comments