@@ -281,20 +281,11 @@ class Node {
281281 }
282282
283283 void print (OutputBuffer &OB) const {
284- printLeft (OB );
284+ OB. printLeft (* this );
285285 if (RHSComponentCache != Cache::No)
286- printRight (OB );
286+ OB. printRight (* this );
287287 }
288288
289- // Print the "left" side of this Node into OutputBuffer.
290- virtual void printLeft (OutputBuffer &) const = 0;
291-
292- // Print the "right". This distinction is necessary to represent C++ types
293- // that appear on the RHS of their subtype, such as arrays or functions.
294- // Since most types don't have such a component, provide a default
295- // implementation.
296- virtual void printRight (OutputBuffer &) const {}
297-
298289 // Print an initializer list of this type. Returns true if we printed a custom
299290 // representation, false if nothing has been printed and the default
300291 // representation should be used.
@@ -310,6 +301,24 @@ class Node {
310301#ifndef NDEBUG
311302 DEMANGLE_DUMP_METHOD void dump () const ;
312303#endif
304+
305+ private:
306+ friend class OutputBuffer ;
307+
308+ // Print the "left" side of this Node into OutputBuffer.
309+ //
310+ // Note, should only be called from OutputBuffer implementations.
311+ // Call \ref OutputBuffer::printLeft instead.
312+ virtual void printLeft (OutputBuffer &) const = 0;
313+
314+ // Print the "right". This distinction is necessary to represent C++ types
315+ // that appear on the RHS of their subtype, such as arrays or functions.
316+ // Since most types don't have such a component, provide a default
317+ // implementation.
318+ //
319+ // Note, should only be called from OutputBuffer implementations.
320+ // Call \ref OutputBuffer::printRight instead.
321+ virtual void printRight (OutputBuffer &) const {}
313322};
314323
315324class NodeArray {
@@ -458,11 +467,11 @@ class QualType final : public Node {
458467 }
459468
460469 void printLeft (OutputBuffer &OB) const override {
461- Child-> printLeft (OB );
470+ OB. printLeft (*Child );
462471 printQuals (OB);
463472 }
464473
465- void printRight (OutputBuffer &OB) const override { Child-> printRight (OB ); }
474+ void printRight (OutputBuffer &OB) const override { OB. printRight (*Child ); }
466475};
467476
468477class ConversionOperatorType final : public Node {
@@ -491,7 +500,7 @@ class PostfixQualifiedType final : public Node {
491500 template <typename Fn> void match (Fn F) const { F (Ty, Postfix); }
492501
493502 void printLeft (OutputBuffer &OB) const override {
494- Ty-> printLeft (OB );
503+ OB. printLeft (*Ty );
495504 OB += Postfix;
496505 }
497506};
@@ -577,7 +586,7 @@ struct AbiTagAttr : Node {
577586 std::string_view getBaseName () const override { return Base->getBaseName (); }
578587
579588 void printLeft (OutputBuffer &OB) const override {
580- Base-> printLeft (OB );
589+ OB. printLeft (*Base );
581590 OB += " [abi:" ;
582591 OB += Tag;
583592 OB += " ]" ;
@@ -644,7 +653,7 @@ class PointerType final : public Node {
644653 // We rewrite objc_object<SomeProtocol>* into id<SomeProtocol>.
645654 if (Pointee->getKind () != KObjCProtoName ||
646655 !static_cast <const ObjCProtoName *>(Pointee)->isObjCObject ()) {
647- Pointee-> printLeft (OB );
656+ OB. printLeft (*Pointee );
648657 if (Pointee->hasArray (OB))
649658 OB += " " ;
650659 if (Pointee->hasArray (OB) || Pointee->hasFunction (OB))
@@ -663,7 +672,7 @@ class PointerType final : public Node {
663672 !static_cast <const ObjCProtoName *>(Pointee)->isObjCObject ()) {
664673 if (Pointee->hasArray (OB) || Pointee->hasFunction (OB))
665674 OB += " )" ;
666- Pointee-> printRight (OB );
675+ OB. printRight (*Pointee );
667676 }
668677 }
669678};
@@ -729,7 +738,7 @@ class ReferenceType : public Node {
729738 std::pair<ReferenceKind, const Node *> Collapsed = collapse (OB);
730739 if (!Collapsed.second )
731740 return ;
732- Collapsed. second -> printLeft (OB );
741+ OB. printLeft (*Collapsed. second );
733742 if (Collapsed.second ->hasArray (OB))
734743 OB += " " ;
735744 if (Collapsed.second ->hasArray (OB) || Collapsed.second ->hasFunction (OB))
@@ -746,7 +755,7 @@ class ReferenceType : public Node {
746755 return ;
747756 if (Collapsed.second ->hasArray (OB) || Collapsed.second ->hasFunction (OB))
748757 OB += " )" ;
749- Collapsed. second -> printRight (OB );
758+ OB. printRight (*Collapsed. second );
750759 }
751760};
752761
@@ -766,7 +775,7 @@ class PointerToMemberType final : public Node {
766775 }
767776
768777 void printLeft (OutputBuffer &OB) const override {
769- MemberType-> printLeft (OB );
778+ OB. printLeft (*MemberType );
770779 if (MemberType->hasArray (OB) || MemberType->hasFunction (OB))
771780 OB += " (" ;
772781 else
@@ -778,7 +787,7 @@ class PointerToMemberType final : public Node {
778787 void printRight (OutputBuffer &OB) const override {
779788 if (MemberType->hasArray (OB) || MemberType->hasFunction (OB))
780789 OB += " )" ;
781- MemberType-> printRight (OB );
790+ OB. printRight (*MemberType );
782791 }
783792};
784793
@@ -798,7 +807,7 @@ class ArrayType final : public Node {
798807 bool hasRHSComponentSlow (OutputBuffer &) const override { return true ; }
799808 bool hasArraySlow (OutputBuffer &) const override { return true ; }
800809
801- void printLeft (OutputBuffer &OB) const override { Base-> printLeft (OB ); }
810+ void printLeft (OutputBuffer &OB) const override { OB. printLeft (*Base ); }
802811
803812 void printRight (OutputBuffer &OB) const override {
804813 if (OB.back () != ' ]' )
@@ -807,7 +816,7 @@ class ArrayType final : public Node {
807816 if (Dimension)
808817 Dimension->print (OB);
809818 OB += " ]" ;
810- Base-> printRight (OB );
819+ OB. printRight (*Base );
811820 }
812821
813822 bool printInitListAsType (OutputBuffer &OB,
@@ -851,15 +860,15 @@ class FunctionType final : public Node {
851860 // by printing out the return types's left, then print our parameters, then
852861 // finally print right of the return type.
853862 void printLeft (OutputBuffer &OB) const override {
854- Ret-> printLeft (OB );
863+ OB. printLeft (*Ret );
855864 OB += " " ;
856865 }
857866
858867 void printRight (OutputBuffer &OB) const override {
859868 OB.printOpen ();
860869 Params.printWithComma (OB);
861870 OB.printClose ();
862- Ret-> printRight (OB );
871+ OB. printRight (*Ret );
863872
864873 if (CVQuals & QualConst)
865874 OB += " const" ;
@@ -964,6 +973,8 @@ class FunctionEncoding final : public Node {
964973 FunctionRefQual getRefQual () const { return RefQual; }
965974 NodeArray getParams () const { return Params; }
966975 const Node *getReturnType () const { return Ret; }
976+ const Node *getAttrs () const { return Attrs; }
977+ const Node *getRequires () const { return Requires; }
967978
968979 bool hasRHSComponentSlow (OutputBuffer &) const override { return true ; }
969980 bool hasFunctionSlow (OutputBuffer &) const override { return true ; }
@@ -972,19 +983,21 @@ class FunctionEncoding final : public Node {
972983
973984 void printLeft (OutputBuffer &OB) const override {
974985 if (Ret) {
975- Ret-> printLeft (OB );
986+ OB. printLeft (*Ret );
976987 if (!Ret->hasRHSComponent (OB))
977988 OB += " " ;
978989 }
990+
979991 Name->print (OB);
980992 }
981993
982994 void printRight (OutputBuffer &OB) const override {
983995 OB.printOpen ();
984996 Params.printWithComma (OB);
985997 OB.printClose ();
998+
986999 if (Ret)
987- Ret-> printRight (OB );
1000+ OB. printRight (*Ret );
9881001
9891002 if (CVQuals & QualConst)
9901003 OB += " const" ;
@@ -1324,14 +1337,14 @@ class NonTypeTemplateParamDecl final : public Node {
13241337 template <typename Fn> void match (Fn F) const { F (Name, Type); }
13251338
13261339 void printLeft (OutputBuffer &OB) const override {
1327- Type-> printLeft (OB );
1340+ OB. printLeft (*Type );
13281341 if (!Type->hasRHSComponent (OB))
13291342 OB += " " ;
13301343 }
13311344
13321345 void printRight (OutputBuffer &OB) const override {
13331346 Name->print (OB);
1334- Type-> printRight (OB );
1347+ OB. printRight (*Type );
13351348 }
13361349};
13371350
@@ -1376,11 +1389,11 @@ class TemplateParamPackDecl final : public Node {
13761389 template <typename Fn> void match (Fn F) const { F (Param); }
13771390
13781391 void printLeft (OutputBuffer &OB) const override {
1379- Param-> printLeft (OB );
1392+ OB. printLeft (*Param );
13801393 OB += " ..." ;
13811394 }
13821395
1383- void printRight (OutputBuffer &OB) const override { Param-> printRight (OB ); }
1396+ void printRight (OutputBuffer &OB) const override { OB. printRight (*Param ); }
13841397};
13851398
13861399// / An unexpanded parameter pack (either in the expression or type context). If
@@ -1445,13 +1458,13 @@ class ParameterPack final : public Node {
14451458 initializePackExpansion (OB);
14461459 size_t Idx = OB.CurrentPackIndex ;
14471460 if (Idx < Data.size ())
1448- Data[Idx]-> printLeft (OB );
1461+ OB. printLeft (* Data[Idx]);
14491462 }
14501463 void printRight (OutputBuffer &OB) const override {
14511464 initializePackExpansion (OB);
14521465 size_t Idx = OB.CurrentPackIndex ;
14531466 if (Idx < Data.size ())
1454- Data[Idx]-> printRight (OB );
1467+ OB. printRight (* Data[Idx]);
14551468 }
14561469};
14571470
@@ -1609,13 +1622,13 @@ struct ForwardTemplateReference : Node {
16091622 if (Printing)
16101623 return ;
16111624 ScopedOverride<bool > SavePrinting (Printing, true );
1612- Ref-> printLeft (OB );
1625+ OB. printLeft (*Ref );
16131626 }
16141627 void printRight (OutputBuffer &OB) const override {
16151628 if (Printing)
16161629 return ;
16171630 ScopedOverride<bool > SavePrinting (Printing, true );
1618- Ref-> printRight (OB );
1631+ OB. printRight (*Ref );
16191632 }
16201633};
16211634
@@ -1767,7 +1780,7 @@ class DtorName : public Node {
17671780
17681781 void printLeft (OutputBuffer &OB) const override {
17691782 OB += " ~" ;
1770- Base-> printLeft (OB );
1783+ OB. printLeft (*Base );
17711784 }
17721785};
17731786
@@ -2047,7 +2060,7 @@ class CastExpr : public Node {
20472060 {
20482061 ScopedOverride<unsigned > LT (OB.GtIsGt , 0 );
20492062 OB += " <" ;
2050- To-> printLeft (OB );
2063+ OB. printLeft (*To );
20512064 OB += " >" ;
20522065 }
20532066 OB.printOpen ();
@@ -6176,6 +6189,10 @@ struct ManglingParser : AbstractManglingParser<ManglingParser<Alloc>, Alloc> {
61766189 Alloc>::AbstractManglingParser;
61776190};
61786191
6192+ inline void OutputBuffer::printLeft (const Node &N) { N.printLeft (*this ); }
6193+
6194+ inline void OutputBuffer::printRight (const Node &N) { N.printRight (*this ); }
6195+
61796196DEMANGLE_NAMESPACE_END
61806197
61816198#if defined(__clang__)
0 commit comments