2012-07-16 20:46:48 +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
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Support/CommandLine.h"
|
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-04-04 20:07:46 +08:00
|
|
|
#include "clang/Frontend/FrontendActions.h"
|
2012-07-16 20:46:48 +08:00
|
|
|
#include "clang/Tooling/CommandLineClangTool.h"
|
2012-04-04 20:07:46 +08:00
|
|
|
#include "clang/Tooling/Tooling.h"
|
|
|
|
|
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-07-16 20:46:48 +08:00
|
|
|
static const char *MoreHelpText =
|
|
|
|
"\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"
|
|
|
|
"\n";
|
2012-07-12 22:34:23 +08:00
|
|
|
|
2012-08-13 18:50:08 +08:00
|
|
|
namespace {
|
|
|
|
class ActionFactory {
|
|
|
|
public:
|
|
|
|
ActionFactory()
|
|
|
|
: Options(createDriverOptTable()),
|
|
|
|
ASTDump(
|
|
|
|
"ast-dump",
|
|
|
|
cl::desc(Options->getOptionHelpText(options::OPT_ast_dump))),
|
|
|
|
ASTList(
|
|
|
|
"ast-list",
|
|
|
|
cl::desc(Options->getOptionHelpText(options::OPT_ast_list))),
|
|
|
|
ASTPrint(
|
|
|
|
"ast-print",
|
|
|
|
cl::desc(Options->getOptionHelpText(options::OPT_ast_print))),
|
|
|
|
ASTDumpFilter(
|
|
|
|
"ast-dump-filter",
|
|
|
|
cl::desc(Options->getOptionHelpText(options::OPT_ast_dump_filter))) {}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
OwningPtr<OptTable> Options;
|
|
|
|
cl::opt<bool> ASTDump;
|
|
|
|
cl::opt<bool> ASTList;
|
|
|
|
cl::opt<bool> ASTPrint;
|
|
|
|
cl::opt<std::string> ASTDumpFilter;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
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-07-16 20:46:48 +08:00
|
|
|
CommandLineClangTool Tool;
|
|
|
|
cl::extrahelp MoreHelp(MoreHelpText);
|
|
|
|
Tool.initialize(argc, argv);
|
2012-08-13 18:50:08 +08:00
|
|
|
return Tool.run(newFrontendActionFactory(&Factory));
|
2012-04-04 20:07:46 +08:00
|
|
|
}
|