24 #include <system_error>
47 SpecialCaseList::SpecialCaseList() : Entries(), Regexps(), IsCompiled(
false) {}
49 std::unique_ptr<SpecialCaseList>
53 for (
auto Path : Paths) {
56 if (std::error_code EC = FileOrErr.
getError()) {
57 Error = (
Twine(
"can't open file '") + Path +
"': " + EC.message()).str();
60 std::string ParseError;
61 if (!SCL->parse(FileOrErr.
get().get(), ParseError)) {
62 Error = (
Twine(
"error parsing file '") + Path +
"': " + ParseError).str();
73 if (!SCL->parse(MB, Error))
79 std::unique_ptr<SpecialCaseList>
82 if (
auto SCL =
create(Paths, Error))
92 for (
auto I = Lines.
begin(), E = Lines.
end();
I != E; ++
I, ++LineNo) {
94 if (
I->empty() ||
I->startswith(
"#"))
97 std::pair<StringRef, StringRef> SplitLine =
I->split(
":");
99 if (SplitLine.second.empty()) {
101 Error = (
Twine(
"malformed line ") +
Twine(LineNo) +
": '" +
102 SplitLine.first +
"'").str();
106 std::pair<StringRef, StringRef> SplitRegexp = SplitLine.second.split(
"=");
107 std::string Regexp = SplitRegexp.first;
108 StringRef Category = SplitRegexp.second;
112 Entries[
Prefix][Category].Strings.insert(Regexp);
117 for (
size_t pos = 0; (pos = Regexp.find(
"*", pos)) != std::string::npos;
118 pos += strlen(
".*")) {
119 Regexp.replace(pos, strlen(
"*"),
".*");
123 Regex CheckRE(Regexp);
125 if (!CheckRE.isValid(REError)) {
126 Error = (Twine(
"malformed regex in line ") + Twine(LineNo) +
": '" +
127 SplitLine.second +
"': " + REError).str();
132 if (!Regexps[Prefix][Category].empty())
133 Regexps[Prefix][Category] +=
"|";
134 Regexps[
Prefix][Category] +=
"^" + Regexp +
"$";
139 void SpecialCaseList::compile() {
140 assert(!IsCompiled &&
"compile() should only be called once");
142 for (StringMap<StringMap<std::string>>::const_iterator
I = Regexps.begin(),
145 for (StringMap<std::string>::const_iterator II =
I->second.begin(),
146 IE =
I->second.end();
148 Entries[
I->getKey()][II->getKey()].RegEx.reset(
new Regex(II->getValue()));
159 assert(IsCompiled &&
"SpecialCaseList::compile() was not called!");
161 if (I == Entries.end())
return false;
163 if (II == I->second.
end())
return false;
std::error_code getError() const
Represents either an error or a value T.
const ValueTy & getValue() const
iterator find(StringRef Key)
StringRef getBuffer() const
static std::unique_ptr< SpecialCaseList > createOrDie(const std::vector< std::string > &Paths)
Parses the special case list entries from files.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const char *reason, bool gen_crash_diag=true)
Reports a serious error, calling any installed error handler.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
size_type count(StringRef Key) const
count - Return 1 if the element is in the map, 0 otherwise.
static bool isLiteralERE(StringRef Str)
If this function returns true, ^Str$ is an extended regular expression that matches Str and only Str...
void SplitString(StringRef Source, SmallVectorImpl< StringRef > &OutFragments, StringRef Delimiters=" \t\n\v\f\r")
SplitString - Split up the specified string according to the specified delimiters, appending the result fragments to the output list.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
This interface provides simple read-only access to a block of memory, and provides simple methods for...
std::unique_ptr< Regex > RegEx
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
Represents a set of regular expressions.
bool inSection(StringRef Section, StringRef Query, StringRef Category=StringRef()) const
Returns true, if special case list contains a line.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatileSize=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.
StringSet - A wrapper for StringMap that provides set-like functionality.
StringRef - Represent a constant reference to a string, i.e.
bool match(StringRef Query) const