Index: libcxxabi/src/demangle/ItaniumDemangle.h =================================================================== --- libcxxabi/src/demangle/ItaniumDemangle.h +++ libcxxabi/src/demangle/ItaniumDemangle.h @@ -737,7 +737,7 @@ void printLeft(OutputBuffer &OB) const override { if (Printing) return; - SwapAndRestore SavePrinting(Printing, true); + DynamicOverride SavePrinting(Printing, true); std::pair Collapsed = collapse(OB); if (!Collapsed.second) return; @@ -752,7 +752,7 @@ void printRight(OutputBuffer &OB) const override { if (Printing) return; - SwapAndRestore SavePrinting(Printing, true); + DynamicOverride SavePrinting(Printing, true); std::pair Collapsed = collapse(OB); if (!Collapsed.second) return; @@ -1260,7 +1260,7 @@ template void match(Fn F) const { F(Name, Params); } void printLeft(OutputBuffer &OB) const override { - SwapAndRestore LT(OB.GtIsGt, 0); + DynamicOverride LT(OB.GtIsGt, 0); OB += "template<"; Params.printWithComma(OB); OB += "> typename "; @@ -1396,8 +1396,8 @@ void printLeft(OutputBuffer &OB) const override { constexpr unsigned Max = std::numeric_limits::max(); - SwapAndRestore SavePackIdx(OB.CurrentPackIndex, Max); - SwapAndRestore SavePackMax(OB.CurrentPackMax, Max); + DynamicOverride SavePackIdx(OB.CurrentPackIndex, Max); + DynamicOverride SavePackMax(OB.CurrentPackMax, Max); size_t StreamPos = OB.getCurrentPosition(); // Print the first element in the pack. If Child contains a ParameterPack, @@ -1438,7 +1438,7 @@ NodeArray getParams() { return Params; } void printLeft(OutputBuffer &OB) const override { - SwapAndRestore LT(OB.GtIsGt, 0); + DynamicOverride LT(OB.GtIsGt, 0); OB += "<"; Params.printWithComma(OB); if (OB.back() == '>') @@ -1488,38 +1488,38 @@ bool hasRHSComponentSlow(OutputBuffer &OB) const override { if (Printing) return false; - SwapAndRestore SavePrinting(Printing, true); + DynamicOverride SavePrinting(Printing, true); return Ref->hasRHSComponent(OB); } bool hasArraySlow(OutputBuffer &OB) const override { if (Printing) return false; - SwapAndRestore SavePrinting(Printing, true); + DynamicOverride SavePrinting(Printing, true); return Ref->hasArray(OB); } bool hasFunctionSlow(OutputBuffer &OB) const override { if (Printing) return false; - SwapAndRestore SavePrinting(Printing, true); + DynamicOverride SavePrinting(Printing, true); return Ref->hasFunction(OB); } const Node *getSyntaxNode(OutputBuffer &OB) const override { if (Printing) return this; - SwapAndRestore SavePrinting(Printing, true); + DynamicOverride SavePrinting(Printing, true); return Ref->getSyntaxNode(OB); } void printLeft(OutputBuffer &OB) const override { if (Printing) return; - SwapAndRestore SavePrinting(Printing, true); + DynamicOverride SavePrinting(Printing, true); Ref->printLeft(OB); } void printRight(OutputBuffer &OB) const override { if (Printing) return; - SwapAndRestore SavePrinting(Printing, true); + DynamicOverride SavePrinting(Printing, true); Ref->printRight(OB); } }; @@ -1736,7 +1736,7 @@ void printDeclarator(OutputBuffer &OB) const { if (!TemplateParams.empty()) { - SwapAndRestore LT(OB.GtIsGt, 0); + DynamicOverride LT(OB.GtIsGt, 0); OB += "<"; TemplateParams.printWithComma(OB); OB += ">"; @@ -1944,7 +1944,7 @@ void printLeft(OutputBuffer &OB) const override { OB += CastKind; { - SwapAndRestore LT(OB.GtIsGt, 0); + DynamicOverride LT(OB.GtIsGt, 0); OB += "<"; To->printLeft(OB); if (OB.back() == '>') @@ -2911,8 +2911,8 @@ return make(Count); } if (consumeIf("Ul")) { - SwapAndRestore SwapParams(ParsingLambdaParamsAtLevel, - TemplateParams.size()); + DynamicOverride SwapParams(ParsingLambdaParamsAtLevel, + TemplateParams.size()); ScopedTemplateParamList LambdaTemplateParams(this); size_t ParamsBegin = Names.size(); @@ -3116,13 +3116,13 @@ if (const auto *Op = parseOperatorEncoding()) { if (Op->getKind() == OperatorInfo::CCast) { // ::= cv # (cast) - SwapAndRestore SaveTemplate(TryToParseTemplateArgs, false); + DynamicOverride 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, - PermitForwardTemplateReferences || - State != nullptr); + DynamicOverride SavePermit(PermitForwardTemplateReferences, + PermitForwardTemplateReferences || + State != nullptr); Node *Ty = getDerived().parseType(); if (Ty == nullptr) return nullptr; @@ -3771,8 +3771,8 @@ StringView ProtoSourceName = Qual.dropFront(std::strlen("objcproto")); StringView Proto; { - SwapAndRestore SaveFirst(First, ProtoSourceName.begin()), - SaveLast(Last, ProtoSourceName.end()); + DynamicOverride SaveFirst(First, ProtoSourceName.begin()), + SaveLast(Last, ProtoSourceName.end()); Proto = parseBareSourceName(); } if (Proto.empty()) @@ -4252,7 +4252,7 @@ return nullptr; Node *Ty; { - SwapAndRestore SaveTemp(TryToParseTemplateArgs, false); + DynamicOverride SaveTemp(TryToParseTemplateArgs, false); Ty = getDerived().parseType(); } @@ -4687,7 +4687,7 @@ // C Cast: (type)expr Node *Ty; { - SwapAndRestore SaveTemp(TryToParseTemplateArgs, false); + DynamicOverride SaveTemp(TryToParseTemplateArgs, false); Ty = getDerived().parseType(); } if (Ty == nullptr) Index: libcxxabi/src/demangle/Utility.h =================================================================== --- libcxxabi/src/demangle/Utility.h +++ libcxxabi/src/demangle/Utility.h @@ -177,21 +177,20 @@ size_t getBufferCapacity() const { return BufferCapacity; } }; -template class SwapAndRestore { - T &Restore; - T OriginalValue; +template class DynamicOverride { + T &Loc; + T Original; public: - SwapAndRestore(T &Restore_) : SwapAndRestore(Restore_, Restore_) {} + DynamicOverride(T &Loc_) : DynamicOverride(Loc_, Loc_) {} - SwapAndRestore(T &Restore_, T NewVal) - : Restore(Restore_), OriginalValue(Restore) { - Restore = std::move(NewVal); + DynamicOverride(T &Loc_, T NewVal) : Loc(Loc_), Original(Loc_) { + Loc_ = std::move(NewVal); } - ~SwapAndRestore() { Restore = std::move(OriginalValue); } + ~DynamicOverride() { Loc = std::move(Original); } - SwapAndRestore(const SwapAndRestore &) = delete; - SwapAndRestore &operator=(const SwapAndRestore &) = delete; + DynamicOverride(const DynamicOverride &) = delete; + DynamicOverride &operator=(const DynamicOverride &) = delete; }; DEMANGLE_NAMESPACE_END Index: llvm/include/llvm/Demangle/ItaniumDemangle.h =================================================================== --- llvm/include/llvm/Demangle/ItaniumDemangle.h +++ llvm/include/llvm/Demangle/ItaniumDemangle.h @@ -737,7 +737,7 @@ void printLeft(OutputBuffer &OB) const override { if (Printing) return; - SwapAndRestore SavePrinting(Printing, true); + DynamicOverride SavePrinting(Printing, true); std::pair Collapsed = collapse(OB); if (!Collapsed.second) return; @@ -752,7 +752,7 @@ void printRight(OutputBuffer &OB) const override { if (Printing) return; - SwapAndRestore SavePrinting(Printing, true); + DynamicOverride SavePrinting(Printing, true); std::pair Collapsed = collapse(OB); if (!Collapsed.second) return; @@ -1260,7 +1260,7 @@ template void match(Fn F) const { F(Name, Params); } void printLeft(OutputBuffer &OB) const override { - SwapAndRestore LT(OB.GtIsGt, 0); + DynamicOverride LT(OB.GtIsGt, 0); OB += "template<"; Params.printWithComma(OB); OB += "> typename "; @@ -1396,8 +1396,8 @@ void printLeft(OutputBuffer &OB) const override { constexpr unsigned Max = std::numeric_limits::max(); - SwapAndRestore SavePackIdx(OB.CurrentPackIndex, Max); - SwapAndRestore SavePackMax(OB.CurrentPackMax, Max); + DynamicOverride SavePackIdx(OB.CurrentPackIndex, Max); + DynamicOverride SavePackMax(OB.CurrentPackMax, Max); size_t StreamPos = OB.getCurrentPosition(); // Print the first element in the pack. If Child contains a ParameterPack, @@ -1438,7 +1438,7 @@ NodeArray getParams() { return Params; } void printLeft(OutputBuffer &OB) const override { - SwapAndRestore LT(OB.GtIsGt, 0); + DynamicOverride LT(OB.GtIsGt, 0); OB += "<"; Params.printWithComma(OB); if (OB.back() == '>') @@ -1488,38 +1488,38 @@ bool hasRHSComponentSlow(OutputBuffer &OB) const override { if (Printing) return false; - SwapAndRestore SavePrinting(Printing, true); + DynamicOverride SavePrinting(Printing, true); return Ref->hasRHSComponent(OB); } bool hasArraySlow(OutputBuffer &OB) const override { if (Printing) return false; - SwapAndRestore SavePrinting(Printing, true); + DynamicOverride SavePrinting(Printing, true); return Ref->hasArray(OB); } bool hasFunctionSlow(OutputBuffer &OB) const override { if (Printing) return false; - SwapAndRestore SavePrinting(Printing, true); + DynamicOverride SavePrinting(Printing, true); return Ref->hasFunction(OB); } const Node *getSyntaxNode(OutputBuffer &OB) const override { if (Printing) return this; - SwapAndRestore SavePrinting(Printing, true); + DynamicOverride SavePrinting(Printing, true); return Ref->getSyntaxNode(OB); } void printLeft(OutputBuffer &OB) const override { if (Printing) return; - SwapAndRestore SavePrinting(Printing, true); + DynamicOverride SavePrinting(Printing, true); Ref->printLeft(OB); } void printRight(OutputBuffer &OB) const override { if (Printing) return; - SwapAndRestore SavePrinting(Printing, true); + DynamicOverride SavePrinting(Printing, true); Ref->printRight(OB); } }; @@ -1736,7 +1736,7 @@ void printDeclarator(OutputBuffer &OB) const { if (!TemplateParams.empty()) { - SwapAndRestore LT(OB.GtIsGt, 0); + DynamicOverride LT(OB.GtIsGt, 0); OB += "<"; TemplateParams.printWithComma(OB); OB += ">"; @@ -1944,7 +1944,7 @@ void printLeft(OutputBuffer &OB) const override { OB += CastKind; { - SwapAndRestore LT(OB.GtIsGt, 0); + DynamicOverride LT(OB.GtIsGt, 0); OB += "<"; To->printLeft(OB); if (OB.back() == '>') @@ -2911,8 +2911,8 @@ return make(Count); } if (consumeIf("Ul")) { - SwapAndRestore SwapParams(ParsingLambdaParamsAtLevel, - TemplateParams.size()); + DynamicOverride SwapParams(ParsingLambdaParamsAtLevel, + TemplateParams.size()); ScopedTemplateParamList LambdaTemplateParams(this); size_t ParamsBegin = Names.size(); @@ -3116,13 +3116,13 @@ if (const auto *Op = parseOperatorEncoding()) { if (Op->getKind() == OperatorInfo::CCast) { // ::= cv # (cast) - SwapAndRestore SaveTemplate(TryToParseTemplateArgs, false); + DynamicOverride 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, - PermitForwardTemplateReferences || - State != nullptr); + DynamicOverride SavePermit(PermitForwardTemplateReferences, + PermitForwardTemplateReferences || + State != nullptr); Node *Ty = getDerived().parseType(); if (Ty == nullptr) return nullptr; @@ -3771,8 +3771,8 @@ StringView ProtoSourceName = Qual.dropFront(std::strlen("objcproto")); StringView Proto; { - SwapAndRestore SaveFirst(First, ProtoSourceName.begin()), - SaveLast(Last, ProtoSourceName.end()); + DynamicOverride SaveFirst(First, ProtoSourceName.begin()), + SaveLast(Last, ProtoSourceName.end()); Proto = parseBareSourceName(); } if (Proto.empty()) @@ -4252,7 +4252,7 @@ return nullptr; Node *Ty; { - SwapAndRestore SaveTemp(TryToParseTemplateArgs, false); + DynamicOverride SaveTemp(TryToParseTemplateArgs, false); Ty = getDerived().parseType(); } @@ -4687,7 +4687,7 @@ // C Cast: (type)expr Node *Ty; { - SwapAndRestore SaveTemp(TryToParseTemplateArgs, false); + DynamicOverride SaveTemp(TryToParseTemplateArgs, false); Ty = getDerived().parseType(); } if (Ty == nullptr) Index: llvm/include/llvm/Demangle/Utility.h =================================================================== --- llvm/include/llvm/Demangle/Utility.h +++ llvm/include/llvm/Demangle/Utility.h @@ -177,21 +177,20 @@ size_t getBufferCapacity() const { return BufferCapacity; } }; -template class SwapAndRestore { - T &Restore; - T OriginalValue; +template class DynamicOverride { + T &Loc; + T Original; public: - SwapAndRestore(T &Restore_) : SwapAndRestore(Restore_, Restore_) {} + DynamicOverride(T &Loc_) : DynamicOverride(Loc_, Loc_) {} - SwapAndRestore(T &Restore_, T NewVal) - : Restore(Restore_), OriginalValue(Restore) { - Restore = std::move(NewVal); + DynamicOverride(T &Loc_, T NewVal) : Loc(Loc_), Original(Loc_) { + Loc_ = std::move(NewVal); } - ~SwapAndRestore() { Restore = std::move(OriginalValue); } + ~DynamicOverride() { Loc = std::move(Original); } - SwapAndRestore(const SwapAndRestore &) = delete; - SwapAndRestore &operator=(const SwapAndRestore &) = delete; + DynamicOverride(const DynamicOverride &) = delete; + DynamicOverride &operator=(const DynamicOverride &) = delete; }; DEMANGLE_NAMESPACE_END Index: llvm/lib/Demangle/RustDemangle.cpp =================================================================== --- llvm/lib/Demangle/RustDemangle.cpp +++ llvm/lib/Demangle/RustDemangle.cpp @@ -23,9 +23,9 @@ using namespace llvm; +using llvm::itanium_demangle::DynamicOverride; using llvm::itanium_demangle::OutputBuffer; using llvm::itanium_demangle::StringView; -using llvm::itanium_demangle::SwapAndRestore; namespace { @@ -119,7 +119,7 @@ if (!Print) return; - SwapAndRestore SavePosition(Position, Position); + DynamicOverride SavePosition(Position, Position); Position = Backref; Demangler(); } @@ -235,7 +235,7 @@ demanglePath(IsInType::No); if (Position != Input.size()) { - SwapAndRestore SavePrint(Print, false); + DynamicOverride SavePrint(Print, false); demanglePath(IsInType::No); } @@ -273,7 +273,8 @@ Error = true; return false; } - SwapAndRestore SaveRecursionLevel(RecursionLevel, RecursionLevel + 1); + DynamicOverride SaveRecursionLevel(RecursionLevel, + RecursionLevel + 1); switch (consume()) { case 'C': { @@ -374,7 +375,7 @@ // = [] // = "s" void Demangler::demangleImplPath(IsInType InType) { - SwapAndRestore SavePrint(Print, false); + DynamicOverride SavePrint(Print, false); parseOptionalBase62Number('s'); demanglePath(InType); } @@ -568,7 +569,8 @@ Error = true; return; } - SwapAndRestore SaveRecursionLevel(RecursionLevel, RecursionLevel + 1); + DynamicOverride SaveRecursionLevel(RecursionLevel, + RecursionLevel + 1); size_t Start = Position; char C = consume(); @@ -651,7 +653,7 @@ // = "C" // | void Demangler::demangleFnSig() { - SwapAndRestore SaveBoundLifetimes(BoundLifetimes, BoundLifetimes); + DynamicOverride SaveBoundLifetimes(BoundLifetimes, BoundLifetimes); demangleOptionalBinder(); if (consumeIf('U')) @@ -693,7 +695,7 @@ // = [] {} "E" void Demangler::demangleDynBounds() { - SwapAndRestore SaveBoundLifetimes(BoundLifetimes, BoundLifetimes); + DynamicOverride SaveBoundLifetimes(BoundLifetimes, BoundLifetimes); print("dyn "); demangleOptionalBinder(); for (size_t I = 0; !Error && !consumeIf('E'); ++I) { @@ -757,7 +759,8 @@ Error = true; return; } - SwapAndRestore SaveRecursionLevel(RecursionLevel, RecursionLevel + 1); + DynamicOverride SaveRecursionLevel(RecursionLevel, + RecursionLevel + 1); char C = consume(); BasicType Type;