#include "llvm/DebugInfo/PDB/Native/TpiStream.h"
#include "llvm/Demangle/MicrosoftDemangle.h"
+#include "PdbUtil.h"
#include "Plugins/ExpressionParser/Clang/ClangASTMetadata.h"
#include "Plugins/ExpressionParser/Clang/ClangUtil.h"
#include "Plugins/Language/CPlusPlus/MSVCUndecoratedNameParser.h"
#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
+#include "SymbolFileNativePDB.h"
+#include "UdtRecordCompleter.h"
#include "lldb/Core/Module.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Utility/LLDBAssert.h"
-#include "PdbUtil.h"
-#include "UdtRecordCompleter.h"
-#include "SymbolFileNativePDB.h"
#include <optional>
+#include <string_view>
using namespace lldb_private;
using namespace lldb_private::npdb;
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)};
#include "PdbUtil.h"
#include "UdtRecordCompleter.h"
#include <optional>
+#include <string_view>
using namespace lldb;
using namespace lldb_private;
}
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);
#define DEMANGLE_ITANIUMDEMANGLE_H
#include "DemangleConfig.h"
-#include "StringView.h"
+#include "StringViewExtras.h"
#include "Utility.h"
#include <algorithm>
#include <cassert>
#include <cstring>
#include <limits>
#include <new>
+#include <string_view>
#include <type_traits>
#include <utility>
// 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;
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<typename Fn> void match(Fn F) const { F(Prefix, Suffix); }
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 <typename Fn> void match(Fn F) const { F(Ty, Ext, TA); }
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<typename Fn> void match(Fn F) const { F(Ty, Postfix); }
};
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<typename Fn> 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; }
};
};
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<typename Fn> void match(Fn F) const { F(Kind, Child); }
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<typename Fn> 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);
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<typename Fn> void match(Fn F) const { F(Ty, Protocol); }
};
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<typename Fn> void match(Fn F) const { F(Special, Child); }
template<typename Fn> 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);
template <typename Fn> 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);
template<typename Fn> 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);
template<typename Fn> 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);
template<typename Fn> 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 += "::";
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;
}
template<typename Fn> 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::itanium_demangle::starts_with(SV, "basic_"));
SV.remove_prefix(sizeof("basic_") - 1);
}
return SV;
};
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<typename Fn> void match(Fn F) const { F(Count); }
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_) {}
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_) {}
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 <typename Fn> void match(Fn F) const {
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 <typename Fn> void match(Fn F) const {
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_) {}
};
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_) {}
class CastExpr : public Node {
// cast_kind<to>(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 <typename Fn> void match(Fn F) const {
};
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 <typename Fn> void match(Fn F) const {
};
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<typename Fn> void match(Fn F) const { F(Number); }
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_) {}
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_) {}
template<typename Fn> 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");
}
};
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<typename Fn> void match(Fn F) const { F(Ty, 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<typename Fn> void match(Fn F) const { F(Type, Value); }
}
template <class Float> 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<typename Fn> 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<Float>::mangled_size;
if (static_cast<std::size_t>(last - first) > N) {
#endif
char num[FloatData<Float>::max_demangled_size] = {0};
int n = snprintf(num, sizeof(num), FloatData<Float>::spec, value);
- OB += StringView(num, n);
+ OB += std::string_view(num, n);
}
}
};
return res;
}
- bool consumeIf(StringView S) {
- if (StringView(First, Last - First).startsWith(S)) {
+ bool consumeIf(std::string_view S) {
+ if (llvm::itanium_demangle::starts_with(
+ std::string_view(First, Last - First), S)) {
First += S.size();
return true;
}
size_t numLeft() const { return static_cast<size_t>(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();
/// Parse the <expr> 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 <class Float> Node *parseFloatingLiteral();
Node *parseFunctionParam();
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::itanium_demangle::starts_with(Res, "operator") &&
"operator name does not start with 'operator'");
Res.remove_prefix(sizeof("operator") - 1);
- if (Res.startsWith(' '))
+ if (llvm::itanium_demangle::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; }
TemplateParams.clear();
if (consumeIf("Ut")) {
- StringView Count = parseNumber();
+ std::string_view Count = parseNumber();
if (!consumeIf('_'))
return nullptr;
return make<UnnamedTypeName>(Count);
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;
}
NodeArray Params = popTrailingNodeArray(ParamsBegin);
- StringView Count = parseNumber();
+ std::string_view Count = parseNumber();
if (!consumeIf('_'))
return nullptr;
return make<ClosureTypeName>(TempParams, Params, Count);
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::itanium_demangle::starts_with(Name, "_GLOBAL__N"))
return make<NameType>("(anonymous namespace)");
return make<NameType>(Name);
}
template <typename Derived, typename Alloc>
Node *AbstractManglingParser<Derived, Alloc>::parseAbiTags(Node *N) {
while (consumeIf('B')) {
- StringView SN = parseBareSourceName();
+ std::string_view SN = parseBareSourceName();
if (SN.empty())
return nullptr;
N = make<AbiTagAttr>(N, SN);
// <number> ::= [n] <non-negative decimal integer>
template <typename Alloc, typename Derived>
-StringView
+std::string_view
AbstractManglingParser<Alloc, Derived>::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);
}
// <positive length number> ::= [0-9]*
}
template <typename Alloc, typename Derived>
-StringView AbstractManglingParser<Alloc, Derived>::parseBareSourceName() {
+std::string_view AbstractManglingParser<Alloc, Derived>::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;
}
// ::= Te <name> # dependent elaborated type specifier using 'enum'
template <typename Derived, typename Alloc>
Node *AbstractManglingParser<Derived, Alloc>::parseClassEnumType() {
- StringView ElabSpef;
+ std::string_view ElabSpef;
if (consumeIf("Ts"))
ElabSpef = "struct";
else if (consumeIf("Tu"))
template <typename Derived, typename Alloc>
Node *AbstractManglingParser<Derived, Alloc>::parseQualifiedType() {
if (consumeIf('U')) {
- StringView Qual = parseBareSourceName();
+ std::string_view Qual = parseBareSourceName();
if (Qual.empty())
return nullptr;
// extension ::= U <objc-name> <objc-type> # objc-type<identifier>
- if (Qual.startsWith("objcproto")) {
- StringView ProtoSourceName = Qual.substr(std::strlen("objcproto"));
- StringView Proto;
+ if (llvm::itanium_demangle::starts_with(Qual, "objcproto")) {
+ std::string_view ProtoSourceName = Qual.substr(std::strlen("objcproto"));
+ std::string_view Proto;
{
- ScopedOverride<const char *> SaveFirst(First, ProtoSourceName.begin()),
- SaveLast(Last, ProtoSourceName.end());
+ ScopedOverride<const char *> SaveFirst(First, &*ProtoSourceName.begin()),
+ SaveLast(Last, &*ProtoSourceName.end());
Proto = parseBareSourceName();
}
if (Proto.empty())
// <builtin-type> ::= u <source-name> # vendor extended type
case 'u': {
++First;
- StringView Res = parseBareSourceName();
+ std::string_view Res = parseBareSourceName();
if (Res.empty())
return nullptr;
// Typically, <builtin-type>s are not considered substitution candidates,
}
template <typename Derived, typename Alloc>
-Node *AbstractManglingParser<Derived, Alloc>::parsePrefixExpr(StringView Kind,
- Node::Prec Prec) {
+Node *
+AbstractManglingParser<Derived, Alloc>::parsePrefixExpr(std::string_view Kind,
+ Node::Prec Prec) {
Node *E = getDerived().parseExpr();
if (E == nullptr)
return nullptr;
}
template <typename Derived, typename Alloc>
-Node *AbstractManglingParser<Derived, Alloc>::parseBinaryExpr(StringView Kind,
- Node::Prec Prec) {
+Node *
+AbstractManglingParser<Derived, Alloc>::parseBinaryExpr(std::string_view Kind,
+ Node::Prec Prec) {
Node *LHS = getDerived().parseExpr();
if (LHS == nullptr)
return nullptr;
}
template <typename Derived, typename Alloc>
-Node *
-AbstractManglingParser<Derived, Alloc>::parseIntegerLiteral(StringView Lit) {
- StringView Tmp = parseNumber(true);
+Node *AbstractManglingParser<Derived, Alloc>::parseIntegerLiteral(
+ std::string_view Lit) {
+ std::string_view Tmp = parseNumber(true);
if (!Tmp.empty() && consumeIf('E'))
return make<IntegerLiteral>(Lit, Tmp);
return nullptr;
return make<NameType>("this");
if (consumeIf("fp")) {
parseCVQualifiers();
- StringView Num = parseNumber();
+ std::string_view Num = parseNumber();
if (!consumeIf('_'))
return nullptr;
return make<FunctionParam>(Num);
if (!consumeIf('p'))
return nullptr;
parseCVQualifiers();
- StringView Num = parseNumber();
+ std::string_view Num = parseNumber();
if (!consumeIf('_'))
return nullptr;
return make<FunctionParam>(Num);
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'))
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<PointerToMemberConversionExpr>(Ty, Expr, Offset, Prec);
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<NameType>(parseNumber());
const size_t N = FloatData<Float>::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;
if (Encoding == nullptr)
return nullptr;
if (look() == '.') {
- Encoding = make<DotSuffix>(Encoding, StringView(First, Last - First));
+ Encoding =
+ make<DotSuffix>(Encoding, std::string_view(First, Last - First));
First = Last;
}
if (numLeft() != 0)
#define LLVM_DEMANGLE_MICROSOFTDEMANGLE_H
#include "llvm/Demangle/MicrosoftDemangleNodes.h"
-#include "llvm/Demangle/StringView.h"
+#include <cassert>
+#include <string_view>
#include <utility>
namespace llvm {
// 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;
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<uint64_t, bool> demangleNumber(StringView &MangledName);
- uint64_t demangleUnsigned(StringView &MangledName);
- int64_t demangleSigned(StringView &MangledName);
+ std::pair<uint64_t, bool> 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<Qualifiers, bool> 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<Qualifiers, bool> demangleQualifiers(std::string_view &MangledName);
// Memory allocator.
ArenaAllocator Arena;
#ifndef LLVM_DEMANGLE_MICROSOFTDEMANGLENODES_H
#define LLVM_DEMANGLE_MICROSOFTDEMANGLENODES_H
-#include "llvm/Demangle/StringView.h"
#include <array>
#include <cstdint>
#include <string>
+#include <string_view>
namespace llvm {
namespace itanium_demangle {
}
using llvm::itanium_demangle::OutputBuffer;
-using llvm::itanium_demangle::StringView;
namespace llvm {
namespace ms_demangle {
void output(OutputBuffer &OB, OutputFlags Flags) const override;
- StringView Name;
+ std::string_view Name;
};
struct IntrinsicFunctionIdentifierNode : public IdentifierNode {
void output(OutputBuffer &OB, OutputFlags Flags) const override;
- StringView Name;
+ std::string_view Name;
};
struct LocalStaticGuardIdentifierNode : public IdentifierNode {
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;
void output(OutputBuffer &OB, OutputFlags Flags) const override;
- StringView DecodedString;
+ std::string_view DecodedString;
bool IsTruncated = false;
CharKind Char = CharKind::Char;
};
#ifndef DEMANGLE_UTILITY_H
#define DEMANGLE_UTILITY_H
-#include "StringView.h"
+#include "DemangleConfig.h"
+
#include <array>
+#include <cassert>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <exception>
#include <limits>
+#include <string_view>
DEMANGLE_NAMESPACE_BEGIN
if (isNeg)
*--TempPtr = '-';
- return operator+=(StringView(TempPtr, Temp.data() + Temp.size() - TempPtr));
+ return operator+=(
+ std::string_view(TempPtr, Temp.data() + Temp.size() - TempPtr));
}
public:
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.
*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;
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); }
//===----------------------------------------------------------------------===//
#include "llvm/Demangle/Demangle.h"
-#include "llvm/Demangle/StringView.h"
#include "llvm/Demangle/Utility.h"
#include <cctype>
using namespace llvm;
using llvm::itanium_demangle::OutputBuffer;
-using llvm::itanium_demangle::StringView;
namespace {
break;
}
- *Demangled << StringView(Mangled, Len);
+ *Demangled << std::string_view(Mangled, Len);
Mangled += Len;
return Mangled;
}
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)
//===----------------------------------------------------------------------===//
#include "llvm/Demangle/MicrosoftDemangle.h"
-#include "llvm/Demangle/Demangle.h"
-#include "llvm/Demangle/MicrosoftDemangleNodes.h"
+#include "llvm/Demangle/Demangle.h"
#include "llvm/Demangle/DemangleConfig.h"
-#include "llvm/Demangle/StringView.h"
+#include "llvm/Demangle/MicrosoftDemangleNodes.h"
+#include "llvm/Demangle/StringViewExtras.h"
#include "llvm/Demangle/Utility.h"
#include <array>
#include <cctype>
#include <cstdio>
+#include <string_view>
#include <tuple>
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());
}
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::itanium_demangle::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::itanium_demangle::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);
}
static SpecialIntrinsicKind
-consumeSpecialIntrinsicKind(StringView &MangledName) {
+consumeSpecialIntrinsicKind(std::string_view &MangledName) {
if (consumeFront(MangledName, "?_7"))
return SpecialIntrinsicKind::Vftable;
if (consumeFront(MangledName, "?_8"))
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;
return true;
}
-static bool isTagType(StringView S) {
+static bool isTagType(std::string_view S) {
switch (S.front()) {
case 'T': // union
case 'U': // struct
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::itanium_demangle::starts_with(S, "$$Q")) // foo &&
return true;
switch (S.front()) {
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::itanium_demangle::starts_with(S, "$$A8@@") ||
+ llvm::itanium_demangle::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'))
}
static std::pair<Qualifiers, PointerAffinity>
-demanglePointerCVQualifiers(StringView &MangledName) {
+demanglePointerCVQualifiers(std::string_view &MangledName) {
if (consumeFront(MangledName, "$$Q"))
return std::make_pair(Q_None, PointerAffinity::RValueReference);
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<NamedIdentifierNode>();
switch (K) {
}
LocalStaticGuardVariableNode *
-Demangler::demangleLocalStaticGuard(StringView &MangledName, bool IsThread) {
+Demangler::demangleLocalStaticGuard(std::string_view &MangledName,
+ bool IsThread) {
LocalStaticGuardIdentifierNode *LSGI =
Arena.alloc<LocalStaticGuardIdentifierNode>();
LSGI->IsThread = IsThread;
}
static NamedIdentifierNode *synthesizeNamedIdentifier(ArenaAllocator &Arena,
- StringView Name) {
+ std::string_view Name) {
NamedIdentifierNode *Id = Arena.alloc<NamedIdentifierNode>();
Id->Name = Name;
return Id;
}
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<VariableSymbolNode>();
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<VariableSymbolNode>();
VariableSymbolNode *
Demangler::demangleRttiBaseClassDescriptorNode(ArenaAllocator &Arena,
- StringView &MangledName) {
+ std::string_view &MangledName) {
RttiBaseClassDescriptorNode *RBCDN =
Arena.alloc<RttiBaseClassDescriptorNode>();
RBCDN->NVOffset = demangleUnsigned(MangledName);
return VSN;
}
-FunctionSymbolNode *Demangler::demangleInitFiniStub(StringView &MangledName,
- bool IsDestructor) {
+FunctionSymbolNode *
+Demangler::demangleInitFiniStub(std::string_view &MangledName,
+ bool IsDestructor) {
DynamicStructorIdentifierNode *DSIN =
Arena.alloc<DynamicStructorIdentifierNode>();
DSIN->IsDestructor = IsDestructor;
return FSN;
}
-SymbolNode *Demangler::demangleSpecialIntrinsic(StringView &MangledName) {
+SymbolNode *Demangler::demangleSpecialIntrinsic(std::string_view &MangledName) {
SpecialIntrinsicKind SIK = consumeSpecialIntrinsicKind(MangledName);
switch (SIK) {
}
IdentifierNode *
-Demangler::demangleFunctionIdentifierCode(StringView &MangledName) {
- assert(MangledName.startsWith('?'));
+Demangler::demangleFunctionIdentifierCode(std::string_view &MangledName) {
+ assert(llvm::itanium_demangle::starts_with(MangledName, '?'));
MangledName.remove_prefix(1);
if (MangledName.empty()) {
Error = true;
}
StructorIdentifierNode *
-Demangler::demangleStructorIdentifier(StringView &MangledName,
+Demangler::demangleStructorIdentifier(std::string_view &MangledName,
bool IsDestructor) {
StructorIdentifierNode *N = Arena.alloc<StructorIdentifierNode>();
N->IsDestructor = IsDestructor;
}
ConversionOperatorIdentifierNode *
-Demangler::demangleConversionOperatorIdentifier(StringView &MangledName) {
+Demangler::demangleConversionOperatorIdentifier(std::string_view &MangledName) {
ConversionOperatorIdentifierNode *N =
Arena.alloc<ConversionOperatorIdentifierNode>();
return N;
}
LiteralOperatorIdentifierNode *
-Demangler::demangleLiteralOperatorIdentifier(StringView &MangledName) {
+Demangler::demangleLiteralOperatorIdentifier(std::string_view &MangledName) {
LiteralOperatorIdentifierNode *N =
Arena.alloc<LiteralOperatorIdentifierNode>();
N->Name = demangleSimpleString(MangledName, /*Memorize=*/false);
}
IdentifierNode *
-Demangler::demangleFunctionIdentifierCode(StringView &MangledName,
+Demangler::demangleFunctionIdentifierCode(std::string_view &MangledName,
FunctionIdentifierCodeGroup Group) {
if (MangledName.empty()) {
Error = true;
DEMANGLE_UNREACHABLE;
}
-SymbolNode *Demangler::demangleEncodedSymbol(StringView &MangledName,
+SymbolNode *Demangler::demangleEncodedSymbol(std::string_view &MangledName,
QualifiedNameNode *Name) {
if (MangledName.empty()) {
Error = true;
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);
return Symbol;
}
-SymbolNode *Demangler::demangleMD5Name(StringView &MangledName) {
- assert(MangledName.startsWith("??@"));
+SymbolNode *Demangler::demangleMD5Name(std::string_view &MangledName) {
+ assert(llvm::itanium_demangle::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:
// either.
consumeFront(MangledName, "??_R4@");
- StringView MD5(Start, MangledName.begin() - Start);
+ std::string_view MD5(Start, &*MangledName.begin() - Start);
SymbolNode *S = Arena.alloc<SymbolNode>(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::itanium_demangle::starts_with(MangledName, '.'));
consumeFront(MangledName, '.');
TypeNode *T = demangleType(MangledName, QualifierMangleMode::Result);
}
// 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::itanium_demangle::starts_with(MangledName, '.'))
return demangleTypeinfoName(MangledName);
- if (MangledName.startsWith("??@"))
+ if (llvm::itanium_demangle::starts_with(MangledName, "??@"))
return demangleMD5Name(MangledName);
// MSVC-style mangled symbols must start with '?'.
- if (!MangledName.startsWith('?')) {
+ if (!llvm::itanium_demangle::starts_with(MangledName, '?')) {
Error = true;
return nullptr;
}
return demangleDeclarator(MangledName);
}
-TagTypeNode *Demangler::parseTagUniqueName(StringView &MangledName) {
+TagTypeNode *Demangler::parseTagUniqueName(std::string_view &MangledName) {
if (!consumeFront(MangledName, ".?A")) {
Error = true;
return nullptr;
// ::= 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<VariableSymbolNode>();
VSN->Type = demangleType(MangledName, QualifierMangleMode::Drop);
// ::= <hex digit>+ @ # when Number == 0 or >= 10
//
// <hex-digit> ::= [A-P] # A = 0, B = 1, ...
-std::pair<uint64_t, bool> Demangler::demangleNumber(StringView &MangledName) {
+std::pair<uint64_t, bool>
+Demangler::demangleNumber(std::string_view &MangledName) {
bool IsNegative = consumeFront(MangledName, '?');
if (startsWithDigit(MangledName)) {
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);
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);
// 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)
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';
// 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::itanium_demangle::starts_with(MangledName, "?$"));
consumeFront(MangledName, "?$");
BackrefContext OuterContext;
return Identifier;
}
-NamedIdentifierNode *Demangler::demangleSimpleName(StringView &MangledName,
- bool Memorize) {
- StringView S = demangleSimpleString(MangledName, Memorize);
+NamedIdentifierNode *
+Demangler::demangleSimpleName(std::string_view &MangledName, bool Memorize) {
+ std::string_view S = demangleSimpleString(MangledName, Memorize);
if (Error)
return nullptr;
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::itanium_demangle::starts_with(MangledName, '?')) {
const uint8_t F = MangledName.front();
MangledName.remove_prefix(1);
return F;
// 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.
return '\0';
}
-wchar_t Demangler::demangleWcharLiteral(StringView &MangledName) {
+wchar_t Demangler::demangleWcharLiteral(std::string_view &MangledName) {
uint8_t C1, C2;
C1 = demangleCharLiteral(MangledName);
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) {
return Result;
}
-FunctionSymbolNode *Demangler::demangleVcallThunkNode(StringView &MangledName) {
+FunctionSymbolNode *
+Demangler::demangleVcallThunkNode(std::string_view &MangledName) {
FunctionSymbolNode *FSN = Arena.alloc<FunctionSymbolNode>();
VcallThunkIdentifierNode *VTIN = Arena.alloc<VcallThunkIdentifierNode>();
FSN->Signature = Arena.alloc<ThunkSignatureNode>();
}
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;
// 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);
// 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;
}
NamedIdentifierNode *
-Demangler::demangleAnonymousNamespaceName(StringView &MangledName) {
- assert(MangledName.startsWith("?A"));
+Demangler::demangleAnonymousNamespaceName(std::string_view &MangledName) {
+ assert(llvm::itanium_demangle::starts_with(MangledName, "?A"));
consumeFront(MangledName, "?A");
NamedIdentifierNode *Node = Arena.alloc<NamedIdentifierNode>();
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<NamedIdentifierNode>();
// 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)
// 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
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
if (startsWithDigit(MangledName))
return demangleBackRefName(MangledName);
- if (MangledName.startsWith("?$"))
+ if (llvm::itanium_demangle::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::itanium_demangle::starts_with(MangledName, "?$"))
return demangleTemplateInstantiationName(MangledName, NBB);
- if (MangledName.startsWith('?'))
+ if (llvm::itanium_demangle::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::itanium_demangle::starts_with(MangledName, "?$"))
return demangleTemplateInstantiationName(MangledName, NBB_Template);
- if (MangledName.startsWith("?A"))
+ if (llvm::itanium_demangle::starts_with(MangledName, "?A"))
return demangleAnonymousNamespaceName(MangledName);
if (startsWithLocalScopePattern(MangledName))
}
QualifiedNameNode *
-Demangler::demangleNameScopeChain(StringView &MangledName,
+Demangler::demangleNameScopeChain(std::string_view &MangledName,
IdentifierNode *UnqualifiedName) {
NodeList *Head = Arena.alloc<NodeList>();
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) {
return FC_Public;
}
-CallingConv Demangler::demangleCallingConvention(StringView &MangledName) {
+CallingConv
+Demangler::demangleCallingConvention(std::string_view &MangledName) {
if (MangledName.empty()) {
Error = true;
return CallingConv::None;
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();
}
std::pair<Qualifiers, bool>
-Demangler::demangleQualifiers(StringView &MangledName) {
+Demangler::demangleQualifiers(std::string_view &MangledName) {
if (MangledName.empty()) {
Error = true;
return std::make_pair(Q_None, false);
// <variable-type> ::= <type> <cvr-qualifiers>
// ::= <type> <pointee-cvr-qualifiers> # pointers, references
-TypeNode *Demangler::demangleType(StringView &MangledName,
+TypeNode *Demangler::demangleType(std::string_view &MangledName,
QualifierMangleMode QMM) {
Qualifiers Quals = Q_None;
bool IsMember = false;
if (consumeFront(MangledName, "$$A8@@"))
Ty = demangleFunctionType(MangledName, true);
else {
- assert(MangledName.startsWith("$$A6"));
+ assert(llvm::itanium_demangle::starts_with(MangledName, "$$A6"));
consumeFront(MangledName, "$$A6");
Ty = demangleFunctionType(MangledName, false);
}
return Ty;
}
-bool Demangler::demangleThrowSpecification(StringView &MangledName) {
+bool Demangler::demangleThrowSpecification(std::string_view &MangledName) {
if (consumeFront(MangledName, "_E"))
return true;
if (consumeFront(MangledName, 'Z'))
return false;
}
-FunctionSignatureNode *Demangler::demangleFunctionType(StringView &MangledName,
- bool HasThisQuals) {
+FunctionSignatureNode *
+Demangler::demangleFunctionType(std::string_view &MangledName,
+ bool HasThisQuals) {
FunctionSignatureNode *FTy = Arena.alloc<FunctionSignatureNode>();
if (HasThisQuals) {
}
FunctionSymbolNode *
-Demangler::demangleFunctionEncoding(StringView &MangledName) {
+Demangler::demangleFunctionEncoding(std::string_view &MangledName) {
FuncClass ExtraFlags = FC_None;
if (consumeFront(MangledName, "$$J0"))
ExtraFlags = FC_ExternC;
return Symbol;
}
-CustomTypeNode *Demangler::demangleCustomType(StringView &MangledName) {
- assert(MangledName.startsWith('?'));
+CustomTypeNode *Demangler::demangleCustomType(std::string_view &MangledName) {
+ assert(llvm::itanium_demangle::starts_with(MangledName, '?'));
MangledName.remove_prefix(1);
CustomTypeNode *CTN = Arena.alloc<CustomTypeNode>();
}
// Reads a primitive type.
-PrimitiveTypeNode *Demangler::demanglePrimitiveType(StringView &MangledName) {
+PrimitiveTypeNode *
+Demangler::demanglePrimitiveType(std::string_view &MangledName) {
if (consumeFront(MangledName, "$$T"))
return Arena.alloc<PrimitiveTypeNode>(PrimitiveKind::Nullptr);
return nullptr;
}
-TagTypeNode *Demangler::demangleClassType(StringView &MangledName) {
+TagTypeNode *Demangler::demangleClassType(std::string_view &MangledName) {
TagTypeNode *TT = nullptr;
const char F = MangledName.front();
// <pointer-type> ::= E? <pointer-cvr-qualifiers> <ext-qualifiers> <type>
// # 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<PointerTypeNode>();
std::tie(Pointer->Quals, Pointer->Affinity) =
return Pointer;
}
-PointerTypeNode *Demangler::demangleMemberPointerType(StringView &MangledName) {
+PointerTypeNode *
+Demangler::demangleMemberPointerType(std::string_view &MangledName) {
PointerTypeNode *Pointer = Arena.alloc<PointerTypeNode>();
std::tie(Pointer->Quals, Pointer->Affinity) =
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);
return Quals;
}
-ArrayTypeNode *Demangler::demangleArrayType(StringView &MangledName) {
+ArrayTypeNode *Demangler::demangleArrayType(std::string_view &MangledName) {
assert(MangledName.front() == 'Y');
MangledName.remove_prefix(1);
}
// 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;
NodeList *Head = Arena.alloc<NodeList>();
NodeList **Current = &Head;
size_t Count = 0;
- while (!Error && !MangledName.startsWith('@') &&
- !MangledName.startsWith('Z')) {
+ while (!Error && !llvm::itanium_demangle::starts_with(MangledName, '@') &&
+ !llvm::itanium_demangle::starts_with(MangledName, 'Z')) {
++Count;
if (startsWithDigit(MangledName)) {
}
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::itanium_demangle::starts_with(MangledName, '@')) {
if (consumeFront(MangledName, "$S") || consumeFront(MangledName, "$$V") ||
consumeFront(MangledName, "$$$V") || consumeFront(MangledName, "$$Z")) {
// parameter pack separator
} 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::itanium_demangle::starts_with(MangledName, "$1") ||
+ llvm::itanium_demangle::starts_with(MangledName, "$H") ||
+ llvm::itanium_demangle::starts_with(MangledName, "$I") ||
+ llvm::itanium_demangle::starts_with(MangledName, "$J")) {
// Pointer to member
TP.N = TPRN = Arena.alloc<TemplateParameterReferenceNode>();
TPRN->IsMemberPointer = true;
char InheritanceSpecifier = MangledName.front();
MangledName.remove_prefix(1);
SymbolNode *S = nullptr;
- if (MangledName.startsWith('?')) {
+ if (llvm::itanium_demangle::starts_with(MangledName, '?')) {
S = parse(MangledName);
if (Error || !S->Name) {
Error = true;
}
TPRN->Affinity = PointerAffinity::Pointer;
TPRN->Symbol = S;
- } else if (MangledName.startsWith("$E?")) {
+ } else if (llvm::itanium_demangle::starts_with(MangledName, "$E?")) {
consumeFront(MangledName, "$E");
// Reference to symbol
TP.N = TPRN = Arena.alloc<TemplateParameterReferenceNode>();
TPRN->Symbol = parse(MangledName);
TPRN->Affinity = PointerAffinity::Reference;
- } else if (MangledName.startsWith("$F") || MangledName.startsWith("$G")) {
+ } else if (llvm::itanium_demangle::starts_with(MangledName, "$F") ||
+ llvm::itanium_demangle::starts_with(MangledName, "$G")) {
TP.N = TPRN = Arena.alloc<TemplateParameterReferenceNode>();
// Data member pointer.
// 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::itanium_demangle::starts_with(
+ MangledName, '@')); // The above loop exits only on '@'.
consumeFront(MangledName, '@');
return nodeListToNodeArray(Arena, Head, Count);
}
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());
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");
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();
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;
}
void NodeArrayNode::output(OutputBuffer &OB, OutputFlags Flags,
- StringView Separator) const {
+ std::string_view Separator) const {
if (Count == 0)
return;
if (Nodes[0])
//===----------------------------------------------------------------------===//
#include "llvm/Demangle/Demangle.h"
-#include "llvm/Demangle/StringView.h"
+#include "llvm/Demangle/StringViewExtras.h"
#include "llvm/Demangle/Utility.h"
#include <algorithm>
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(); }
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.
Demangler(size_t MaxRecursionLevel = 500);
- bool demangle(StringView MangledName);
+ bool demangle(std::string_view MangledName);
private:
bool demanglePath(IsInType Type,
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);
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::itanium_demangle::starts_with(Mangled, "_R"))
return nullptr;
Demangler D;
// responsibility of the caller to free the memory behind the output stream.
//
// <symbol-name> = "_R" <path> [<instantiating-crate>]
-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::itanium_demangle::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);
if (Position != Input.size())
Error = true;
- if (Dot != StringView::npos) {
+ if (Dot != std::string_view::npos) {
print(" (");
print(Mangled.substr(Dot));
print(")");
if (consumeIf('n'))
print('-');
- StringView HexDigits;
+ std::string_view HexDigits;
uint64_t Value = parseHexNumber(HexDigits);
if (HexDigits.size() <= 16) {
printDecimalNumber(Value);
// <const-data> = "0_" // false
// | "1_" // true
void Demangler::demangleConstBool() {
- StringView HexDigits;
+ std::string_view HexDigits;
parseHexNumber(HexDigits);
if (HexDigits == "0")
print("false");
// <const-data> = <hex-number>
void Demangler::demangleConstChar() {
- StringView HexDigits;
+ std::string_view HexDigits;
uint64_t CodePoint = parseHexNumber(HexDigits);
if (Error || HexDigits.size() > 6) {
Error = true;
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)) {
//
// <hex-number> = "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;
}
if (Error) {
- HexDigits = StringView();
+ HexDigits = std::string_view();
return 0;
}
Output += C;
}
-void Demangler::print(StringView S) {
+void Demangler::print(std::string_view S) {
if (Error || !Print)
return;
// 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];
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;
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) {
- ID.AddString(llvm::StringRef(Str.begin(), Str.size()));
+ void operator()(std::string_view Str) {
+ ID.AddString(llvm::StringRef(&*Str.begin(), Str.size()));
}
template <typename T>
std::enable_if_t<std::is_integral_v<T> || std::is_enum_v<T>> operator()(T V) {
N = Demangler.parse();
else
N = Demangler.make<itanium_demangle::NameType>(
- StringView(Mangling.data(), Mangling.size()));
+ std::string_view(Mangling.data(), Mangling.size()));
return reinterpret_cast<ItaniumManglingCanonicalizer::Key>(N);
}
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <cstdlib>
+#include <string_view>
#include <vector>
using namespace llvm;
}
static std::string toString(OutputBuffer &OB) {
- StringView SV = OB;
+ std::string_view SV = OB;
return {SV.begin(), SV.end()};
}
OutputBuffer OB;
Node *N = AbstractManglingParser<TestParser, TestAllocator>::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
#include "llvm/Demangle/Utility.h"
#include "gtest/gtest.h"
#include <string>
+#include <string_view>
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()};
}