aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Demangle/MicrosoftDemangle.cpp
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@acm.org>2022-03-01 08:36:24 -0800
committerNathan Sidwell <nathan@acm.org>2022-03-28 11:19:55 -0700
commit1066e397fa907629f0da370f9721821c838ed30a (patch)
treefe0c8f680df1ec22eb5643b2703b987f94227780 /llvm/lib/Demangle/MicrosoftDemangle.cpp
parentb6dab4ebac595c61ed00c8559307a15fd3b9d077 (diff)
downloadllvm-1066e397fa907629f0da370f9721821c838ed30a.zip
llvm-1066e397fa907629f0da370f9721821c838ed30a.tar.gz
llvm-1066e397fa907629f0da370f9721821c838ed30a.tar.bz2
[demangler] Add StringView conversion operator
The OutputBuffer class tries to present a NUL-terminated string API to consumers. But several of them would prefer a StringView. In particular the Microsoft demangler, juggles between NUL-terminated and StringView, which is confusing. This adds a StringView conversion, and adjusts the Demanglers that can benefit from that. Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D120990
Diffstat (limited to 'llvm/lib/Demangle/MicrosoftDemangle.cpp')
-rw-r--r--llvm/lib/Demangle/MicrosoftDemangle.cpp25
1 files changed, 9 insertions, 16 deletions
diff --git a/llvm/lib/Demangle/MicrosoftDemangle.cpp b/llvm/lib/Demangle/MicrosoftDemangle.cpp
index a009bef..aca8cf7 100644
--- a/llvm/lib/Demangle/MicrosoftDemangle.cpp
+++ b/llvm/lib/Demangle/MicrosoftDemangle.cpp
@@ -970,12 +970,9 @@ void Demangler::memorizeIdentifier(IdentifierNode *Identifier) {
// FIXME: Propagate out-of-memory as an error?
std::terminate();
Identifier->output(OB, OF_Default);
- OB << '\0';
- char *Name = OB.getBuffer();
-
- StringView Owned = copyString(Name);
+ StringView Owned = copyString(OB);
memorizeString(Owned);
- std::free(Name);
+ std::free(OB.getBuffer());
}
IdentifierNode *
@@ -1279,7 +1276,6 @@ Demangler::demangleStringLiteral(StringView &MangledName) {
bool IsWcharT = false;
bool IsNegative = false;
size_t CrcEndPos = 0;
- char *ResultBuffer = nullptr;
EncodedStringLiteralNode *Result = Arena.alloc<EncodedStringLiteralNode>();
@@ -1375,10 +1371,8 @@ Demangler::demangleStringLiteral(StringView &MangledName) {
}
}
- OB << '\0';
- ResultBuffer = OB.getBuffer();
- Result->DecodedString = copyString(ResultBuffer);
- std::free(ResultBuffer);
+ Result->DecodedString = copyString(OB);
+ std::free(OB.getBuffer());
return Result;
StringLiteralError:
@@ -1455,10 +1449,9 @@ Demangler::demangleLocallyScopedNamePiece(StringView &MangledName) {
Scope->output(OB, OF_Default);
OB << '\'';
OB << "::`" << Number << "'";
- OB << '\0';
- char *Result = OB.getBuffer();
- Identifier->Name = copyString(Result);
- std::free(Result);
+
+ Identifier->Name = copyString(OB);
+ std::free(OB.getBuffer());
return Identifier;
}
@@ -2322,8 +2315,8 @@ void Demangler::dumpBackReferences() {
TypeNode *T = Backrefs.FunctionParams[I];
T->output(OB, OF_Default);
- std::printf(" [%d] - %.*s\n", (int)I, (int)OB.getCurrentPosition(),
- OB.getBuffer());
+ StringView B = OB;
+ std::printf(" [%d] - %.*s\n", (int)I, (int)B.size(), B.begin());
}
std::free(OB.getBuffer());