#include "clang/Driver/Options.h"
#include "clang/Frontend/ASTConsumers.h"
#include "clang/Frontend/CompilerInstance.h"
+#include "clang/StaticAnalyzer/Frontend/FrontendActions.h"
#include "clang/Rewrite/Frontend/FixItRewriter.h"
#include "clang/Rewrite/Frontend/FrontendActions.h"
#include "clang/Tooling/CommonOptionsParser.h"
static cl::opt<std::string> ASTDumpFilter(
"ast-dump-filter",
cl::desc(Options->getOptionHelpText(options::OPT_ast_dump_filter)));
+static cl::opt<bool> Analyze(
+ "analyze",
+ cl::desc(Options->getOptionHelpText(options::OPT_analyze)));
static cl::opt<bool> Fixit(
"fixit",
: Extra(Extra), Pos(Pos) {
}
+ InsertAdjuster(const char *Extra, Position Pos)
+ : Extra(1, std::string(Extra)), Pos(Pos) {
+ }
+
virtual CommandLineArguments
Adjust(const CommandLineArguments &Args) LLVM_OVERRIDE {
CommandLineArguments Return(Args);
ClangTool Tool(OptionsParser.getCompilations(),
OptionsParser.getSourcePathList());
- if (ArgsAfter.size() > 0)
- Tool.appendArgumentsAdjuster(new InsertAdjuster(ArgsAfter, InsertAdjuster::END));
- if (ArgsBefore.size() > 0)
- Tool.appendArgumentsAdjuster(new InsertAdjuster(ArgsBefore, InsertAdjuster::BEGIN));
+ // Clear adjusters because -fsyntax-only is inserted by the default chain.
+ Tool.clearArgumentsAdjusters();
+ Tool.appendArgumentsAdjuster(new ClangStripOutputAdjuster());
+ if (ArgsAfter.size() > 0) {
+ Tool.appendArgumentsAdjuster(new InsertAdjuster(ArgsAfter,
+ InsertAdjuster::END));
+ }
+ if (ArgsBefore.size() > 0) {
+ Tool.appendArgumentsAdjuster(new InsertAdjuster(ArgsBefore,
+ InsertAdjuster::BEGIN));
+ }
+
+ // Running the analyzer requires --analyze. Other modes can work with the
+ // -fsyntax-only option.
+ Tool.appendArgumentsAdjuster(new InsertAdjuster(
+ Analyze ? "--analyze" : "-fsyntax-only", InsertAdjuster::BEGIN));
+
+ clang_check::ClangCheckActionFactory CheckFactory;
+ FrontendActionFactory *FrontendFactory;
+
+ // Choose the correct factory based on the selected mode.
+ if (Analyze)
+ FrontendFactory = newFrontendActionFactory<clang::ento::AnalysisAction>();
+ else if (Fixit)
+ FrontendFactory = newFrontendActionFactory<FixItAction>();
+ else
+ FrontendFactory = newFrontendActionFactory(&CheckFactory);
- if (Fixit)
- return Tool.run(newFrontendActionFactory<FixItAction>());
- clang_check::ClangCheckActionFactory Factory;
- return Tool.run(newFrontendActionFactory(&Factory));
+ return Tool.run(FrontendFactory);
}