Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/llvm/llvm-project.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@acm.org>2022-02-28 21:18:14 +0300
committerNathan Sidwell <nathan@acm.org>2022-04-06 22:55:35 +0300
commit51f6caf2fbb5118569f2de33a85ffcc52568e0a7 (patch)
tree0c9e97ab607b66cd24fadc13c418d82ad34cf04a /libcxxabi/src/demangle
parent7594e236795f695c7cf9336ee24ef76c275d8703 (diff)
[demangler][NFC] Rename SwapAndRestore to ScopedOverride
The demangler has a utility class 'SwapAndRestore'. That name is confusing. It's not swapping anything, and the restore part happens at the object's destruction. What it's actually doing is allowing a override of some value that is dynamically accessible within the lifetime of a lexical scope. Thus rename it to ScopedOverride, and tweak it's member variable names. Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D122606
Diffstat (limited to 'libcxxabi/src/demangle')
-rw-r--r--libcxxabi/src/demangle/ItaniumDemangle.h42
-rw-r--r--libcxxabi/src/demangle/Utility.h19
2 files changed, 30 insertions, 31 deletions
diff --git a/libcxxabi/src/demangle/ItaniumDemangle.h b/libcxxabi/src/demangle/ItaniumDemangle.h
index fd6835ab9aba..36fe26b44620 100644
--- a/libcxxabi/src/demangle/ItaniumDemangle.h
+++ b/libcxxabi/src/demangle/ItaniumDemangle.h
@@ -656,7 +656,7 @@ public:
void printLeft(OutputBuffer &OB) const override {
if (Printing)
return;
- SwapAndRestore<bool> SavePrinting(Printing, true);
+ ScopedOverride<bool> SavePrinting(Printing, true);
std::pair<ReferenceKind, const Node *> Collapsed = collapse(OB);
if (!Collapsed.second)
return;
@@ -671,7 +671,7 @@ public:
void printRight(OutputBuffer &OB) const override {
if (Printing)
return;
- SwapAndRestore<bool> SavePrinting(Printing, true);
+ ScopedOverride<bool> SavePrinting(Printing, true);
std::pair<ReferenceKind, const Node *> Collapsed = collapse(OB);
if (!Collapsed.second)
return;
@@ -1180,7 +1180,7 @@ public:
template<typename Fn> void match(Fn F) const { F(Name, Params); }
void printLeft(OutputBuffer &OB) const override {
- SwapAndRestore<unsigned> LT(OB.GtIsGt, 0);
+ ScopedOverride<unsigned> LT(OB.GtIsGt, 0);
OB += "template<";
Params.printWithComma(OB);
OB += "> typename ";
@@ -1316,8 +1316,8 @@ public:
void printLeft(OutputBuffer &OB) const override {
constexpr unsigned Max = std::numeric_limits<unsigned>::max();
- SwapAndRestore<unsigned> SavePackIdx(OB.CurrentPackIndex, Max);
- SwapAndRestore<unsigned> SavePackMax(OB.CurrentPackMax, Max);
+ ScopedOverride<unsigned> SavePackIdx(OB.CurrentPackIndex, Max);
+ ScopedOverride<unsigned> SavePackMax(OB.CurrentPackMax, Max);
size_t StreamPos = OB.getCurrentPosition();
// Print the first element in the pack. If Child contains a ParameterPack,
@@ -1358,7 +1358,7 @@ public:
NodeArray getParams() { return Params; }
void printLeft(OutputBuffer &OB) const override {
- SwapAndRestore<unsigned> LT(OB.GtIsGt, 0);
+ ScopedOverride<unsigned> LT(OB.GtIsGt, 0);
OB += "<";
Params.printWithComma(OB);
if (OB.back() == '>')
@@ -1408,38 +1408,38 @@ struct ForwardTemplateReference : Node {
bool hasRHSComponentSlow(OutputBuffer &OB) const override {
if (Printing)
return false;
- SwapAndRestore<bool> SavePrinting(Printing, true);
+ ScopedOverride<bool> SavePrinting(Printing, true);
return Ref->hasRHSComponent(OB);
}
bool hasArraySlow(OutputBuffer &OB) const override {
if (Printing)
return false;
- SwapAndRestore<bool> SavePrinting(Printing, true);
+ ScopedOverride<bool> SavePrinting(Printing, true);
return Ref->hasArray(OB);
}
bool hasFunctionSlow(OutputBuffer &OB) const override {
if (Printing)
return false;
- SwapAndRestore<bool> SavePrinting(Printing, true);
+ ScopedOverride<bool> SavePrinting(Printing, true);
return Ref->hasFunction(OB);
}
const Node *getSyntaxNode(OutputBuffer &OB) const override {
if (Printing)
return this;
- SwapAndRestore<bool> SavePrinting(Printing, true);
+ ScopedOverride<bool> SavePrinting(Printing, true);
return Ref->getSyntaxNode(OB);
}
void printLeft(OutputBuffer &OB) const override {
if (Printing)
return;
- SwapAndRestore<bool> SavePrinting(Printing, true);
+ ScopedOverride<bool> SavePrinting(Printing, true);
Ref->printLeft(OB);
}
void printRight(OutputBuffer &OB) const override {
if (Printing)
return;
- SwapAndRestore<bool> SavePrinting(Printing, true);
+ ScopedOverride<bool> SavePrinting(Printing, true);
Ref->printRight(OB);
}
};
@@ -1656,7 +1656,7 @@ public:
void printDeclarator(OutputBuffer &OB) const {
if (!TemplateParams.empty()) {
- SwapAndRestore<unsigned> LT(OB.GtIsGt, 0);
+ ScopedOverride<unsigned> LT(OB.GtIsGt, 0);
OB += "<";
TemplateParams.printWithComma(OB);
OB += ">";
@@ -1880,7 +1880,7 @@ public:
void printLeft(OutputBuffer &OB) const override {
OB += CastKind;
{
- SwapAndRestore<unsigned> LT(OB.GtIsGt, 0);
+ ScopedOverride<unsigned> LT(OB.GtIsGt, 0);
OB += "<";
To->printLeft(OB);
if (OB.back() == '>')
@@ -2857,7 +2857,7 @@ AbstractManglingParser<Derived, Alloc>::parseUnnamedTypeName(NameState *State) {
return make<UnnamedTypeName>(Count);
}
if (consumeIf("Ul")) {
- SwapAndRestore<size_t> SwapParams(ParsingLambdaParamsAtLevel,
+ ScopedOverride<size_t> SwapParams(ParsingLambdaParamsAtLevel,
TemplateParams.size());
ScopedTemplateParamList LambdaTemplateParams(this);
@@ -3062,11 +3062,11 @@ AbstractManglingParser<Derived, Alloc>::parseOperatorName(NameState *State) {
if (const auto *Op = parseOperatorEncoding()) {
if (Op->getKind() == OperatorInfo::CCast) {
// ::= cv <type> # (cast)
- SwapAndRestore<bool> SaveTemplate(TryToParseTemplateArgs, false);
+ ScopedOverride<bool> SaveTemplate(TryToParseTemplateArgs, false);
// If we're parsing an encoding, State != nullptr and the conversion
// operators' <type> could have a <template-param> that refers to some
// <template-arg>s further ahead in the mangled name.
- SwapAndRestore<bool> SavePermit(PermitForwardTemplateReferences,
+ ScopedOverride<bool> SavePermit(PermitForwardTemplateReferences,
PermitForwardTemplateReferences ||
State != nullptr);
Node *Ty = getDerived().parseType();
@@ -3718,8 +3718,8 @@ Node *AbstractManglingParser<Derived, Alloc>::parseQualifiedType() {
StringView ProtoSourceName = Qual.dropFront(std::strlen("objcproto"));
StringView Proto;
{
- SwapAndRestore<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())
@@ -4199,7 +4199,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseConversionExpr() {
return nullptr;
Node *Ty;
{
- SwapAndRestore<bool> SaveTemp(TryToParseTemplateArgs, false);
+ ScopedOverride<bool> SaveTemp(TryToParseTemplateArgs, false);
Ty = getDerived().parseType();
}
@@ -4634,7 +4634,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseExpr() {
// C Cast: (type)expr
Node *Ty;
{
- SwapAndRestore<bool> SaveTemp(TryToParseTemplateArgs, false);
+ ScopedOverride<bool> SaveTemp(TryToParseTemplateArgs, false);
Ty = getDerived().parseType();
}
if (Ty == nullptr)
diff --git a/libcxxabi/src/demangle/Utility.h b/libcxxabi/src/demangle/Utility.h
index 1390f14b10d4..6e0fa38632c8 100644
--- a/libcxxabi/src/demangle/Utility.h
+++ b/libcxxabi/src/demangle/Utility.h
@@ -181,21 +181,20 @@ public:
size_t getBufferCapacity() const { return BufferCapacity; }
};
-template <class T> class SwapAndRestore {
- T &Restore;
- T OriginalValue;
+template <class T> class ScopedOverride {
+ T &Loc;
+ T Original;
public:
- SwapAndRestore(T &Restore_) : SwapAndRestore(Restore_, Restore_) {}
+ ScopedOverride(T &Loc_) : ScopedOverride(Loc_, Loc_) {}
- SwapAndRestore(T &Restore_, T NewVal)
- : Restore(Restore_), OriginalValue(Restore) {
- Restore = std::move(NewVal);
+ ScopedOverride(T &Loc_, T NewVal) : Loc(Loc_), Original(Loc_) {
+ Loc_ = std::move(NewVal);
}
- ~SwapAndRestore() { Restore = std::move(OriginalValue); }
+ ~ScopedOverride() { Loc = std::move(Original); }
- SwapAndRestore(const SwapAndRestore &) = delete;
- SwapAndRestore &operator=(const SwapAndRestore &) = delete;
+ ScopedOverride(const ScopedOverride &) = delete;
+ ScopedOverride &operator=(const ScopedOverride &) = delete;
};
inline bool initializeOutputBuffer(char *Buf, size_t *N, OutputBuffer &OB,