20
20
#include " llvm/Support/LineIterator.h"
21
21
#include " llvm/Support/MemoryBuffer.h"
22
22
#include " llvm/Support/VirtualFileSystem.h"
23
+ #include < algorithm>
23
24
#include < limits>
24
25
#include < stdio.h>
25
26
#include < string>
@@ -69,14 +70,15 @@ Error SpecialCaseList::Matcher::insert(StringRef Pattern, unsigned LineNumber,
69
70
return Error::success ();
70
71
}
71
72
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 {
73
76
for (const auto &Glob : reverse (Globs))
74
77
if (Glob->Pattern .match (Query))
75
- return Glob->LineNo ;
78
+ Cb (Glob-> Name , Glob->LineNo ) ;
76
79
for (const auto &[Regex, LineNumber] : reverse (RegExes))
77
80
if (Regex->match (Query))
78
- return LineNumber;
79
- return 0 ;
81
+ Cb (/* FIXME: there is no users of this param yet */ " " , LineNumber);
80
82
}
81
83
82
84
// TODO: Refactor this to return Expected<...>
@@ -227,7 +229,7 @@ std::pair<unsigned, unsigned>
227
229
SpecialCaseList::inSectionBlame (StringRef Section, StringRef Prefix,
228
230
StringRef Query, StringRef Category) const {
229
231
for (const auto &S : reverse (Sections)) {
230
- if (S.SectionMatcher .match (Section)) {
232
+ if (S.SectionMatcher .matchAny (Section)) {
231
233
unsigned Blame = S.getLastMatch (Prefix, Query, Category);
232
234
if (Blame)
233
235
return {S.FileIdx , Blame};
@@ -236,17 +238,29 @@ SpecialCaseList::inSectionBlame(StringRef Section, StringRef Prefix,
236
238
return NotFound;
237
239
}
238
240
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 {
242
244
SectionEntries::const_iterator I = Entries.find (Prefix);
243
245
if (I == Entries.end ())
244
- return 0 ;
246
+ return nullptr ;
245
247
StringMap<Matcher>::const_iterator II = I->second .find (Category);
246
248
if (II == I->second .end ())
247
- return 0 ;
249
+ return nullptr ;
250
+
251
+ return &II->second ;
252
+ }
248
253
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;
250
264
}
251
265
252
266
} // namespace llvm
0 commit comments