diff options
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Demangle/RustDemangle.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/lib/Demangle/RustDemangle.cpp | 58 |
1 files changed, 14 insertions, 44 deletions
diff --git a/contrib/llvm-project/llvm/lib/Demangle/RustDemangle.cpp b/contrib/llvm-project/llvm/lib/Demangle/RustDemangle.cpp index dcac0bd63859..32b10db2a968 100644 --- a/contrib/llvm-project/llvm/lib/Demangle/RustDemangle.cpp +++ b/contrib/llvm-project/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 @@ private: if (!Print) return; - SwapAndRestore<size_t> SavePosition(Position, Position); + ScopedOverride<size_t> SavePosition(Position, Position); Position = Backref; Demangler(); } @@ -147,57 +147,27 @@ private: } // namespace -char *llvm::rustDemangle(const char *MangledName, char *Buf, size_t *N, - int *Status) { - if (MangledName == nullptr || (Buf != nullptr && N == nullptr)) { - if (Status != nullptr) - *Status = demangle_invalid_args; +char *llvm::rustDemangle(const char *MangledName) { + if (MangledName == nullptr) return nullptr; - } // Return early if mangled name doesn't look like a Rust symbol. StringView Mangled(MangledName); - if (!Mangled.startsWith("_R")) { - if (Status != nullptr) - *Status = demangle_invalid_mangled_name; + if (!Mangled.startsWith("_R")) return nullptr; - } Demangler D; - if (!initializeOutputBuffer(nullptr, nullptr, D.Output, 1024)) { - if (Status != nullptr) - *Status = demangle_memory_alloc_failure; + if (!initializeOutputBuffer(nullptr, nullptr, D.Output, 1024)) return nullptr; - } if (!D.demangle(Mangled)) { - if (Status != nullptr) - *Status = demangle_invalid_mangled_name; std::free(D.Output.getBuffer()); return nullptr; } D.Output += '\0'; - char *Demangled = D.Output.getBuffer(); - size_t DemangledLen = D.Output.getCurrentPosition(); - - if (Buf != nullptr) { - if (DemangledLen <= *N) { - std::memcpy(Buf, Demangled, DemangledLen); - std::free(Demangled); - Demangled = Buf; - } else { - std::free(Buf); - } - } - - if (N != nullptr) - *N = DemangledLen; - - if (Status != nullptr) - *Status = demangle_success; - return Demangled; + return D.Output.getBuffer(); } Demangler::Demangler(size_t MaxRecursionLevel) @@ -241,7 +211,7 @@ bool Demangler::demangle(StringView Mangled) { demanglePath(IsInType::No); if (Position != Input.size()) { - SwapAndRestore<bool> SavePrint(Print, false); + ScopedOverride<bool> SavePrint(Print, false); demanglePath(IsInType::No); } @@ -279,7 +249,7 @@ bool Demangler::demanglePath(IsInType InType, LeaveGenericsOpen LeaveOpen) { Error = true; return false; } - SwapAndRestore<size_t> SaveRecursionLevel(RecursionLevel, RecursionLevel + 1); + ScopedOverride<size_t> SaveRecursionLevel(RecursionLevel, RecursionLevel + 1); switch (consume()) { case 'C': { @@ -380,7 +350,7 @@ bool Demangler::demanglePath(IsInType InType, LeaveGenericsOpen LeaveOpen) { // <impl-path> = [<disambiguator>] <path> // <disambiguator> = "s" <base-62-number> void Demangler::demangleImplPath(IsInType InType) { - SwapAndRestore<bool> SavePrint(Print, false); + ScopedOverride<bool> SavePrint(Print, false); parseOptionalBase62Number('s'); demanglePath(InType); } @@ -574,7 +544,7 @@ void Demangler::demangleType() { Error = true; return; } - SwapAndRestore<size_t> SaveRecursionLevel(RecursionLevel, RecursionLevel + 1); + ScopedOverride<size_t> SaveRecursionLevel(RecursionLevel, RecursionLevel + 1); size_t Start = Position; char C = consume(); @@ -657,7 +627,7 @@ void Demangler::demangleType() { // <abi> = "C" // | <undisambiguated-identifier> void Demangler::demangleFnSig() { - SwapAndRestore<size_t> SaveBoundLifetimes(BoundLifetimes, BoundLifetimes); + ScopedOverride<size_t> SaveBoundLifetimes(BoundLifetimes, BoundLifetimes); demangleOptionalBinder(); if (consumeIf('U')) @@ -699,7 +669,7 @@ void Demangler::demangleFnSig() { // <dyn-bounds> = [<binder>] {<dyn-trait>} "E" void Demangler::demangleDynBounds() { - SwapAndRestore<size_t> SaveBoundLifetimes(BoundLifetimes, BoundLifetimes); + ScopedOverride<size_t> SaveBoundLifetimes(BoundLifetimes, BoundLifetimes); print("dyn "); demangleOptionalBinder(); for (size_t I = 0; !Error && !consumeIf('E'); ++I) { @@ -763,7 +733,7 @@ void Demangler::demangleConst() { Error = true; return; } - SwapAndRestore<size_t> SaveRecursionLevel(RecursionLevel, RecursionLevel + 1); + ScopedOverride<size_t> SaveRecursionLevel(RecursionLevel, RecursionLevel + 1); char C = consume(); BasicType Type; |