blob: a71df0c717a052b04978441a841a46445b35a9e0 [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 <vector>
21
22using namespace clang::ast_matchers;
23using namespace clang::driver;
24using namespace clang::tooling;
25using namespace llvm;
26
27cl::OptionCategory ClangTidyCategory("clang-tidy options");
28
Manuel Klimek814f9bd2013-11-14 15:49:44 +000029static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
Daniel Jasperd07c8402013-07-29 08:19:24 +000030
31static cl::opt<std::string> Checks(
32 "checks",
33 cl::desc("Regular expression matching the names of the checks to be run."),
34 cl::init(".*"), cl::cat(ClangTidyCategory));
35static cl::opt<bool> Fix("fix", cl::desc("Fix detected errors if possible."),
36 cl::init(false), cl::cat(ClangTidyCategory));
37
38// FIXME: Add option to list name/description of all checks.
39
40int main(int argc, const char **argv) {
Alexander Kornienko06ff5a72013-12-12 10:01:39 +000041 CommonOptionsParser OptionsParser(argc, argv, ClangTidyCategory);
Daniel Jasperd07c8402013-07-29 08:19:24 +000042
43 SmallVector<clang::tidy::ClangTidyError, 16> Errors;
Manuel Klimek814f9bd2013-11-14 15:49:44 +000044 clang::tidy::runClangTidy(Checks, OptionsParser.getCompilations(),
45 OptionsParser.getSourcePathList(), &Errors);
Daniel Jasperd07c8402013-07-29 08:19:24 +000046 clang::tidy::handleErrors(Errors, Fix);
47
48 return 0;
49}
Daniel Jasper89bbab02013-08-04 15:56:30 +000050
51namespace clang {
52namespace tidy {
53
54// This anchor is used to force the linker to link the LLVMModule.
55extern volatile int LLVMModuleAnchorSource;
56static int LLVMModuleAnchorDestination = LLVMModuleAnchorSource;
57
58// This anchor is used to force the linker to link the GoogleModule.
59extern volatile int GoogleModuleAnchorSource;
60static int GoogleModuleAnchorDestination = GoogleModuleAnchorSource;
61
62} // namespace tidy
63} // namespace clang