Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //===--- ClangTidy.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_CLANGTIDY_H
0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDY_H
0011 
0012 #include "ClangTidyDiagnosticConsumer.h"
0013 #include "ClangTidyOptions.h"
0014 #include "llvm/ADT/StringSet.h"
0015 #include <memory>
0016 #include <vector>
0017 
0018 namespace llvm {
0019 class raw_ostream;
0020 } // namespace llvm
0021 
0022 namespace clang {
0023 
0024 class ASTConsumer;
0025 class CompilerInstance;
0026 namespace tooling {
0027 class CompilationDatabase;
0028 } // namespace tooling
0029 
0030 namespace tidy {
0031 
0032 class ClangTidyCheckFactories;
0033 
0034 class ClangTidyASTConsumerFactory {
0035 public:
0036   ClangTidyASTConsumerFactory(
0037       ClangTidyContext &Context,
0038       IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFS = nullptr);
0039 
0040   /// Returns an ASTConsumer that runs the specified clang-tidy checks.
0041   std::unique_ptr<clang::ASTConsumer>
0042   createASTConsumer(clang::CompilerInstance &Compiler, StringRef File);
0043 
0044   /// Get the list of enabled checks.
0045   std::vector<std::string> getCheckNames();
0046 
0047   /// Get the union of options from all checks.
0048   ClangTidyOptions::OptionMap getCheckOptions();
0049 
0050 private:
0051   ClangTidyContext &Context;
0052   IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFS;
0053   std::unique_ptr<ClangTidyCheckFactories> CheckFactories;
0054 };
0055 
0056 /// Fills the list of check names that are enabled when the provided
0057 /// filters are applied.
0058 std::vector<std::string> getCheckNames(const ClangTidyOptions &Options,
0059                                        bool AllowEnablingAnalyzerAlphaCheckers);
0060 
0061 struct ChecksAndOptions {
0062   llvm::StringSet<> Checks;
0063   llvm::StringSet<> Options;
0064 };
0065 
0066 ChecksAndOptions
0067 getAllChecksAndOptions(bool AllowEnablingAnalyzerAlphaCheckers = true);
0068 
0069 /// Returns the effective check-specific options.
0070 ///
0071 /// The method configures ClangTidy with the specified \p Options and collects
0072 /// effective options from all created checks. The returned set of options
0073 /// includes default check-specific options for all keys not overridden by \p
0074 /// Options.
0075 ClangTidyOptions::OptionMap
0076 getCheckOptions(const ClangTidyOptions &Options,
0077                 bool AllowEnablingAnalyzerAlphaCheckers);
0078 
0079 /// Run a set of clang-tidy checks on a set of files.
0080 ///
0081 /// \param EnableCheckProfile If provided, it enables check profile collection
0082 /// in MatchFinder, and will contain the result of the profile.
0083 /// \param StoreCheckProfile If provided, and EnableCheckProfile is true,
0084 /// the profile will not be output to stderr, but will instead be stored
0085 /// as a JSON file in the specified directory.
0086 std::vector<ClangTidyError>
0087 runClangTidy(clang::tidy::ClangTidyContext &Context,
0088              const tooling::CompilationDatabase &Compilations,
0089              ArrayRef<std::string> InputFiles,
0090              llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> BaseFS,
0091              bool ApplyAnyFix, bool EnableCheckProfile = false,
0092              llvm::StringRef StoreCheckProfile = StringRef());
0093 
0094 /// Controls what kind of fixes clang-tidy is allowed to apply.
0095 enum FixBehaviour {
0096   /// Don't try to apply any fix.
0097   FB_NoFix,
0098   /// Only apply fixes added to warnings.
0099   FB_Fix,
0100   /// Apply fixes found in notes.
0101   FB_FixNotes
0102 };
0103 
0104 // FIXME: This interface will need to be significantly extended to be useful.
0105 // FIXME: Implement confidence levels for displaying/fixing errors.
0106 //
0107 /// Displays the found \p Errors to the users. If \p Fix is \ref FB_Fix or \ref
0108 /// FB_FixNotes, \p Errors containing fixes are automatically applied and
0109 /// reformatted. If no clang-format configuration file is found, the given \P
0110 /// FormatStyle is used.
0111 void handleErrors(llvm::ArrayRef<ClangTidyError> Errors,
0112                   ClangTidyContext &Context, FixBehaviour Fix,
0113                   unsigned &WarningsAsErrorsCount,
0114                   llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS);
0115 
0116 /// Serializes replacements into YAML and writes them to the specified
0117 /// output stream.
0118 void exportReplacements(StringRef MainFilePath,
0119                         const std::vector<ClangTidyError> &Errors,
0120                         raw_ostream &OS);
0121 
0122 } // end namespace tidy
0123 } // end namespace clang
0124 
0125 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDY_H