@@ -36,17 +36,7 @@ class DuplicateIncludeCallbacks : public PPCallbacks {
3636public:
3737 DuplicateIncludeCallbacks (DuplicateIncludeCheck &Check,
3838 const SourceManager &SM,
39- const std::vector<StringRef> &IgnoredList)
40- : Check(Check), SM(SM) {
41- // The main file doesn't participate in the FileChanged notification.
42- Files.emplace_back ();
43-
44- AllowedRegexes.reserve (IgnoredList.size ());
45- for (const StringRef &It : IgnoredList) {
46- if (!It.empty ())
47- AllowedRegexes.emplace_back (It);
48- }
49- }
39+ const std::vector<StringRef> &IgnoredList);
5040
5141 void FileChanged (SourceLocation Loc, FileChangeReason Reason,
5242 SrcMgr::CharacteristicKind FileType,
@@ -67,26 +57,12 @@ class DuplicateIncludeCallbacks : public PPCallbacks {
6757 const MacroDirective *Undef) override ;
6858
6959private:
60+ bool isAllowedDuplicate (StringRef FileName, OptionalFileEntryRef File) const ;
7061 // A list of included files is kept for each file we enter.
7162 SmallVector<FileList> Files;
7263 DuplicateIncludeCheck &Check;
7364 const SourceManager &SM;
7465 std::vector<llvm::Regex> AllowedRegexes;
75-
76- bool isAllowedDuplicate (StringRef FileName, OptionalFileEntryRef File) const {
77- if (llvm::any_of (AllowedRegexes,
78- [&](const llvm::Regex &R) { return R.match (FileName); }))
79- return true ;
80-
81- if (File) {
82- const StringRef Resolved = File->getName ();
83- if (llvm::any_of (AllowedRegexes,
84- [&](const llvm::Regex &R) { return R.match (Resolved); }))
85- return true ;
86- }
87-
88- return false ;
89- }
9066};
9167
9268} // namespace
@@ -97,6 +73,37 @@ DuplicateIncludeCheck::DuplicateIncludeCheck(StringRef Name,
9773 IgnoredFilesList (utils::options::parseStringList(
9874 Options.get(" IgnoredFilesList" , " " ))) {}
9975
76+ DuplicateIncludeCallbacks::DuplicateIncludeCallbacks (
77+ DuplicateIncludeCheck &Check, const SourceManager &SM,
78+ const std::vector<StringRef> &IgnoredList)
79+ : Check(Check), SM(SM) {
80+ // The main file doesn't participate in the FileChanged notification.
81+ Files.emplace_back ();
82+
83+ AllowedRegexes.reserve (IgnoredList.size ());
84+ for (const StringRef &It : IgnoredList) {
85+ if (!It.empty ())
86+ AllowedRegexes.emplace_back (It);
87+ }
88+ }
89+
90+ bool DuplicateIncludeCallbacks::isAllowedDuplicate (
91+ StringRef FileName, OptionalFileEntryRef File) const {
92+ if (llvm::any_of (AllowedRegexes, [&FileName](const llvm::Regex &R) {
93+ return R.match (FileName);
94+ }))
95+ return true ;
96+
97+ if (File) {
98+ const StringRef Resolved = File->getName ();
99+ return llvm::any_of (AllowedRegexes, [&Resolved](const llvm::Regex &R) {
100+ return R.match (Resolved);
101+ });
102+ }
103+
104+ return false ;
105+ }
106+
100107void DuplicateIncludeCallbacks::FileChanged (SourceLocation Loc,
101108 FileChangeReason Reason,
102109 SrcMgr::CharacteristicKind FileType,
@@ -117,9 +124,8 @@ void DuplicateIncludeCallbacks::InclusionDirective(
117124 FilenameRange.getEnd ().isMacroID ())
118125 return ;
119126 if (llvm::is_contained (Files.back (), FileName)) {
120- if (isAllowedDuplicate (FileName, File)) {
127+ if (isAllowedDuplicate (FileName, File))
121128 return ;
122- }
123129 // We want to delete the entire line, so make sure that [Start,End] covers
124130 // everything.
125131 const SourceLocation Start =
0 commit comments