clang-tools 10.0.0

ClangTidy.h
Go to the documentation of this file.
1 //===--- ClangTidy.h - clang-tidy -------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDY_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDY_H
11
12 #include "ClangTidyCheck.h"
13 #include "ClangTidyDiagnosticConsumer.h"
14 #include "ClangTidyOptions.h"
15 #include "llvm/Support/raw_ostream.h"
16 #include <memory>
17 #include <vector>
18
19 namespace clang {
20
21 class CompilerInstance;
22 namespace tooling {
23 class CompilationDatabase;
24 }
25
26 namespace tidy {
27
28 class ClangTidyCheckFactories;
29
30 class ClangTidyASTConsumerFactory {
31 public:
32 ClangTidyASTConsumerFactory(
33 ClangTidyContext &Context,
34 IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFS = nullptr);
35
36 /// Returns an ASTConsumer that runs the specified clang-tidy checks.
37 std::unique_ptr<clang::ASTConsumer>
38 CreateASTConsumer(clang::CompilerInstance &Compiler, StringRef File);
39
40 /// Get the list of enabled checks.
41 std::vector<std::string> getCheckNames();
42
43 /// Get the union of options from all checks.
44 ClangTidyOptions::OptionMap getCheckOptions();
45
46 private:
47 ClangTidyContext &Context;
48 IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFS;
49 std::unique_ptr<ClangTidyCheckFactories> CheckFactories;
50 };
51
52 /// Fills the list of check names that are enabled when the provided
53 /// filters are applied.
54 std::vector<std::string> getCheckNames(const ClangTidyOptions &Options,
55 bool AllowEnablingAnalyzerAlphaCheckers);
56
57 /// Returns the effective check-specific options.
58 ///
59 /// The method configures ClangTidy with the specified \p Options and collects
60 /// effective options from all created checks. The returned set of options
61 /// includes default check-specific options for all keys not overridden by \p
62 /// Options.
63 ClangTidyOptions::OptionMap
64 getCheckOptions(const ClangTidyOptions &Options,
65 bool AllowEnablingAnalyzerAlphaCheckers);
66
67 /// Run a set of clang-tidy checks on a set of files.
68 ///
69 /// \param EnableCheckProfile If provided, it enables check profile collection
70 /// in MatchFinder, and will contain the result of the profile.
71 /// \param StoreCheckProfile If provided, and EnableCheckProfile is true,
72 /// the profile will not be output to stderr, but will instead be stored
73 /// as a JSON file in the specified directory.
74 std::vector<ClangTidyError>
75 runClangTidy(clang::tidy::ClangTidyContext &Context,
76 const tooling::CompilationDatabase &Compilations,
77 ArrayRef<std::string> InputFiles,
78 llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> BaseFS,
79 bool EnableCheckProfile = false,
80 llvm::StringRef StoreCheckProfile = StringRef());
81
82 // FIXME: This interface will need to be significantly extended to be useful.
83 // FIXME: Implement confidence levels for displaying/fixing errors.
84 //
85 /// Displays the found \p Errors to the users. If \p Fix is true, \p
86 /// Errors containing fixes are automatically applied and reformatted. If no
87 /// clang-format configuration file is found, the given \P FormatStyle is used.
88 void handleErrors(llvm::ArrayRef<ClangTidyError> Errors,
89 ClangTidyContext &Context, bool Fix,
90 unsigned &WarningsAsErrorsCount,
91 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS);
92
93 /// Serializes replacements into YAML and writes them to the specified
94 /// output stream.
95 void exportReplacements(StringRef MainFilePath,
96 const std::vector<ClangTidyError> &Errors,
97 raw_ostream &OS);
98
99 } // end namespace tidy
100 } // end namespace clang
101
102 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDY_H
ClangTidyCheck.h
clang::tidy::ClangTidyASTConsumerFactory
Definition: ClangTidy.h:30
StoreCheckProfile
static cl::opt< std::string > StoreCheckProfile("store-check-profile", cl::desc(R"( By default reports are printed in tabulated format to stderr. When this option is passed, these per-TU profiles are instead stored as JSON. )"), cl::value_desc("prefix"), cl::cat(ClangTidyCategory))
clang::tidy::ClangTidyOptions
Contains options for clang-tidy.
Definition: ClangTidyOptions.h:50
clang::tidy::getCheckOptions
ClangTidyOptions::OptionMap getCheckOptions(const ClangTidyOptions &Options, bool AllowEnablingAnalyzerAlphaCheckers)
Returns the effective check-specific options.
Definition: ClangTidy.cpp:480
ClangTidyOptions.h
clang::tidy::handleErrors
void handleErrors(llvm::ArrayRef< ClangTidyError > Errors, ClangTidyContext &Context, bool Fix, unsigned &WarningsAsErrorsCount, llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > BaseFS)
Displays the found Errors to the users.
Definition: ClangTidy.cpp:568
clang::tidy::exportReplacements
void exportReplacements(StringRef MainFilePath, const std::vector< ClangTidyError > &Errors, raw_ostream &OS)
Serializes replacements into YAML and writes them to the specified output stream. ...
AllowEnablingAnalyzerAlphaCheckers
static cl::opt< bool > AllowEnablingAnalyzerAlphaCheckers("allow-enabling-analyzer-alpha-checkers", cl::init(false), cl::Hidden, cl::cat(ClangTidyCategory))
This option allows enabling the experimental alpha checkers from the static analyzer.
ClangTidyDiagnosticConsumer.h
clang::tidy::ClangTidyOptions::OptionMap
std::map< std::string, std::string > OptionMap
Definition: ClangTidyOptions.h:97
EnableCheckProfile
static cl::opt< bool > EnableCheckProfile("enable-check-profile", cl::desc(R"( Enable per-check timing profiles, and print a report to stderr. )"), cl::init(false), cl::cat(ClangTidyCategory))
clang::tidy::runClangTidy
std::vector< ClangTidyError > runClangTidy(clang::tidy::ClangTidyContext &Context, const tooling::CompilationDatabase &Compilations, ArrayRef< std::string > InputFiles, llvm::IntrusiveRefCntPtr< llvm::vfs::OverlayFileSystem > BaseFS, bool EnableCheckProfile=false, llvm::StringRef StoreCheckProfile=StringRef())
Run a set of clang-tidy checks on a set of files.
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::tidy::getCheckNames
std::vector< std::string > getCheckNames(const ClangTidyOptions &Options, bool AllowEnablingAnalyzerAlphaCheckers)
Fills the list of check names that are enabled when the provided filters are applied.
Definition: ClangTidy.cpp:469
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:77
Fix
static cl::opt< bool > Fix("fix", cl::desc(R"( Apply suggested fixes. Without -fix-errors clang-tidy will bail out if any compilation errors were found. )"), cl::init(false), cl::cat(ClangTidyCategory))