23 #include <system_error> 31 std::string &REError) {
33 REError =
"Supplied regexp was blank";
38 Strings[Regexp] = LineNumber;
44 for (
size_t pos = 0; (pos = Regexp.find(
'*', pos)) != std::string::npos;
45 pos += strlen(
".*")) {
46 Regexp.replace(pos, strlen(
"*"),
".*");
52 Regex CheckRE(Regexp);
57 std::make_pair(std::make_unique<Regex>(std::move(CheckRE)), LineNumber));
62 auto It = Strings.
find(Query);
63 if (It != Strings.
end())
67 for (
auto& RegExKV : RegExes)
68 if (RegExKV.first->match(Query))
69 return RegExKV.second;
73 std::unique_ptr<SpecialCaseList>
77 if (SCL->createInternal(Paths, FS, Error))
85 if (SCL->createInternal(MB, Error))
90 std::unique_ptr<SpecialCaseList>
94 if (
auto SCL =
create(Paths, FS, Error))
102 for (
const auto &Path : Paths) {
105 if (std::error_code EC = FileOrErr.
getError()) {
106 Error = (
Twine(
"can't open file '") + Path +
"': " + EC.message()).str();
109 std::string ParseError;
111 Error = (
Twine(
"error parsing file '") + Path +
"': " + ParseError).str();
119 std::string &
Error) {
121 if (!
parse(MB, Sections, Error))
128 std::string &
Error) {
136 for (
auto I = Lines.
begin(),
E = Lines.
end();
I !=
E; ++
I, ++LineNo) {
139 if (
I->empty() ||
I->startswith(
"#"))
143 if (
I->startswith(
"[")) {
144 if (!
I->endswith(
"]")) {
145 Error = (
Twine(
"malformed section header on line ") +
Twine(LineNo) +
150 Section =
I->slice(1,
I->size() - 1);
153 Regex CheckRE(Section);
154 if (!CheckRE.
isValid(REError)) {
156 (
Twine(
"malformed regex for section ") + Section +
": '" + REError)
165 std::pair<StringRef, StringRef> SplitLine =
I->split(
":");
167 if (SplitLine.second.empty()) {
169 Error = (
Twine(
"malformed line ") +
Twine(LineNo) +
": '" +
170 SplitLine.first +
"'").str();
174 std::pair<StringRef, StringRef> SplitRegexp = SplitLine.second.split(
"=");
175 std::string Regexp = SplitRegexp.first;
179 if (SectionsMap.
find(Section) == SectionsMap.
end()) {
180 std::unique_ptr<Matcher> M = std::make_unique<Matcher>();
182 if (!M->insert(Section, LineNo, REError)) {
183 Error = (
Twine(
"malformed section ") + Section +
": '" + REError).str();
188 Sections.emplace_back(std::move(M));
193 if (!
Entry.insert(std::move(Regexp), LineNo, REError)) {
194 Error = (
Twine(
"malformed regex in line ") +
Twine(LineNo) +
": '" +
195 SplitLine.second +
"': " + REError).str();
213 if (SectionIter.SectionMatcher->match(Section)) {
226 if (I == Entries.
end())
return 0;
228 if (II == I->second.end())
return 0;
230 return II->getValue().match(Query);
Represents either an error or a value T.
StringRef getBuffer() const
unsigned inSectionBlame(StringRef Section, StringRef Prefix, StringRef Query, StringRef Category=StringRef()) const
Returns the line number corresponding to the special case list entry if the special case list contain...
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
bool isDefinitelyOut(StringRef Query) const
Returns true, if special case list definitely does not have a line that matches the query...
iterator find(StringRef Key)
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > getBufferForFile(const Twine &Name, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatile=false)
This is a convenience method that opens a file, gets its content and then closes the file...
bool inSection(StringRef Section, StringRef Prefix, StringRef Query, StringRef Category=StringRef()) const
Returns true, if special case list contains a line.
unsigned match(StringRef Query) const
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
bool parse(const MemoryBuffer *MB, StringMap< size_t > &SectionsMap, std::string &Error)
Parses just-constructed SpecialCaseList entries from a memory buffer.
bool createInternal(const std::vector< std::string > &Paths, vfs::FileSystem &VFS, std::string &Error)
void insert(std::string Regex)
Inserts a new Regex into the index.
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
std::error_code getError() const
SpecialCaseList()=default
static std::unique_ptr< SpecialCaseList > createOrDie(const std::vector< std::string > &Paths, llvm::vfs::FileSystem &FS)
Parses the special case list entries from files.
static bool isLiteralERE(StringRef Str)
If this function returns true, ^Str$ is an extended regular expression that matches Str and only Str...
std::vector< Section > Sections
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
The virtual file system interface.
bool isValid(std::string &Error) const
isValid - returns the error encountered during regex compilation, if any.
This interface provides simple read-only access to a block of memory, and provides simple methods for...
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
Defines the virtual file system interface vfs::FileSystem.
static std::unique_ptr< SpecialCaseList > create(const std::vector< std::string > &Paths, llvm::vfs::FileSystem &FS, std::string &Error)
Parses the special case list entries from files.
bool insert(std::string Regexp, unsigned LineNumber, std::string &REError)
Lightweight error class with error context and mandatory checking.
StringRef - Represent a constant reference to a string, i.e.