1111#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYDIAGNOSTICCONSUMER_H
1212
1313#include " ClangTidyOptions.h"
14+ #include " ClangTidyProfiling.h"
1415#include " clang/Basic/Diagnostic.h"
1516#include " clang/Basic/SourceManager.h"
17+ #include " clang/Tooling/Core/Diagnostic.h"
1618#include " clang/Tooling/Refactoring.h"
1719#include " llvm/ADT/DenseMap.h"
1820#include " llvm/ADT/StringMap.h"
@@ -32,49 +34,17 @@ class CompilationDatabase;
3234
3335namespace tidy {
3436
35- // / \brief A message from a clang-tidy check.
36- // /
37- // / Note that this is independent of a \c SourceManager.
38- struct ClangTidyMessage {
39- ClangTidyMessage (StringRef Message = " " );
40- ClangTidyMessage (StringRef Message, const SourceManager &Sources,
41- SourceLocation Loc);
42- std::string Message;
43- std::string FilePath;
44- unsigned FileOffset;
45- };
46-
4737// / \brief A detected error complete with information to display diagnostic and
4838// / automatic fix.
4939// /
5040// / This is used as an intermediate format to transport Diagnostics without a
5141// / dependency on a SourceManager.
5242// /
5343// / FIXME: Make Diagnostics flexible enough to support this directly.
54- struct ClangTidyError {
55- enum Level {
56- Warning = DiagnosticsEngine::Warning,
57- Error = DiagnosticsEngine::Error
58- };
59-
60- ClangTidyError (StringRef CheckName, Level DiagLevel, bool IsWarningAsError,
61- StringRef BuildDirectory);
62-
63- std::string CheckName;
64- ClangTidyMessage Message;
65- tooling::Replacements Fix;
66- SmallVector<ClangTidyMessage, 1 > Notes;
67-
68- // A build directory of the diagnostic source file.
69- //
70- // It's an absolute path which is `directory` field of the source file in
71- // compilation database. If users don't specify the compilation database
72- // directory, it is the current directory where clang-tidy runs.
73- //
74- // Note: it is empty in unittest.
75- std::string BuildDirectory;
76-
77- Level DiagLevel;
44+ struct ClangTidyError : tooling::Diagnostic {
45+ ClangTidyError (StringRef CheckName, Level DiagLevel, StringRef BuildDirectory,
46+ bool IsWarningAsError);
47+
7848 bool IsWarningAsError;
7949};
8050
@@ -118,11 +88,6 @@ struct ClangTidyStats {
11888 }
11989};
12090
121- // / \brief Container for clang-tidy profiling data.
122- struct ProfileData {
123- llvm::StringMap<llvm::TimeRecord> Records;
124- };
125-
12691// / \brief Every \c ClangTidyCheck reports errors through a \c DiagnosticsEngine
12792// / provided by this context.
12893// /
@@ -135,7 +100,10 @@ struct ProfileData {
135100class ClangTidyContext {
136101public:
137102 // / \brief Initializes \c ClangTidyContext instance.
138- ClangTidyContext (std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider);
103+ ClangTidyContext (std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider,
104+ bool AllowEnablingAnalyzerAlphaCheckers = false );
105+
106+ ~ClangTidyContext ();
139107
140108 // / \brief Report any errors detected using this method.
141109 // /
@@ -167,14 +135,14 @@ class ClangTidyContext {
167135 // / diagnostic ID.
168136 StringRef getCheckName (unsigned DiagnosticID) const ;
169137
170- // / \brief Returns check filter for the \c CurrentFile.
138+ // / \brief Returns \c true if the check is enabled for the \c CurrentFile.
171139 // /
172140 // / The \c CurrentFile can be changed using \c setCurrentFile.
173- GlobList & getChecksFilter () ;
141+ bool isCheckEnabled (StringRef CheckName) const ;
174142
175- // / \brief Returns check filter for the \c CurrentFile which
176- // / selects checks for upgrade to error .
177- GlobList & getWarningAsErrorFilter () ;
143+ // / \brief Returns \c true if the check should be upgraded to error for the
144+ // / \c CurrentFile .
145+ bool treatAsError (StringRef CheckName) const ;
178146
179147 // / \brief Returns global options.
180148 const ClangTidyGlobalOptions &getGlobalOptions () const ;
@@ -193,17 +161,19 @@ class ClangTidyContext {
193161 const ClangTidyStats &getStats () const { return Stats; }
194162
195163 // / \brief Returns all collected errors.
196- const std::vector <ClangTidyError> & getErrors () const { return Errors; }
164+ ArrayRef <ClangTidyError> getErrors () const { return Errors; }
197165
198166 // / \brief Clears collected errors.
199167 void clearErrors () { Errors.clear (); }
200168
201- // / \brief Set the output struct for profile data.
202- // /
203- // / Setting a non-null pointer here will enable profile collection in
204- // / clang-tidy.
205- void setCheckProfileData (ProfileData *Profile);
206- ProfileData *getCheckProfileData () const { return Profile; }
169+ // / \brief Control profile collection in clang-tidy.
170+ void setEnableProfiling (bool Profile);
171+ bool getEnableProfiling () const { return Profile; }
172+
173+ // / \brief Control storage of profile date.
174+ void setProfileStoragePrefix (StringRef ProfilePrefix);
175+ llvm::Optional<ClangTidyProfiling::StorageParams>
176+ getProfileStorageParams () const ;
207177
208178 // / \brief Should be called when starting to process new translation unit.
209179 void setCurrentBuildDirectory (StringRef BuildDirectory) {
@@ -215,6 +185,12 @@ class ClangTidyContext {
215185 return CurrentBuildDirectory;
216186 }
217187
188+ // / \brief If the experimental alpha checkers from the static analyzer can be
189+ // / enabled.
190+ bool canEnableAnalyzerAlphaCheckers () const {
191+ return AllowEnablingAnalyzerAlphaCheckers;
192+ }
193+
218194private:
219195 // Calls setDiagnosticsEngine() and storeError().
220196 friend class ClangTidyDiagnosticConsumer ;
@@ -233,8 +209,9 @@ class ClangTidyContext {
233209
234210 std::string CurrentFile;
235211 ClangTidyOptions CurrentOptions;
236- std::unique_ptr<GlobList> CheckFilter;
237- std::unique_ptr<GlobList> WarningAsErrorFilter;
212+ class CachedGlobList ;
213+ std::unique_ptr<CachedGlobList> CheckFilter;
214+ std::unique_ptr<CachedGlobList> WarningAsErrorFilter;
238215
239216 LangOptions LangOpts;
240217
@@ -244,7 +221,10 @@ class ClangTidyContext {
244221
245222 llvm::DenseMap<unsigned , std::string> CheckNamesByDiagnosticID;
246223
247- ProfileData *Profile;
224+ bool Profile;
225+ std::string ProfilePrefix;
226+
227+ bool AllowEnablingAnalyzerAlphaCheckers;
248228};
249229
250230// / \brief A diagnostic consumer that turns each \c Diagnostic into a
@@ -254,7 +234,8 @@ class ClangTidyContext {
254234// implementation file.
255235class ClangTidyDiagnosticConsumer : public DiagnosticConsumer {
256236public:
257- ClangTidyDiagnosticConsumer (ClangTidyContext &Ctx);
237+ ClangTidyDiagnosticConsumer (ClangTidyContext &Ctx,
238+ bool RemoveIncompatibleErrors = true );
258239
259240 // FIXME: The concept of converting between FixItHints and Replacements is
260241 // more generic and should be pulled out into a more useful Diagnostics
@@ -280,11 +261,13 @@ class ClangTidyDiagnosticConsumer : public DiagnosticConsumer {
280261 bool passesLineFilter (StringRef FileName, unsigned LineNumber) const ;
281262
282263 ClangTidyContext &Context;
264+ bool RemoveIncompatibleErrors;
283265 std::unique_ptr<DiagnosticsEngine> Diags;
284266 SmallVector<ClangTidyError, 8 > Errors;
285267 std::unique_ptr<llvm::Regex> HeaderFilter;
286268 bool LastErrorRelatesToUserCode;
287269 bool LastErrorPassesLineFilter;
270+ bool LastErrorWasIgnored;
288271};
289272
290273} // end namespace tidy
0 commit comments