blob: b1c1e4d5b9d1714cef02012cea82198dae59ccf7 [file] [log] [blame]
Daniel Jasperd07c8402013-07-29 08:19:24 +00001//===--- tools/extra/clang-tidy/ClangTidyMain.cpp - Clang tidy tool -------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9///
10/// \file This file implements a clang-tidy tool.
11///
12/// This tool uses the Clang Tooling infrastructure, see
13/// http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html
14/// for details on setting it up with LLVM source tree.
15///
16//===----------------------------------------------------------------------===//
17
18#include "../ClangTidy.h"
Manuel Klimek814f9bd2013-11-14 15:49:44 +000019#include "clang/Tooling/CommonOptionsParser.h"
Daniel Jasperd07c8402013-07-29 08:19:24 +000020#include "llvm/Support/CommandLine.h"
21#include <vector>
22
23using namespace clang::ast_matchers;
24using namespace clang::driver;
25using namespace clang::tooling;
26using namespace llvm;
27
28cl::OptionCategory ClangTidyCategory("clang-tidy options");
29
Manuel Klimek814f9bd2013-11-14 15:49:44 +000030static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
Daniel Jasperd07c8402013-07-29 08:19:24 +000031
32static cl::opt<std::string> Checks(
33 "checks",
34 cl::desc("Regular expression matching the names of the checks to be run."),
35 cl::init(".*"), cl::cat(ClangTidyCategory));
36static cl::opt<bool> Fix("fix", cl::desc("Fix detected errors if possible."),
37 cl::init(false), cl::cat(ClangTidyCategory));
38
39// FIXME: Add option to list name/description of all checks.
40
41int main(int argc, const char **argv) {
Manuel Klimek814f9bd2013-11-14 15:49:44 +000042 CommonOptionsParser OptionsParser(argc, argv);
Daniel Jasperd07c8402013-07-29 08:19:24 +000043
44 SmallVector<clang::tidy::ClangTidyError, 16> Errors;
Manuel Klimek814f9bd2013-11-14 15:49:44 +000045 clang::tidy::runClangTidy(Checks, OptionsParser.getCompilations(),
46 OptionsParser.getSourcePathList(), &Errors);
Daniel Jasperd07c8402013-07-29 08:19:24 +000047 clang::tidy::handleErrors(Errors, Fix);
48
49 return 0;
50}
Daniel Jasper89bbab02013-08-04 15:56:30 +000051
52namespace clang {
53namespace tidy {
54
55// This anchor is used to force the linker to link the LLVMModule.
56extern volatile int LLVMModuleAnchorSource;
57static int LLVMModuleAnchorDestination = LLVMModuleAnchorSource;
58
59// This anchor is used to force the linker to link the GoogleModule.
60extern volatile int GoogleModuleAnchorSource;
61static int GoogleModuleAnchorDestination = GoogleModuleAnchorSource;
62
63} // namespace tidy
64} // namespace clang