Index: libcxxabi/src/demangle/ItaniumDemangle.h =================================================================== --- libcxxabi/src/demangle/ItaniumDemangle.h +++ libcxxabi/src/demangle/ItaniumDemangle.h @@ -276,19 +276,19 @@ // would construct an equivalent node. //template void match(Fn F) const; - bool hasRHSComponent(OutputStream &S) const { + bool hasRHSComponent(OutputString &S) const { if (RHSComponentCache != Cache::Unknown) return RHSComponentCache == Cache::Yes; return hasRHSComponentSlow(S); } - bool hasArray(OutputStream &S) const { + bool hasArray(OutputString &S) const { if (ArrayCache != Cache::Unknown) return ArrayCache == Cache::Yes; return hasArraySlow(S); } - bool hasFunction(OutputStream &S) const { + bool hasFunction(OutputString &S) const { if (FunctionCache != Cache::Unknown) return FunctionCache == Cache::Yes; return hasFunctionSlow(S); @@ -296,30 +296,30 @@ Kind getKind() const { return K; } - virtual bool hasRHSComponentSlow(OutputStream &) const { return false; } - virtual bool hasArraySlow(OutputStream &) const { return false; } - virtual bool hasFunctionSlow(OutputStream &) const { return false; } + virtual bool hasRHSComponentSlow(OutputString &) const { return false; } + virtual bool hasArraySlow(OutputString &) const { return false; } + virtual bool hasFunctionSlow(OutputString &) const { return false; } // Dig through "glue" nodes like ParameterPack and ForwardTemplateReference to // get at a node that actually represents some concrete syntax. - virtual const Node *getSyntaxNode(OutputStream &) const { + virtual const Node *getSyntaxNode(OutputString &) const { return this; } - void print(OutputStream &S) const { + void print(OutputString &S) const { printLeft(S); if (RHSComponentCache != Cache::No) printRight(S); } - // Print the "left" side of this Node into OutputStream. - virtual void printLeft(OutputStream &) const = 0; + // Print the "left" side of this Node into OutputString. + virtual void printLeft(OutputString &) const = 0; // Print the "right". This distinction is necessary to represent C++ types // that appear on the RHS of their subtype, such as arrays or functions. // Since most types don't have such a component, provide a default // implementation. - virtual void printRight(OutputStream &) const {} + virtual void printRight(OutputString &) const {} virtual StringView getBaseName() const { return StringView(); } @@ -348,7 +348,7 @@ Node *operator[](size_t Idx) const { return Elements[Idx]; } - void printWithComma(OutputStream &S) const { + void printWithComma(OutputString &S) const { bool FirstElement = true; for (size_t Idx = 0; Idx != NumElements; ++Idx) { size_t BeforeComma = S.getCurrentPosition(); @@ -375,7 +375,7 @@ template void match(Fn F) const { F(Array); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { Array.printWithComma(S); } }; @@ -390,7 +390,7 @@ template void match(Fn F) const { F(Prefix, Suffix); } - void printLeft(OutputStream &s) const override { + void printLeft(OutputString &s) const override { Prefix->print(s); s += " ("; s += Suffix; @@ -409,7 +409,7 @@ template void match(Fn F) const { F(Ty, Ext, TA); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { Ty->print(S); S += " "; S += Ext; @@ -440,7 +440,7 @@ const Qualifiers Quals; const Node *Child; - void printQuals(OutputStream &S) const { + void printQuals(OutputString &S) const { if (Quals & QualConst) S += " const"; if (Quals & QualVolatile) @@ -457,22 +457,22 @@ template void match(Fn F) const { F(Child, Quals); } - bool hasRHSComponentSlow(OutputStream &S) const override { + bool hasRHSComponentSlow(OutputString &S) const override { return Child->hasRHSComponent(S); } - bool hasArraySlow(OutputStream &S) const override { + bool hasArraySlow(OutputString &S) const override { return Child->hasArray(S); } - bool hasFunctionSlow(OutputStream &S) const override { + bool hasFunctionSlow(OutputString &S) const override { return Child->hasFunction(S); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { Child->printLeft(S); printQuals(S); } - void printRight(OutputStream &S) const override { Child->printRight(S); } + void printRight(OutputString &S) const override { Child->printRight(S); } }; class ConversionOperatorType final : public Node { @@ -484,7 +484,7 @@ template void match(Fn F) const { F(Ty); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "operator "; Ty->print(S); } @@ -500,7 +500,7 @@ template void match(Fn F) const { F(Ty, Postfix); } - void printLeft(OutputStream &s) const override { + void printLeft(OutputString &s) const override { Ty->printLeft(s); s += Postfix; } @@ -517,7 +517,7 @@ StringView getName() const { return Name; } StringView getBaseName() const override { return Name; } - void printLeft(OutputStream &s) const override { s += Name; } + void printLeft(OutputString &s) const override { s += Name; } }; class ElaboratedTypeSpefType : public Node { @@ -529,7 +529,7 @@ template void match(Fn F) const { F(Kind, Child); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += Kind; S += ' '; Child->print(S); @@ -547,7 +547,7 @@ template void match(Fn F) const { F(Base, Tag); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { Base->printLeft(S); S += "[abi:"; S += Tag; @@ -563,7 +563,7 @@ template void match(Fn F) const { F(Conditions); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += " [enable_if:"; Conditions.printWithComma(S); S += ']'; @@ -587,7 +587,7 @@ static_cast(Ty)->getName() == "objc_object"; } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { Ty->print(S); S += "<"; S += Protocol; @@ -605,11 +605,11 @@ template void match(Fn F) const { F(Pointee); } - bool hasRHSComponentSlow(OutputStream &S) const override { + bool hasRHSComponentSlow(OutputString &S) const override { return Pointee->hasRHSComponent(S); } - void printLeft(OutputStream &s) const override { + void printLeft(OutputString &s) const override { // We rewrite objc_object* into id. if (Pointee->getKind() != KObjCProtoName || !static_cast(Pointee)->isObjCObject()) { @@ -627,7 +627,7 @@ } } - void printRight(OutputStream &s) const override { + void printRight(OutputString &s) const override { if (Pointee->getKind() != KObjCProtoName || !static_cast(Pointee)->isObjCObject()) { if (Pointee->hasArray(s) || Pointee->hasFunction(s)) @@ -656,7 +656,7 @@ // A combination of a TemplateForwardReference and a back-ref Substitution // from an ill-formed string may have created a cycle; use cycle detection to // avoid looping forever. - std::pair collapse(OutputStream &S) const { + std::pair collapse(OutputString &S) const { auto SoFar = std::make_pair(RK, Pointee); // Track the chain of nodes for the Floyd's 'tortoise and hare' // cycle-detection algorithm, since getSyntaxNode(S) is impure @@ -687,11 +687,11 @@ template void match(Fn F) const { F(Pointee, RK); } - bool hasRHSComponentSlow(OutputStream &S) const override { + bool hasRHSComponentSlow(OutputString &S) const override { return Pointee->hasRHSComponent(S); } - void printLeft(OutputStream &s) const override { + void printLeft(OutputString &s) const override { if (Printing) return; SwapAndRestore SavePrinting(Printing, true); @@ -706,7 +706,7 @@ s += (Collapsed.first == ReferenceKind::LValue ? "&" : "&&"); } - void printRight(OutputStream &s) const override { + void printRight(OutputString &s) const override { if (Printing) return; SwapAndRestore SavePrinting(Printing, true); @@ -730,11 +730,11 @@ template void match(Fn F) const { F(ClassType, MemberType); } - bool hasRHSComponentSlow(OutputStream &S) const override { + bool hasRHSComponentSlow(OutputString &S) const override { return MemberType->hasRHSComponent(S); } - void printLeft(OutputStream &s) const override { + void printLeft(OutputString &s) const override { MemberType->printLeft(s); if (MemberType->hasArray(s) || MemberType->hasFunction(s)) s += "("; @@ -744,7 +744,7 @@ s += "::*"; } - void printRight(OutputStream &s) const override { + void printRight(OutputString &s) const override { if (MemberType->hasArray(s) || MemberType->hasFunction(s)) s += ")"; MemberType->printRight(s); @@ -764,12 +764,12 @@ template void match(Fn F) const { F(Base, Dimension); } - bool hasRHSComponentSlow(OutputStream &) const override { return true; } - bool hasArraySlow(OutputStream &) const override { return true; } + bool hasRHSComponentSlow(OutputString &) const override { return true; } + bool hasArraySlow(OutputString &) const override { return true; } - void printLeft(OutputStream &S) const override { Base->printLeft(S); } + void printLeft(OutputString &S) const override { Base->printLeft(S); } - void printRight(OutputStream &S) const override { + void printRight(OutputString &S) const override { if (S.back() != ']') S += " "; S += "["; @@ -800,8 +800,8 @@ F(Ret, Params, CVQuals, RefQual, ExceptionSpec); } - bool hasRHSComponentSlow(OutputStream &) const override { return true; } - bool hasFunctionSlow(OutputStream &) const override { return true; } + bool hasRHSComponentSlow(OutputString &) const override { return true; } + bool hasFunctionSlow(OutputString &) const override { return true; } // Handle C++'s ... quirky decl grammar by using the left & right // distinction. Consider: @@ -810,12 +810,12 @@ // that takes a char and returns an int. If we're trying to print f, start // by printing out the return types's left, then print our parameters, then // finally print right of the return type. - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { Ret->printLeft(S); S += " "; } - void printRight(OutputStream &S) const override { + void printRight(OutputString &S) const override { S += "("; Params.printWithComma(S); S += ")"; @@ -847,7 +847,7 @@ template void match(Fn F) const { F(E); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "noexcept("; E->print(S); S += ")"; @@ -862,7 +862,7 @@ template void match(Fn F) const { F(Types); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "throw("; Types.printWithComma(S); S += ')'; @@ -896,12 +896,12 @@ NodeArray getParams() const { return Params; } const Node *getReturnType() const { return Ret; } - bool hasRHSComponentSlow(OutputStream &) const override { return true; } - bool hasFunctionSlow(OutputStream &) const override { return true; } + bool hasRHSComponentSlow(OutputString &) const override { return true; } + bool hasFunctionSlow(OutputString &) const override { return true; } const Node *getName() const { return Name; } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { if (Ret) { Ret->printLeft(S); if (!Ret->hasRHSComponent(S)) @@ -910,7 +910,7 @@ Name->print(S); } - void printRight(OutputStream &S) const override { + void printRight(OutputString &S) const override { S += "("; Params.printWithComma(S); S += ")"; @@ -943,7 +943,7 @@ template void match(Fn F) const { F(OpName); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "operator\"\" "; OpName->print(S); } @@ -959,7 +959,7 @@ template void match(Fn F) const { F(Special, Child); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += Special; Child->print(S); } @@ -976,7 +976,7 @@ template void match(Fn F) const { F(FirstType, SecondType); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "construction vtable for "; FirstType->print(S); S += "-in-"; @@ -995,7 +995,7 @@ StringView getBaseName() const override { return Name->getBaseName(); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { Qual->print(S); S += "::"; Name->print(S); @@ -1011,7 +1011,7 @@ template void match(Fn F) const { F(Encoding, Entity); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { Encoding->print(S); S += "::"; Entity->print(S); @@ -1031,7 +1031,7 @@ StringView getBaseName() const override { return Name->getBaseName(); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { Qualifier->print(S); S += "::"; Name->print(S); @@ -1049,7 +1049,7 @@ template void match(Fn F) const { F(BaseType, Dimension); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { BaseType->print(S); S += " vector["; if (Dimension) @@ -1067,7 +1067,7 @@ template void match(Fn F) const { F(Dimension); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { // FIXME: This should demangle as "vector pixel". S += "pixel vector["; Dimension->print(S); @@ -1084,7 +1084,7 @@ template void match(Fn F) const { F(Dimension); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "_Float"; Dimension->print(S); } @@ -1108,7 +1108,7 @@ template void match(Fn F) const { F(Kind, Index); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { switch (Kind) { case TemplateParamKind::Type: S += "$T"; @@ -1135,11 +1135,11 @@ template void match(Fn F) const { F(Name); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "typename "; } - void printRight(OutputStream &S) const override { + void printRight(OutputString &S) const override { Name->print(S); } }; @@ -1155,13 +1155,13 @@ template void match(Fn F) const { F(Name, Type); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { Type->printLeft(S); if (!Type->hasRHSComponent(S)) S += " "; } - void printRight(OutputStream &S) const override { + void printRight(OutputString &S) const override { Name->print(S); Type->printRight(S); } @@ -1180,13 +1180,13 @@ template void match(Fn F) const { F(Name, Params); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "template<"; Params.printWithComma(S); S += "> typename "; } - void printRight(OutputStream &S) const override { + void printRight(OutputString &S) const override { Name->print(S); } }; @@ -1201,12 +1201,12 @@ template void match(Fn F) const { F(Param); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { Param->printLeft(S); S += "..."; } - void printRight(OutputStream &S) const override { + void printRight(OutputString &S) const override { Param->printRight(S); } }; @@ -1222,8 +1222,8 @@ class ParameterPack final : public Node { NodeArray Data; - // Setup OutputStream for a pack expansion unless we're already expanding one. - void initializePackExpansion(OutputStream &S) const { + // Setup OutputString for a pack expansion unless we're already expanding one. + void initializePackExpansion(OutputString &S) const { if (S.CurrentPackMax == std::numeric_limits::max()) { S.CurrentPackMax = static_cast(Data.size()); S.CurrentPackIndex = 0; @@ -1249,34 +1249,34 @@ template void match(Fn F) const { F(Data); } - bool hasRHSComponentSlow(OutputStream &S) const override { + bool hasRHSComponentSlow(OutputString &S) const override { initializePackExpansion(S); size_t Idx = S.CurrentPackIndex; return Idx < Data.size() && Data[Idx]->hasRHSComponent(S); } - bool hasArraySlow(OutputStream &S) const override { + bool hasArraySlow(OutputString &S) const override { initializePackExpansion(S); size_t Idx = S.CurrentPackIndex; return Idx < Data.size() && Data[Idx]->hasArray(S); } - bool hasFunctionSlow(OutputStream &S) const override { + bool hasFunctionSlow(OutputString &S) const override { initializePackExpansion(S); size_t Idx = S.CurrentPackIndex; return Idx < Data.size() && Data[Idx]->hasFunction(S); } - const Node *getSyntaxNode(OutputStream &S) const override { + const Node *getSyntaxNode(OutputString &S) const override { initializePackExpansion(S); size_t Idx = S.CurrentPackIndex; return Idx < Data.size() ? Data[Idx]->getSyntaxNode(S) : this; } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { initializePackExpansion(S); size_t Idx = S.CurrentPackIndex; if (Idx < Data.size()) Data[Idx]->printLeft(S); } - void printRight(OutputStream &S) const override { + void printRight(OutputString &S) const override { initializePackExpansion(S); size_t Idx = S.CurrentPackIndex; if (Idx < Data.size()) @@ -1299,7 +1299,7 @@ NodeArray getElements() const { return Elements; } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { Elements.printWithComma(S); } }; @@ -1317,7 +1317,7 @@ const Node *getChild() const { return Child; } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { constexpr unsigned Max = std::numeric_limits::max(); SwapAndRestore SavePackIdx(S.CurrentPackIndex, Max); SwapAndRestore SavePackMax(S.CurrentPackMax, Max); @@ -1360,7 +1360,7 @@ NodeArray getParams() { return Params; } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "<"; Params.printWithComma(S); if (S.back() == '>') @@ -1407,38 +1407,38 @@ // special handling. template void match(Fn F) const = delete; - bool hasRHSComponentSlow(OutputStream &S) const override { + bool hasRHSComponentSlow(OutputString &S) const override { if (Printing) return false; SwapAndRestore SavePrinting(Printing, true); return Ref->hasRHSComponent(S); } - bool hasArraySlow(OutputStream &S) const override { + bool hasArraySlow(OutputString &S) const override { if (Printing) return false; SwapAndRestore SavePrinting(Printing, true); return Ref->hasArray(S); } - bool hasFunctionSlow(OutputStream &S) const override { + bool hasFunctionSlow(OutputString &S) const override { if (Printing) return false; SwapAndRestore SavePrinting(Printing, true); return Ref->hasFunction(S); } - const Node *getSyntaxNode(OutputStream &S) const override { + const Node *getSyntaxNode(OutputString &S) const override { if (Printing) return this; SwapAndRestore SavePrinting(Printing, true); return Ref->getSyntaxNode(S); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { if (Printing) return; SwapAndRestore SavePrinting(Printing, true); Ref->printLeft(S); } - void printRight(OutputStream &S) const override { + void printRight(OutputString &S) const override { if (Printing) return; SwapAndRestore SavePrinting(Printing, true); @@ -1458,7 +1458,7 @@ StringView getBaseName() const override { return Name->getBaseName(); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { Name->print(S); TemplateArgs->print(S); } @@ -1475,7 +1475,7 @@ StringView getBaseName() const override { return Child->getBaseName(); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "::"; Child->print(S); } @@ -1490,7 +1490,7 @@ StringView getBaseName() const override { return Child->getBaseName(); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "std::"; Child->print(S); } @@ -1532,7 +1532,7 @@ DEMANGLE_UNREACHABLE; } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { switch (SSK) { case SpecialSubKind::allocator: S += "std::allocator"; @@ -1584,7 +1584,7 @@ DEMANGLE_UNREACHABLE; } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { switch (SSK) { case SpecialSubKind::allocator: S += "std::allocator"; @@ -1620,7 +1620,7 @@ template void match(Fn F) const { F(Basename, IsDtor, Variant); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { if (IsDtor) S += "~"; S += Basename->getBaseName(); @@ -1635,7 +1635,7 @@ template void match(Fn F) const { F(Base); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "~"; Base->printLeft(S); } @@ -1649,7 +1649,7 @@ template void match(Fn F) const { F(Count); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "'unnamed"; S += Count; S += "\'"; @@ -1671,7 +1671,7 @@ F(TemplateParams, Params, Count); } - void printDeclarator(OutputStream &S) const { + void printDeclarator(OutputString &S) const { if (!TemplateParams.empty()) { S += "<"; TemplateParams.printWithComma(S); @@ -1682,7 +1682,7 @@ S += ")"; } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "\'lambda"; S += Count; S += "\'"; @@ -1698,7 +1698,7 @@ template void match(Fn F) const { F(Bindings); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += '['; Bindings.printWithComma(S); S += ']'; @@ -1719,7 +1719,7 @@ template void match(Fn F) const { F(LHS, InfixOperator, RHS); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { // might be a template argument expression, then we need to disambiguate // with parens. if (InfixOperator == ">") @@ -1748,7 +1748,7 @@ template void match(Fn F) const { F(Op1, Op2); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "("; Op1->print(S); S += ")["; @@ -1767,7 +1767,7 @@ template void match(Fn F) const { F(Child, Operator); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "("; Child->print(S); S += ")"; @@ -1786,7 +1786,7 @@ template void match(Fn F) const { F(Cond, Then, Else); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "("; Cond->print(S); S += ") ? ("; @@ -1808,7 +1808,7 @@ template void match(Fn F) const { F(LHS, Kind, RHS); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { LHS->print(S); S += Kind; RHS->print(S); @@ -1832,7 +1832,7 @@ F(Type, SubExpr, Offset, UnionSelectors, OnePastTheEnd); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { SubExpr->print(S); S += ".<"; Type->print(S); @@ -1861,7 +1861,7 @@ template void match(Fn F) const { F(Prefix, Infix, Postfix); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += Prefix; Infix->print(S); S += Postfix; @@ -1880,7 +1880,7 @@ template void match(Fn F) const { F(CastKind, To, From); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += CastKind; S += "<"; To->printLeft(S); @@ -1899,7 +1899,7 @@ template void match(Fn F) const { F(Pack); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "sizeof...("; ParameterPackExpansion PPE(Pack); PPE.printLeft(S); @@ -1917,7 +1917,7 @@ template void match(Fn F) const { F(Callee, Args); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { Callee->print(S); S += "("; Args.printWithComma(S); @@ -1942,7 +1942,7 @@ F(ExprList, Type, InitList, IsGlobal, IsArray); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { if (IsGlobal) S += "::operator "; S += "new"; @@ -1975,7 +1975,7 @@ template void match(Fn F) const { F(Op, IsGlobal, IsArray); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { if (IsGlobal) S += "::"; S += "delete"; @@ -1995,7 +1995,7 @@ template void match(Fn F) const { F(Prefix, Child); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += Prefix; S += "("; Child->print(S); @@ -2011,7 +2011,7 @@ template void match(Fn F) const { F(Number); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "fp"; S += Number; } @@ -2027,7 +2027,7 @@ template void match(Fn F) const { F(Type, Expressions); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "("; Type->print(S); S += ")("; @@ -2049,7 +2049,7 @@ template void match(Fn F) const { F(Type, SubExpr, Offset); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "("; Type->print(S); S += ")("; @@ -2067,7 +2067,7 @@ template void match(Fn F) const { F(Ty, Inits); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { if (Ty) Ty->print(S); S += '{'; @@ -2086,7 +2086,7 @@ template void match(Fn F) const { F(Elem, Init, IsArray); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { if (IsArray) { S += '['; Elem->print(S); @@ -2111,7 +2111,7 @@ template void match(Fn F) const { F(First, Last, Init); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += '['; First->print(S); S += " ... "; @@ -2138,7 +2138,7 @@ F(IsLeftFold, OperatorName, Pack, Init); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { auto PrintPack = [&] { S += '('; ParameterPackExpansion(Pack).print(S); @@ -2186,7 +2186,7 @@ template void match(Fn F) const { F(Op); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "throw "; Op->print(S); } @@ -2200,7 +2200,7 @@ template void match(Fn F) const { F(Value); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += Value ? StringView("true") : StringView("false"); } }; @@ -2213,7 +2213,7 @@ template void match(Fn F) const { F(Type); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "\"<"; Type->print(S); S += ">\""; @@ -2228,7 +2228,7 @@ template void match(Fn F) const { F(Type); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "[]"; if (Type->getKind() == KClosureTypeName) static_cast(Type)->printDeclarator(S); @@ -2247,7 +2247,7 @@ template void match(Fn F) const { F(Ty, Integer); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S << "("; Ty->print(S); S << ")"; @@ -2269,7 +2269,7 @@ template void match(Fn F) const { F(Type, Value); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { if (Type.size() > 3) { S += "("; S += Type; @@ -2313,7 +2313,7 @@ template void match(Fn F) const { F(Contents); } - void printLeft(OutputStream &s) const override { + void printLeft(OutputString &s) const override { const char *first = Contents.begin(); const char *last = Contents.end() + 1; Index: libcxxabi/src/demangle/Utility.h =================================================================== --- libcxxabi/src/demangle/Utility.h +++ libcxxabi/src/demangle/Utility.h @@ -24,7 +24,7 @@ // Stream that AST nodes write their string representation into after the AST // has been parsed. -class OutputStream { +class OutputString { char *Buffer = nullptr; size_t CurrentPosition = 0; size_t BufferCapacity = 0; @@ -63,9 +63,9 @@ } public: - OutputStream(char *StartBuf, size_t Size) + OutputString(char *StartBuf, size_t Size) : Buffer(StartBuf), CurrentPosition(0), BufferCapacity(Size) {} - OutputStream() = default; + OutputString() = default; void reset(char *Buffer_, size_t BufferCapacity_) { CurrentPosition = 0; Buffer = Buffer_; @@ -77,7 +77,7 @@ unsigned CurrentPackIndex = std::numeric_limits::max(); unsigned CurrentPackMax = std::numeric_limits::max(); - OutputStream &operator+=(StringView R) { + OutputString &operator+=(StringView R) { size_t Size = R.size(); if (Size == 0) return *this; @@ -87,17 +87,17 @@ return *this; } - OutputStream &operator+=(char C) { + OutputString &operator+=(char C) { grow(1); Buffer[CurrentPosition++] = C; return *this; } - OutputStream &operator<<(StringView R) { return (*this += R); } + OutputString &operator<<(StringView R) { return (*this += R); } - OutputStream &operator<<(char C) { return (*this += C); } + OutputString &operator<<(char C) { return (*this += C); } - OutputStream &operator<<(long long N) { + OutputString &operator<<(long long N) { if (N < 0) writeUnsigned(static_cast(-N), true); else @@ -105,24 +105,24 @@ return *this; } - OutputStream &operator<<(unsigned long long N) { + OutputString &operator<<(unsigned long long N) { writeUnsigned(N, false); return *this; } - OutputStream &operator<<(long N) { + OutputString &operator<<(long N) { return this->operator<<(static_cast(N)); } - OutputStream &operator<<(unsigned long N) { + OutputString &operator<<(unsigned long N) { return this->operator<<(static_cast(N)); } - OutputStream &operator<<(int N) { + OutputString &operator<<(int N) { return this->operator<<(static_cast(N)); } - OutputStream &operator<<(unsigned int N) { + OutputString &operator<<(unsigned int N) { return this->operator<<(static_cast(N)); } @@ -181,7 +181,7 @@ SwapAndRestore &operator=(const SwapAndRestore &) = delete; }; -inline bool initializeOutputStream(char *Buf, size_t *N, OutputStream &S, +inline bool initializeOutputString(char *Buf, size_t *N, OutputString &S, size_t InitSize) { size_t BufferSize; if (Buf == nullptr) { Index: llvm/include/llvm/Demangle/ItaniumDemangle.h =================================================================== --- llvm/include/llvm/Demangle/ItaniumDemangle.h +++ llvm/include/llvm/Demangle/ItaniumDemangle.h @@ -276,19 +276,19 @@ // would construct an equivalent node. //template void match(Fn F) const; - bool hasRHSComponent(OutputStream &S) const { + bool hasRHSComponent(OutputString &S) const { if (RHSComponentCache != Cache::Unknown) return RHSComponentCache == Cache::Yes; return hasRHSComponentSlow(S); } - bool hasArray(OutputStream &S) const { + bool hasArray(OutputString &S) const { if (ArrayCache != Cache::Unknown) return ArrayCache == Cache::Yes; return hasArraySlow(S); } - bool hasFunction(OutputStream &S) const { + bool hasFunction(OutputString &S) const { if (FunctionCache != Cache::Unknown) return FunctionCache == Cache::Yes; return hasFunctionSlow(S); @@ -296,30 +296,30 @@ Kind getKind() const { return K; } - virtual bool hasRHSComponentSlow(OutputStream &) const { return false; } - virtual bool hasArraySlow(OutputStream &) const { return false; } - virtual bool hasFunctionSlow(OutputStream &) const { return false; } + virtual bool hasRHSComponentSlow(OutputString &) const { return false; } + virtual bool hasArraySlow(OutputString &) const { return false; } + virtual bool hasFunctionSlow(OutputString &) const { return false; } // Dig through "glue" nodes like ParameterPack and ForwardTemplateReference to // get at a node that actually represents some concrete syntax. - virtual const Node *getSyntaxNode(OutputStream &) const { + virtual const Node *getSyntaxNode(OutputString &) const { return this; } - void print(OutputStream &S) const { + void print(OutputString &S) const { printLeft(S); if (RHSComponentCache != Cache::No) printRight(S); } - // Print the "left" side of this Node into OutputStream. - virtual void printLeft(OutputStream &) const = 0; + // Print the "left" side of this Node into OutputString. + virtual void printLeft(OutputString &) const = 0; // Print the "right". This distinction is necessary to represent C++ types // that appear on the RHS of their subtype, such as arrays or functions. // Since most types don't have such a component, provide a default // implementation. - virtual void printRight(OutputStream &) const {} + virtual void printRight(OutputString &) const {} virtual StringView getBaseName() const { return StringView(); } @@ -348,7 +348,7 @@ Node *operator[](size_t Idx) const { return Elements[Idx]; } - void printWithComma(OutputStream &S) const { + void printWithComma(OutputString &S) const { bool FirstElement = true; for (size_t Idx = 0; Idx != NumElements; ++Idx) { size_t BeforeComma = S.getCurrentPosition(); @@ -375,7 +375,7 @@ template void match(Fn F) const { F(Array); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { Array.printWithComma(S); } }; @@ -390,7 +390,7 @@ template void match(Fn F) const { F(Prefix, Suffix); } - void printLeft(OutputStream &s) const override { + void printLeft(OutputString &s) const override { Prefix->print(s); s += " ("; s += Suffix; @@ -409,7 +409,7 @@ template void match(Fn F) const { F(Ty, Ext, TA); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { Ty->print(S); S += " "; S += Ext; @@ -440,7 +440,7 @@ const Qualifiers Quals; const Node *Child; - void printQuals(OutputStream &S) const { + void printQuals(OutputString &S) const { if (Quals & QualConst) S += " const"; if (Quals & QualVolatile) @@ -457,22 +457,22 @@ template void match(Fn F) const { F(Child, Quals); } - bool hasRHSComponentSlow(OutputStream &S) const override { + bool hasRHSComponentSlow(OutputString &S) const override { return Child->hasRHSComponent(S); } - bool hasArraySlow(OutputStream &S) const override { + bool hasArraySlow(OutputString &S) const override { return Child->hasArray(S); } - bool hasFunctionSlow(OutputStream &S) const override { + bool hasFunctionSlow(OutputString &S) const override { return Child->hasFunction(S); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { Child->printLeft(S); printQuals(S); } - void printRight(OutputStream &S) const override { Child->printRight(S); } + void printRight(OutputString &S) const override { Child->printRight(S); } }; class ConversionOperatorType final : public Node { @@ -484,7 +484,7 @@ template void match(Fn F) const { F(Ty); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "operator "; Ty->print(S); } @@ -500,7 +500,7 @@ template void match(Fn F) const { F(Ty, Postfix); } - void printLeft(OutputStream &s) const override { + void printLeft(OutputString &s) const override { Ty->printLeft(s); s += Postfix; } @@ -517,7 +517,7 @@ StringView getName() const { return Name; } StringView getBaseName() const override { return Name; } - void printLeft(OutputStream &s) const override { s += Name; } + void printLeft(OutputString &s) const override { s += Name; } }; class ElaboratedTypeSpefType : public Node { @@ -529,7 +529,7 @@ template void match(Fn F) const { F(Kind, Child); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += Kind; S += ' '; Child->print(S); @@ -547,7 +547,7 @@ template void match(Fn F) const { F(Base, Tag); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { Base->printLeft(S); S += "[abi:"; S += Tag; @@ -563,7 +563,7 @@ template void match(Fn F) const { F(Conditions); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += " [enable_if:"; Conditions.printWithComma(S); S += ']'; @@ -587,7 +587,7 @@ static_cast(Ty)->getName() == "objc_object"; } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { Ty->print(S); S += "<"; S += Protocol; @@ -605,11 +605,11 @@ template void match(Fn F) const { F(Pointee); } - bool hasRHSComponentSlow(OutputStream &S) const override { + bool hasRHSComponentSlow(OutputString &S) const override { return Pointee->hasRHSComponent(S); } - void printLeft(OutputStream &s) const override { + void printLeft(OutputString &s) const override { // We rewrite objc_object* into id. if (Pointee->getKind() != KObjCProtoName || !static_cast(Pointee)->isObjCObject()) { @@ -627,7 +627,7 @@ } } - void printRight(OutputStream &s) const override { + void printRight(OutputString &s) const override { if (Pointee->getKind() != KObjCProtoName || !static_cast(Pointee)->isObjCObject()) { if (Pointee->hasArray(s) || Pointee->hasFunction(s)) @@ -656,7 +656,7 @@ // A combination of a TemplateForwardReference and a back-ref Substitution // from an ill-formed string may have created a cycle; use cycle detection to // avoid looping forever. - std::pair collapse(OutputStream &S) const { + std::pair collapse(OutputString &S) const { auto SoFar = std::make_pair(RK, Pointee); // Track the chain of nodes for the Floyd's 'tortoise and hare' // cycle-detection algorithm, since getSyntaxNode(S) is impure @@ -669,7 +669,7 @@ SoFar.second = RT->Pointee; SoFar.first = std::min(SoFar.first, RT->RK); - // The middle of `Prev` is the 'slow' pointer moving at half speed + // The middle of Prev is the 'slow' pointer moving at half speed Prev.push_back(SoFar.second); if (Prev.size() > 1 && SoFar.second == Prev[(Prev.size() - 1) / 2]) { // Cycle detected @@ -687,11 +687,11 @@ template void match(Fn F) const { F(Pointee, RK); } - bool hasRHSComponentSlow(OutputStream &S) const override { + bool hasRHSComponentSlow(OutputString &S) const override { return Pointee->hasRHSComponent(S); } - void printLeft(OutputStream &s) const override { + void printLeft(OutputString &s) const override { if (Printing) return; SwapAndRestore SavePrinting(Printing, true); @@ -706,7 +706,7 @@ s += (Collapsed.first == ReferenceKind::LValue ? "&" : "&&"); } - void printRight(OutputStream &s) const override { + void printRight(OutputString &s) const override { if (Printing) return; SwapAndRestore SavePrinting(Printing, true); @@ -730,11 +730,11 @@ template void match(Fn F) const { F(ClassType, MemberType); } - bool hasRHSComponentSlow(OutputStream &S) const override { + bool hasRHSComponentSlow(OutputString &S) const override { return MemberType->hasRHSComponent(S); } - void printLeft(OutputStream &s) const override { + void printLeft(OutputString &s) const override { MemberType->printLeft(s); if (MemberType->hasArray(s) || MemberType->hasFunction(s)) s += "("; @@ -744,7 +744,7 @@ s += "::*"; } - void printRight(OutputStream &s) const override { + void printRight(OutputString &s) const override { if (MemberType->hasArray(s) || MemberType->hasFunction(s)) s += ")"; MemberType->printRight(s); @@ -764,12 +764,12 @@ template void match(Fn F) const { F(Base, Dimension); } - bool hasRHSComponentSlow(OutputStream &) const override { return true; } - bool hasArraySlow(OutputStream &) const override { return true; } + bool hasRHSComponentSlow(OutputString &) const override { return true; } + bool hasArraySlow(OutputString &) const override { return true; } - void printLeft(OutputStream &S) const override { Base->printLeft(S); } + void printLeft(OutputString &S) const override { Base->printLeft(S); } - void printRight(OutputStream &S) const override { + void printRight(OutputString &S) const override { if (S.back() != ']') S += " "; S += "["; @@ -800,8 +800,8 @@ F(Ret, Params, CVQuals, RefQual, ExceptionSpec); } - bool hasRHSComponentSlow(OutputStream &) const override { return true; } - bool hasFunctionSlow(OutputStream &) const override { return true; } + bool hasRHSComponentSlow(OutputString &) const override { return true; } + bool hasFunctionSlow(OutputString &) const override { return true; } // Handle C++'s ... quirky decl grammar by using the left & right // distinction. Consider: @@ -810,12 +810,12 @@ // that takes a char and returns an int. If we're trying to print f, start // by printing out the return types's left, then print our parameters, then // finally print right of the return type. - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { Ret->printLeft(S); S += " "; } - void printRight(OutputStream &S) const override { + void printRight(OutputString &S) const override { S += "("; Params.printWithComma(S); S += ")"; @@ -847,7 +847,7 @@ template void match(Fn F) const { F(E); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "noexcept("; E->print(S); S += ")"; @@ -862,7 +862,7 @@ template void match(Fn F) const { F(Types); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "throw("; Types.printWithComma(S); S += ')'; @@ -896,12 +896,12 @@ NodeArray getParams() const { return Params; } const Node *getReturnType() const { return Ret; } - bool hasRHSComponentSlow(OutputStream &) const override { return true; } - bool hasFunctionSlow(OutputStream &) const override { return true; } + bool hasRHSComponentSlow(OutputString &) const override { return true; } + bool hasFunctionSlow(OutputString &) const override { return true; } const Node *getName() const { return Name; } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { if (Ret) { Ret->printLeft(S); if (!Ret->hasRHSComponent(S)) @@ -910,7 +910,7 @@ Name->print(S); } - void printRight(OutputStream &S) const override { + void printRight(OutputString &S) const override { S += "("; Params.printWithComma(S); S += ")"; @@ -943,7 +943,7 @@ template void match(Fn F) const { F(OpName); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "operator\"\" "; OpName->print(S); } @@ -959,7 +959,7 @@ template void match(Fn F) const { F(Special, Child); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += Special; Child->print(S); } @@ -976,7 +976,7 @@ template void match(Fn F) const { F(FirstType, SecondType); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "construction vtable for "; FirstType->print(S); S += "-in-"; @@ -995,7 +995,7 @@ StringView getBaseName() const override { return Name->getBaseName(); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { Qual->print(S); S += "::"; Name->print(S); @@ -1011,7 +1011,7 @@ template void match(Fn F) const { F(Encoding, Entity); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { Encoding->print(S); S += "::"; Entity->print(S); @@ -1031,7 +1031,7 @@ StringView getBaseName() const override { return Name->getBaseName(); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { Qualifier->print(S); S += "::"; Name->print(S); @@ -1049,7 +1049,7 @@ template void match(Fn F) const { F(BaseType, Dimension); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { BaseType->print(S); S += " vector["; if (Dimension) @@ -1067,7 +1067,7 @@ template void match(Fn F) const { F(Dimension); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { // FIXME: This should demangle as "vector pixel". S += "pixel vector["; Dimension->print(S); @@ -1084,7 +1084,7 @@ template void match(Fn F) const { F(Dimension); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "_Float"; Dimension->print(S); } @@ -1108,7 +1108,7 @@ template void match(Fn F) const { F(Kind, Index); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { switch (Kind) { case TemplateParamKind::Type: S += "$T"; @@ -1135,11 +1135,11 @@ template void match(Fn F) const { F(Name); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "typename "; } - void printRight(OutputStream &S) const override { + void printRight(OutputString &S) const override { Name->print(S); } }; @@ -1155,13 +1155,13 @@ template void match(Fn F) const { F(Name, Type); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { Type->printLeft(S); if (!Type->hasRHSComponent(S)) S += " "; } - void printRight(OutputStream &S) const override { + void printRight(OutputString &S) const override { Name->print(S); Type->printRight(S); } @@ -1180,13 +1180,13 @@ template void match(Fn F) const { F(Name, Params); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "template<"; Params.printWithComma(S); S += "> typename "; } - void printRight(OutputStream &S) const override { + void printRight(OutputString &S) const override { Name->print(S); } }; @@ -1201,12 +1201,12 @@ template void match(Fn F) const { F(Param); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { Param->printLeft(S); S += "..."; } - void printRight(OutputStream &S) const override { + void printRight(OutputString &S) const override { Param->printRight(S); } }; @@ -1222,8 +1222,8 @@ class ParameterPack final : public Node { NodeArray Data; - // Setup OutputStream for a pack expansion unless we're already expanding one. - void initializePackExpansion(OutputStream &S) const { + // Setup OutputString for a pack expansion unless we're already expanding one. + void initializePackExpansion(OutputString &S) const { if (S.CurrentPackMax == std::numeric_limits::max()) { S.CurrentPackMax = static_cast(Data.size()); S.CurrentPackIndex = 0; @@ -1249,34 +1249,34 @@ template void match(Fn F) const { F(Data); } - bool hasRHSComponentSlow(OutputStream &S) const override { + bool hasRHSComponentSlow(OutputString &S) const override { initializePackExpansion(S); size_t Idx = S.CurrentPackIndex; return Idx < Data.size() && Data[Idx]->hasRHSComponent(S); } - bool hasArraySlow(OutputStream &S) const override { + bool hasArraySlow(OutputString &S) const override { initializePackExpansion(S); size_t Idx = S.CurrentPackIndex; return Idx < Data.size() && Data[Idx]->hasArray(S); } - bool hasFunctionSlow(OutputStream &S) const override { + bool hasFunctionSlow(OutputString &S) const override { initializePackExpansion(S); size_t Idx = S.CurrentPackIndex; return Idx < Data.size() && Data[Idx]->hasFunction(S); } - const Node *getSyntaxNode(OutputStream &S) const override { + const Node *getSyntaxNode(OutputString &S) const override { initializePackExpansion(S); size_t Idx = S.CurrentPackIndex; return Idx < Data.size() ? Data[Idx]->getSyntaxNode(S) : this; } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { initializePackExpansion(S); size_t Idx = S.CurrentPackIndex; if (Idx < Data.size()) Data[Idx]->printLeft(S); } - void printRight(OutputStream &S) const override { + void printRight(OutputString &S) const override { initializePackExpansion(S); size_t Idx = S.CurrentPackIndex; if (Idx < Data.size()) @@ -1299,7 +1299,7 @@ NodeArray getElements() const { return Elements; } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { Elements.printWithComma(S); } }; @@ -1317,7 +1317,7 @@ const Node *getChild() const { return Child; } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { constexpr unsigned Max = std::numeric_limits::max(); SwapAndRestore SavePackIdx(S.CurrentPackIndex, Max); SwapAndRestore SavePackMax(S.CurrentPackMax, Max); @@ -1360,7 +1360,7 @@ NodeArray getParams() { return Params; } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "<"; Params.printWithComma(S); if (S.back() == '>') @@ -1407,38 +1407,38 @@ // special handling. template void match(Fn F) const = delete; - bool hasRHSComponentSlow(OutputStream &S) const override { + bool hasRHSComponentSlow(OutputString &S) const override { if (Printing) return false; SwapAndRestore SavePrinting(Printing, true); return Ref->hasRHSComponent(S); } - bool hasArraySlow(OutputStream &S) const override { + bool hasArraySlow(OutputString &S) const override { if (Printing) return false; SwapAndRestore SavePrinting(Printing, true); return Ref->hasArray(S); } - bool hasFunctionSlow(OutputStream &S) const override { + bool hasFunctionSlow(OutputString &S) const override { if (Printing) return false; SwapAndRestore SavePrinting(Printing, true); return Ref->hasFunction(S); } - const Node *getSyntaxNode(OutputStream &S) const override { + const Node *getSyntaxNode(OutputString &S) const override { if (Printing) return this; SwapAndRestore SavePrinting(Printing, true); return Ref->getSyntaxNode(S); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { if (Printing) return; SwapAndRestore SavePrinting(Printing, true); Ref->printLeft(S); } - void printRight(OutputStream &S) const override { + void printRight(OutputString &S) const override { if (Printing) return; SwapAndRestore SavePrinting(Printing, true); @@ -1458,7 +1458,7 @@ StringView getBaseName() const override { return Name->getBaseName(); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { Name->print(S); TemplateArgs->print(S); } @@ -1475,7 +1475,7 @@ StringView getBaseName() const override { return Child->getBaseName(); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "::"; Child->print(S); } @@ -1490,7 +1490,7 @@ StringView getBaseName() const override { return Child->getBaseName(); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "std::"; Child->print(S); } @@ -1532,7 +1532,7 @@ DEMANGLE_UNREACHABLE; } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { switch (SSK) { case SpecialSubKind::allocator: S += "std::allocator"; @@ -1584,7 +1584,7 @@ DEMANGLE_UNREACHABLE; } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { switch (SSK) { case SpecialSubKind::allocator: S += "std::allocator"; @@ -1620,7 +1620,7 @@ template void match(Fn F) const { F(Basename, IsDtor, Variant); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { if (IsDtor) S += "~"; S += Basename->getBaseName(); @@ -1635,7 +1635,7 @@ template void match(Fn F) const { F(Base); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "~"; Base->printLeft(S); } @@ -1649,7 +1649,7 @@ template void match(Fn F) const { F(Count); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "'unnamed"; S += Count; S += "\'"; @@ -1671,7 +1671,7 @@ F(TemplateParams, Params, Count); } - void printDeclarator(OutputStream &S) const { + void printDeclarator(OutputString &S) const { if (!TemplateParams.empty()) { S += "<"; TemplateParams.printWithComma(S); @@ -1682,7 +1682,7 @@ S += ")"; } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "\'lambda"; S += Count; S += "\'"; @@ -1698,7 +1698,7 @@ template void match(Fn F) const { F(Bindings); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += '['; Bindings.printWithComma(S); S += ']'; @@ -1719,7 +1719,7 @@ template void match(Fn F) const { F(LHS, InfixOperator, RHS); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { // might be a template argument expression, then we need to disambiguate // with parens. if (InfixOperator == ">") @@ -1748,7 +1748,7 @@ template void match(Fn F) const { F(Op1, Op2); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "("; Op1->print(S); S += ")["; @@ -1767,7 +1767,7 @@ template void match(Fn F) const { F(Child, Operator); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "("; Child->print(S); S += ")"; @@ -1786,7 +1786,7 @@ template void match(Fn F) const { F(Cond, Then, Else); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "("; Cond->print(S); S += ") ? ("; @@ -1808,7 +1808,7 @@ template void match(Fn F) const { F(LHS, Kind, RHS); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { LHS->print(S); S += Kind; RHS->print(S); @@ -1832,7 +1832,7 @@ F(Type, SubExpr, Offset, UnionSelectors, OnePastTheEnd); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { SubExpr->print(S); S += ".<"; Type->print(S); @@ -1861,7 +1861,7 @@ template void match(Fn F) const { F(Prefix, Infix, Postfix); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += Prefix; Infix->print(S); S += Postfix; @@ -1880,7 +1880,7 @@ template void match(Fn F) const { F(CastKind, To, From); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += CastKind; S += "<"; To->printLeft(S); @@ -1899,7 +1899,7 @@ template void match(Fn F) const { F(Pack); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "sizeof...("; ParameterPackExpansion PPE(Pack); PPE.printLeft(S); @@ -1917,7 +1917,7 @@ template void match(Fn F) const { F(Callee, Args); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { Callee->print(S); S += "("; Args.printWithComma(S); @@ -1942,7 +1942,7 @@ F(ExprList, Type, InitList, IsGlobal, IsArray); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { if (IsGlobal) S += "::operator "; S += "new"; @@ -1975,7 +1975,7 @@ template void match(Fn F) const { F(Op, IsGlobal, IsArray); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { if (IsGlobal) S += "::"; S += "delete"; @@ -1995,7 +1995,7 @@ template void match(Fn F) const { F(Prefix, Child); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += Prefix; S += "("; Child->print(S); @@ -2011,7 +2011,7 @@ template void match(Fn F) const { F(Number); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "fp"; S += Number; } @@ -2027,7 +2027,7 @@ template void match(Fn F) const { F(Type, Expressions); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "("; Type->print(S); S += ")("; @@ -2049,7 +2049,7 @@ template void match(Fn F) const { F(Type, SubExpr, Offset); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "("; Type->print(S); S += ")("; @@ -2067,7 +2067,7 @@ template void match(Fn F) const { F(Ty, Inits); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { if (Ty) Ty->print(S); S += '{'; @@ -2086,7 +2086,7 @@ template void match(Fn F) const { F(Elem, Init, IsArray); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { if (IsArray) { S += '['; Elem->print(S); @@ -2111,7 +2111,7 @@ template void match(Fn F) const { F(First, Last, Init); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += '['; First->print(S); S += " ... "; @@ -2138,7 +2138,7 @@ F(IsLeftFold, OperatorName, Pack, Init); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { auto PrintPack = [&] { S += '('; ParameterPackExpansion(Pack).print(S); @@ -2186,7 +2186,7 @@ template void match(Fn F) const { F(Op); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "throw "; Op->print(S); } @@ -2200,7 +2200,7 @@ template void match(Fn F) const { F(Value); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += Value ? StringView("true") : StringView("false"); } }; @@ -2213,7 +2213,7 @@ template void match(Fn F) const { F(Type); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "\"<"; Type->print(S); S += ">\""; @@ -2228,7 +2228,7 @@ template void match(Fn F) const { F(Type); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S += "[]"; if (Type->getKind() == KClosureTypeName) static_cast(Type)->printDeclarator(S); @@ -2247,7 +2247,7 @@ template void match(Fn F) const { F(Ty, Integer); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { S << "("; Ty->print(S); S << ")"; @@ -2269,7 +2269,7 @@ template void match(Fn F) const { F(Type, Value); } - void printLeft(OutputStream &S) const override { + void printLeft(OutputString &S) const override { if (Type.size() > 3) { S += "("; S += Type; @@ -2313,7 +2313,7 @@ template void match(Fn F) const { F(Contents); } - void printLeft(OutputStream &s) const override { + void printLeft(OutputString &s) const override { const char *first = Contents.begin(); const char *last = Contents.end() + 1; Index: llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h =================================================================== --- llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h +++ llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h @@ -21,11 +21,11 @@ namespace llvm { namespace itanium_demangle { -class OutputStream; +class OutputString; } } -using llvm::itanium_demangle::OutputStream; +using llvm::itanium_demangle::OutputString; using llvm::itanium_demangle::StringView; namespace llvm { @@ -261,7 +261,7 @@ NodeKind kind() const { return Kind; } - virtual void output(OutputStream &OS, OutputFlags Flags) const = 0; + virtual void output(OutputString &OS, OutputFlags Flags) const = 0; std::string toString(OutputFlags Flags = OF_Default) const; @@ -300,10 +300,10 @@ struct TypeNode : public Node { explicit TypeNode(NodeKind K) : Node(K) {} - virtual void outputPre(OutputStream &OS, OutputFlags Flags) const = 0; - virtual void outputPost(OutputStream &OS, OutputFlags Flags) const = 0; + virtual void outputPre(OutputString &OS, OutputFlags Flags) const = 0; + virtual void outputPost(OutputString &OS, OutputFlags Flags) const = 0; - void output(OutputStream &OS, OutputFlags Flags) const override { + void output(OutputString &OS, OutputFlags Flags) const override { outputPre(OS, Flags); outputPost(OS, Flags); } @@ -315,8 +315,8 @@ explicit PrimitiveTypeNode(PrimitiveKind K) : TypeNode(NodeKind::PrimitiveType), PrimKind(K) {} - void outputPre(OutputStream &OS, OutputFlags Flags) const override; - void outputPost(OutputStream &OS, OutputFlags Flags) const override {} + void outputPre(OutputString &OS, OutputFlags Flags) const override; + void outputPost(OutputString &OS, OutputFlags Flags) const override {} PrimitiveKind PrimKind; }; @@ -325,8 +325,8 @@ explicit FunctionSignatureNode(NodeKind K) : TypeNode(K) {} FunctionSignatureNode() : TypeNode(NodeKind::FunctionSignature) {} - void outputPre(OutputStream &OS, OutputFlags Flags) const override; - void outputPost(OutputStream &OS, OutputFlags Flags) const override; + void outputPre(OutputString &OS, OutputFlags Flags) const override; + void outputPost(OutputString &OS, OutputFlags Flags) const override; // Valid if this FunctionTypeNode is the Pointee of a PointerType or // MemberPointerType. @@ -359,13 +359,13 @@ NodeArrayNode *TemplateParams = nullptr; protected: - void outputTemplateParameters(OutputStream &OS, OutputFlags Flags) const; + void outputTemplateParameters(OutputString &OS, OutputFlags Flags) const; }; struct VcallThunkIdentifierNode : public IdentifierNode { VcallThunkIdentifierNode() : IdentifierNode(NodeKind::VcallThunkIdentifier) {} - void output(OutputStream &OS, OutputFlags Flags) const override; + void output(OutputString &OS, OutputFlags Flags) const override; uint64_t OffsetInVTable = 0; }; @@ -374,7 +374,7 @@ DynamicStructorIdentifierNode() : IdentifierNode(NodeKind::DynamicStructorIdentifier) {} - void output(OutputStream &OS, OutputFlags Flags) const override; + void output(OutputString &OS, OutputFlags Flags) const override; VariableSymbolNode *Variable = nullptr; QualifiedNameNode *Name = nullptr; @@ -384,7 +384,7 @@ struct NamedIdentifierNode : public IdentifierNode { NamedIdentifierNode() : IdentifierNode(NodeKind::NamedIdentifier) {} - void output(OutputStream &OS, OutputFlags Flags) const override; + void output(OutputString &OS, OutputFlags Flags) const override; StringView Name; }; @@ -394,7 +394,7 @@ : IdentifierNode(NodeKind::IntrinsicFunctionIdentifier), Operator(Operator) {} - void output(OutputStream &OS, OutputFlags Flags) const override; + void output(OutputString &OS, OutputFlags Flags) const override; IntrinsicFunctionKind Operator; }; @@ -403,7 +403,7 @@ LiteralOperatorIdentifierNode() : IdentifierNode(NodeKind::LiteralOperatorIdentifier) {} - void output(OutputStream &OS, OutputFlags Flags) const override; + void output(OutputString &OS, OutputFlags Flags) const override; StringView Name; }; @@ -412,7 +412,7 @@ LocalStaticGuardIdentifierNode() : IdentifierNode(NodeKind::LocalStaticGuardIdentifier) {} - void output(OutputStream &OS, OutputFlags Flags) const override; + void output(OutputString &OS, OutputFlags Flags) const override; bool IsThread = false; uint32_t ScopeIndex = 0; @@ -422,7 +422,7 @@ ConversionOperatorIdentifierNode() : IdentifierNode(NodeKind::ConversionOperatorIdentifier) {} - void output(OutputStream &OS, OutputFlags Flags) const override; + void output(OutputString &OS, OutputFlags Flags) const override; // The type that this operator converts too. TypeNode *TargetType = nullptr; @@ -434,7 +434,7 @@ : IdentifierNode(NodeKind::StructorIdentifier), IsDestructor(IsDestructor) {} - void output(OutputStream &OS, OutputFlags Flags) const override; + void output(OutputString &OS, OutputFlags Flags) const override; // The name of the class that this is a structor of. IdentifierNode *Class = nullptr; @@ -444,8 +444,8 @@ struct ThunkSignatureNode : public FunctionSignatureNode { ThunkSignatureNode() : FunctionSignatureNode(NodeKind::ThunkSignature) {} - void outputPre(OutputStream &OS, OutputFlags Flags) const override; - void outputPost(OutputStream &OS, OutputFlags Flags) const override; + void outputPre(OutputString &OS, OutputFlags Flags) const override; + void outputPost(OutputString &OS, OutputFlags Flags) const override; struct ThisAdjustor { uint32_t StaticOffset = 0; @@ -459,8 +459,8 @@ struct PointerTypeNode : public TypeNode { PointerTypeNode() : TypeNode(NodeKind::PointerType) {} - void outputPre(OutputStream &OS, OutputFlags Flags) const override; - void outputPost(OutputStream &OS, OutputFlags Flags) const override; + void outputPre(OutputString &OS, OutputFlags Flags) const override; + void outputPost(OutputString &OS, OutputFlags Flags) const override; // Is this a pointer, reference, or rvalue-reference? PointerAffinity Affinity = PointerAffinity::None; @@ -476,8 +476,8 @@ struct TagTypeNode : public TypeNode { explicit TagTypeNode(TagKind Tag) : TypeNode(NodeKind::TagType), Tag(Tag) {} - void outputPre(OutputStream &OS, OutputFlags Flags) const override; - void outputPost(OutputStream &OS, OutputFlags Flags) const override; + void outputPre(OutputString &OS, OutputFlags Flags) const override; + void outputPost(OutputString &OS, OutputFlags Flags) const override; QualifiedNameNode *QualifiedName = nullptr; TagKind Tag; @@ -486,11 +486,11 @@ struct ArrayTypeNode : public TypeNode { ArrayTypeNode() : TypeNode(NodeKind::ArrayType) {} - void outputPre(OutputStream &OS, OutputFlags Flags) const override; - void outputPost(OutputStream &OS, OutputFlags Flags) const override; + void outputPre(OutputString &OS, OutputFlags Flags) const override; + void outputPost(OutputString &OS, OutputFlags Flags) const override; - void outputDimensionsImpl(OutputStream &OS, OutputFlags Flags) const; - void outputOneDimension(OutputStream &OS, OutputFlags Flags, Node *N) const; + void outputDimensionsImpl(OutputString &OS, OutputFlags Flags) const; + void outputOneDimension(OutputString &OS, OutputFlags Flags, Node *N) const; // A list of array dimensions. e.g. [3,4,5] in `int Foo[3][4][5]` NodeArrayNode *Dimensions = nullptr; @@ -501,14 +501,14 @@ struct IntrinsicNode : public TypeNode { IntrinsicNode() : TypeNode(NodeKind::IntrinsicType) {} - void output(OutputStream &OS, OutputFlags Flags) const override {} + void output(OutputString &OS, OutputFlags Flags) const override {} }; struct CustomTypeNode : public TypeNode { CustomTypeNode() : TypeNode(NodeKind::Custom) {} - void outputPre(OutputStream &OS, OutputFlags Flags) const override; - void outputPost(OutputStream &OS, OutputFlags Flags) const override; + void outputPre(OutputString &OS, OutputFlags Flags) const override; + void outputPost(OutputString &OS, OutputFlags Flags) const override; IdentifierNode *Identifier = nullptr; }; @@ -516,9 +516,9 @@ struct NodeArrayNode : public Node { NodeArrayNode() : Node(NodeKind::NodeArray) {} - void output(OutputStream &OS, OutputFlags Flags) const override; + void output(OutputString &OS, OutputFlags Flags) const override; - void output(OutputStream &OS, OutputFlags Flags, StringView Separator) const; + void output(OutputString &OS, OutputFlags Flags, StringView Separator) const; Node **Nodes = nullptr; size_t Count = 0; @@ -527,7 +527,7 @@ struct QualifiedNameNode : public Node { QualifiedNameNode() : Node(NodeKind::QualifiedName) {} - void output(OutputStream &OS, OutputFlags Flags) const override; + void output(OutputString &OS, OutputFlags Flags) const override; NodeArrayNode *Components = nullptr; @@ -541,7 +541,7 @@ TemplateParameterReferenceNode() : Node(NodeKind::TemplateParameterReference) {} - void output(OutputStream &OS, OutputFlags Flags) const override; + void output(OutputString &OS, OutputFlags Flags) const override; SymbolNode *Symbol = nullptr; @@ -556,7 +556,7 @@ IntegerLiteralNode(uint64_t Value, bool IsNegative) : Node(NodeKind::IntegerLiteral), Value(Value), IsNegative(IsNegative) {} - void output(OutputStream &OS, OutputFlags Flags) const override; + void output(OutputString &OS, OutputFlags Flags) const override; uint64_t Value = 0; bool IsNegative = false; @@ -566,7 +566,7 @@ RttiBaseClassDescriptorNode() : IdentifierNode(NodeKind::RttiBaseClassDescriptor) {} - void output(OutputStream &OS, OutputFlags Flags) const override; + void output(OutputString &OS, OutputFlags Flags) const override; uint32_t NVOffset = 0; int32_t VBPtrOffset = 0; @@ -576,7 +576,7 @@ struct SymbolNode : public Node { explicit SymbolNode(NodeKind K) : Node(K) {} - void output(OutputStream &OS, OutputFlags Flags) const override; + void output(OutputString &OS, OutputFlags Flags) const override; QualifiedNameNode *Name = nullptr; }; @@ -584,7 +584,7 @@ explicit SpecialTableSymbolNode() : SymbolNode(NodeKind::SpecialTableSymbol) {} - void output(OutputStream &OS, OutputFlags Flags) const override; + void output(OutputString &OS, OutputFlags Flags) const override; QualifiedNameNode *TargetName = nullptr; Qualifiers Quals = Qualifiers::Q_None; }; @@ -593,7 +593,7 @@ LocalStaticGuardVariableNode() : SymbolNode(NodeKind::LocalStaticGuardVariable) {} - void output(OutputStream &OS, OutputFlags Flags) const override; + void output(OutputString &OS, OutputFlags Flags) const override; bool IsVisible = false; }; @@ -601,7 +601,7 @@ struct EncodedStringLiteralNode : public SymbolNode { EncodedStringLiteralNode() : SymbolNode(NodeKind::EncodedStringLiteral) {} - void output(OutputStream &OS, OutputFlags Flags) const override; + void output(OutputString &OS, OutputFlags Flags) const override; StringView DecodedString; bool IsTruncated = false; @@ -611,7 +611,7 @@ struct VariableSymbolNode : public SymbolNode { VariableSymbolNode() : SymbolNode(NodeKind::VariableSymbol) {} - void output(OutputStream &OS, OutputFlags Flags) const override; + void output(OutputString &OS, OutputFlags Flags) const override; StorageClass SC = StorageClass::None; TypeNode *Type = nullptr; @@ -620,7 +620,7 @@ struct FunctionSymbolNode : public SymbolNode { FunctionSymbolNode() : SymbolNode(NodeKind::FunctionSymbol) {} - void output(OutputStream &OS, OutputFlags Flags) const override; + void output(OutputString &OS, OutputFlags Flags) const override; FunctionSignatureNode *Signature = nullptr; }; Index: llvm/include/llvm/Demangle/Utility.h =================================================================== --- llvm/include/llvm/Demangle/Utility.h +++ llvm/include/llvm/Demangle/Utility.h @@ -24,7 +24,7 @@ // Stream that AST nodes write their string representation into after the AST // has been parsed. -class OutputStream { +class OutputString { char *Buffer = nullptr; size_t CurrentPosition = 0; size_t BufferCapacity = 0; @@ -63,9 +63,9 @@ } public: - OutputStream(char *StartBuf, size_t Size) + OutputString(char *StartBuf, size_t Size) : Buffer(StartBuf), CurrentPosition(0), BufferCapacity(Size) {} - OutputStream() = default; + OutputString() = default; void reset(char *Buffer_, size_t BufferCapacity_) { CurrentPosition = 0; Buffer = Buffer_; @@ -77,7 +77,7 @@ unsigned CurrentPackIndex = std::numeric_limits::max(); unsigned CurrentPackMax = std::numeric_limits::max(); - OutputStream &operator+=(StringView R) { + OutputString &operator+=(StringView R) { size_t Size = R.size(); if (Size == 0) return *this; @@ -87,17 +87,17 @@ return *this; } - OutputStream &operator+=(char C) { + OutputString &operator+=(char C) { grow(1); Buffer[CurrentPosition++] = C; return *this; } - OutputStream &operator<<(StringView R) { return (*this += R); } + OutputString &operator<<(StringView R) { return (*this += R); } - OutputStream &operator<<(char C) { return (*this += C); } + OutputString &operator<<(char C) { return (*this += C); } - OutputStream &operator<<(long long N) { + OutputString &operator<<(long long N) { if (N < 0) writeUnsigned(static_cast(-N), true); else @@ -105,24 +105,24 @@ return *this; } - OutputStream &operator<<(unsigned long long N) { + OutputString &operator<<(unsigned long long N) { writeUnsigned(N, false); return *this; } - OutputStream &operator<<(long N) { + OutputString &operator<<(long N) { return this->operator<<(static_cast(N)); } - OutputStream &operator<<(unsigned long N) { + OutputString &operator<<(unsigned long N) { return this->operator<<(static_cast(N)); } - OutputStream &operator<<(int N) { + OutputString &operator<<(int N) { return this->operator<<(static_cast(N)); } - OutputStream &operator<<(unsigned int N) { + OutputString &operator<<(unsigned int N) { return this->operator<<(static_cast(N)); } @@ -181,7 +181,7 @@ SwapAndRestore &operator=(const SwapAndRestore &) = delete; }; -inline bool initializeOutputStream(char *Buf, size_t *N, OutputStream &S, +inline bool initializeOutputString(char *Buf, size_t *N, OutputString &S, size_t InitSize) { size_t BufferSize; if (Buf == nullptr) { Index: llvm/lib/Demangle/ItaniumDemangle.cpp =================================================================== --- llvm/lib/Demangle/ItaniumDemangle.cpp +++ llvm/lib/Demangle/ItaniumDemangle.cpp @@ -333,13 +333,13 @@ int InternalStatus = demangle_success; Demangler Parser(MangledName, MangledName + std::strlen(MangledName)); - OutputStream S; + OutputString S; Node *AST = Parser.parse(); if (AST == nullptr) InternalStatus = demangle_invalid_mangled_name; - else if (!initializeOutputStream(Buf, N, S, 1024)) + else if (!initializeOutputString(Buf, N, S, 1024)) InternalStatus = demangle_memory_alloc_failure; else { assert(Parser.ForwardTemplateRefs.empty()); @@ -385,8 +385,8 @@ } static char *printNode(const Node *RootNode, char *Buf, size_t *N) { - OutputStream S; - if (!initializeOutputStream(Buf, N, S, 128)) + OutputString S; + if (!initializeOutputString(Buf, N, S, 128)) return nullptr; RootNode->print(S); S += '\0'; @@ -430,8 +430,8 @@ return nullptr; const Node *Name = static_cast(RootNode)->getName(); - OutputStream S; - if (!initializeOutputStream(Buf, N, S, 128)) + OutputString S; + if (!initializeOutputString(Buf, N, S, 128)) return nullptr; KeepGoingLocalFunction: @@ -483,8 +483,8 @@ return nullptr; NodeArray Params = static_cast(RootNode)->getParams(); - OutputStream S; - if (!initializeOutputStream(Buf, N, S, 128)) + OutputString S; + if (!initializeOutputString(Buf, N, S, 128)) return nullptr; S += '('; @@ -501,8 +501,8 @@ if (!isFunction()) return nullptr; - OutputStream S; - if (!initializeOutputStream(Buf, N, S, 128)) + OutputString S; + if (!initializeOutputString(Buf, N, S, 128)) return nullptr; if (const Node *Ret = Index: llvm/lib/Demangle/MicrosoftDemangle.cpp =================================================================== --- llvm/lib/Demangle/MicrosoftDemangle.cpp +++ llvm/lib/Demangle/MicrosoftDemangle.cpp @@ -965,8 +965,8 @@ void Demangler::memorizeIdentifier(IdentifierNode *Identifier) { // Render this class template name into a string buffer so that we can // memorize it for the purpose of back-referencing. - OutputStream OS; - if (!initializeOutputStream(nullptr, nullptr, OS, 1024)) + OutputString OS; + if (!initializeOutputString(nullptr, nullptr, OS, 1024)) // FIXME: Propagate out-of-memory as an error? std::terminate(); Identifier->output(OS, OF_Default); @@ -1107,7 +1107,7 @@ *Buffer = (Digit < 10) ? ('0' + Digit) : ('A' + Digit - 10); } -static void outputHex(OutputStream &OS, unsigned C) { +static void outputHex(OutputString &OS, unsigned C) { assert (C != 0); // It's easier to do the math if we can work from right to left, but we need @@ -1133,7 +1133,7 @@ OS << StringView(&TempBuffer[Pos + 1]); } -static void outputEscapedChar(OutputStream &OS, unsigned C) { +static void outputEscapedChar(OutputString &OS, unsigned C) { switch (C) { case '\0': // nul OS << "\\0"; @@ -1273,7 +1273,7 @@ EncodedStringLiteralNode * Demangler::demangleStringLiteral(StringView &MangledName) { // This function uses goto, so declare all variables up front. - OutputStream OS; + OutputString OS; StringView CRC; uint64_t StringByteSize; bool IsWcharT = false; @@ -1284,7 +1284,7 @@ EncodedStringLiteralNode *Result = Arena.alloc(); // Must happen before the first `goto StringLiteralError`. - if (!initializeOutputStream(nullptr, nullptr, OS, 1024)) + if (!initializeOutputString(nullptr, nullptr, OS, 1024)) // FIXME: Propagate out-of-memory as an error? std::terminate(); @@ -1447,8 +1447,8 @@ return nullptr; // Render the parent symbol's name into a buffer. - OutputStream OS; - if (!initializeOutputStream(nullptr, nullptr, OS, 1024)) + OutputString OS; + if (!initializeOutputString(nullptr, nullptr, OS, 1024)) // FIXME: Propagate out-of-memory as an error? std::terminate(); OS << '`'; @@ -2313,8 +2313,8 @@ (int)Backrefs.FunctionParamCount); // Create an output stream so we can render each type. - OutputStream OS; - if (!initializeOutputStream(nullptr, nullptr, OS, 1024)) + OutputString OS; + if (!initializeOutputString(nullptr, nullptr, OS, 1024)) std::terminate(); for (size_t I = 0; I < Backrefs.FunctionParamCount; ++I) { OS.setCurrentPosition(0); @@ -2342,7 +2342,7 @@ char *Buf, size_t *N, int *Status, MSDemangleFlags Flags) { Demangler D; - OutputStream S; + OutputString S; StringView Name{MangledName}; SymbolNode *AST = D.parse(Name); @@ -2365,7 +2365,7 @@ int InternalStatus = demangle_success; if (D.Error) InternalStatus = demangle_invalid_mangled_name; - else if (!initializeOutputStream(Buf, N, S, 1024)) + else if (!initializeOutputString(Buf, N, S, 1024)) InternalStatus = demangle_memory_alloc_failure; else { AST->output(S, OF); Index: llvm/lib/Demangle/MicrosoftDemangleNodes.cpp =================================================================== --- llvm/lib/Demangle/MicrosoftDemangleNodes.cpp +++ llvm/lib/Demangle/MicrosoftDemangleNodes.cpp @@ -25,7 +25,7 @@ break; // Writes a space if the last token does not end with a punctuation. -static void outputSpaceIfNecessary(OutputStream &OS) { +static void outputSpaceIfNecessary(OutputString &OS) { if (OS.empty()) return; @@ -34,7 +34,7 @@ OS << " "; } -static void outputSingleQualifier(OutputStream &OS, Qualifiers Q) { +static void outputSingleQualifier(OutputString &OS, Qualifiers Q) { switch (Q) { case Q_Const: OS << "const"; @@ -50,7 +50,7 @@ } } -static bool outputQualifierIfPresent(OutputStream &OS, Qualifiers Q, +static bool outputQualifierIfPresent(OutputString &OS, Qualifiers Q, Qualifiers Mask, bool NeedSpace) { if (!(Q & Mask)) return NeedSpace; @@ -62,7 +62,7 @@ return true; } -static void outputQualifiers(OutputStream &OS, Qualifiers Q, bool SpaceBefore, +static void outputQualifiers(OutputString &OS, Qualifiers Q, bool SpaceBefore, bool SpaceAfter) { if (Q == Q_None) return; @@ -76,7 +76,7 @@ OS << " "; } -static void outputCallingConvention(OutputStream &OS, CallingConv CC) { +static void outputCallingConvention(OutputString &OS, CallingConv CC) { outputSpaceIfNecessary(OS); switch (CC) { @@ -119,8 +119,8 @@ } std::string Node::toString(OutputFlags Flags) const { - OutputStream OS; - initializeOutputStream(nullptr, nullptr, OS, 1024); + OutputString OS; + initializeOutputString(nullptr, nullptr, OS, 1024); this->output(OS, Flags); OS << '\0'; std::string Owned(OS.getBuffer()); @@ -128,7 +128,7 @@ return Owned; } -void PrimitiveTypeNode::outputPre(OutputStream &OS, OutputFlags Flags) const { +void PrimitiveTypeNode::outputPre(OutputString &OS, OutputFlags Flags) const { switch (PrimKind) { OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Void, "void"); OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Bool, "bool"); @@ -155,11 +155,11 @@ outputQualifiers(OS, Quals, true, false); } -void NodeArrayNode::output(OutputStream &OS, OutputFlags Flags) const { +void NodeArrayNode::output(OutputString &OS, OutputFlags Flags) const { output(OS, Flags, ", "); } -void NodeArrayNode::output(OutputStream &OS, OutputFlags Flags, +void NodeArrayNode::output(OutputString &OS, OutputFlags Flags, StringView Separator) const { if (Count == 0) return; @@ -171,7 +171,7 @@ } } -void EncodedStringLiteralNode::output(OutputStream &OS, +void EncodedStringLiteralNode::output(OutputString &OS, OutputFlags Flags) const { switch (Char) { case CharKind::Wchar: @@ -192,13 +192,13 @@ OS << "..."; } -void IntegerLiteralNode::output(OutputStream &OS, OutputFlags Flags) const { +void IntegerLiteralNode::output(OutputString &OS, OutputFlags Flags) const { if (IsNegative) OS << '-'; OS << Value; } -void TemplateParameterReferenceNode::output(OutputStream &OS, +void TemplateParameterReferenceNode::output(OutputString &OS, OutputFlags Flags) const { if (ThunkOffsetCount > 0) OS << "{"; @@ -220,7 +220,7 @@ OS << "}"; } -void IdentifierNode::outputTemplateParameters(OutputStream &OS, +void IdentifierNode::outputTemplateParameters(OutputString &OS, OutputFlags Flags) const { if (!TemplateParams) return; @@ -229,7 +229,7 @@ OS << ">"; } -void DynamicStructorIdentifierNode::output(OutputStream &OS, +void DynamicStructorIdentifierNode::output(OutputString &OS, OutputFlags Flags) const { if (IsDestructor) OS << "`dynamic atexit destructor for "; @@ -247,12 +247,12 @@ } } -void NamedIdentifierNode::output(OutputStream &OS, OutputFlags Flags) const { +void NamedIdentifierNode::output(OutputString &OS, OutputFlags Flags) const { OS << Name; outputTemplateParameters(OS, Flags); } -void IntrinsicFunctionIdentifierNode::output(OutputStream &OS, +void IntrinsicFunctionIdentifierNode::output(OutputString &OS, OutputFlags Flags) const { switch (Operator) { OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, New, "operator new"); @@ -353,7 +353,7 @@ outputTemplateParameters(OS, Flags); } -void LocalStaticGuardIdentifierNode::output(OutputStream &OS, +void LocalStaticGuardIdentifierNode::output(OutputString &OS, OutputFlags Flags) const { if (IsThread) OS << "`local static thread guard'"; @@ -363,7 +363,7 @@ OS << "{" << ScopeIndex << "}"; } -void ConversionOperatorIdentifierNode::output(OutputStream &OS, +void ConversionOperatorIdentifierNode::output(OutputString &OS, OutputFlags Flags) const { OS << "operator"; outputTemplateParameters(OS, Flags); @@ -371,20 +371,20 @@ TargetType->output(OS, Flags); } -void StructorIdentifierNode::output(OutputStream &OS, OutputFlags Flags) const { +void StructorIdentifierNode::output(OutputString &OS, OutputFlags Flags) const { if (IsDestructor) OS << "~"; Class->output(OS, Flags); outputTemplateParameters(OS, Flags); } -void LiteralOperatorIdentifierNode::output(OutputStream &OS, +void LiteralOperatorIdentifierNode::output(OutputString &OS, OutputFlags Flags) const { OS << "operator \"\"" << Name; outputTemplateParameters(OS, Flags); } -void FunctionSignatureNode::outputPre(OutputStream &OS, +void FunctionSignatureNode::outputPre(OutputString &OS, OutputFlags Flags) const { if (!(Flags & OF_NoAccessSpecifier)) { if (FunctionClass & FC_Public) @@ -416,7 +416,7 @@ outputCallingConvention(OS, CallConvention); } -void FunctionSignatureNode::outputPost(OutputStream &OS, +void FunctionSignatureNode::outputPost(OutputString &OS, OutputFlags Flags) const { if (!(FunctionClass & FC_NoParameterList)) { OS << "("; @@ -454,13 +454,13 @@ ReturnType->outputPost(OS, Flags); } -void ThunkSignatureNode::outputPre(OutputStream &OS, OutputFlags Flags) const { +void ThunkSignatureNode::outputPre(OutputString &OS, OutputFlags Flags) const { OS << "[thunk]: "; FunctionSignatureNode::outputPre(OS, Flags); } -void ThunkSignatureNode::outputPost(OutputStream &OS, OutputFlags Flags) const { +void ThunkSignatureNode::outputPost(OutputString &OS, OutputFlags Flags) const { if (FunctionClass & FC_StaticThisAdjust) { OS << "`adjustor{" << ThisAdjust.StaticOffset << "}'"; } else if (FunctionClass & FC_VirtualThisAdjust) { @@ -477,7 +477,7 @@ FunctionSignatureNode::outputPost(OS, Flags); } -void PointerTypeNode::outputPre(OutputStream &OS, OutputFlags Flags) const { +void PointerTypeNode::outputPre(OutputString &OS, OutputFlags Flags) const { if (Pointee->kind() == NodeKind::FunctionSignature) { // If this is a pointer to a function, don't output the calling convention. // It needs to go inside the parentheses. @@ -523,7 +523,7 @@ outputQualifiers(OS, Quals, false, false); } -void PointerTypeNode::outputPost(OutputStream &OS, OutputFlags Flags) const { +void PointerTypeNode::outputPost(OutputString &OS, OutputFlags Flags) const { if (Pointee->kind() == NodeKind::ArrayType || Pointee->kind() == NodeKind::FunctionSignature) OS << ")"; @@ -531,7 +531,7 @@ Pointee->outputPost(OS, Flags); } -void TagTypeNode::outputPre(OutputStream &OS, OutputFlags Flags) const { +void TagTypeNode::outputPre(OutputString &OS, OutputFlags Flags) const { if (!(Flags & OF_NoTagSpecifier)) { switch (Tag) { OUTPUT_ENUM_CLASS_VALUE(TagKind, Class, "class"); @@ -545,14 +545,14 @@ outputQualifiers(OS, Quals, true, false); } -void TagTypeNode::outputPost(OutputStream &OS, OutputFlags Flags) const {} +void TagTypeNode::outputPost(OutputString &OS, OutputFlags Flags) const {} -void ArrayTypeNode::outputPre(OutputStream &OS, OutputFlags Flags) const { +void ArrayTypeNode::outputPre(OutputString &OS, OutputFlags Flags) const { ElementType->outputPre(OS, Flags); outputQualifiers(OS, Quals, true, false); } -void ArrayTypeNode::outputOneDimension(OutputStream &OS, OutputFlags Flags, +void ArrayTypeNode::outputOneDimension(OutputString &OS, OutputFlags Flags, Node *N) const { assert(N->kind() == NodeKind::IntegerLiteral); IntegerLiteralNode *ILN = static_cast(N); @@ -560,7 +560,7 @@ ILN->output(OS, Flags); } -void ArrayTypeNode::outputDimensionsImpl(OutputStream &OS, +void ArrayTypeNode::outputDimensionsImpl(OutputString &OS, OutputFlags Flags) const { if (Dimensions->Count == 0) return; @@ -572,7 +572,7 @@ } } -void ArrayTypeNode::outputPost(OutputStream &OS, OutputFlags Flags) const { +void ArrayTypeNode::outputPost(OutputString &OS, OutputFlags Flags) const { OS << "["; outputDimensionsImpl(OS, Flags); OS << "]"; @@ -580,18 +580,18 @@ ElementType->outputPost(OS, Flags); } -void SymbolNode::output(OutputStream &OS, OutputFlags Flags) const { +void SymbolNode::output(OutputString &OS, OutputFlags Flags) const { Name->output(OS, Flags); } -void FunctionSymbolNode::output(OutputStream &OS, OutputFlags Flags) const { +void FunctionSymbolNode::output(OutputString &OS, OutputFlags Flags) const { Signature->outputPre(OS, Flags); outputSpaceIfNecessary(OS); Name->output(OS, Flags); Signature->outputPost(OS, Flags); } -void VariableSymbolNode::output(OutputStream &OS, OutputFlags Flags) const { +void VariableSymbolNode::output(OutputString &OS, OutputFlags Flags) const { const char *AccessSpec = nullptr; bool IsStatic = true; switch (SC) { @@ -622,16 +622,16 @@ Type->outputPost(OS, Flags); } -void CustomTypeNode::outputPre(OutputStream &OS, OutputFlags Flags) const { +void CustomTypeNode::outputPre(OutputString &OS, OutputFlags Flags) const { Identifier->output(OS, Flags); } -void CustomTypeNode::outputPost(OutputStream &OS, OutputFlags Flags) const {} +void CustomTypeNode::outputPost(OutputString &OS, OutputFlags Flags) const {} -void QualifiedNameNode::output(OutputStream &OS, OutputFlags Flags) const { +void QualifiedNameNode::output(OutputString &OS, OutputFlags Flags) const { Components->output(OS, Flags, "::"); } -void RttiBaseClassDescriptorNode::output(OutputStream &OS, +void RttiBaseClassDescriptorNode::output(OutputString &OS, OutputFlags Flags) const { OS << "`RTTI Base Class Descriptor at ("; OS << NVOffset << ", " << VBPtrOffset << ", " << VBTableOffset << ", " @@ -639,17 +639,17 @@ OS << ")'"; } -void LocalStaticGuardVariableNode::output(OutputStream &OS, +void LocalStaticGuardVariableNode::output(OutputString &OS, OutputFlags Flags) const { Name->output(OS, Flags); } -void VcallThunkIdentifierNode::output(OutputStream &OS, +void VcallThunkIdentifierNode::output(OutputString &OS, OutputFlags Flags) const { OS << "`vcall'{" << OffsetInVTable << ", {flat}}"; } -void SpecialTableSymbolNode::output(OutputStream &OS, OutputFlags Flags) const { +void SpecialTableSymbolNode::output(OutputString &OS, OutputFlags Flags) const { outputQualifiers(OS, Quals, false, true); Name->output(OS, Flags); if (TargetName) { Index: llvm/lib/Demangle/RustDemangle.cpp =================================================================== --- llvm/lib/Demangle/RustDemangle.cpp +++ llvm/lib/Demangle/RustDemangle.cpp @@ -23,7 +23,7 @@ using namespace llvm; -using llvm::itanium_demangle::OutputStream; +using llvm::itanium_demangle::OutputString; using llvm::itanium_demangle::StringView; using llvm::itanium_demangle::SwapAndRestore; @@ -88,7 +88,7 @@ public: // Demangled output. - OutputStream Output; + OutputString Output; Demangler(size_t MaxRecursionLevel = 500); @@ -164,7 +164,7 @@ } Demangler D; - if (!initializeOutputStream(nullptr, nullptr, D.Output, 1024)) { + if (!initializeOutputString(nullptr, nullptr, D.Output, 1024)) { if (Status != nullptr) *Status = demangle_memory_alloc_failure; return nullptr; @@ -1094,7 +1094,7 @@ return false; } -static void removeNullBytes(OutputStream &Output, size_t StartIdx) { +static void removeNullBytes(OutputString &Output, size_t StartIdx) { char *Buffer = Output.getBuffer(); char *Start = Buffer + StartIdx; char *End = Buffer + Output.getCurrentPosition(); @@ -1138,7 +1138,7 @@ // Decodes string encoded using punycode and appends results to Output. // Returns true if decoding was successful. -static bool decodePunycode(StringView Input, OutputStream &Output) { +static bool decodePunycode(StringView Input, OutputString &Output) { size_t OutputSize = Output.getCurrentPosition(); size_t InputIdx = 0; Index: llvm/unittests/Demangle/CMakeLists.txt =================================================================== --- llvm/unittests/Demangle/CMakeLists.txt +++ llvm/unittests/Demangle/CMakeLists.txt @@ -6,7 +6,7 @@ add_llvm_unittest(DemangleTests DemangleTest.cpp ItaniumDemangleTest.cpp - OutputStreamTest.cpp + OutputStringTest.cpp PartialDemangleTest.cpp RustDemangleTest.cpp StringViewTest.cpp Index: llvm/unittests/Demangle/ItaniumDemangleTest.cpp =================================================================== --- llvm/unittests/Demangle/ItaniumDemangleTest.cpp +++ llvm/unittests/Demangle/ItaniumDemangleTest.cpp @@ -52,7 +52,7 @@ EXPECT_THAT(Parser.Types, testing::ElementsAre('i', 'j', 'l')); } -static std::string toString(OutputStream &OS) { +static std::string toString(OutputString &OS) { return {OS.getBuffer(), OS.getCurrentPosition()}; } @@ -64,7 +64,7 @@ : AbstractManglingParser(Str, Str + strlen(Str)) {} Node *parseType() { - OutputStream OS; + OutputString OS; Node *N = AbstractManglingParser::parseType(); N->printLeft(OS); StringView Name = N->getBaseName(); Index: llvm/unittests/Demangle/OutputStringTest.cpp =================================================================== --- llvm/unittests/Demangle/OutputStringTest.cpp +++ llvm/unittests/Demangle/OutputStringTest.cpp @@ -11,21 +11,21 @@ #include using namespace llvm; -using llvm::itanium_demangle::OutputStream; +using llvm::itanium_demangle::OutputString; -static std::string toString(OutputStream &OS) { +static std::string toString(OutputString &OS) { return {OS.getBuffer(), OS.getCurrentPosition()}; } template static std::string printToString(const T &Value) { - OutputStream OS; + OutputString OS; OS << Value; std::string s = toString(OS); std::free(OS.getBuffer()); return s; } -TEST(OutputStreamTest, Format) { +TEST(OutputStringTest, Format) { EXPECT_EQ("0", printToString(0)); EXPECT_EQ("1", printToString(1)); EXPECT_EQ("-1", printToString(-1)); @@ -39,8 +39,8 @@ EXPECT_EQ("abc", printToString("abc")); } -TEST(OutputStreamTest, Insert) { - OutputStream OS; +TEST(OutputStringTest, Insert) { + OutputString OS; OS.insert(0, "", 0); EXPECT_EQ("", toString(OS));