17
17
#include " llvm/ADT/STLExtras.h"
18
18
#include " llvm/Support/LineIterator.h"
19
19
#include " llvm/Support/MemoryBuffer.h"
20
+ #include " llvm/Support/Path.h"
20
21
#include " llvm/Support/VirtualFileSystem.h"
21
- #include " llvm/TargetParser/Host.h"
22
- #include " llvm/TargetParser/Triple.h"
23
22
#include < stdio.h>
24
23
#include < string>
25
24
#include < system_error>
@@ -59,21 +58,22 @@ Error SpecialCaseList::Matcher::insert(StringRef Pattern, unsigned LineNumber,
59
58
auto Glob = std::make_unique<Matcher::Glob>();
60
59
Glob->Name = Pattern.str ();
61
60
Glob->LineNo = LineNumber;
62
- // Backslashes are valid in posix-style filenames.
63
- bool IsSlashAgnostic = Triple (sys::getDefaultTargetTriple ()).isOSWindows ();
64
61
// We must be sure to use the string in `Glob` rather than the provided
65
62
// reference which could be destroyed before match() is called
66
- if (auto Err = GlobPattern::create (Glob->Name , /* MaxSubPatterns=*/ 1024 ,
67
- /* IsSlashAgnostic=*/ IsSlashAgnostic)
63
+ if (auto Err = GlobPattern::create (Glob->Name , /* MaxSubPatterns=*/ 1024 )
68
64
.moveInto (Glob->Pattern ))
69
65
return Err;
70
66
Globs.push_back (std::move (Glob));
71
67
return Error::success ();
72
68
}
73
69
74
- unsigned SpecialCaseList::Matcher::match (StringRef Query) const {
70
+ unsigned SpecialCaseList::Matcher::match (StringRef Query,
71
+ bool IsFilename) const {
72
+ static bool HaveWindowsPathStyle =
73
+ llvm::sys::path::is_style_windows (llvm::sys::path::Style::native);
75
74
for (const auto &Glob : reverse (Globs))
76
- if (Glob->Pattern .match (Query))
75
+ if (Glob->Pattern .match (
76
+ Query, /* IsSlashAgnostic=*/ (HaveWindowsPathStyle && IsFilename)))
77
77
return Glob->LineNo ;
78
78
for (const auto &[Regex, LineNumber] : reverse (RegExes))
79
79
if (Regex->match (Query))
@@ -223,7 +223,8 @@ std::pair<unsigned, unsigned>
223
223
SpecialCaseList::inSectionBlame (StringRef Section, StringRef Prefix,
224
224
StringRef Query, StringRef Category) const {
225
225
for (const auto &S : reverse (Sections)) {
226
- if (S.SectionMatcher ->match (Section)) {
226
+ bool IsFilename = Prefix == " src" || Prefix == " mainfile" ;
227
+ if (S.SectionMatcher ->match (Section, IsFilename)) {
227
228
unsigned Blame = inSectionBlame (S.Entries , Prefix, Query, Category);
228
229
if (Blame)
229
230
return {S.FileIdx , Blame};
@@ -242,7 +243,8 @@ unsigned SpecialCaseList::inSectionBlame(const SectionEntries &Entries,
242
243
if (II == I->second .end ())
243
244
return 0 ;
244
245
245
- return II->getValue ().match (Query);
246
+ bool IsFilename = Prefix == " src" || Prefix == " mainfile" ;
247
+ return II->getValue ().match (Query, IsFilename);
246
248
}
247
249
248
250
} // namespace llvm
0 commit comments