aboutsummaryrefslogtreecommitdiff
path: root/clang-tidy/ClangTidy.h
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2013-11-14 15:49:44 +0000
committerManuel Klimek <klimek@google.com>2013-11-14 15:49:44 +0000
commitb6cf4afd66e0deb43f94b20ade51266f5425d78a (patch)
treefa82c36f50c61bfaf39f1a496d26c3ca33920fe5 /clang-tidy/ClangTidy.h
parentdd426dfa348fa311e932a53716382f66a573f92e (diff)
Make clang's static analyzer checks available through clang-tidy.
This is implemented in a way that the current static analyzer architecture allows, in the future we might want to revisit this. With this change static analyzer checks are available from clang-tidy by specifying -checks=clang-analyzer-<name>. This change also fixes the use of the compilation database to allow clang-tidy to be used like any other clang tool. git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@194707 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'clang-tidy/ClangTidy.h')
-rw-r--r--clang-tidy/ClangTidy.h64
1 files changed, 6 insertions, 58 deletions
diff --git a/clang-tidy/ClangTidy.h b/clang-tidy/ClangTidy.h
index 3e17c298..1916a524 100644
--- a/clang-tidy/ClangTidy.h
+++ b/clang-tidy/ClangTidy.h
@@ -14,6 +14,7 @@
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Tooling/Refactoring.h"
+#include "ClangTidyDiagnosticConsumer.h"
namespace clang {
@@ -27,64 +28,6 @@ class CompilationDatabase;
namespace tidy {
-/// \brief A detected error complete with information to display diagnostic and
-/// automatic fix.
-///
-/// This is used as an intermediate format to transport Diagnostics without a
-/// dependency on a SourceManager.
-///
-/// FIXME: Make Diagnostics flexible enough to support this directly.
-struct ClangTidyError {
- ClangTidyError(const SourceManager &Sources, SourceLocation Loc,
- StringRef Message, const tooling::Replacements &Fix);
-
- std::string Message;
- unsigned FileOffset;
- std::string FilePath;
- tooling::Replacements Fix;
-};
-
-/// \brief Every \c ClangTidyCheck reports errors through a \c DiagnosticEngine
-/// provided by this context.
-///
-/// A \c ClangTidyCheck always has access to the active context to report
-/// warnings like:
-/// \code
-/// Context->Diag(Loc, "Single-argument constructors must be explicit")
-/// << FixItHint::CreateInsertion(Loc, "explicit ");
-/// \endcode
-class ClangTidyContext {
-public:
- ClangTidyContext(SmallVectorImpl<ClangTidyError> *Errors) : Errors(Errors) {}
-
- /// \brief Report any errors detected using this method.
- ///
- /// This is still under heavy development and will likely change towards using
- /// tablegen'd diagnostic IDs.
- /// FIXME: Figure out a way to manage ID spaces.
- DiagnosticBuilder Diag(SourceLocation Loc, StringRef Message);
-
- /// \brief Sets the \c DiagnosticsEngine so that Diagnostics can be generated
- /// correctly.
- ///
- /// This is called from the \c ClangTidyCheck base class.
- void setDiagnosticsEngine(DiagnosticsEngine *Engine);
-
- /// \brief Sets the \c SourceManager of the used \c DiagnosticsEngine.
- ///
- /// This is called from the \c ClangTidyCheck base class.
- void setSourceManager(SourceManager *SourceMgr);
-
-private:
- friend class ClangTidyDiagnosticConsumer; // Calls storeError().
-
- /// \brief Store a \c ClangTidyError.
- void storeError(const ClangTidyError &Error);
-
- SmallVectorImpl<ClangTidyError> *Errors;
- DiagnosticsEngine *DiagEngine;
-};
-
/// \brief Base class for all clang-tidy checks.
///
/// To implement a \c ClangTidyCheck, write a subclass and overwrite some of the
@@ -142,6 +85,11 @@ private:
virtual void run(const ast_matchers::MatchFinder::MatchResult &Result);
};
+/// \brief Returns an action factory that runs the specified clang-tidy checks.
+tooling::FrontendActionFactory *
+createClangTidyActionFactory(StringRef CheckRegexString,
+ ClangTidyContext &Context);
+
/// \brief Run a set of clang-tidy checks on a set of files.
void runClangTidy(StringRef CheckRegexString,
const tooling::CompilationDatabase &Compilations,