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(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, Error))
85 if (SCL->createInternal(MB, Error))
90 std::unique_ptr<SpecialCaseList>
93 if (
auto SCL =
create(Paths, Error))
101 for (
const auto &Path : Paths) {
104 if (std::error_code EC = FileOrErr.
getError()) {
105 Error = (
Twine(
"can't open file '") + Path +
"': " + EC.message()).str();
108 std::string ParseError;
110 Error = (
Twine(
"error parsing file '") + Path +
"': " + ParseError).str();
118 std::string &
Error) {
120 if (!
parse(MB, Sections, Error))
127 std::string &
Error) {
135 for (
auto I = Lines.
begin(),
E = Lines.
end();
I !=
E; ++
I, ++LineNo) {
138 if (
I->empty() ||
I->startswith(
"#"))
142 if (
I->startswith(
"[")) {
143 if (!
I->endswith(
"]")) {
144 Error = (
Twine(
"malformed section header on line ") +
Twine(LineNo) +
149 Section =
I->slice(1,
I->size() - 1);
152 Regex CheckRE(Section);
153 if (!CheckRE.
isValid(REError)) {
155 (
Twine(
"malformed regex for section ") + Section +
": '" + REError)
164 std::pair<StringRef, StringRef> SplitLine =
I->split(
":");
166 if (SplitLine.second.empty()) {
168 Error = (
Twine(
"malformed line ") +
Twine(LineNo) +
": '" +
169 SplitLine.first +
"'").str();
173 std::pair<StringRef, StringRef> SplitRegexp = SplitLine.second.split(
"=");
174 std::string Regexp = SplitRegexp.first;
178 if (SectionsMap.
find(Section) == SectionsMap.
end()) {
179 std::unique_ptr<Matcher> M = make_unique<Matcher>();
181 if (!M->insert(Section, LineNo, REError)) {
182 Error = (
Twine(
"malformed section ") + Section +
": '" + REError).str();
187 Sections.emplace_back(std::move(M));
192 if (!Entry.insert(std::move(Regexp), LineNo, REError)) {
193 Error = (
Twine(
"malformed regex in line ") +
Twine(LineNo) +
": '" +
194 SplitLine.second +
"': " + REError).str();
212 if (SectionIter.SectionMatcher->match(Section)) {
225 if (I == Entries.
end())
return 0;
227 if (II == I->second.end())
return 0;
229 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 createInternal(const std::vector< std::string > &Paths, std::string &Error)
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)
bool inSection(StringRef Section, StringRef Prefix, StringRef Query, StringRef Category=StringRef()) const
Returns true, if special case list contains a line.
static std::unique_ptr< SpecialCaseList > createOrDie(const std::vector< std::string > &Paths)
Parses the special case list entries from files.
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.
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")
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
std::error_code getError() const
SpecialCaseList()=default
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.
bool isValid(std::string &Error) const
isValid - returns the error encountered during regex compilation, or matching, 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"...
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
static void Query(const MachineInstr &MI, AliasAnalysis &AA, bool &Read, bool &Write, bool &Effects, bool &StackPointer)
bool insert(std::string Regexp, unsigned LineNumber, std::string &REError)
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatile=false)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null.
static std::unique_ptr< SpecialCaseList > create(const std::vector< std::string > &Paths, std::string &Error)
Parses the special case list entries from files.
Lightweight error class with error context and mandatory checking.
StringRef - Represent a constant reference to a string, i.e.