Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:20

0001 //===--- IncludeCleanerCheck.h - clang-tidy ---------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_INCLUDECLEANER_H
0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_INCLUDECLEANER_H
0011 
0012 #include "../ClangTidyCheck.h"
0013 #include "../ClangTidyDiagnosticConsumer.h"
0014 #include "../ClangTidyOptions.h"
0015 #include "clang-include-cleaner/Record.h"
0016 #include "clang-include-cleaner/Types.h"
0017 #include "clang/ASTMatchers/ASTMatchFinder.h"
0018 #include "clang/Basic/LLVM.h"
0019 #include "clang/Basic/SourceLocation.h"
0020 #include "clang/Lex/HeaderSearch.h"
0021 #include "clang/Lex/Preprocessor.h"
0022 #include "llvm/Support/Regex.h"
0023 #include <vector>
0024 
0025 namespace clang::tidy::misc {
0026 
0027 /// Checks for unused and missing includes. Generates findings only for
0028 /// the main file of a translation unit.
0029 /// Findings correspond to https://clangd.llvm.org/design/include-cleaner.
0030 ///
0031 /// For the user-facing documentation see:
0032 /// http://clang.llvm.org/extra/clang-tidy/checks/misc/include-cleaner.html
0033 class IncludeCleanerCheck : public ClangTidyCheck {
0034 public:
0035   IncludeCleanerCheck(StringRef Name, ClangTidyContext *Context);
0036   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
0037   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
0038   void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
0039                            Preprocessor *ModuleExpanderPP) override;
0040   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
0041   bool isLanguageVersionSupported(const LangOptions &LangOpts) const override;
0042 
0043 private:
0044   include_cleaner::RecordedPP RecordedPreprocessor;
0045   include_cleaner::PragmaIncludes RecordedPI;
0046   const Preprocessor *PP = nullptr;
0047   std::vector<StringRef> IgnoreHeaders;
0048   // Whether emit only one finding per usage of a symbol.
0049   const bool DeduplicateFindings;
0050   llvm::SmallVector<llvm::Regex> IgnoreHeadersRegex;
0051   bool shouldIgnore(const include_cleaner::Header &H);
0052 };
0053 
0054 } // namespace clang::tidy::misc
0055 
0056 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_INCLUDECLEANER_H