diff options
Diffstat (limited to 'ELF/Strings.cpp')
-rw-r--r-- | ELF/Strings.cpp | 31 |
1 files changed, 4 insertions, 27 deletions
diff --git a/ELF/Strings.cpp b/ELF/Strings.cpp index bca86384002de..0ef33a14bc3d4 100644 --- a/ELF/Strings.cpp +++ b/ELF/Strings.cpp @@ -9,7 +9,7 @@ #include "Strings.h" #include "Config.h" -#include "Error.h" +#include "lld/Common/ErrorHandler.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Twine.h" @@ -54,32 +54,9 @@ std::vector<uint8_t> elf::parseHex(StringRef S) { return Hex; } -static bool isAlpha(char C) { - return ('a' <= C && C <= 'z') || ('A' <= C && C <= 'Z') || C == '_'; -} - -static bool isAlnum(char C) { return isAlpha(C) || ('0' <= C && C <= '9'); } - // Returns true if S is valid as a C language identifier. bool elf::isValidCIdentifier(StringRef S) { - return !S.empty() && isAlpha(S[0]) && - std::all_of(S.begin() + 1, S.end(), isAlnum); -} - -// Returns the demangled C++ symbol name for Name. -Optional<std::string> elf::demangle(StringRef Name) { - // itaniumDemangle can be used to demangle strings other than symbol - // names which do not necessarily start with "_Z". Name can be - // either a C or C++ symbol. Don't call itaniumDemangle if the name - // does not look like a C++ symbol name to avoid getting unexpected - // result for a C symbol that happens to match a mangled type name. - if (!Name.startswith("_Z")) - return None; - - char *Buf = itaniumDemangle(Name.str().c_str(), nullptr, nullptr, nullptr); - if (!Buf) - return None; - std::string S(Buf); - free(Buf); - return S; + return !S.empty() && (isAlpha(S[0]) || S[0] == '_') && + std::all_of(S.begin() + 1, S.end(), + [](char C) { return C == '_' || isAlnum(C); }); } |