diff options
author | Rui Ueyama <ruiu@google.com> | 2016-06-29 09:08:02 +0000 |
---|---|---|
committer | Rui Ueyama <ruiu@google.com> | 2016-06-29 09:08:02 +0000 |
commit | cbe9851d306f3c31ecd3643c1dab931a0e06b4c1 (patch) | |
tree | 74e43902f55d97de86e8e0709ca1b931e91b90fc | |
parent | 9bdbd6e48ed4bd82dfa229b0dcd499a6de763886 (diff) |
Move isValidCIdentifier to Strings.cpp.
git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@274112 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | ELF/OutputSections.cpp | 13 | ||||
-rw-r--r-- | ELF/Strings.cpp | 13 | ||||
-rw-r--r-- | ELF/Strings.h | 1 | ||||
-rw-r--r-- | ELF/Writer.cpp | 1 |
4 files changed, 16 insertions, 12 deletions
diff --git a/ELF/OutputSections.cpp b/ELF/OutputSections.cpp index 4636b9990..4be844739 100644 --- a/ELF/OutputSections.cpp +++ b/ELF/OutputSections.cpp @@ -11,6 +11,7 @@ #include "Config.h" #include "EhFrame.h" #include "LinkerScript.h" +#include "Strings.h" #include "SymbolTable.h" #include "Target.h" #include "lld/Core/Parallel.h" @@ -29,18 +30,6 @@ using namespace llvm::ELF; using namespace lld; using namespace lld::elf; -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); -} - template <class ELFT> OutputSectionBase<ELFT>::OutputSectionBase(StringRef Name, uint32_t Type, uintX_t Flags) diff --git a/ELF/Strings.cpp b/ELF/Strings.cpp index a7aecf090..21d7f428e 100644 --- a/ELF/Strings.cpp +++ b/ELF/Strings.cpp @@ -11,6 +11,7 @@ #include "Error.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Twine.h" +#include <algorithm> using namespace llvm; using namespace lld; @@ -55,3 +56,15 @@ 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); +} diff --git a/ELF/Strings.h b/ELF/Strings.h index 1930a0aab..002e8c2b8 100644 --- a/ELF/Strings.h +++ b/ELF/Strings.h @@ -17,6 +17,7 @@ namespace lld { namespace elf { bool globMatch(StringRef S, StringRef T); std::vector<uint8_t> parseHex(StringRef S); +bool isValidCIdentifier(StringRef S); } } diff --git a/ELF/Writer.cpp b/ELF/Writer.cpp index 849a67f03..323a791c3 100644 --- a/ELF/Writer.cpp +++ b/ELF/Writer.cpp @@ -12,6 +12,7 @@ #include "LinkerScript.h" #include "OutputSections.h" #include "Relocations.h" +#include "Strings.h" #include "SymbolTable.h" #include "Target.h" |