2012-08-23 04:52:52 +08:00
|
|
|
//===--- tools/clang-check/ClangCheck.cpp - Clang check tool --------------===//
|
2012-04-04 20:07:46 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements a clang-check tool that runs the
|
|
|
|
// clang::SyntaxOnlyAction over a number of translation units.
|
|
|
|
//
|
2012-07-16 20:46:48 +08:00
|
|
|
// This tool uses the Clang Tooling infrastructure, see
|
|
|
|
// http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html
|
|
|
|
// for details on setting it up with LLVM source tree.
|
|
|
|
//
|
2012-04-04 20:07:46 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-08-13 18:50:08 +08:00
|
|
|
#include "clang/AST/ASTConsumer.h"
|
|
|
|
#include "clang/Driver/OptTable.h"
|
|
|
|
#include "clang/Driver/Options.h"
|
|
|
|
#include "clang/Frontend/ASTConsumers.h"
|
2012-08-23 04:52:52 +08:00
|
|
|
#include "clang/Tooling/CommonOptionsParser.h"
|
2012-04-04 20:07:46 +08:00
|
|
|
#include "clang/Tooling/Tooling.h"
|
2012-08-23 04:52:52 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2012-04-04 20:07:46 +08:00
|
|
|
|
2012-08-13 18:50:08 +08:00
|
|
|
using namespace clang::driver;
|
2012-04-04 20:07:46 +08:00
|
|
|
using namespace clang::tooling;
|
|
|
|
using namespace llvm;
|
|
|
|
|
2012-08-24 08:39:14 +08:00
|
|
|
static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
|
2012-08-23 04:52:52 +08:00
|
|
|
static cl::extrahelp MoreHelp(
|
2012-07-16 20:46:48 +08:00
|
|
|
"\tFor example, to run clang-check on all files in a subtree of the\n"
|
|
|
|
"\tsource tree, use:\n"
|
2012-07-12 22:34:23 +08:00
|
|
|
"\n"
|
2012-07-16 20:46:48 +08:00
|
|
|
"\t find path/in/subtree -name '*.cpp'|xargs clang-check\n"
|
2012-07-12 22:34:23 +08:00
|
|
|
"\n"
|
2012-07-16 20:46:48 +08:00
|
|
|
"\tor using a specific build path:\n"
|
2012-07-12 22:34:23 +08:00
|
|
|
"\n"
|
2012-07-16 20:46:48 +08:00
|
|
|
"\t find path/in/subtree -name '*.cpp'|xargs clang-check -p build/path\n"
|
2012-07-12 22:34:23 +08:00
|
|
|
"\n"
|
2012-07-16 20:46:48 +08:00
|
|
|
"\tNote, that path/in/subtree and current directory should follow the\n"
|
|
|
|
"\trules described above.\n"
|
2012-08-23 04:52:52 +08:00
|
|
|
"\n"
|
|
|
|
);
|
|
|
|
|
|
|
|
static OwningPtr<OptTable> Options(createDriverOptTable());
|
|
|
|
static cl::opt<bool> ASTDump(
|
|
|
|
"ast-dump",
|
|
|
|
cl::desc(Options->getOptionHelpText(options::OPT_ast_dump)));
|
|
|
|
static cl::opt<bool> ASTList(
|
|
|
|
"ast-list",
|
|
|
|
cl::desc(Options->getOptionHelpText(options::OPT_ast_list)));
|
|
|
|
static cl::opt<bool> ASTPrint(
|
|
|
|
"ast-print",
|
|
|
|
cl::desc(Options->getOptionHelpText(options::OPT_ast_print)));
|
|
|
|
static cl::opt<std::string> ASTDumpFilter(
|
|
|
|
"ast-dump-filter",
|
|
|
|
cl::desc(Options->getOptionHelpText(options::OPT_ast_dump_filter)));
|
2012-07-12 22:34:23 +08:00
|
|
|
|
2012-09-08 06:44:34 +08:00
|
|
|
// Anonymous namespace here causes problems with gcc <= 4.4 on MacOS:
|
|
|
|
// http://llvm.org/bugs/show_bug.cgi?id=13777
|
|
|
|
// namespace {
|
2012-08-13 18:50:08 +08:00
|
|
|
class ActionFactory {
|
|
|
|
public:
|
|
|
|
clang::ASTConsumer *newASTConsumer() {
|
|
|
|
if (ASTList)
|
|
|
|
return clang::CreateASTDeclNodeLister();
|
|
|
|
if (ASTDump)
|
|
|
|
return clang::CreateASTDumper(ASTDumpFilter);
|
|
|
|
if (ASTPrint)
|
|
|
|
return clang::CreateASTPrinter(&llvm::outs(), ASTDumpFilter);
|
|
|
|
return new clang::ASTConsumer();
|
|
|
|
}
|
|
|
|
};
|
2012-09-08 06:44:34 +08:00
|
|
|
// }
|
2012-08-13 18:50:08 +08:00
|
|
|
|
2012-04-18 15:41:50 +08:00
|
|
|
int main(int argc, const char **argv) {
|
2012-08-13 18:50:08 +08:00
|
|
|
ActionFactory Factory;
|
2012-08-23 04:52:52 +08:00
|
|
|
CommonOptionsParser OptionsParser(argc, argv);
|
|
|
|
ClangTool Tool(OptionsParser.GetCompilations(),
|
|
|
|
OptionsParser.GetSourcePathList());
|
2012-08-13 18:50:08 +08:00
|
|
|
return Tool.run(newFrontendActionFactory(&Factory));
|
2012-04-04 20:07:46 +08:00
|
|
|
}
|