Index: lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp =================================================================== --- lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp +++ lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp @@ -25,6 +25,7 @@ #include "UdtRecordCompleter.h" #include "SymbolFileNativePDB.h" #include +#include using namespace lldb_private; using namespace lldb_private::npdb; @@ -174,7 +175,7 @@ return CreateDeclInfoForUndecoratedName(record.Name); llvm::ms_demangle::Demangler demangler; - StringView sv(record.UniqueName.begin(), record.UniqueName.size()); + std::string_view sv(record.UniqueName.begin(), record.UniqueName.size()); llvm::ms_demangle::TagTypeNode *ttn = demangler.parseTagUniqueName(sv); if (demangler.Error) return {m_clang.GetTranslationUnitDecl(), std::string(record.UniqueName)}; Index: lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp =================================================================== --- lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp +++ lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp @@ -57,6 +57,7 @@ #include "PdbUtil.h" #include "UdtRecordCompleter.h" #include +#include using namespace lldb; using namespace lldb_private; @@ -631,7 +632,7 @@ } llvm::ms_demangle::Demangler demangler; - StringView sv(record.UniqueName.begin(), record.UniqueName.size()); + std::string_view sv(record.UniqueName.begin(), record.UniqueName.size()); llvm::ms_demangle::TagTypeNode *ttn = demangler.parseTagUniqueName(sv); if (demangler.Error) return std::string(record.Name); Index: llvm/include/llvm/Demangle/ItaniumDemangle.h =================================================================== --- llvm/include/llvm/Demangle/ItaniumDemangle.h +++ llvm/include/llvm/Demangle/ItaniumDemangle.h @@ -16,8 +16,9 @@ #ifndef DEMANGLE_ITANIUMDEMANGLE_H #define DEMANGLE_ITANIUMDEMANGLE_H +#include + #include "DemangleConfig.h" -#include "StringView.h" #include "Utility.h" #include #include @@ -27,6 +28,7 @@ #include #include #include +#include #include #include @@ -287,7 +289,7 @@ // implementation. virtual void printRight(OutputBuffer &) const {} - virtual StringView getBaseName() const { return StringView(); } + virtual std::string_view getBaseName() const { return {}; } // Silence compiler warnings, this dtor will never be called. virtual ~Node() = default; @@ -346,10 +348,10 @@ class DotSuffix final : public Node { const Node *Prefix; - const StringView Suffix; + const std::string_view Suffix; public: - DotSuffix(const Node *Prefix_, StringView Suffix_) + DotSuffix(const Node *Prefix_, std::string_view Suffix_) : Node(KDotSuffix), Prefix(Prefix_), Suffix(Suffix_) {} template void match(Fn F) const { F(Prefix, Suffix); } @@ -364,15 +366,15 @@ class VendorExtQualType final : public Node { const Node *Ty; - StringView Ext; + std::string_view Ext; const Node *TA; public: - VendorExtQualType(const Node *Ty_, StringView Ext_, const Node *TA_) + VendorExtQualType(const Node *Ty_, std::string_view Ext_, const Node *TA_) : Node(KVendorExtQualType), Ty(Ty_), Ext(Ext_), TA(TA_) {} const Node *getTy() const { return Ty; } - StringView getExt() const { return Ext; } + std::string_view getExt() const { return Ext; } const Node *getTA() const { return TA; } template void match(Fn F) const { F(Ty, Ext, TA); } @@ -463,10 +465,10 @@ class PostfixQualifiedType final : public Node { const Node *Ty; - const StringView Postfix; + const std::string_view Postfix; public: - PostfixQualifiedType(const Node *Ty_, StringView Postfix_) + PostfixQualifiedType(const Node *Ty_, std::string_view Postfix_) : Node(KPostfixQualifiedType), Ty(Ty_), Postfix(Postfix_) {} template void match(Fn F) const { F(Ty, Postfix); } @@ -478,15 +480,15 @@ }; class NameType final : public Node { - const StringView Name; + const std::string_view Name; public: - NameType(StringView Name_) : Node(KNameType), Name(Name_) {} + NameType(std::string_view Name_) : Node(KNameType), Name(Name_) {} template void match(Fn F) const { F(Name); } - StringView getName() const { return Name; } - StringView getBaseName() const override { return Name; } + std::string_view getName() const { return Name; } + std::string_view getBaseName() const override { return Name; } void printLeft(OutputBuffer &OB) const override { OB += Name; } }; @@ -512,10 +514,10 @@ }; class ElaboratedTypeSpefType : public Node { - StringView Kind; + std::string_view Kind; Node *Child; public: - ElaboratedTypeSpefType(StringView Kind_, Node *Child_) + ElaboratedTypeSpefType(std::string_view Kind_, Node *Child_) : Node(KElaboratedTypeSpefType), Kind(Kind_), Child(Child_) {} template void match(Fn F) const { F(Kind, Child); } @@ -529,16 +531,16 @@ struct AbiTagAttr : Node { Node *Base; - StringView Tag; + std::string_view Tag; - AbiTagAttr(Node *Base_, StringView Tag_) + AbiTagAttr(Node *Base_, std::string_view Tag_) : Node(KAbiTagAttr, Base_->RHSComponentCache, Base_->ArrayCache, Base_->FunctionCache), Base(Base_), Tag(Tag_) {} template void match(Fn F) const { F(Base, Tag); } - StringView getBaseName() const override { return Base->getBaseName(); } + std::string_view getBaseName() const override { return Base->getBaseName(); } void printLeft(OutputBuffer &OB) const override { Base->printLeft(OB); @@ -565,12 +567,12 @@ class ObjCProtoName : public Node { const Node *Ty; - StringView Protocol; + std::string_view Protocol; friend class PointerType; public: - ObjCProtoName(const Node *Ty_, StringView Protocol_) + ObjCProtoName(const Node *Ty_, std::string_view Protocol_) : Node(KObjCProtoName), Ty(Ty_), Protocol(Protocol_) {} template void match(Fn F) const { F(Ty, Protocol); } @@ -947,11 +949,11 @@ }; class SpecialName final : public Node { - const StringView Special; + const std::string_view Special; const Node *Child; public: - SpecialName(StringView Special_, const Node *Child_) + SpecialName(std::string_view Special_, const Node *Child_) : Node(KSpecialName), Special(Special_), Child(Child_) {} template void match(Fn F) const { F(Special, Child); } @@ -990,7 +992,7 @@ template void match(Fn F) const { F(Qual, Name); } - StringView getBaseName() const override { return Name->getBaseName(); } + std::string_view getBaseName() const override { return Name->getBaseName(); } void printLeft(OutputBuffer &OB) const override { Qual->print(OB); @@ -1030,7 +1032,7 @@ template void match(Fn F) const { F(Module, Name); } - StringView getBaseName() const override { return Name->getBaseName(); } + std::string_view getBaseName() const override { return Name->getBaseName(); } void printLeft(OutputBuffer &OB) const override { Name->print(OB); @@ -1066,7 +1068,7 @@ template void match(Fn F) const { F(Qualifier, Name); } - StringView getBaseName() const override { return Name->getBaseName(); } + std::string_view getBaseName() const override { return Name->getBaseName(); } void printLeft(OutputBuffer &OB) const override { Qualifier->print(OB); @@ -1488,7 +1490,7 @@ template void match(Fn F) const { F(Name, TemplateArgs); } - StringView getBaseName() const override { return Name->getBaseName(); } + std::string_view getBaseName() const override { return Name->getBaseName(); } void printLeft(OutputBuffer &OB) const override { Name->print(OB); @@ -1505,7 +1507,7 @@ template void match(Fn F) const { F(Child); } - StringView getBaseName() const override { return Child->getBaseName(); } + std::string_view getBaseName() const override { return Child->getBaseName(); } void printLeft(OutputBuffer &OB) const override { OB += "::"; @@ -1541,20 +1543,20 @@ return unsigned(SSK) >= unsigned(SpecialSubKind::string); } - StringView getBaseName() const override { + std::string_view getBaseName() const override { switch (SSK) { case SpecialSubKind::allocator: - return StringView("allocator"); + return {"allocator"}; case SpecialSubKind::basic_string: - return StringView("basic_string"); + return {"basic_string"}; case SpecialSubKind::string: - return StringView("basic_string"); + return {"basic_string"}; case SpecialSubKind::istream: - return StringView("basic_istream"); + return {"basic_istream"}; case SpecialSubKind::ostream: - return StringView("basic_ostream"); + return {"basic_ostream"}; case SpecialSubKind::iostream: - return StringView("basic_iostream"); + return {"basic_iostream"}; } DEMANGLE_UNREACHABLE; } @@ -1578,11 +1580,11 @@ template void match(Fn F) const { F(SSK); } - StringView getBaseName() const override { - auto SV = ExpandedSpecialSubstitution::getBaseName(); + std::string_view getBaseName() const override { + std::string_view SV = ExpandedSpecialSubstitution::getBaseName(); if (isInstantiation()) { // The instantiations are typedefs that drop the "basic_" prefix. - assert(SV.startsWith("basic_")); + assert(llvm::starts_with(SV, "basic_")); SV.remove_prefix(sizeof("basic_") - 1); } return SV; @@ -1631,10 +1633,11 @@ }; class UnnamedTypeName : public Node { - const StringView Count; + const std::string_view Count; public: - UnnamedTypeName(StringView Count_) : Node(KUnnamedTypeName), Count(Count_) {} + UnnamedTypeName(std::string_view Count_) + : Node(KUnnamedTypeName), Count(Count_) {} template void match(Fn F) const { F(Count); } @@ -1648,11 +1651,11 @@ class ClosureTypeName : public Node { NodeArray TemplateParams; NodeArray Params; - StringView Count; + std::string_view Count; public: ClosureTypeName(NodeArray TemplateParams_, NodeArray Params_, - StringView Count_) + std::string_view Count_) : Node(KClosureTypeName), TemplateParams(TemplateParams_), Params(Params_), Count(Count_) {} @@ -1699,12 +1702,12 @@ class BinaryExpr : public Node { const Node *LHS; - const StringView InfixOperator; + const std::string_view InfixOperator; const Node *RHS; public: - BinaryExpr(const Node *LHS_, StringView InfixOperator_, const Node *RHS_, - Prec Prec_) + BinaryExpr(const Node *LHS_, std::string_view InfixOperator_, + const Node *RHS_, Prec Prec_) : Node(KBinaryExpr, Prec_), LHS(LHS_), InfixOperator(InfixOperator_), RHS(RHS_) {} @@ -1753,10 +1756,10 @@ class PostfixExpr : public Node { const Node *Child; - const StringView Operator; + const std::string_view Operator; public: - PostfixExpr(const Node *Child_, StringView Operator_, Prec Prec_) + PostfixExpr(const Node *Child_, std::string_view Operator_, Prec Prec_) : Node(KPostfixExpr, Prec_), Child(Child_), Operator(Operator_) {} template void match(Fn F) const { @@ -1794,11 +1797,12 @@ class MemberExpr : public Node { const Node *LHS; - const StringView Kind; + const std::string_view Kind; const Node *RHS; public: - MemberExpr(const Node *LHS_, StringView Kind_, const Node *RHS_, Prec Prec_) + MemberExpr(const Node *LHS_, std::string_view Kind_, const Node *RHS_, + Prec Prec_) : Node(KMemberExpr, Prec_), LHS(LHS_), Kind(Kind_), RHS(RHS_) {} template void match(Fn F) const { @@ -1815,13 +1819,14 @@ class SubobjectExpr : public Node { const Node *Type; const Node *SubExpr; - StringView Offset; + std::string_view Offset; NodeArray UnionSelectors; bool OnePastTheEnd; public: - SubobjectExpr(const Node *Type_, const Node *SubExpr_, StringView Offset_, - NodeArray UnionSelectors_, bool OnePastTheEnd_) + SubobjectExpr(const Node *Type_, const Node *SubExpr_, + std::string_view Offset_, NodeArray UnionSelectors_, + bool OnePastTheEnd_) : Node(KSubobjectExpr), Type(Type_), SubExpr(SubExpr_), Offset(Offset_), UnionSelectors(UnionSelectors_), OnePastTheEnd(OnePastTheEnd_) {} @@ -1847,12 +1852,12 @@ }; class EnclosingExpr : public Node { - const StringView Prefix; + const std::string_view Prefix; const Node *Infix; - const StringView Postfix; + const std::string_view Postfix; public: - EnclosingExpr(StringView Prefix_, const Node *Infix_, + EnclosingExpr(std::string_view Prefix_, const Node *Infix_, Prec Prec_ = Prec::Primary) : Node(KEnclosingExpr, Prec_), Prefix(Prefix_), Infix(Infix_) {} @@ -1871,12 +1876,13 @@ class CastExpr : public Node { // cast_kind(from) - const StringView CastKind; + const std::string_view CastKind; const Node *To; const Node *From; public: - CastExpr(StringView CastKind_, const Node *To_, const Node *From_, Prec Prec_) + CastExpr(std::string_view CastKind_, const Node *To_, const Node *From_, + Prec Prec_) : Node(KCastExpr, Prec_), CastKind(CastKind_), To(To_), From(From_) {} template void match(Fn F) const { @@ -1999,11 +2005,11 @@ }; class PrefixExpr : public Node { - StringView Prefix; + std::string_view Prefix; Node *Child; public: - PrefixExpr(StringView Prefix_, Node *Child_, Prec Prec_) + PrefixExpr(std::string_view Prefix_, Node *Child_, Prec Prec_) : Node(KPrefixExpr, Prec_), Prefix(Prefix_), Child(Child_) {} template void match(Fn F) const { @@ -2017,10 +2023,11 @@ }; class FunctionParam : public Node { - StringView Number; + std::string_view Number; public: - FunctionParam(StringView Number_) : Node(KFunctionParam), Number(Number_) {} + FunctionParam(std::string_view Number_) + : Node(KFunctionParam), Number(Number_) {} template void match(Fn F) const { F(Number); } @@ -2055,11 +2062,11 @@ class PointerToMemberConversionExpr : public Node { const Node *Type; const Node *SubExpr; - StringView Offset; + std::string_view Offset; public: PointerToMemberConversionExpr(const Node *Type_, const Node *SubExpr_, - StringView Offset_, Prec Prec_) + std::string_view Offset_, Prec Prec_) : Node(KPointerToMemberConversionExpr, Prec_), Type(Type_), SubExpr(SubExpr_), Offset(Offset_) {} @@ -2144,11 +2151,11 @@ class FoldExpr : public Node { const Node *Pack, *Init; - StringView OperatorName; + std::string_view OperatorName; bool IsLeftFold; public: - FoldExpr(bool IsLeftFold_, StringView OperatorName_, const Node *Pack_, + FoldExpr(bool IsLeftFold_, std::string_view OperatorName_, const Node *Pack_, const Node *Init_) : Node(KFoldExpr), Pack(Pack_), Init(Init_), OperatorName(OperatorName_), IsLeftFold(IsLeftFold_) {} @@ -2212,7 +2219,7 @@ template void match(Fn F) const { F(Value); } void printLeft(OutputBuffer &OB) const override { - OB += Value ? StringView("true") : StringView("false"); + OB += Value ? std::string_view("true") : std::string_view("false"); } }; @@ -2250,10 +2257,10 @@ class EnumLiteral : public Node { // ty(integer) const Node *Ty; - StringView Integer; + std::string_view Integer; public: - EnumLiteral(const Node *Ty_, StringView Integer_) + EnumLiteral(const Node *Ty_, std::string_view Integer_) : Node(KEnumLiteral), Ty(Ty_), Integer(Integer_) {} template void match(Fn F) const { F(Ty, Integer); } @@ -2271,11 +2278,11 @@ }; class IntegerLiteral : public Node { - StringView Type; - StringView Value; + std::string_view Type; + std::string_view Value; public: - IntegerLiteral(StringView Type_, StringView Value_) + IntegerLiteral(std::string_view Type_, std::string_view Value_) : Node(KIntegerLiteral), Type(Type_), Value(Value_) {} template void match(Fn F) const { F(Type, Value); } @@ -2312,20 +2319,20 @@ } template class FloatLiteralImpl : public Node { - const StringView Contents; + const std::string_view Contents; static constexpr Kind KindForClass = float_literal_impl::getFloatLiteralKind((Float *)nullptr); public: - FloatLiteralImpl(StringView Contents_) + FloatLiteralImpl(std::string_view Contents_) : Node(KindForClass), Contents(Contents_) {} template void match(Fn F) const { F(Contents); } void printLeft(OutputBuffer &OB) const override { - const char *first = Contents.begin(); - const char *last = Contents.end() + 1; + const char *first = &*Contents.begin(); + const char *last = &*Contents.end() + 1; const size_t N = FloatData::mangled_size; if (static_cast(last - first) > N) { @@ -2349,7 +2356,7 @@ #endif char num[FloatData::max_demangled_size] = {0}; int n = snprintf(num, sizeof(num), FloatData::spec, value); - OB += StringView(num, n); + OB += std::string_view(num, n); } } }; @@ -2476,8 +2483,8 @@ return res; } - bool consumeIf(StringView S) { - if (StringView(First, Last - First).startsWith(S)) { + bool consumeIf(std::string_view S) { + if (llvm::starts_with(std::string_view(First, Last - First), S)) { First += S.size(); return true; } @@ -2502,10 +2509,10 @@ size_t numLeft() const { return static_cast(Last - First); } - StringView parseNumber(bool AllowNegative = false); + std::string_view parseNumber(bool AllowNegative = false); Qualifiers parseCVQualifiers(); bool parsePositiveInteger(size_t *Out); - StringView parseBareSourceName(); + std::string_view parseBareSourceName(); bool parseSeqId(size_t *Out); Node *parseSubstitution(); @@ -2516,9 +2523,9 @@ /// Parse the production. Node *parseExpr(); - Node *parsePrefixExpr(StringView Kind, Node::Prec Prec); - Node *parseBinaryExpr(StringView Kind, Node::Prec Prec); - Node *parseIntegerLiteral(StringView Lit); + Node *parsePrefixExpr(std::string_view Kind, Node::Prec Prec); + Node *parseBinaryExpr(std::string_view Kind, Node::Prec Prec); + Node *parseIntegerLiteral(std::string_view Lit); Node *parseExprPrimary(); template Node *parseFloatingLiteral(); Node *parseFunctionParam(); @@ -2626,18 +2633,18 @@ bool operator!=(const char *Peek) const { return !this->operator==(Peek); } public: - StringView getSymbol() const { - StringView Res = Name; + std::string_view getSymbol() const { + std::string_view Res = Name; if (Kind < Unnameable) { - assert(Res.startsWith("operator") && + assert(llvm::starts_with(Res, "operator") && "operator name does not start with 'operator'"); Res.remove_prefix(sizeof("operator") - 1); - if (Res.startsWith(' ')) + if (llvm::starts_with(Res, ' ')) Res.remove_prefix(1); } return Res; } - StringView getName() const { return Name; } + std::string_view getName() const { return Name; } OIKind getKind() const { return Kind; } bool getFlag() const { return Flag; } Node::Prec getPrecedence() const { return Prec; } @@ -2857,7 +2864,7 @@ TemplateParams.clear(); if (consumeIf("Ut")) { - StringView Count = parseNumber(); + std::string_view Count = parseNumber(); if (!consumeIf('_')) return nullptr; return make(Count); @@ -2869,7 +2876,7 @@ size_t ParamsBegin = Names.size(); while (look() == 'T' && - StringView("yptn").find(look(1)) != StringView::npos) { + std::string_view("yptn").find(look(1)) != std::string_view::npos) { Node *T = parseTemplateParamDecl(); if (!T) return nullptr; @@ -2912,7 +2919,7 @@ } NodeArray Params = popTrailingNodeArray(ParamsBegin); - StringView Count = parseNumber(); + std::string_view Count = parseNumber(); if (!consumeIf('_')) return nullptr; return make(TempParams, Params, Count); @@ -2934,9 +2941,9 @@ return nullptr; if (numLeft() < Length || Length == 0) return nullptr; - StringView Name(First, Length); + std::string_view Name(First, Length); First += Length; - if (Name.startsWith("_GLOBAL__N")) + if (llvm::starts_with(Name, "_GLOBAL__N")) return make("(anonymous namespace)"); return make(Name); } @@ -3450,7 +3457,7 @@ template Node *AbstractManglingParser::parseAbiTags(Node *N) { while (consumeIf('B')) { - StringView SN = parseBareSourceName(); + std::string_view SN = parseBareSourceName(); if (SN.empty()) return nullptr; N = make(N, SN); @@ -3462,16 +3469,16 @@ // ::= [n] template -StringView +std::string_view AbstractManglingParser::parseNumber(bool AllowNegative) { const char *Tmp = First; if (AllowNegative) consumeIf('n'); if (numLeft() == 0 || !std::isdigit(*First)) - return StringView(); + return std::string_view(); while (numLeft() != 0 && std::isdigit(*First)) ++First; - return StringView(Tmp, First - Tmp); + return std::string_view(Tmp, First - Tmp); } // ::= [0-9]* @@ -3488,11 +3495,11 @@ } template -StringView AbstractManglingParser::parseBareSourceName() { +std::string_view AbstractManglingParser::parseBareSourceName() { size_t Int = 0; if (parsePositiveInteger(&Int) || numLeft() < Int) - return StringView(); - StringView R(First, Int); + return {}; + std::string_view R(First, Int); First += Int; return R; } @@ -3676,7 +3683,7 @@ // ::= Te # dependent elaborated type specifier using 'enum' template Node *AbstractManglingParser::parseClassEnumType() { - StringView ElabSpef; + std::string_view ElabSpef; if (consumeIf("Ts")) ElabSpef = "struct"; else if (consumeIf("Tu")) @@ -3700,14 +3707,14 @@ template Node *AbstractManglingParser::parseQualifiedType() { if (consumeIf('U')) { - StringView Qual = parseBareSourceName(); + std::string_view Qual = parseBareSourceName(); if (Qual.empty()) return nullptr; // extension ::= U # objc-type - if (Qual.startsWith("objcproto")) { - StringView ProtoSourceName = Qual.substr(std::strlen("objcproto")); - StringView Proto; + if (llvm::starts_with(Qual, "objcproto")) { + std::string_view ProtoSourceName = Qual.substr(std::strlen("objcproto")); + std::string_view Proto; { ScopedOverride SaveFirst(First, ProtoSourceName.begin()), SaveLast(Last, ProtoSourceName.end()); @@ -3878,7 +3885,7 @@ // ::= u # vendor extended type case 'u': { ++First; - StringView Res = parseBareSourceName(); + std::string_view Res = parseBareSourceName(); if (Res.empty()) return nullptr; // Typically, s are not considered substitution candidates, @@ -4126,8 +4133,9 @@ } template -Node *AbstractManglingParser::parsePrefixExpr(StringView Kind, - Node::Prec Prec) { +Node * +AbstractManglingParser::parsePrefixExpr(std::string_view Kind, + Node::Prec Prec) { Node *E = getDerived().parseExpr(); if (E == nullptr) return nullptr; @@ -4135,8 +4143,9 @@ } template -Node *AbstractManglingParser::parseBinaryExpr(StringView Kind, - Node::Prec Prec) { +Node * +AbstractManglingParser::parseBinaryExpr(std::string_view Kind, + Node::Prec Prec) { Node *LHS = getDerived().parseExpr(); if (LHS == nullptr) return nullptr; @@ -4147,9 +4156,9 @@ } template -Node * -AbstractManglingParser::parseIntegerLiteral(StringView Lit) { - StringView Tmp = parseNumber(true); +Node *AbstractManglingParser::parseIntegerLiteral( + std::string_view Lit) { + std::string_view Tmp = parseNumber(true); if (!Tmp.empty() && consumeIf('E')) return make(Lit, Tmp); return nullptr; @@ -4179,7 +4188,7 @@ return make("this"); if (consumeIf("fp")) { parseCVQualifiers(); - StringView Num = parseNumber(); + std::string_view Num = parseNumber(); if (!consumeIf('_')) return nullptr; return make(Num); @@ -4190,7 +4199,7 @@ if (!consumeIf('p')) return nullptr; parseCVQualifiers(); - StringView Num = parseNumber(); + std::string_view Num = parseNumber(); if (!consumeIf('_')) return nullptr; return make(Num); @@ -4344,7 +4353,7 @@ Node *T = getDerived().parseType(); if (T == nullptr) return nullptr; - StringView N = parseNumber(/*AllowNegative=*/true); + std::string_view N = parseNumber(/*AllowNegative=*/true); if (N.empty()) return nullptr; if (!consumeIf('E')) @@ -4467,7 +4476,7 @@ Node *Expr = getDerived().parseExpr(); if (!Expr) return nullptr; - StringView Offset = getDerived().parseNumber(true); + std::string_view Offset = getDerived().parseNumber(true); if (!consumeIf('E')) return nullptr; return make(Ty, Expr, Offset, Prec); @@ -4485,7 +4494,7 @@ Node *Expr = getDerived().parseExpr(); if (!Expr) return nullptr; - StringView Offset = getDerived().parseNumber(true); + std::string_view Offset = getDerived().parseNumber(true); size_t SelectorsBegin = Names.size(); while (consumeIf('_')) { Node *Selector = make(parseNumber()); @@ -5144,7 +5153,7 @@ const size_t N = FloatData::mangled_size; if (numLeft() <= N) return nullptr; - StringView Data(First, N); + std::string_view Data(First, N); for (char C : Data) if (!std::isxdigit(C)) return nullptr; @@ -5464,7 +5473,8 @@ if (Encoding == nullptr) return nullptr; if (look() == '.') { - Encoding = make(Encoding, StringView(First, Last - First)); + Encoding = + make(Encoding, std::string_view(First, Last - First)); First = Last; } if (numLeft() != 0) Index: llvm/include/llvm/Demangle/MicrosoftDemangle.h =================================================================== --- llvm/include/llvm/Demangle/MicrosoftDemangle.h +++ llvm/include/llvm/Demangle/MicrosoftDemangle.h @@ -10,8 +10,9 @@ #define LLVM_DEMANGLE_MICROSOFTDEMANGLE_H #include "llvm/Demangle/MicrosoftDemangleNodes.h" -#include "llvm/Demangle/StringView.h" +#include +#include #include namespace llvm { @@ -142,9 +143,9 @@ // You are supposed to call parse() first and then check if error is true. If // it is false, call output() to write the formatted name to the given stream. - SymbolNode *parse(StringView &MangledName); + SymbolNode *parse(std::string_view &MangledName); - TagTypeNode *parseTagUniqueName(StringView &MangledName); + TagTypeNode *parseTagUniqueName(std::string_view &MangledName); // True if an error occurred. bool Error = false; @@ -152,104 +153,110 @@ void dumpBackReferences(); private: - SymbolNode *demangleEncodedSymbol(StringView &MangledName, + SymbolNode *demangleEncodedSymbol(std::string_view &MangledName, QualifiedNameNode *QN); - SymbolNode *demangleDeclarator(StringView &MangledName); - SymbolNode *demangleMD5Name(StringView &MangledName); - SymbolNode *demangleTypeinfoName(StringView &MangledName); + SymbolNode *demangleDeclarator(std::string_view &MangledName); + SymbolNode *demangleMD5Name(std::string_view &MangledName); + SymbolNode *demangleTypeinfoName(std::string_view &MangledName); - VariableSymbolNode *demangleVariableEncoding(StringView &MangledName, + VariableSymbolNode *demangleVariableEncoding(std::string_view &MangledName, StorageClass SC); - FunctionSymbolNode *demangleFunctionEncoding(StringView &MangledName); + FunctionSymbolNode *demangleFunctionEncoding(std::string_view &MangledName); - Qualifiers demanglePointerExtQualifiers(StringView &MangledName); + Qualifiers demanglePointerExtQualifiers(std::string_view &MangledName); // Parser functions. This is a recursive-descent parser. - TypeNode *demangleType(StringView &MangledName, QualifierMangleMode QMM); - PrimitiveTypeNode *demanglePrimitiveType(StringView &MangledName); - CustomTypeNode *demangleCustomType(StringView &MangledName); - TagTypeNode *demangleClassType(StringView &MangledName); - PointerTypeNode *demanglePointerType(StringView &MangledName); - PointerTypeNode *demangleMemberPointerType(StringView &MangledName); - FunctionSignatureNode *demangleFunctionType(StringView &MangledName, + TypeNode *demangleType(std::string_view &MangledName, QualifierMangleMode QMM); + PrimitiveTypeNode *demanglePrimitiveType(std::string_view &MangledName); + CustomTypeNode *demangleCustomType(std::string_view &MangledName); + TagTypeNode *demangleClassType(std::string_view &MangledName); + PointerTypeNode *demanglePointerType(std::string_view &MangledName); + PointerTypeNode *demangleMemberPointerType(std::string_view &MangledName); + FunctionSignatureNode *demangleFunctionType(std::string_view &MangledName, bool HasThisQuals); - ArrayTypeNode *demangleArrayType(StringView &MangledName); + ArrayTypeNode *demangleArrayType(std::string_view &MangledName); - NodeArrayNode *demangleFunctionParameterList(StringView &MangledName, + NodeArrayNode *demangleFunctionParameterList(std::string_view &MangledName, bool &IsVariadic); - NodeArrayNode *demangleTemplateParameterList(StringView &MangledName); + NodeArrayNode *demangleTemplateParameterList(std::string_view &MangledName); - std::pair demangleNumber(StringView &MangledName); - uint64_t demangleUnsigned(StringView &MangledName); - int64_t demangleSigned(StringView &MangledName); + std::pair demangleNumber(std::string_view &MangledName); + uint64_t demangleUnsigned(std::string_view &MangledName); + int64_t demangleSigned(std::string_view &MangledName); - void memorizeString(StringView s); + void memorizeString(std::string_view s); void memorizeIdentifier(IdentifierNode *Identifier); /// Allocate a copy of \p Borrowed into memory that we own. - StringView copyString(StringView Borrowed); + std::string_view copyString(std::string_view Borrowed); - QualifiedNameNode *demangleFullyQualifiedTypeName(StringView &MangledName); - QualifiedNameNode *demangleFullyQualifiedSymbolName(StringView &MangledName); + QualifiedNameNode * + demangleFullyQualifiedTypeName(std::string_view &MangledName); + QualifiedNameNode * + demangleFullyQualifiedSymbolName(std::string_view &MangledName); - IdentifierNode *demangleUnqualifiedTypeName(StringView &MangledName, + IdentifierNode *demangleUnqualifiedTypeName(std::string_view &MangledName, bool Memorize); - IdentifierNode *demangleUnqualifiedSymbolName(StringView &MangledName, + IdentifierNode *demangleUnqualifiedSymbolName(std::string_view &MangledName, NameBackrefBehavior NBB); - QualifiedNameNode *demangleNameScopeChain(StringView &MangledName, + QualifiedNameNode *demangleNameScopeChain(std::string_view &MangledName, IdentifierNode *UnqualifiedName); - IdentifierNode *demangleNameScopePiece(StringView &MangledName); + IdentifierNode *demangleNameScopePiece(std::string_view &MangledName); - NamedIdentifierNode *demangleBackRefName(StringView &MangledName); - IdentifierNode *demangleTemplateInstantiationName(StringView &MangledName, - NameBackrefBehavior NBB); + NamedIdentifierNode *demangleBackRefName(std::string_view &MangledName); + IdentifierNode * + demangleTemplateInstantiationName(std::string_view &MangledName, + NameBackrefBehavior NBB); IntrinsicFunctionKind translateIntrinsicFunctionCode(char CH, FunctionIdentifierCodeGroup Group); - IdentifierNode *demangleFunctionIdentifierCode(StringView &MangledName); + IdentifierNode *demangleFunctionIdentifierCode(std::string_view &MangledName); IdentifierNode * - demangleFunctionIdentifierCode(StringView &MangledName, + demangleFunctionIdentifierCode(std::string_view &MangledName, FunctionIdentifierCodeGroup Group); - StructorIdentifierNode *demangleStructorIdentifier(StringView &MangledName, - bool IsDestructor); + StructorIdentifierNode * + demangleStructorIdentifier(std::string_view &MangledName, bool IsDestructor); ConversionOperatorIdentifierNode * - demangleConversionOperatorIdentifier(StringView &MangledName); + demangleConversionOperatorIdentifier(std::string_view &MangledName); LiteralOperatorIdentifierNode * - demangleLiteralOperatorIdentifier(StringView &MangledName); + demangleLiteralOperatorIdentifier(std::string_view &MangledName); - SymbolNode *demangleSpecialIntrinsic(StringView &MangledName); + SymbolNode *demangleSpecialIntrinsic(std::string_view &MangledName); SpecialTableSymbolNode * - demangleSpecialTableSymbolNode(StringView &MangledName, + demangleSpecialTableSymbolNode(std::string_view &MangledName, SpecialIntrinsicKind SIK); LocalStaticGuardVariableNode * - demangleLocalStaticGuard(StringView &MangledName, bool IsThread); + demangleLocalStaticGuard(std::string_view &MangledName, bool IsThread); VariableSymbolNode *demangleUntypedVariable(ArenaAllocator &Arena, - StringView &MangledName, - StringView VariableName); + std::string_view &MangledName, + std::string_view VariableName); VariableSymbolNode * demangleRttiBaseClassDescriptorNode(ArenaAllocator &Arena, - StringView &MangledName); - FunctionSymbolNode *demangleInitFiniStub(StringView &MangledName, + std::string_view &MangledName); + FunctionSymbolNode *demangleInitFiniStub(std::string_view &MangledName, bool IsDestructor); - NamedIdentifierNode *demangleSimpleName(StringView &MangledName, + NamedIdentifierNode *demangleSimpleName(std::string_view &MangledName, bool Memorize); - NamedIdentifierNode *demangleAnonymousNamespaceName(StringView &MangledName); - NamedIdentifierNode *demangleLocallyScopedNamePiece(StringView &MangledName); - EncodedStringLiteralNode *demangleStringLiteral(StringView &MangledName); - FunctionSymbolNode *demangleVcallThunkNode(StringView &MangledName); - - StringView demangleSimpleString(StringView &MangledName, bool Memorize); - - FuncClass demangleFunctionClass(StringView &MangledName); - CallingConv demangleCallingConvention(StringView &MangledName); - StorageClass demangleVariableStorageClass(StringView &MangledName); - bool demangleThrowSpecification(StringView &MangledName); - wchar_t demangleWcharLiteral(StringView &MangledName); - uint8_t demangleCharLiteral(StringView &MangledName); - - std::pair demangleQualifiers(StringView &MangledName); + NamedIdentifierNode * + demangleAnonymousNamespaceName(std::string_view &MangledName); + NamedIdentifierNode * + demangleLocallyScopedNamePiece(std::string_view &MangledName); + EncodedStringLiteralNode *demangleStringLiteral(std::string_view &MangledName); + FunctionSymbolNode *demangleVcallThunkNode(std::string_view &MangledName); + + std::string_view demangleSimpleString(std::string_view &MangledName, + bool Memorize); + + FuncClass demangleFunctionClass(std::string_view &MangledName); + CallingConv demangleCallingConvention(std::string_view &MangledName); + StorageClass demangleVariableStorageClass(std::string_view &MangledName); + bool demangleThrowSpecification(std::string_view &MangledName); + wchar_t demangleWcharLiteral(std::string_view &MangledName); + uint8_t demangleCharLiteral(std::string_view &MangledName); + + std::pair demangleQualifiers(std::string_view &MangledName); // Memory allocator. ArenaAllocator Arena; Index: llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h =================================================================== --- llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h +++ llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h @@ -13,10 +13,10 @@ #ifndef LLVM_DEMANGLE_MICROSOFTDEMANGLENODES_H #define LLVM_DEMANGLE_MICROSOFTDEMANGLENODES_H -#include "llvm/Demangle/StringView.h" #include #include #include +#include namespace llvm { namespace itanium_demangle { @@ -25,7 +25,6 @@ } using llvm::itanium_demangle::OutputBuffer; -using llvm::itanium_demangle::StringView; namespace llvm { namespace ms_demangle { @@ -384,7 +383,7 @@ void output(OutputBuffer &OB, OutputFlags Flags) const override; - StringView Name; + std::string_view Name; }; struct IntrinsicFunctionIdentifierNode : public IdentifierNode { @@ -403,7 +402,7 @@ void output(OutputBuffer &OB, OutputFlags Flags) const override; - StringView Name; + std::string_view Name; }; struct LocalStaticGuardIdentifierNode : public IdentifierNode { @@ -516,7 +515,8 @@ void output(OutputBuffer &OB, OutputFlags Flags) const override; - void output(OutputBuffer &OB, OutputFlags Flags, StringView Separator) const; + void output(OutputBuffer &OB, OutputFlags Flags, + std::string_view Separator) const; Node **Nodes = nullptr; size_t Count = 0; @@ -601,7 +601,7 @@ void output(OutputBuffer &OB, OutputFlags Flags) const override; - StringView DecodedString; + std::string_view DecodedString; bool IsTruncated = false; CharKind Char = CharKind::Char; }; Index: llvm/include/llvm/Demangle/Utility.h =================================================================== --- llvm/include/llvm/Demangle/Utility.h +++ llvm/include/llvm/Demangle/Utility.h @@ -16,13 +16,16 @@ #ifndef DEMANGLE_UTILITY_H #define DEMANGLE_UTILITY_H -#include "StringView.h" +#include "DemangleConfig.h" + #include +#include #include #include #include #include #include +#include DEMANGLE_NAMESPACE_BEGIN @@ -64,7 +67,8 @@ if (isNeg) *--TempPtr = '-'; - return operator+=(StringView(TempPtr, Temp.data() + Temp.size() - TempPtr)); + return operator+=( + std::string_view(TempPtr, Temp.data() + Temp.size() - TempPtr)); } public: @@ -77,7 +81,9 @@ OutputBuffer(const OutputBuffer &) = delete; OutputBuffer &operator=(const OutputBuffer &) = delete; - operator StringView() const { return StringView(Buffer, CurrentPosition); } + operator std::string_view() const { + return std::string_view(Buffer, CurrentPosition); + } /// If a ParameterPackExpansion (or similar type) is encountered, the offset /// into the pack that we're currently printing. @@ -99,10 +105,10 @@ *this += Close; } - OutputBuffer &operator+=(StringView R) { + OutputBuffer &operator+=(std::string_view R) { if (size_t Size = R.size()) { grow(Size); - std::memcpy(Buffer + CurrentPosition, R.begin(), Size); + std::memcpy(Buffer + CurrentPosition, &*R.begin(), Size); CurrentPosition += Size; } return *this; @@ -114,18 +120,18 @@ return *this; } - OutputBuffer &prepend(StringView R) { + OutputBuffer &prepend(std::string_view R) { size_t Size = R.size(); grow(Size); std::memmove(Buffer + Size, Buffer, CurrentPosition); - std::memcpy(Buffer, R.begin(), Size); + std::memcpy(Buffer, &*R.begin(), Size); CurrentPosition += Size; return *this; } - OutputBuffer &operator<<(StringView R) { return (*this += R); } + OutputBuffer &operator<<(std::string_view R) { return (*this += R); } OutputBuffer &operator<<(char C) { return (*this += C); } Index: llvm/lib/Demangle/DLangDemangle.cpp =================================================================== --- llvm/lib/Demangle/DLangDemangle.cpp +++ llvm/lib/Demangle/DLangDemangle.cpp @@ -14,7 +14,6 @@ //===----------------------------------------------------------------------===// #include "llvm/Demangle/Demangle.h" -#include "llvm/Demangle/StringView.h" #include "llvm/Demangle/Utility.h" #include @@ -23,7 +22,6 @@ using namespace llvm; using llvm::itanium_demangle::OutputBuffer; -using llvm::itanium_demangle::StringView; namespace { @@ -530,7 +528,7 @@ break; } - *Demangled << StringView(Mangled, Len); + *Demangled << std::string_view(Mangled, Len); Mangled += Len; return Mangled; Index: llvm/lib/Demangle/ItaniumDemangle.cpp =================================================================== --- llvm/lib/Demangle/ItaniumDemangle.cpp +++ llvm/lib/Demangle/ItaniumDemangle.cpp @@ -78,8 +78,8 @@ } void printStr(const char *S) { fprintf(stderr, "%s", S); } - void print(StringView SV) { - fprintf(stderr, "\"%.*s\"", (int)SV.size(), SV.begin()); + void print(std::string_view SV) { + fprintf(stderr, "\"%.*s\"", (int)SV.size(), &*SV.begin()); } void print(const Node *N) { if (N) Index: llvm/lib/Demangle/MicrosoftDemangle.cpp =================================================================== --- llvm/lib/Demangle/MicrosoftDemangle.cpp +++ llvm/lib/Demangle/MicrosoftDemangle.cpp @@ -14,22 +14,23 @@ //===----------------------------------------------------------------------===// #include "llvm/Demangle/MicrosoftDemangle.h" -#include "llvm/Demangle/Demangle.h" -#include "llvm/Demangle/MicrosoftDemangleNodes.h" +#include "llvm/ADT/StringViewExtras.h" +#include "llvm/Demangle/Demangle.h" #include "llvm/Demangle/DemangleConfig.h" -#include "llvm/Demangle/StringView.h" +#include "llvm/Demangle/MicrosoftDemangleNodes.h" #include "llvm/Demangle/Utility.h" #include #include #include +#include #include using namespace llvm; using namespace ms_demangle; -static bool startsWithDigit(StringView S) { +static bool startsWithDigit(std::string_view S) { return !S.empty() && std::isdigit(S.front()); } @@ -38,21 +39,21 @@ NodeList *Next = nullptr; }; -static bool consumeFront(StringView &S, char C) { - if (!S.startsWith(C)) +static bool consumeFront(std::string_view &S, char C) { + if (!llvm::starts_with(S, C)) return false; S.remove_prefix(1); return true; } -static bool consumeFront(StringView &S, StringView C) { - if (!S.startsWith(C)) +static bool consumeFront(std::string_view &S, std::string_view C) { + if (!llvm::starts_with(S, C)) return false; S.remove_prefix(C.size()); return true; } -static bool isMemberPointer(StringView MangledName, bool &Error) { +static bool isMemberPointer(std::string_view MangledName, bool &Error) { Error = false; const char F = MangledName.front(); MangledName.remove_prefix(1); @@ -118,7 +119,7 @@ } static SpecialIntrinsicKind -consumeSpecialIntrinsicKind(StringView &MangledName) { +consumeSpecialIntrinsicKind(std::string_view &MangledName) { if (consumeFront(MangledName, "?_7")) return SpecialIntrinsicKind::Vftable; if (consumeFront(MangledName, "?_8")) @@ -154,14 +155,14 @@ return SpecialIntrinsicKind::None; } -static bool startsWithLocalScopePattern(StringView S) { +static bool startsWithLocalScopePattern(std::string_view S) { if (!consumeFront(S, '?')) return false; size_t End = S.find('?'); - if (End == StringView::npos) + if (End == std::string_view::npos) return false; - StringView Candidate = S.substr(0, End); + std::string_view Candidate = S.substr(0, End); if (Candidate.empty()) return false; @@ -193,7 +194,7 @@ return true; } -static bool isTagType(StringView S) { +static bool isTagType(std::string_view S) { switch (S.front()) { case 'T': // union case 'U': // struct @@ -204,10 +205,10 @@ return false; } -static bool isCustomType(StringView S) { return S[0] == '?'; } +static bool isCustomType(std::string_view S) { return S[0] == '?'; } -static bool isPointerType(StringView S) { - if (S.startsWith("$$Q")) // foo && +static bool isPointerType(std::string_view S) { + if (llvm::starts_with(S, "$$Q")) // foo && return true; switch (S.front()) { @@ -221,14 +222,14 @@ return false; } -static bool isArrayType(StringView S) { return S[0] == 'Y'; } +static bool isArrayType(std::string_view S) { return S[0] == 'Y'; } -static bool isFunctionType(StringView S) { - return S.startsWith("$$A8@@") || S.startsWith("$$A6"); +static bool isFunctionType(std::string_view S) { + return llvm::starts_with(S, "$$A8@@") || llvm::starts_with(S, "$$A6"); } static FunctionRefQualifier -demangleFunctionRefQualifier(StringView &MangledName) { +demangleFunctionRefQualifier(std::string_view &MangledName) { if (consumeFront(MangledName, 'G')) return FunctionRefQualifier::Reference; else if (consumeFront(MangledName, 'H')) @@ -237,7 +238,7 @@ } static std::pair -demanglePointerCVQualifiers(StringView &MangledName) { +demanglePointerCVQualifiers(std::string_view &MangledName) { if (consumeFront(MangledName, "$$Q")) return std::make_pair(Q_None, PointerAffinity::RValueReference); @@ -261,18 +262,18 @@ DEMANGLE_UNREACHABLE; } -StringView Demangler::copyString(StringView Borrowed) { +std::string_view Demangler::copyString(std::string_view Borrowed) { char *Stable = Arena.allocUnalignedBuffer(Borrowed.size()); // This is not a micro-optimization, it avoids UB, should Borrowed be an null // buffer. if (Borrowed.size()) - std::memcpy(Stable, Borrowed.begin(), Borrowed.size()); + std::memcpy(Stable, &*Borrowed.begin(), Borrowed.size()); return {Stable, Borrowed.size()}; } SpecialTableSymbolNode * -Demangler::demangleSpecialTableSymbolNode(StringView &MangledName, +Demangler::demangleSpecialTableSymbolNode(std::string_view &MangledName, SpecialIntrinsicKind K) { NamedIdentifierNode *NI = Arena.alloc(); switch (K) { @@ -313,7 +314,8 @@ } LocalStaticGuardVariableNode * -Demangler::demangleLocalStaticGuard(StringView &MangledName, bool IsThread) { +Demangler::demangleLocalStaticGuard(std::string_view &MangledName, + bool IsThread) { LocalStaticGuardIdentifierNode *LSGI = Arena.alloc(); LSGI->IsThread = IsThread; @@ -337,7 +339,7 @@ } static NamedIdentifierNode *synthesizeNamedIdentifier(ArenaAllocator &Arena, - StringView Name) { + std::string_view Name) { NamedIdentifierNode *Id = Arena.alloc(); Id->Name = Name; return Id; @@ -354,22 +356,24 @@ } static QualifiedNameNode *synthesizeQualifiedName(ArenaAllocator &Arena, - StringView Name) { + std::string_view Name) { NamedIdentifierNode *Id = synthesizeNamedIdentifier(Arena, Name); return synthesizeQualifiedName(Arena, Id); } static VariableSymbolNode *synthesizeVariable(ArenaAllocator &Arena, TypeNode *Type, - StringView VariableName) { + std::string_view VariableName) { VariableSymbolNode *VSN = Arena.alloc(); VSN->Type = Type; VSN->Name = synthesizeQualifiedName(Arena, VariableName); return VSN; } -VariableSymbolNode *Demangler::demangleUntypedVariable( - ArenaAllocator &Arena, StringView &MangledName, StringView VariableName) { +VariableSymbolNode * +Demangler::demangleUntypedVariable(ArenaAllocator &Arena, + std::string_view &MangledName, + std::string_view VariableName) { NamedIdentifierNode *NI = synthesizeNamedIdentifier(Arena, VariableName); QualifiedNameNode *QN = demangleNameScopeChain(MangledName, NI); VariableSymbolNode *VSN = Arena.alloc(); @@ -383,7 +387,7 @@ VariableSymbolNode * Demangler::demangleRttiBaseClassDescriptorNode(ArenaAllocator &Arena, - StringView &MangledName) { + std::string_view &MangledName) { RttiBaseClassDescriptorNode *RBCDN = Arena.alloc(); RBCDN->NVOffset = demangleUnsigned(MangledName); @@ -399,8 +403,9 @@ return VSN; } -FunctionSymbolNode *Demangler::demangleInitFiniStub(StringView &MangledName, - bool IsDestructor) { +FunctionSymbolNode * +Demangler::demangleInitFiniStub(std::string_view &MangledName, + bool IsDestructor) { DynamicStructorIdentifierNode *DSIN = Arena.alloc(); DSIN->IsDestructor = IsDestructor; @@ -448,7 +453,7 @@ return FSN; } -SymbolNode *Demangler::demangleSpecialIntrinsic(StringView &MangledName) { +SymbolNode *Demangler::demangleSpecialIntrinsic(std::string_view &MangledName) { SpecialIntrinsicKind SIK = consumeSpecialIntrinsicKind(MangledName); switch (SIK) { @@ -502,8 +507,8 @@ } IdentifierNode * -Demangler::demangleFunctionIdentifierCode(StringView &MangledName) { - assert(MangledName.startsWith('?')); +Demangler::demangleFunctionIdentifierCode(std::string_view &MangledName) { + assert(llvm::starts_with(MangledName, '?')); MangledName.remove_prefix(1); if (MangledName.empty()) { Error = true; @@ -521,7 +526,7 @@ } StructorIdentifierNode * -Demangler::demangleStructorIdentifier(StringView &MangledName, +Demangler::demangleStructorIdentifier(std::string_view &MangledName, bool IsDestructor) { StructorIdentifierNode *N = Arena.alloc(); N->IsDestructor = IsDestructor; @@ -529,14 +534,14 @@ } ConversionOperatorIdentifierNode * -Demangler::demangleConversionOperatorIdentifier(StringView &MangledName) { +Demangler::demangleConversionOperatorIdentifier(std::string_view &MangledName) { ConversionOperatorIdentifierNode *N = Arena.alloc(); return N; } LiteralOperatorIdentifierNode * -Demangler::demangleLiteralOperatorIdentifier(StringView &MangledName) { +Demangler::demangleLiteralOperatorIdentifier(std::string_view &MangledName) { LiteralOperatorIdentifierNode *N = Arena.alloc(); N->Name = demangleSimpleString(MangledName, /*Memorize=*/false); @@ -684,7 +689,7 @@ } IdentifierNode * -Demangler::demangleFunctionIdentifierCode(StringView &MangledName, +Demangler::demangleFunctionIdentifierCode(std::string_view &MangledName, FunctionIdentifierCodeGroup Group) { if (MangledName.empty()) { Error = true; @@ -722,7 +727,7 @@ DEMANGLE_UNREACHABLE; } -SymbolNode *Demangler::demangleEncodedSymbol(StringView &MangledName, +SymbolNode *Demangler::demangleEncodedSymbol(std::string_view &MangledName, QualifiedNameNode *Name) { if (MangledName.empty()) { Error = true; @@ -752,7 +757,7 @@ return FSN; } -SymbolNode *Demangler::demangleDeclarator(StringView &MangledName) { +SymbolNode *Demangler::demangleDeclarator(std::string_view &MangledName) { // What follows is a main symbol name. This may include namespaces or class // back references. QualifiedNameNode *QN = demangleFullyQualifiedSymbolName(MangledName); @@ -776,17 +781,17 @@ return Symbol; } -SymbolNode *Demangler::demangleMD5Name(StringView &MangledName) { - assert(MangledName.startsWith("??@")); +SymbolNode *Demangler::demangleMD5Name(std::string_view &MangledName) { + assert(llvm::starts_with(MangledName, "??@")); // This is an MD5 mangled name. We can't demangle it, just return the // mangled name. // An MD5 mangled name is ??@ followed by 32 characters and a terminating @. size_t MD5Last = MangledName.find('@', strlen("??@")); - if (MD5Last == StringView::npos) { + if (MD5Last == std::string_view::npos) { Error = true; return nullptr; } - const char *Start = MangledName.begin(); + const char *Start = &*MangledName.begin(); MangledName.remove_prefix(MD5Last + 1); // There are two additional special cases for MD5 names: @@ -801,15 +806,15 @@ // either. consumeFront(MangledName, "??_R4@"); - StringView MD5(Start, MangledName.begin() - Start); + std::string_view MD5(Start, &*MangledName.begin() - Start); SymbolNode *S = Arena.alloc(NodeKind::Md5Symbol); S->Name = synthesizeQualifiedName(Arena, MD5); return S; } -SymbolNode *Demangler::demangleTypeinfoName(StringView &MangledName) { - assert(MangledName.startsWith('.')); +SymbolNode *Demangler::demangleTypeinfoName(std::string_view &MangledName) { + assert(llvm::starts_with(MangledName, '.')); consumeFront(MangledName, '.'); TypeNode *T = demangleType(MangledName, QualifierMangleMode::Result); @@ -821,18 +826,18 @@ } // Parser entry point. -SymbolNode *Demangler::parse(StringView &MangledName) { +SymbolNode *Demangler::parse(std::string_view &MangledName) { // Typeinfo names are strings stored in RTTI data. They're not symbol names. // It's still useful to demangle them. They're the only demangled entity // that doesn't start with a "?" but a ".". - if (MangledName.startsWith('.')) + if (llvm::starts_with(MangledName, '.')) return demangleTypeinfoName(MangledName); - if (MangledName.startsWith("??@")) + if (llvm::starts_with(MangledName, "??@")) return demangleMD5Name(MangledName); // MSVC-style mangled symbols must start with '?'. - if (!MangledName.startsWith('?')) { + if (!llvm::starts_with(MangledName, '?')) { Error = true; return nullptr; } @@ -847,7 +852,7 @@ return demangleDeclarator(MangledName); } -TagTypeNode *Demangler::parseTagUniqueName(StringView &MangledName) { +TagTypeNode *Demangler::parseTagUniqueName(std::string_view &MangledName) { if (!consumeFront(MangledName, ".?A")) { Error = true; return nullptr; @@ -868,8 +873,9 @@ // ::= 3 # global // ::= 4 # static local -VariableSymbolNode *Demangler::demangleVariableEncoding(StringView &MangledName, - StorageClass SC) { +VariableSymbolNode * +Demangler::demangleVariableEncoding(std::string_view &MangledName, + StorageClass SC) { VariableSymbolNode *VSN = Arena.alloc(); VSN->Type = demangleType(MangledName, QualifierMangleMode::Drop); @@ -919,7 +925,8 @@ // ::= + @ # when Number == 0 or >= 10 // // ::= [A-P] # A = 0, B = 1, ... -std::pair Demangler::demangleNumber(StringView &MangledName) { +std::pair +Demangler::demangleNumber(std::string_view &MangledName) { bool IsNegative = consumeFront(MangledName, '?'); if (startsWithDigit(MangledName)) { @@ -946,7 +953,7 @@ return {0ULL, false}; } -uint64_t Demangler::demangleUnsigned(StringView &MangledName) { +uint64_t Demangler::demangleUnsigned(std::string_view &MangledName) { bool IsNegative = false; uint64_t Number = 0; std::tie(Number, IsNegative) = demangleNumber(MangledName); @@ -955,7 +962,7 @@ return Number; } -int64_t Demangler::demangleSigned(StringView &MangledName) { +int64_t Demangler::demangleSigned(std::string_view &MangledName) { bool IsNegative = false; uint64_t Number = 0; std::tie(Number, IsNegative) = demangleNumber(MangledName); @@ -967,7 +974,7 @@ // First 10 strings can be referenced by special BackReferences ?0, ?1, ..., ?9. // Memorize it. -void Demangler::memorizeString(StringView S) { +void Demangler::memorizeString(std::string_view S) { if (Backrefs.NamesCount >= BackrefContext::Max) return; for (size_t i = 0; i < Backrefs.NamesCount; ++i) @@ -978,7 +985,8 @@ Backrefs.Names[Backrefs.NamesCount++] = N; } -NamedIdentifierNode *Demangler::demangleBackRefName(StringView &MangledName) { +NamedIdentifierNode * +Demangler::demangleBackRefName(std::string_view &MangledName) { assert(startsWithDigit(MangledName)); size_t I = MangledName[0] - '0'; @@ -996,15 +1004,15 @@ // memorize it for the purpose of back-referencing. OutputBuffer OB; Identifier->output(OB, OF_Default); - StringView Owned = copyString(OB); + std::string_view Owned = copyString(OB); memorizeString(Owned); std::free(OB.getBuffer()); } IdentifierNode * -Demangler::demangleTemplateInstantiationName(StringView &MangledName, +Demangler::demangleTemplateInstantiationName(std::string_view &MangledName, NameBackrefBehavior NBB) { - assert(MangledName.startsWith("?$")); + assert(llvm::starts_with(MangledName, "?$")); consumeFront(MangledName, "?$"); BackrefContext OuterContext; @@ -1035,9 +1043,9 @@ return Identifier; } -NamedIdentifierNode *Demangler::demangleSimpleName(StringView &MangledName, +NamedIdentifierNode *Demangler::demangleSimpleName(std::string_view &MangledName, bool Memorize) { - StringView S = demangleSimpleString(MangledName, Memorize); + std::string_view S = demangleSimpleString(MangledName, Memorize); if (Error) return nullptr; @@ -1053,9 +1061,9 @@ return (C <= 'J') ? (C - 'A') : (10 + C - 'K'); } -uint8_t Demangler::demangleCharLiteral(StringView &MangledName) { +uint8_t Demangler::demangleCharLiteral(std::string_view &MangledName) { assert(!MangledName.empty()); - if (!MangledName.startsWith('?')) { + if (!llvm::starts_with(MangledName, '?')) { const uint8_t F = MangledName.front(); MangledName.remove_prefix(1); return F; @@ -1069,7 +1077,7 @@ // Two hex digits if (MangledName.size() < 2) goto CharLiteralError; - StringView Nibbles = MangledName.substr(0, 2); + std::string_view Nibbles = MangledName.substr(0, 2); if (!isRebasedHexDigit(Nibbles[0]) || !isRebasedHexDigit(Nibbles[1])) goto CharLiteralError; // Don't append the null terminator. @@ -1111,7 +1119,7 @@ return '\0'; } -wchar_t Demangler::demangleWcharLiteral(StringView &MangledName) { +wchar_t Demangler::demangleWcharLiteral(std::string_view &MangledName) { uint8_t C1, C2; C1 = demangleCharLiteral(MangledName); @@ -1156,7 +1164,7 @@ TempBuffer[Pos--] = 'x'; assert(Pos >= 0); TempBuffer[Pos--] = '\\'; - OB << StringView(&TempBuffer[Pos + 1]); + OB << std::string_view(&TempBuffer[Pos + 1]); } static void outputEscapedChar(OutputBuffer &OB, unsigned C) { @@ -1278,7 +1286,8 @@ return Result; } -FunctionSymbolNode *Demangler::demangleVcallThunkNode(StringView &MangledName) { +FunctionSymbolNode * +Demangler::demangleVcallThunkNode(std::string_view &MangledName) { FunctionSymbolNode *FSN = Arena.alloc(); VcallThunkIdentifierNode *VTIN = Arena.alloc(); FSN->Signature = Arena.alloc(); @@ -1297,10 +1306,10 @@ } EncodedStringLiteralNode * -Demangler::demangleStringLiteral(StringView &MangledName) { +Demangler::demangleStringLiteral(std::string_view &MangledName) { // This function uses goto, so declare all variables up front. OutputBuffer OB; - StringView CRC; + std::string_view CRC; uint64_t StringByteSize; bool IsWcharT = false; bool IsNegative = false; @@ -1335,7 +1344,7 @@ // CRC 32 (always 8 characters plus a terminator) CrcEndPos = MangledName.find('@'); - if (CrcEndPos == StringView::npos) + if (CrcEndPos == std::string_view::npos) goto StringLiteralError; CRC = MangledName.substr(0, CrcEndPos); MangledName.remove_prefix(CrcEndPos + 1); @@ -1410,9 +1419,9 @@ // Returns MangledName's prefix before the first '@', or an error if // MangledName contains no '@' or the prefix has length 0. -StringView Demangler::demangleSimpleString(StringView &MangledName, - bool Memorize) { - StringView S; +std::string_view Demangler::demangleSimpleString(std::string_view &MangledName, + bool Memorize) { + std::string_view S; for (size_t i = 0; i < MangledName.size(); ++i) { if (MangledName[i] != '@') continue; @@ -1431,25 +1440,25 @@ } NamedIdentifierNode * -Demangler::demangleAnonymousNamespaceName(StringView &MangledName) { - assert(MangledName.startsWith("?A")); +Demangler::demangleAnonymousNamespaceName(std::string_view &MangledName) { + assert(llvm::starts_with(MangledName, "?A")); consumeFront(MangledName, "?A"); NamedIdentifierNode *Node = Arena.alloc(); Node->Name = "`anonymous namespace'"; size_t EndPos = MangledName.find('@'); - if (EndPos == StringView::npos) { + if (EndPos == std::string_view::npos) { Error = true; return nullptr; } - StringView NamespaceKey = MangledName.substr(0, EndPos); + std::string_view NamespaceKey = MangledName.substr(0, EndPos); memorizeString(NamespaceKey); MangledName = MangledName.substr(EndPos + 1); return Node; } NamedIdentifierNode * -Demangler::demangleLocallyScopedNamePiece(StringView &MangledName) { +Demangler::demangleLocallyScopedNamePiece(std::string_view &MangledName) { assert(startsWithLocalScopePattern(MangledName)); NamedIdentifierNode *Identifier = Arena.alloc(); @@ -1481,7 +1490,7 @@ // Parses a type name in the form of A@B@C@@ which represents C::B::A. QualifiedNameNode * -Demangler::demangleFullyQualifiedTypeName(StringView &MangledName) { +Demangler::demangleFullyQualifiedTypeName(std::string_view &MangledName) { IdentifierNode *Identifier = demangleUnqualifiedTypeName(MangledName, /*Memorize=*/true); if (Error) @@ -1499,7 +1508,7 @@ // Symbol names have slightly different rules regarding what can appear // so we separate out the implementations for flexibility. QualifiedNameNode * -Demangler::demangleFullyQualifiedSymbolName(StringView &MangledName) { +Demangler::demangleFullyQualifiedSymbolName(std::string_view &MangledName) { // This is the final component of a symbol name (i.e. the leftmost component // of a mangled name. Since the only possible template instantiation that // can appear in this context is a function template, and since those are @@ -1528,8 +1537,9 @@ return QN; } -IdentifierNode *Demangler::demangleUnqualifiedTypeName(StringView &MangledName, - bool Memorize) { +IdentifierNode * +Demangler::demangleUnqualifiedTypeName(std::string_view &MangledName, + bool Memorize) { // An inner-most name can be a back-reference, because a fully-qualified name // (e.g. Scope + Inner) can contain other fully qualified names inside of // them (for example template parameters), and these nested parameters can @@ -1537,32 +1547,33 @@ if (startsWithDigit(MangledName)) return demangleBackRefName(MangledName); - if (MangledName.startsWith("?$")) + if (llvm::starts_with(MangledName, "?$")) return demangleTemplateInstantiationName(MangledName, NBB_Template); return demangleSimpleName(MangledName, Memorize); } IdentifierNode * -Demangler::demangleUnqualifiedSymbolName(StringView &MangledName, +Demangler::demangleUnqualifiedSymbolName(std::string_view &MangledName, NameBackrefBehavior NBB) { if (startsWithDigit(MangledName)) return demangleBackRefName(MangledName); - if (MangledName.startsWith("?$")) + if (llvm::starts_with(MangledName, "?$")) return demangleTemplateInstantiationName(MangledName, NBB); - if (MangledName.startsWith('?')) + if (llvm::starts_with(MangledName, '?')) return demangleFunctionIdentifierCode(MangledName); return demangleSimpleName(MangledName, /*Memorize=*/(NBB & NBB_Simple) != 0); } -IdentifierNode *Demangler::demangleNameScopePiece(StringView &MangledName) { +IdentifierNode * +Demangler::demangleNameScopePiece(std::string_view &MangledName) { if (startsWithDigit(MangledName)) return demangleBackRefName(MangledName); - if (MangledName.startsWith("?$")) + if (llvm::starts_with(MangledName, "?$")) return demangleTemplateInstantiationName(MangledName, NBB_Template); - if (MangledName.startsWith("?A")) + if (llvm::starts_with(MangledName, "?A")) return demangleAnonymousNamespaceName(MangledName); if (startsWithLocalScopePattern(MangledName)) @@ -1584,7 +1595,7 @@ } QualifiedNameNode * -Demangler::demangleNameScopeChain(StringView &MangledName, +Demangler::demangleNameScopeChain(std::string_view &MangledName, IdentifierNode *UnqualifiedName) { NodeList *Head = Arena.alloc(); @@ -1615,7 +1626,7 @@ return QN; } -FuncClass Demangler::demangleFunctionClass(StringView &MangledName) { +FuncClass Demangler::demangleFunctionClass(std::string_view &MangledName) { const char F = MangledName.front(); MangledName.remove_prefix(1); switch (F) { @@ -1702,7 +1713,7 @@ return FC_Public; } -CallingConv Demangler::demangleCallingConvention(StringView &MangledName) { +CallingConv Demangler::demangleCallingConvention(std::string_view &MangledName) { if (MangledName.empty()) { Error = true; return CallingConv::None; @@ -1743,7 +1754,8 @@ return CallingConv::None; } -StorageClass Demangler::demangleVariableStorageClass(StringView &MangledName) { +StorageClass +Demangler::demangleVariableStorageClass(std::string_view &MangledName) { assert(MangledName.front() >= '0' && MangledName.front() <= '4'); const char F = MangledName.front(); @@ -1764,7 +1776,7 @@ } std::pair -Demangler::demangleQualifiers(StringView &MangledName) { +Demangler::demangleQualifiers(std::string_view &MangledName) { if (MangledName.empty()) { Error = true; return std::make_pair(Q_None, false); @@ -1798,7 +1810,7 @@ // ::= // ::= # pointers, references -TypeNode *Demangler::demangleType(StringView &MangledName, +TypeNode *Demangler::demangleType(std::string_view &MangledName, QualifierMangleMode QMM) { Qualifiers Quals = Q_None; bool IsMember = false; @@ -1830,7 +1842,7 @@ if (consumeFront(MangledName, "$$A8@@")) Ty = demangleFunctionType(MangledName, true); else { - assert(MangledName.startsWith("$$A6")); + assert(llvm::starts_with(MangledName, "$$A6")); consumeFront(MangledName, "$$A6"); Ty = demangleFunctionType(MangledName, false); } @@ -1846,7 +1858,7 @@ return Ty; } -bool Demangler::demangleThrowSpecification(StringView &MangledName) { +bool Demangler::demangleThrowSpecification(std::string_view &MangledName) { if (consumeFront(MangledName, "_E")) return true; if (consumeFront(MangledName, 'Z')) @@ -1856,8 +1868,9 @@ return false; } -FunctionSignatureNode *Demangler::demangleFunctionType(StringView &MangledName, - bool HasThisQuals) { +FunctionSignatureNode * +Demangler::demangleFunctionType(std::string_view &MangledName, + bool HasThisQuals) { FunctionSignatureNode *FTy = Arena.alloc(); if (HasThisQuals) { @@ -1883,7 +1896,7 @@ } FunctionSymbolNode * -Demangler::demangleFunctionEncoding(StringView &MangledName) { +Demangler::demangleFunctionEncoding(std::string_view &MangledName) { FuncClass ExtraFlags = FC_None; if (consumeFront(MangledName, "$$J0")) ExtraFlags = FC_ExternC; @@ -1935,8 +1948,8 @@ return Symbol; } -CustomTypeNode *Demangler::demangleCustomType(StringView &MangledName) { - assert(MangledName.startsWith('?')); +CustomTypeNode *Demangler::demangleCustomType(std::string_view &MangledName) { + assert(llvm::starts_with(MangledName, '?')); MangledName.remove_prefix(1); CustomTypeNode *CTN = Arena.alloc(); @@ -1949,7 +1962,8 @@ } // Reads a primitive type. -PrimitiveTypeNode *Demangler::demanglePrimitiveType(StringView &MangledName) { +PrimitiveTypeNode * +Demangler::demanglePrimitiveType(std::string_view &MangledName) { if (consumeFront(MangledName, "$$T")) return Arena.alloc(PrimitiveKind::Nullptr); @@ -2012,7 +2026,7 @@ return nullptr; } -TagTypeNode *Demangler::demangleClassType(StringView &MangledName) { +TagTypeNode *Demangler::demangleClassType(std::string_view &MangledName) { TagTypeNode *TT = nullptr; const char F = MangledName.front(); @@ -2044,7 +2058,7 @@ // ::= E? // # the E is required for 64-bit non-static pointers -PointerTypeNode *Demangler::demanglePointerType(StringView &MangledName) { +PointerTypeNode *Demangler::demanglePointerType(std::string_view &MangledName) { PointerTypeNode *Pointer = Arena.alloc(); std::tie(Pointer->Quals, Pointer->Affinity) = @@ -2062,7 +2076,8 @@ return Pointer; } -PointerTypeNode *Demangler::demangleMemberPointerType(StringView &MangledName) { +PointerTypeNode * +Demangler::demangleMemberPointerType(std::string_view &MangledName) { PointerTypeNode *Pointer = Arena.alloc(); std::tie(Pointer->Quals, Pointer->Affinity) = @@ -2092,7 +2107,8 @@ return Pointer; } -Qualifiers Demangler::demanglePointerExtQualifiers(StringView &MangledName) { +Qualifiers +Demangler::demanglePointerExtQualifiers(std::string_view &MangledName) { Qualifiers Quals = Q_None; if (consumeFront(MangledName, 'E')) Quals = Qualifiers(Quals | Q_Pointer64); @@ -2104,7 +2120,7 @@ return Quals; } -ArrayTypeNode *Demangler::demangleArrayType(StringView &MangledName) { +ArrayTypeNode *Demangler::demangleArrayType(std::string_view &MangledName) { assert(MangledName.front() == 'Y'); MangledName.remove_prefix(1); @@ -2149,8 +2165,9 @@ } // Reads a function's parameters. -NodeArrayNode *Demangler::demangleFunctionParameterList(StringView &MangledName, - bool &IsVariadic) { +NodeArrayNode * +Demangler::demangleFunctionParameterList(std::string_view &MangledName, + bool &IsVariadic) { // Empty parameter list. if (consumeFront(MangledName, 'X')) return nullptr; @@ -2158,8 +2175,8 @@ NodeList *Head = Arena.alloc(); NodeList **Current = &Head; size_t Count = 0; - while (!Error && !MangledName.startsWith('@') && - !MangledName.startsWith('Z')) { + while (!Error && !llvm::starts_with(MangledName, '@') && + !llvm::starts_with(MangledName, 'Z')) { ++Count; if (startsWithDigit(MangledName)) { @@ -2215,12 +2232,12 @@ } NodeArrayNode * -Demangler::demangleTemplateParameterList(StringView &MangledName) { +Demangler::demangleTemplateParameterList(std::string_view &MangledName) { NodeList *Head = nullptr; NodeList **Current = &Head; size_t Count = 0; - while (!MangledName.startsWith('@')) { + while (!llvm::starts_with(MangledName, '@')) { if (consumeFront(MangledName, "$S") || consumeFront(MangledName, "$$V") || consumeFront(MangledName, "$$$V") || consumeFront(MangledName, "$$Z")) { // parameter pack separator @@ -2244,8 +2261,10 @@ } else if (consumeFront(MangledName, "$$C")) { // Type has qualifiers. TP.N = demangleType(MangledName, QualifierMangleMode::Mangle); - } else if (MangledName.startsWith("$1") || MangledName.startsWith("$H") || - MangledName.startsWith("$I") || MangledName.startsWith("$J")) { + } else if (llvm::starts_with(MangledName, "$1") || + llvm::starts_with(MangledName, "$H") || + llvm::starts_with(MangledName, "$I") || + llvm::starts_with(MangledName, "$J")) { // Pointer to member TP.N = TPRN = Arena.alloc(); TPRN->IsMemberPointer = true; @@ -2258,7 +2277,7 @@ char InheritanceSpecifier = MangledName.front(); MangledName.remove_prefix(1); SymbolNode *S = nullptr; - if (MangledName.startsWith('?')) { + if (llvm::starts_with(MangledName, '?')) { S = parse(MangledName); if (Error || !S->Name) { Error = true; @@ -2287,13 +2306,14 @@ } TPRN->Affinity = PointerAffinity::Pointer; TPRN->Symbol = S; - } else if (MangledName.startsWith("$E?")) { + } else if (llvm::starts_with(MangledName, "$E?")) { consumeFront(MangledName, "$E"); // Reference to symbol TP.N = TPRN = Arena.alloc(); TPRN->Symbol = parse(MangledName); TPRN->Affinity = PointerAffinity::Reference; - } else if (MangledName.startsWith("$F") || MangledName.startsWith("$G")) { + } else if (llvm::starts_with(MangledName, "$F") || + llvm::starts_with(MangledName, "$G")) { TP.N = TPRN = Arena.alloc(); // Data member pointer. @@ -2338,7 +2358,8 @@ // Template parameter lists cannot be variadic, so it can only be terminated // by @ (as opposed to 'Z' in the function parameter case). - assert(MangledName.startsWith('@')); // The above loop exits only on '@'. + assert( + llvm::starts_with(MangledName, '@')); // The above loop exits only on '@'. consumeFront(MangledName, '@'); return nodeListToNodeArray(Arena, Head, Count); } @@ -2355,8 +2376,8 @@ TypeNode *T = Backrefs.FunctionParams[I]; T->output(OB, OF_Default); - StringView B = OB; - std::printf(" [%d] - %.*s\n", (int)I, (int)B.size(), B.begin()); + std::string_view B = OB; + std::printf(" [%d] - %.*s\n", (int)I, (int)B.size(), &*B.begin()); } std::free(OB.getBuffer()); @@ -2365,7 +2386,7 @@ std::printf("%d name backreferences\n", (int)Backrefs.NamesCount); for (size_t I = 0; I < Backrefs.NamesCount; ++I) { std::printf(" [%d] - %.*s\n", (int)I, (int)Backrefs.Names[I]->Name.size(), - Backrefs.Names[I]->Name.begin()); + &*Backrefs.Names[I]->Name.begin()); } if (Backrefs.NamesCount > 0) std::printf("\n"); @@ -2376,10 +2397,10 @@ int *Status, MSDemangleFlags Flags) { Demangler D; - StringView Name{MangledName}; + std::string_view Name{MangledName}; SymbolNode *AST = D.parse(Name); if (!D.Error && NMangled) - *NMangled = Name.begin() - MangledName; + *NMangled = &*Name.begin() - MangledName; if (Flags & MSDF_DumpBackrefs) D.dumpBackReferences(); Index: llvm/lib/Demangle/MicrosoftDemangleNodes.cpp =================================================================== --- llvm/lib/Demangle/MicrosoftDemangleNodes.cpp +++ llvm/lib/Demangle/MicrosoftDemangleNodes.cpp @@ -120,7 +120,7 @@ std::string Node::toString(OutputFlags Flags) const { OutputBuffer OB; this->output(OB, Flags); - StringView SV = OB; + std::string_view SV = OB; std::string Owned(SV.begin(), SV.end()); std::free(OB.getBuffer()); return Owned; @@ -158,7 +158,7 @@ } void NodeArrayNode::output(OutputBuffer &OB, OutputFlags Flags, - StringView Separator) const { + std::string_view Separator) const { if (Count == 0) return; if (Nodes[0]) Index: llvm/lib/Demangle/RustDemangle.cpp =================================================================== --- llvm/lib/Demangle/RustDemangle.cpp +++ llvm/lib/Demangle/RustDemangle.cpp @@ -11,8 +11,8 @@ // //===----------------------------------------------------------------------===// +#include "llvm/ADT/StringViewExtras.h" #include "llvm/Demangle/Demangle.h" -#include "llvm/Demangle/StringView.h" #include "llvm/Demangle/Utility.h" #include @@ -25,12 +25,11 @@ using llvm::itanium_demangle::OutputBuffer; using llvm::itanium_demangle::ScopedOverride; -using llvm::itanium_demangle::StringView; namespace { struct Identifier { - StringView Name; + std::string_view Name; bool Punycode; bool empty() const { return Name.empty(); } @@ -77,7 +76,7 @@ size_t RecursionLevel; size_t BoundLifetimes; // Input string that is being demangled with "_R" prefix removed. - StringView Input; + std::string_view Input; // Position in the input string. size_t Position; // When true, print methods append the output to the stream. @@ -92,7 +91,7 @@ Demangler(size_t MaxRecursionLevel = 500); - bool demangle(StringView MangledName); + bool demangle(std::string_view MangledName); private: bool demanglePath(IsInType Type, @@ -128,10 +127,10 @@ uint64_t parseOptionalBase62Number(char Tag); uint64_t parseBase62Number(); uint64_t parseDecimalNumber(); - uint64_t parseHexNumber(StringView &HexDigits); + uint64_t parseHexNumber(std::string_view &HexDigits); void print(char C); - void print(StringView S); + void print(std::string_view S); void printDecimalNumber(uint64_t N); void printBasicType(BasicType); void printLifetime(uint64_t Index); @@ -152,8 +151,8 @@ return nullptr; // Return early if mangled name doesn't look like a Rust symbol. - StringView Mangled(MangledName); - if (!Mangled.startsWith("_R")) + std::string_view Mangled(MangledName); + if (!llvm::starts_with(Mangled, "_R")) return nullptr; Demangler D; @@ -190,20 +189,20 @@ // responsibility of the caller to free the memory behind the output stream. // // = "_R" [] -bool Demangler::demangle(StringView Mangled) { +bool Demangler::demangle(std::string_view Mangled) { Position = 0; Error = false; Print = true; RecursionLevel = 0; BoundLifetimes = 0; - if (!Mangled.startsWith("_R")) { + if (!llvm::starts_with(Mangled, "_R")) { Error = true; return false; } Mangled.remove_prefix(2); size_t Dot = Mangled.find('.'); - Input = Dot == StringView::npos ? Mangled : Mangled.substr(0, Dot); + Input = Dot == std::string_view::npos ? Mangled : Mangled.substr(0, Dot); demanglePath(IsInType::No); @@ -215,7 +214,7 @@ if (Position != Input.size()) Error = true; - if (Dot != StringView::npos) { + if (Dot != std::string_view::npos) { print(" ("); print(Mangled.substr(Dot)); print(")"); @@ -775,7 +774,7 @@ if (consumeIf('n')) print('-'); - StringView HexDigits; + std::string_view HexDigits; uint64_t Value = parseHexNumber(HexDigits); if (HexDigits.size() <= 16) { printDecimalNumber(Value); @@ -788,7 +787,7 @@ // = "0_" // false // | "1_" // true void Demangler::demangleConstBool() { - StringView HexDigits; + std::string_view HexDigits; parseHexNumber(HexDigits); if (HexDigits == "0") print("false"); @@ -805,7 +804,7 @@ // = void Demangler::demangleConstChar() { - StringView HexDigits; + std::string_view HexDigits; uint64_t CodePoint = parseHexNumber(HexDigits); if (Error || HexDigits.size() > 6) { Error = true; @@ -859,7 +858,7 @@ Error = true; return {}; } - StringView S = Input.substr(Position, Bytes); + std::string_view S = Input.substr(Position, Bytes); Position += Bytes; if (!std::all_of(S.begin(), S.end(), isValid)) { @@ -967,7 +966,7 @@ // // = "0_" // | <1-9a-f> {<0-9a-f>} "_" -uint64_t Demangler::parseHexNumber(StringView &HexDigits) { +uint64_t Demangler::parseHexNumber(std::string_view &HexDigits) { size_t Start = Position; uint64_t Value = 0; @@ -991,7 +990,7 @@ } if (Error) { - HexDigits = StringView(); + HexDigits = std::string_view(); return 0; } @@ -1008,7 +1007,7 @@ Output += C; } -void Demangler::print(StringView S) { +void Demangler::print(std::string_view S) { if (Error || !Print) return; @@ -1105,17 +1104,17 @@ // Decodes string encoded using punycode and appends results to Output. // Returns true if decoding was successful. -static bool decodePunycode(StringView Input, OutputBuffer &Output) { +static bool decodePunycode(std::string_view Input, OutputBuffer &Output) { size_t OutputSize = Output.getCurrentPosition(); size_t InputIdx = 0; // Rust uses an underscore as a delimiter. - size_t DelimiterPos = StringView::npos; + size_t DelimiterPos = std::string_view::npos; for (size_t I = 0; I != Input.size(); ++I) if (Input[I] == '_') DelimiterPos = I; - if (DelimiterPos != StringView::npos) { + if (DelimiterPos != std::string_view::npos) { // Copy basic code points before the last delimiter to the output. for (; InputIdx != DelimiterPos; ++InputIdx) { char C = Input[InputIdx]; @@ -1123,7 +1122,7 @@ return false; // Code points are padded with zeros while decoding is in progress. char UTF8[4] = {C}; - Output += StringView(UTF8, 4); + Output += std::string_view(UTF8, 4); } // Skip over the delimiter. ++InputIdx; Index: llvm/lib/ProfileData/ItaniumManglingCanonicalizer.cpp =================================================================== --- llvm/lib/ProfileData/ItaniumManglingCanonicalizer.cpp +++ llvm/lib/ProfileData/ItaniumManglingCanonicalizer.cpp @@ -17,13 +17,12 @@ using llvm::itanium_demangle::ForwardTemplateReference; using llvm::itanium_demangle::Node; using llvm::itanium_demangle::NodeKind; -using llvm::itanium_demangle::StringView; namespace { struct FoldingSetNodeIDBuilder { llvm::FoldingSetNodeID &ID; void operator()(const Node *P) { ID.AddPointer(P); } - void operator()(StringView Str) { + void operator()(std::string_view Str) { ID.AddString(llvm::StringRef(Str.begin(), Str.size())); } template @@ -292,7 +291,7 @@ N = Demangler.parse(); else N = Demangler.make( - StringView(Mangling.data(), Mangling.size())); + std::string_view(Mangling.data(), Mangling.size())); return reinterpret_cast(N); } Index: llvm/unittests/Demangle/ItaniumDemangleTest.cpp =================================================================== --- llvm/unittests/Demangle/ItaniumDemangleTest.cpp +++ llvm/unittests/Demangle/ItaniumDemangleTest.cpp @@ -11,6 +11,7 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" #include +#include #include using namespace llvm; @@ -83,7 +84,7 @@ } static std::string toString(OutputBuffer &OB) { - StringView SV = OB; + std::string_view SV = OB; return {SV.begin(), SV.end()}; } @@ -98,7 +99,7 @@ OutputBuffer OB; Node *N = AbstractManglingParser::parseType(); N->printLeft(OB); - StringView Name = N->getBaseName(); + std::string_view Name = N->getBaseName(); if (!Name.empty()) Types.push_back(std::string(Name.begin(), Name.end())); else Index: llvm/unittests/Demangle/OutputBufferTest.cpp =================================================================== --- llvm/unittests/Demangle/OutputBufferTest.cpp +++ llvm/unittests/Demangle/OutputBufferTest.cpp @@ -10,12 +10,13 @@ #include "llvm/Demangle/Utility.h" #include "gtest/gtest.h" #include +#include using namespace llvm; using llvm::itanium_demangle::OutputBuffer; static std::string toString(OutputBuffer &OB) { - StringView SV = OB; + std::string_view SV = OB; return {SV.begin(), SV.end()}; }