diff --git a/libcxxabi/src/cxa_demangle.cpp b/libcxxabi/src/cxa_demangle.cpp --- a/libcxxabi/src/cxa_demangle.cpp +++ b/libcxxabi/src/cxa_demangle.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include using namespace itanium_demangle; @@ -78,8 +79,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) diff --git a/libcxxabi/src/demangle/ItaniumDemangle.h b/libcxxabi/src/demangle/ItaniumDemangle.h --- a/libcxxabi/src/demangle/ItaniumDemangle.h +++ b/libcxxabi/src/demangle/ItaniumDemangle.h @@ -17,7 +17,7 @@ #define DEMANGLE_ITANIUMDEMANGLE_H #include "DemangleConfig.h" -#include "StringView.h" +#include "StringViewExtras.h" #include "Utility.h" #include <__cxxabi_config.h> #include @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -293,7 +294,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; @@ -352,10 +353,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); } @@ -370,15 +371,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); } @@ -469,10 +470,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); } @@ -484,15 +485,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; } }; @@ -518,10 +519,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); } @@ -535,16 +536,16 @@ struct AbiTagAttr : Node { Node *Base; - StringView Tag; + std::string_view Tag; - AbiTagAttr(Node* Base_, StringView Tag_) - : Node(KAbiTagAttr, Base_->RHSComponentCache, - Base_->ArrayCache, Base_->FunctionCache), + 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); @@ -571,12 +572,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); } @@ -953,11 +954,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); } @@ -996,7 +997,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); @@ -1036,7 +1037,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); @@ -1072,7 +1073,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); @@ -1494,7 +1495,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); @@ -1511,7 +1512,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 += "::"; @@ -1547,20 +1548,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; } @@ -1584,12 +1585,12 @@ 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_")); - SV = SV.dropFront(sizeof("basic_") - 1); + assert(starts_with(SV, "basic_")); + SV.remove_prefix(sizeof("basic_") - 1); } return SV; } @@ -1637,10 +1638,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); } @@ -1654,11 +1656,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_) {} @@ -1705,12 +1707,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_) {} @@ -1759,10 +1761,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 { @@ -1800,11 +1802,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 { @@ -1821,13 +1824,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_) {} @@ -1844,7 +1848,7 @@ OB += "0"; } else if (Offset[0] == 'n') { OB += "-"; - OB += Offset.dropFront(); + OB += std::string_view(Offset.data() + 1, Offset.size() - 1); } else { OB += Offset; } @@ -1853,12 +1857,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_) {} @@ -1877,12 +1881,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 { @@ -2005,11 +2010,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 { @@ -2023,10 +2028,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); } @@ -2061,11 +2067,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_) {} @@ -2150,11 +2156,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_) {} @@ -2218,7 +2224,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"); } }; @@ -2256,10 +2262,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); } @@ -2270,18 +2276,18 @@ OB.printClose(); if (Integer[0] == 'n') - OB << "-" << Integer.dropFront(1); + OB << '-' << std::string_view(Integer.data() + 1, Integer.size() - 1); else OB << Integer; } }; 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); } @@ -2293,10 +2299,9 @@ OB.printClose(); } - if (Value[0] == 'n') { - OB += '-'; - OB += Value.dropFront(1); - } else + if (Value[0] == 'n') + OB << '-' << std::string_view(Value.data() + 1, Value.size() - 1); + else OB += Value; if (Type.size() <= 3) @@ -2319,29 +2324,26 @@ } 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 size_t N = FloatData::mangled_size; - if (static_cast(last - first) > N) { - last = first + N; + if (Contents.size() >= N) { union { Float value; char buf[sizeof(Float)]; }; - const char *t = first; + const char *t = &*Contents.begin(); + const char *last = t + N; char *e = buf; for (; t != last; ++t, ++e) { unsigned d1 = isdigit(*t) ? static_cast(*t - '0') @@ -2356,7 +2358,7 @@ #endif char num[FloatData::max_demangled_size] = {0}; int n = snprintf(num, sizeof(num), FloatData::spec, value); - OB += StringView(num, num + n); + OB += std::string_view(num, n); } } }; @@ -2483,8 +2485,8 @@ return res; } - bool consumeIf(StringView S) { - if (StringView(First, Last).startsWith(S)) { + bool consumeIf(std::string_view S) { + if (starts_with(std::string_view(First, Last - First), S)) { First += S.size(); return true; } @@ -2509,10 +2511,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(); @@ -2523,9 +2525,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(); @@ -2633,17 +2635,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(starts_with(Res, "operator") && "operator name does not start with 'operator'"); - Res = Res.dropFront(sizeof("operator") - 1); - Res.consumeFront(' '); + Res.remove_prefix(sizeof("operator") - 1); + if (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; } @@ -2863,7 +2866,7 @@ TemplateParams.clear(); if (consumeIf("Ut")) { - StringView Count = parseNumber(); + std::string_view Count = parseNumber(); if (!consumeIf('_')) return nullptr; return make(Count); @@ -2875,7 +2878,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; @@ -2918,7 +2921,7 @@ } NodeArray Params = popTrailingNodeArray(ParamsBegin); - StringView Count = parseNumber(); + std::string_view Count = parseNumber(); if (!consumeIf('_')) return nullptr; return make(TempParams, Params, Count); @@ -2940,9 +2943,9 @@ return nullptr; if (numLeft() < Length || Length == 0) return nullptr; - StringView Name(First, First + Length); + std::string_view Name(First, Length); First += Length; - if (Name.startsWith("_GLOBAL__N")) + if (starts_with(Name, "_GLOBAL__N")) return make("(anonymous namespace)"); return make(Name); } @@ -3456,7 +3459,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); @@ -3468,16 +3471,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); + return std::string_view(Tmp, First - Tmp); } // ::= [0-9]* @@ -3494,11 +3497,11 @@ } template -StringView AbstractManglingParser::parseBareSourceName() { +std::string_view AbstractManglingParser::parseBareSourceName() { size_t Int = 0; if (parsePositiveInteger(&Int) || numLeft() < Int) - return StringView(); - StringView R(First, First + Int); + return {}; + std::string_view R(First, Int); First += Int; return R; } @@ -3682,7 +3685,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")) @@ -3706,17 +3709,18 @@ 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.dropFront(std::strlen("objcproto")); - StringView Proto; + if (starts_with(Qual, "objcproto")) { + constexpr size_t Len = sizeof("objcproto") - 1; + std::string_view ProtoSourceName(Qual.data() + Len, Qual.size() - Len); + std::string_view Proto; { - ScopedOverride SaveFirst(First, ProtoSourceName.begin()), - SaveLast(Last, ProtoSourceName.end()); + ScopedOverride SaveFirst(First, &*ProtoSourceName.begin()), + SaveLast(Last, &*ProtoSourceName.rbegin() + 1); Proto = parseBareSourceName(); } if (Proto.empty()) @@ -3884,7 +3888,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, @@ -4132,8 +4136,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; @@ -4141,8 +4146,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; @@ -4153,9 +4159,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; @@ -4185,7 +4191,7 @@ return make("this"); if (consumeIf("fp")) { parseCVQualifiers(); - StringView Num = parseNumber(); + std::string_view Num = parseNumber(); if (!consumeIf('_')) return nullptr; return make(Num); @@ -4196,7 +4202,7 @@ if (!consumeIf('p')) return nullptr; parseCVQualifiers(); - StringView Num = parseNumber(); + std::string_view Num = parseNumber(); if (!consumeIf('_')) return nullptr; return make(Num); @@ -4350,7 +4356,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')) @@ -4473,7 +4479,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); @@ -4491,7 +4497,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()); @@ -5150,7 +5156,7 @@ const size_t N = FloatData::mangled_size; if (numLeft() <= N) return nullptr; - StringView Data(First, First + N); + std::string_view Data(First, N); for (char C : Data) if (!std::isxdigit(C)) return nullptr; @@ -5470,7 +5476,8 @@ if (Encoding == nullptr) return nullptr; if (look() == '.') { - Encoding = make(Encoding, StringView(First, Last)); + Encoding = + make(Encoding, std::string_view(First, Last - First)); First = Last; } if (numLeft() != 0) diff --git a/libcxxabi/src/demangle/StringView.h b/libcxxabi/src/demangle/StringView.h --- a/libcxxabi/src/demangle/StringView.h +++ b/libcxxabi/src/demangle/StringView.h @@ -38,8 +38,6 @@ template StringView(const char (&Str)[N]) : First(Str), Last(Str + N - 1) {} - StringView(const char *First_, const char *Last_) - : First(First_), Last(Last_) {} StringView(const char *First_, size_t Len) : First(First_), Last(First_ + Len) {} StringView(const char *Str) : First(Str), Last(Str + std::strlen(Str)) {} @@ -62,16 +60,13 @@ return npos; } - StringView dropFront(size_t N = 1) const { - if (N >= size()) - N = size(); - return StringView(First + N, Last); + void remove_prefix(size_t N) { + assert(size() >= N); + First += N; } - - StringView dropBack(size_t N = 1) const { - if (N >= size()) - N = size(); - return StringView(First, Last - N); + void remove_suffix(size_t N) { + assert(size() >= N); + Last -= N; } char front() const { @@ -84,25 +79,6 @@ return *(end() - 1); } - char popFront() { - assert(!empty()); - return *First++; - } - - bool consumeFront(char C) { - if (!startsWith(C)) - return false; - *this = dropFront(1); - return true; - } - - bool consumeFront(StringView S) { - if (!startsWith(S)) - return false; - *this = dropFront(S.size()); - return true; - } - bool startsWith(char C) const { return !empty() && *begin() == C; } bool startsWith(StringView Str) const { diff --git a/libcxxabi/src/demangle/Utility.h b/libcxxabi/src/demangle/Utility.h --- a/libcxxabi/src/demangle/Utility.h +++ b/libcxxabi/src/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())); + 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); }