#ifndef LLVM_CLANG_GR_ANALYSISCONSUMER_H
#define LLVM_CLANG_GR_ANALYSISCONSUMER_H
+#include "clang/AST/ASTConsumer.h"
#include "clang/Basic/LLVM.h"
#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
+#include "clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h"
#include <string>
namespace clang {
-class ASTConsumer;
class Preprocessor;
class DiagnosticsEngine;
namespace ento {
class CheckerManager;
+class AnalysisASTConsumer : public ASTConsumer {
+public:
+ virtual void AddDiagnosticConsumer(PathDiagnosticConsumer *Consumer) = 0;
+};
+
/// CreateAnalysisConsumer - Creates an ASTConsumer to run various code
/// analysis passes. (The set of analyses run is controlled by command-line
/// options.)
-ASTConsumer* CreateAnalysisConsumer(const Preprocessor &pp,
- const std::string &output,
- AnalyzerOptionsRef opts,
- ArrayRef<std::string> plugins);
+AnalysisASTConsumer *CreateAnalysisConsumer(const Preprocessor &pp,
+ const std::string &output,
+ AnalyzerOptionsRef opts,
+ ArrayRef<std::string> plugins);
} // end GR namespace
namespace {
-class AnalysisConsumer : public ASTConsumer,
+class AnalysisConsumer : public AnalysisASTConsumer,
public DataRecursiveASTVisitor<AnalysisConsumer> {
enum {
AM_None = 0,
}
void DigestAnalyzerOptions() {
- // Create the PathDiagnosticConsumer.
- ClangDiagPathDiagConsumer *clangDiags =
- new ClangDiagPathDiagConsumer(PP.getDiagnostics());
- PathConsumers.push_back(clangDiags);
-
- if (Opts->AnalysisDiagOpt == PD_TEXT) {
- clangDiags->enablePaths();
-
- } else if (!OutDir.empty()) {
- switch (Opts->AnalysisDiagOpt) {
- default:
-#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATEFN) \
- case PD_##NAME: CREATEFN(*Opts.getPtr(), PathConsumers, OutDir, PP);\
- break;
+ if (Opts->AnalysisDiagOpt != PD_NONE) {
+ // Create the PathDiagnosticConsumer.
+ ClangDiagPathDiagConsumer *clangDiags =
+ new ClangDiagPathDiagConsumer(PP.getDiagnostics());
+ PathConsumers.push_back(clangDiags);
+
+ if (Opts->AnalysisDiagOpt == PD_TEXT) {
+ clangDiags->enablePaths();
+
+ } else if (!OutDir.empty()) {
+ switch (Opts->AnalysisDiagOpt) {
+ default:
+#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATEFN) \
+ case PD_##NAME: \
+ CREATEFN(*Opts.getPtr(), PathConsumers, OutDir, PP); \
+ break;
#include "clang/StaticAnalyzer/Core/Analyses.def"
+ }
}
}
return true;
}
+ virtual void
+ AddDiagnosticConsumer(PathDiagnosticConsumer *Consumer) LLVM_OVERRIDE {
+ PathConsumers.push_back(Consumer);
+ }
+
private:
void storeTopLevelDecls(DeclGroupRef DG);
// AnalysisConsumer creation.
//===----------------------------------------------------------------------===//
-ASTConsumer* ento::CreateAnalysisConsumer(const Preprocessor& pp,
- const std::string& outDir,
- AnalyzerOptionsRef opts,
- ArrayRef<std::string> plugins) {
+AnalysisASTConsumer *
+ento::CreateAnalysisConsumer(const Preprocessor &pp, const std::string &outDir,
+ AnalyzerOptionsRef opts,
+ ArrayRef<std::string> plugins) {
// Disable the effects of '-Werror' when using the AnalysisConsumer.
pp.getDiagnostics().setWarningsAsErrors(false);