Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion llvm/include/llvm/Support/SpecialCaseList.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class SpecialCaseList {
}

struct Glob {
Glob(StringRef Name, unsigned LineNo) : Name(Name), LineNo(LineNo) {}
std::string Name;
unsigned LineNo;
GlobPattern Pattern;
Expand All @@ -143,8 +144,18 @@ class SpecialCaseList {
Glob() = default;
};

struct Reg {
Reg(StringRef Name, unsigned LineNo, Regex &&Rg)
: Name(Name), LineNo(LineNo), Rg(std::move(Rg)) {}
std::string Name;
unsigned LineNo;
Regex Rg;
Reg(Reg &&) = delete;
Reg() = default;
};

std::vector<std::unique_ptr<Matcher::Glob>> Globs;
std::vector<std::pair<std::unique_ptr<Regex>, unsigned>> RegExes;
std::vector<std::unique_ptr<Reg>> RegExes;
};

using SectionEntries = StringMap<StringMap<Matcher>>;
Expand Down
15 changes: 7 additions & 8 deletions llvm/lib/Support/SpecialCaseList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,14 @@ Error SpecialCaseList::Matcher::insert(StringRef Pattern, unsigned LineNumber,
if (!CheckRE.isValid(REError))
return createStringError(errc::invalid_argument, REError);

RegExes.emplace_back(std::make_pair(
std::make_unique<Regex>(std::move(CheckRE)), LineNumber));
auto Rg =
std::make_unique<Matcher::Reg>(Pattern, LineNumber, std::move(CheckRE));
RegExes.emplace_back(std::move(Rg));

return Error::success();
}

auto Glob = std::make_unique<Matcher::Glob>();
Glob->Name = Pattern.str();
Glob->LineNo = LineNumber;
auto Glob = std::make_unique<Matcher::Glob>(Pattern, LineNumber);
// We must be sure to use the string in `Glob` rather than the provided
// reference which could be destroyed before match() is called
if (auto Err = GlobPattern::create(Glob->Name, /*MaxSubPatterns=*/1024)
Expand All @@ -76,9 +75,9 @@ void SpecialCaseList::Matcher::match(
for (const auto &Glob : reverse(Globs))
if (Glob->Pattern.match(Query))
Cb(Glob->Name, Glob->LineNo);
for (const auto &[Regex, LineNumber] : reverse(RegExes))
if (Regex->match(Query))
Cb(/*FIXME: there is no users of this param yet */ "", LineNumber);
for (const auto &Regex : reverse(RegExes))
if (Regex->Rg.match(Query))
Cb(Regex->Name, Regex->LineNo);
}

// TODO: Refactor this to return Expected<...>
Expand Down