23#include <system_error>
33 (UseGlobs ?
"glob" :
"regex") +
" was blank");
38 for (
size_t pos = 0; (pos = Regexp.find(
'*', pos)) != std::string::npos;
39 pos += strlen(
".*")) {
40 Regexp.replace(pos, strlen(
"*"),
".*");
46 Regex CheckRE(Regexp);
51 RegExes.emplace_back(std::make_pair(
52 std::make_unique<Regex>(std::move(CheckRE)), LineNumber));
57 auto Glob = std::make_unique<Matcher::Glob>();
80std::unique_ptr<SpecialCaseList>
84 if (SCL->createInternal(Paths, FS,
Error))
92 if (SCL->createInternal(MB,
Error))
97std::unique_ptr<SpecialCaseList>
108 for (
size_t i = 0; i < Paths.size(); ++i) {
109 const auto &Path = Paths[i];
112 if (std::error_code EC = FileOrErr.
getError()) {
113 Error = (
Twine(
"can't open file '") + Path +
"': " + EC.message()).str();
116 std::string ParseError;
117 if (!
parse(i, FileOrErr.
get().get(), ParseError)) {
118 Error = (
Twine(
"error parsing file '") + Path +
"': " + ParseError).str();
126 std::string &
Error) {
134 unsigned LineNo,
bool UseGlobs) {
135 Sections.emplace_back(SectionStr, FileNo);
140 "malformed section at line " +
Twine(LineNo) +
149 std::string &
Error) {
151 if (
auto Err =
addSection(
"*", FileIdx, 1).moveInto(CurrentSection)) {
165 unsigned LineNo = LineIt.line_number();
171 if (Line.starts_with(
"[")) {
172 if (!Line.ends_with(
"]")) {
174 (
"malformed section header on line " +
Twine(LineNo) +
": " + Line)
179 if (
auto Err =
addSection(Line.drop_front().drop_back(), FileIdx, LineNo,
181 .moveInto(CurrentSection)) {
189 auto [Prefix, Postfix] = Line.split(
":");
190 if (Postfix.empty()) {
192 Error = (
"malformed line " +
Twine(LineNo) +
": '" + Line +
"'").str();
196 auto [
Pattern, Category] = Postfix.split(
"=");
197 auto &Entry = CurrentSection->
Entries[Prefix][Category];
198 if (
auto Err = Entry.insert(
Pattern, LineNo, UseGlobs)) {
200 (
Twine(
"malformed ") + (UseGlobs ?
"glob" :
"regex") +
" in line " +
217std::pair<unsigned, unsigned>
221 if (S.SectionMatcher->match(
Section)) {
222 unsigned Blame =
inSectionBlame(S.Entries, Prefix, Query, Category);
224 return {S.FileIdx, Blame};
234 if (
I == Entries.end())
237 if (
II ==
I->second.end())
240 return II->getValue().match(Query);
uint64_t IntrinsicInst * II
Defines the virtual file system interface vfs::FileSystem.
Represents either an error or a value T.
std::error_code getError() const
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
LLVM_ABI bool match(StringRef S) const
static LLVM_ABI Expected< GlobPattern > create(StringRef Pat, std::optional< size_t > MaxSubPatterns={})
This interface provides simple read-only access to a block of memory, and provides simple methods for...
StringRef getBuffer() const
LLVM_ABI bool isValid(std::string &Error) const
isValid - returns the error encountered during regex compilation, if any.
LLVM_ABI bool match(StringRef String, SmallVectorImpl< StringRef > *Matches=nullptr, std::string *Error=nullptr) const
matches - Match the regex against a given String.
std::vector< std::pair< std::unique_ptr< Regex >, unsigned > > RegExes
LLVM_ABI unsigned match(StringRef Query) const
std::vector< std::unique_ptr< Matcher::Glob > > Globs
LLVM_ABI Error insert(StringRef Pattern, unsigned LineNumber, bool UseRegex)
std::vector< Section > Sections
static constexpr std::pair< unsigned, unsigned > NotFound
LLVM_ABI std::pair< unsigned, unsigned > inSectionBlame(StringRef Section, StringRef Prefix, StringRef Query, StringRef Category=StringRef()) const
Returns the file index and the line number <FileIdx, LineNo> corresponding to the special case list e...
LLVM_ABI bool createInternal(const std::vector< std::string > &Paths, vfs::FileSystem &VFS, std::string &Error)
static LLVM_ABI std::unique_ptr< SpecialCaseList > createOrDie(const std::vector< std::string > &Paths, llvm::vfs::FileSystem &FS)
Parses the special case list entries from files.
static LLVM_ABI 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.
SpecialCaseList()=default
LLVM_ABI ~SpecialCaseList()
LLVM_ABI Expected< Section * > addSection(StringRef SectionStr, unsigned FileIdx, unsigned LineNo, bool UseGlobs=true)
LLVM_ABI bool parse(unsigned FileIdx, const MemoryBuffer *MB, std::string &Error)
Parses just-constructed SpecialCaseList entries from a memory buffer.
LLVM_ABI bool inSection(StringRef Section, StringRef Prefix, StringRef Query, StringRef Category=StringRef()) const
Returns true, if special case list contains a line.
StringRef - Represent a constant reference to a string, i.e.
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
A forward iterator which reads text lines from a buffer.
bool is_at_eof() const
Return true if we've reached EOF or are an "end" iterator.
The virtual file system interface.
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > getBufferForFile(const Twine &Name, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatile=false, bool IsText=true)
This is a convenience method that opens a file, gets its content and then closes the file.
This is an optimization pass for GlobalISel generic memory operations.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
auto reverse(ContainerTy &&C)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
const char * toString(DWARFSectionKind Kind)
std::unique_ptr< Matcher > SectionMatcher