2020#include " llvm/Support/LineIterator.h"
2121#include " llvm/Support/MemoryBuffer.h"
2222#include " llvm/Support/VirtualFileSystem.h"
23+ #include < algorithm>
2324#include < limits>
2425#include < stdio.h>
2526#include < string>
@@ -69,14 +70,15 @@ Error SpecialCaseList::Matcher::insert(StringRef Pattern, unsigned LineNumber,
6970 return Error::success ();
7071}
7172
72- unsigned SpecialCaseList::Matcher::match (StringRef Query) const {
73+ void SpecialCaseList::Matcher::match (
74+ StringRef Query,
75+ llvm::function_ref<void (StringRef Rule, unsigned LineNo)> Cb) const {
7376 for (const auto &Glob : reverse (Globs))
7477 if (Glob->Pattern .match (Query))
75- return Glob->LineNo ;
78+ Cb (Glob-> Name , Glob->LineNo ) ;
7679 for (const auto &[Regex, LineNumber] : reverse (RegExes))
7780 if (Regex->match (Query))
78- return LineNumber;
79- return 0 ;
81+ Cb (/* FIXME: there is no users of this param yet */ " " , LineNumber);
8082}
8183
8284// TODO: Refactor this to return Expected<...>
@@ -227,7 +229,7 @@ std::pair<unsigned, unsigned>
227229SpecialCaseList::inSectionBlame (StringRef Section, StringRef Prefix,
228230 StringRef Query, StringRef Category) const {
229231 for (const auto &S : reverse (Sections)) {
230- if (S.SectionMatcher .match (Section)) {
232+ if (S.SectionMatcher .matchAny (Section)) {
231233 unsigned Blame = S.getLastMatch (Prefix, Query, Category);
232234 if (Blame)
233235 return {S.FileIdx , Blame};
@@ -236,17 +238,29 @@ SpecialCaseList::inSectionBlame(StringRef Section, StringRef Prefix,
236238 return NotFound;
237239}
238240
239- unsigned SpecialCaseList::Section::getLastMatch (StringRef Prefix,
240- StringRef Query ,
241- StringRef Category) const {
241+ const SpecialCaseList::Matcher *
242+ SpecialCaseList::Section::findMatcher ( StringRef Prefix ,
243+ StringRef Category) const {
242244 SectionEntries::const_iterator I = Entries.find (Prefix);
243245 if (I == Entries.end ())
244- return 0 ;
246+ return nullptr ;
245247 StringMap<Matcher>::const_iterator II = I->second .find (Category);
246248 if (II == I->second .end ())
247- return 0 ;
249+ return nullptr ;
250+
251+ return &II->second ;
252+ }
248253
249- return II->getValue ().match (Query);
254+ unsigned SpecialCaseList::Section::getLastMatch (StringRef Prefix,
255+ StringRef Query,
256+ StringRef Category) const {
257+ unsigned LastLine = 0 ;
258+ if (const Matcher *M = findMatcher (Prefix, Category)) {
259+ M->match (Query, [&](StringRef, unsigned LineNo) {
260+ LastLine = std::max (LastLine, LineNo);
261+ });
262+ }
263+ return LastLine;
250264}
251265
252266} // namespace llvm
0 commit comments