diff options
Diffstat (limited to 'contrib/llvm/tools/lld/ELF/Strings.cpp')
-rw-r--r-- | contrib/llvm/tools/lld/ELF/Strings.cpp | 80 |
1 files changed, 45 insertions, 35 deletions
diff --git a/contrib/llvm/tools/lld/ELF/Strings.cpp b/contrib/llvm/tools/lld/ELF/Strings.cpp index 0c21e88..ec3d1f1 100644 --- a/contrib/llvm/tools/lld/ELF/Strings.cpp +++ b/contrib/llvm/tools/lld/ELF/Strings.cpp @@ -8,44 +8,59 @@ //===----------------------------------------------------------------------===// #include "Strings.h" +#include "Config.h" #include "Error.h" +#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Twine.h" -#include "llvm/Config/config.h" +#include "llvm/Demangle/Demangle.h" #include <algorithm> - -#ifdef HAVE_CXXABI_H -#include <cxxabi.h> -#endif +#include <cstring> using namespace llvm; using namespace lld; using namespace lld::elf; -// Returns true if S matches T. S can contain glob meta-characters. -// The asterisk ('*') matches zero or more characters, and the question -// mark ('?') matches one character. -bool elf::globMatch(StringRef S, StringRef T) { - for (;;) { - if (S.empty()) - return T.empty(); - if (S[0] == '*') { - S = S.substr(1); - if (S.empty()) - // Fast path. If a pattern is '*', it matches anything. - return true; - for (size_t I = 0, E = T.size(); I < E; ++I) - if (globMatch(S, T.substr(I))) - return true; - return false; - } - if (T.empty() || (S[0] != T[0] && S[0] != '?')) - return false; - S = S.substr(1); - T = T.substr(1); +StringMatcher::StringMatcher(ArrayRef<StringRef> Pat) { + for (StringRef S : Pat) { + Expected<GlobPattern> Pat = GlobPattern::create(S); + if (!Pat) + error(toString(Pat.takeError())); + else + Patterns.push_back(*Pat); } } +bool StringMatcher::match(StringRef S) const { + for (const GlobPattern &Pat : Patterns) + if (Pat.match(S)) + return true; + return false; +} + +// If an input string is in the form of "foo.N" where N is a number, +// return N. Otherwise, returns 65536, which is one greater than the +// lowest priority. +int elf::getPriority(StringRef S) { + size_t Pos = S.rfind('.'); + if (Pos == StringRef::npos) + return 65536; + int V; + if (S.substr(Pos + 1).getAsInteger(10, V)) + return 65536; + return V; +} + +bool elf::hasWildcard(StringRef S) { + return S.find_first_of("?*[") != StringRef::npos; +} + +StringRef elf::unquote(StringRef S) { + if (!S.startswith("\"")) + return S; + return S.substr(1, S.size() - 2); +} + // Converts a hex string (e.g. "deadbeef") to a vector. std::vector<uint8_t> elf::parseHex(StringRef S) { std::vector<uint8_t> Hex; @@ -75,24 +90,19 @@ bool elf::isValidCIdentifier(StringRef S) { } // Returns the demangled C++ symbol name for Name. -std::string elf::demangle(StringRef Name) { -#if !defined(HAVE_CXXABI_H) - return Name; -#else +Optional<std::string> elf::demangle(StringRef Name) { // __cxa_demangle 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 __cxa_demangle 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 Name; + return None; - char *Buf = - abi::__cxa_demangle(Name.str().c_str(), nullptr, nullptr, nullptr); + char *Buf = itaniumDemangle(Name.str().c_str(), nullptr, nullptr, nullptr); if (!Buf) - return Name; + return None; std::string S(Buf); free(Buf); return S; -#endif } |