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 @@ -656,7 +656,7 @@ void printLeft(OutputBuffer &OB) const override { if (Printing) return; - SwapAndRestore SavePrinting(Printing, true); + ScopedOverride SavePrinting(Printing, true); std::pair Collapsed = collapse(OB); if (!Collapsed.second) return; @@ -671,7 +671,7 @@ void printRight(OutputBuffer &OB) const override { if (Printing) return; - SwapAndRestore SavePrinting(Printing, true); + ScopedOverride SavePrinting(Printing, true); std::pair Collapsed = collapse(OB); if (!Collapsed.second) return; @@ -1180,7 +1180,7 @@ template void match(Fn F) const { F(Name, Params); } void printLeft(OutputBuffer &OB) const override { - SwapAndRestore LT(OB.GtIsGt, 0); + ScopedOverride LT(OB.GtIsGt, 0); OB += "template<"; Params.printWithComma(OB); OB += "> typename "; @@ -1316,8 +1316,8 @@ void printLeft(OutputBuffer &OB) const override { constexpr unsigned Max = std::numeric_limits::max(); - SwapAndRestore SavePackIdx(OB.CurrentPackIndex, Max); - SwapAndRestore SavePackMax(OB.CurrentPackMax, Max); + ScopedOverride SavePackIdx(OB.CurrentPackIndex, Max); + ScopedOverride 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 @@ NodeArray getParams() { return Params; } void printLeft(OutputBuffer &OB) const override { - SwapAndRestore LT(OB.GtIsGt, 0); + ScopedOverride LT(OB.GtIsGt, 0); OB += "<"; Params.printWithComma(OB); if (OB.back() == '>') @@ -1408,38 +1408,38 @@ bool hasRHSComponentSlow(OutputBuffer &OB) const override { if (Printing) return false; - SwapAndRestore SavePrinting(Printing, true); + ScopedOverride SavePrinting(Printing, true); return Ref->hasRHSComponent(OB); } bool hasArraySlow(OutputBuffer &OB) const override { if (Printing) return false; - SwapAndRestore SavePrinting(Printing, true); + ScopedOverride SavePrinting(Printing, true); return Ref->hasArray(OB); } bool hasFunctionSlow(OutputBuffer &OB) const override { if (Printing) return false; - SwapAndRestore SavePrinting(Printing, true); + ScopedOverride SavePrinting(Printing, true); return Ref->hasFunction(OB); } const Node *getSyntaxNode(OutputBuffer &OB) const override { if (Printing) return this; - SwapAndRestore SavePrinting(Printing, true); + ScopedOverride SavePrinting(Printing, true); return Ref->getSyntaxNode(OB); } void printLeft(OutputBuffer &OB) const override { if (Printing) return; - SwapAndRestore SavePrinting(Printing, true); + ScopedOverride SavePrinting(Printing, true); Ref->printLeft(OB); } void printRight(OutputBuffer &OB) const override { if (Printing) return; - SwapAndRestore SavePrinting(Printing, true); + ScopedOverride SavePrinting(Printing, true); Ref->printRight(OB); } }; @@ -1656,7 +1656,7 @@ void printDeclarator(OutputBuffer &OB) const { if (!TemplateParams.empty()) { - SwapAndRestore LT(OB.GtIsGt, 0); + ScopedOverride LT(OB.GtIsGt, 0); OB += "<"; TemplateParams.printWithComma(OB); OB += ">"; @@ -1880,7 +1880,7 @@ void printLeft(OutputBuffer &OB) const override { OB += CastKind; { - SwapAndRestore LT(OB.GtIsGt, 0); + ScopedOverride LT(OB.GtIsGt, 0); OB += "<"; To->printLeft(OB); if (OB.back() == '>') @@ -2857,7 +2857,7 @@ return make(Count); } if (consumeIf("Ul")) { - SwapAndRestore SwapParams(ParsingLambdaParamsAtLevel, + ScopedOverride SwapParams(ParsingLambdaParamsAtLevel, TemplateParams.size()); ScopedTemplateParamList LambdaTemplateParams(this); @@ -3062,11 +3062,11 @@ if (const auto *Op = parseOperatorEncoding()) { if (Op->getKind() == OperatorInfo::CCast) { // ::= cv # (cast) - SwapAndRestore SaveTemplate(TryToParseTemplateArgs, false); + ScopedOverride SaveTemplate(TryToParseTemplateArgs, false); // If we're parsing an encoding, State != nullptr and the conversion // operators' could have a that refers to some // s further ahead in the mangled name. - SwapAndRestore SavePermit(PermitForwardTemplateReferences, + ScopedOverride SavePermit(PermitForwardTemplateReferences, PermitForwardTemplateReferences || State != nullptr); Node *Ty = getDerived().parseType(); @@ -3718,8 +3718,8 @@ StringView ProtoSourceName = Qual.dropFront(std::strlen("objcproto")); StringView Proto; { - SwapAndRestore SaveFirst(First, ProtoSourceName.begin()), - SaveLast(Last, ProtoSourceName.end()); + ScopedOverride SaveFirst(First, ProtoSourceName.begin()), + SaveLast(Last, ProtoSourceName.end()); Proto = parseBareSourceName(); } if (Proto.empty()) @@ -4199,7 +4199,7 @@ return nullptr; Node *Ty; { - SwapAndRestore SaveTemp(TryToParseTemplateArgs, false); + ScopedOverride SaveTemp(TryToParseTemplateArgs, false); Ty = getDerived().parseType(); } @@ -4634,7 +4634,7 @@ // C Cast: (type)expr Node *Ty; { - SwapAndRestore SaveTemp(TryToParseTemplateArgs, false); + ScopedOverride SaveTemp(TryToParseTemplateArgs, false); Ty = getDerived().parseType(); } if (Ty == nullptr) 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 @@ -181,21 +181,20 @@ size_t getBufferCapacity() const { return BufferCapacity; } }; -template class SwapAndRestore { - T &Restore; - T OriginalValue; +template 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, diff --git a/llvm/include/llvm/Demangle/ItaniumDemangle.h b/llvm/include/llvm/Demangle/ItaniumDemangle.h --- a/llvm/include/llvm/Demangle/ItaniumDemangle.h +++ b/llvm/include/llvm/Demangle/ItaniumDemangle.h @@ -656,7 +656,7 @@ void printLeft(OutputBuffer &OB) const override { if (Printing) return; - SwapAndRestore SavePrinting(Printing, true); + ScopedOverride SavePrinting(Printing, true); std::pair Collapsed = collapse(OB); if (!Collapsed.second) return; @@ -671,7 +671,7 @@ void printRight(OutputBuffer &OB) const override { if (Printing) return; - SwapAndRestore SavePrinting(Printing, true); + ScopedOverride SavePrinting(Printing, true); std::pair Collapsed = collapse(OB); if (!Collapsed.second) return; @@ -1180,7 +1180,7 @@ template void match(Fn F) const { F(Name, Params); } void printLeft(OutputBuffer &OB) const override { - SwapAndRestore LT(OB.GtIsGt, 0); + ScopedOverride LT(OB.GtIsGt, 0); OB += "template<"; Params.printWithComma(OB); OB += "> typename "; @@ -1316,8 +1316,8 @@ void printLeft(OutputBuffer &OB) const override { constexpr unsigned Max = std::numeric_limits::max(); - SwapAndRestore SavePackIdx(OB.CurrentPackIndex, Max); - SwapAndRestore SavePackMax(OB.CurrentPackMax, Max); + ScopedOverride SavePackIdx(OB.CurrentPackIndex, Max); + ScopedOverride 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 @@ NodeArray getParams() { return Params; } void printLeft(OutputBuffer &OB) const override { - SwapAndRestore LT(OB.GtIsGt, 0); + ScopedOverride LT(OB.GtIsGt, 0); OB += "<"; Params.printWithComma(OB); if (OB.back() == '>') @@ -1408,38 +1408,38 @@ bool hasRHSComponentSlow(OutputBuffer &OB) const override { if (Printing) return false; - SwapAndRestore SavePrinting(Printing, true); + ScopedOverride SavePrinting(Printing, true); return Ref->hasRHSComponent(OB); } bool hasArraySlow(OutputBuffer &OB) const override { if (Printing) return false; - SwapAndRestore SavePrinting(Printing, true); + ScopedOverride SavePrinting(Printing, true); return Ref->hasArray(OB); } bool hasFunctionSlow(OutputBuffer &OB) const override { if (Printing) return false; - SwapAndRestore SavePrinting(Printing, true); + ScopedOverride SavePrinting(Printing, true); return Ref->hasFunction(OB); } const Node *getSyntaxNode(OutputBuffer &OB) const override { if (Printing) return this; - SwapAndRestore SavePrinting(Printing, true); + ScopedOverride SavePrinting(Printing, true); return Ref->getSyntaxNode(OB); } void printLeft(OutputBuffer &OB) const override { if (Printing) return; - SwapAndRestore SavePrinting(Printing, true); + ScopedOverride SavePrinting(Printing, true); Ref->printLeft(OB); } void printRight(OutputBuffer &OB) const override { if (Printing) return; - SwapAndRestore SavePrinting(Printing, true); + ScopedOverride SavePrinting(Printing, true); Ref->printRight(OB); } }; @@ -1656,7 +1656,7 @@ void printDeclarator(OutputBuffer &OB) const { if (!TemplateParams.empty()) { - SwapAndRestore LT(OB.GtIsGt, 0); + ScopedOverride LT(OB.GtIsGt, 0); OB += "<"; TemplateParams.printWithComma(OB); OB += ">"; @@ -1880,7 +1880,7 @@ void printLeft(OutputBuffer &OB) const override { OB += CastKind; { - SwapAndRestore LT(OB.GtIsGt, 0); + ScopedOverride LT(OB.GtIsGt, 0); OB += "<"; To->printLeft(OB); if (OB.back() == '>') @@ -2857,7 +2857,7 @@ return make(Count); } if (consumeIf("Ul")) { - SwapAndRestore SwapParams(ParsingLambdaParamsAtLevel, + ScopedOverride SwapParams(ParsingLambdaParamsAtLevel, TemplateParams.size()); ScopedTemplateParamList LambdaTemplateParams(this); @@ -3062,11 +3062,11 @@ if (const auto *Op = parseOperatorEncoding()) { if (Op->getKind() == OperatorInfo::CCast) { // ::= cv # (cast) - SwapAndRestore SaveTemplate(TryToParseTemplateArgs, false); + ScopedOverride SaveTemplate(TryToParseTemplateArgs, false); // If we're parsing an encoding, State != nullptr and the conversion // operators' could have a that refers to some // s further ahead in the mangled name. - SwapAndRestore SavePermit(PermitForwardTemplateReferences, + ScopedOverride SavePermit(PermitForwardTemplateReferences, PermitForwardTemplateReferences || State != nullptr); Node *Ty = getDerived().parseType(); @@ -3718,8 +3718,8 @@ StringView ProtoSourceName = Qual.dropFront(std::strlen("objcproto")); StringView Proto; { - SwapAndRestore SaveFirst(First, ProtoSourceName.begin()), - SaveLast(Last, ProtoSourceName.end()); + ScopedOverride SaveFirst(First, ProtoSourceName.begin()), + SaveLast(Last, ProtoSourceName.end()); Proto = parseBareSourceName(); } if (Proto.empty()) @@ -4199,7 +4199,7 @@ return nullptr; Node *Ty; { - SwapAndRestore SaveTemp(TryToParseTemplateArgs, false); + ScopedOverride SaveTemp(TryToParseTemplateArgs, false); Ty = getDerived().parseType(); } @@ -4634,7 +4634,7 @@ // C Cast: (type)expr Node *Ty; { - SwapAndRestore SaveTemp(TryToParseTemplateArgs, false); + ScopedOverride SaveTemp(TryToParseTemplateArgs, false); Ty = getDerived().parseType(); } if (Ty == nullptr) diff --git a/llvm/include/llvm/Demangle/Utility.h b/llvm/include/llvm/Demangle/Utility.h --- a/llvm/include/llvm/Demangle/Utility.h +++ b/llvm/include/llvm/Demangle/Utility.h @@ -181,21 +181,20 @@ size_t getBufferCapacity() const { return BufferCapacity; } }; -template class SwapAndRestore { - T &Restore; - T OriginalValue; +template 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, diff --git a/llvm/lib/Demangle/RustDemangle.cpp b/llvm/lib/Demangle/RustDemangle.cpp --- a/llvm/lib/Demangle/RustDemangle.cpp +++ b/llvm/lib/Demangle/RustDemangle.cpp @@ -24,8 +24,8 @@ using namespace llvm; using llvm::itanium_demangle::OutputBuffer; +using llvm::itanium_demangle::ScopedOverride; using llvm::itanium_demangle::StringView; -using llvm::itanium_demangle::SwapAndRestore; namespace { @@ -119,7 +119,7 @@ if (!Print) return; - SwapAndRestore SavePosition(Position, Position); + ScopedOverride SavePosition(Position, Position); Position = Backref; Demangler(); } @@ -241,7 +241,7 @@ demanglePath(IsInType::No); if (Position != Input.size()) { - SwapAndRestore SavePrint(Print, false); + ScopedOverride SavePrint(Print, false); demanglePath(IsInType::No); } @@ -279,7 +279,7 @@ Error = true; return false; } - SwapAndRestore SaveRecursionLevel(RecursionLevel, RecursionLevel + 1); + ScopedOverride SaveRecursionLevel(RecursionLevel, RecursionLevel + 1); switch (consume()) { case 'C': { @@ -380,7 +380,7 @@ // = [] // = "s" void Demangler::demangleImplPath(IsInType InType) { - SwapAndRestore SavePrint(Print, false); + ScopedOverride SavePrint(Print, false); parseOptionalBase62Number('s'); demanglePath(InType); } @@ -574,7 +574,7 @@ Error = true; return; } - SwapAndRestore SaveRecursionLevel(RecursionLevel, RecursionLevel + 1); + ScopedOverride SaveRecursionLevel(RecursionLevel, RecursionLevel + 1); size_t Start = Position; char C = consume(); @@ -657,7 +657,7 @@ // = "C" // | void Demangler::demangleFnSig() { - SwapAndRestore SaveBoundLifetimes(BoundLifetimes, BoundLifetimes); + ScopedOverride SaveBoundLifetimes(BoundLifetimes, BoundLifetimes); demangleOptionalBinder(); if (consumeIf('U')) @@ -699,7 +699,7 @@ // = [] {} "E" void Demangler::demangleDynBounds() { - SwapAndRestore SaveBoundLifetimes(BoundLifetimes, BoundLifetimes); + ScopedOverride SaveBoundLifetimes(BoundLifetimes, BoundLifetimes); print("dyn "); demangleOptionalBinder(); for (size_t I = 0; !Error && !consumeIf('E'); ++I) { @@ -763,7 +763,7 @@ Error = true; return; } - SwapAndRestore SaveRecursionLevel(RecursionLevel, RecursionLevel + 1); + ScopedOverride SaveRecursionLevel(RecursionLevel, RecursionLevel + 1); char C = consume(); BasicType Type;