blob: 47aefe7be0ea718ae07f1d619ecacce586bf083b [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"
Daniel Jasperd07c8402013-07-29 08:19:24 +000019#include "llvm/Support/CommandLine.h"
20#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
29cl::list<std::string>
30Ranges(cl::Positional, cl::desc("<range0> [... <rangeN>]"), cl::OneOrMore);
31
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) {
42 cl::ParseCommandLineOptions(argc, argv, "TBD\n");
43 OwningPtr<clang::tooling::CompilationDatabase> Compilations(
44 FixedCompilationDatabase::loadFromCommandLine(argc, argv));
45 if (!Compilations)
46 return 0;
47 // FIXME: Load other compilation databases.
48
49 SmallVector<clang::tidy::ClangTidyError, 16> Errors;
50 clang::tidy::runClangTidy(Checks, *Compilations, Ranges, &Errors);
51 clang::tidy::handleErrors(Errors, Fix);
52
53 return 0;
54}
Daniel Jasper89bbab02013-08-04 15:56:30 +000055
56namespace clang {
57namespace tidy {
58
59// This anchor is used to force the linker to link the LLVMModule.
60extern volatile int LLVMModuleAnchorSource;
61static int LLVMModuleAnchorDestination = LLVMModuleAnchorSource;
62
63// This anchor is used to force the linker to link the GoogleModule.
64extern volatile int GoogleModuleAnchorSource;
65static int GoogleModuleAnchorDestination = GoogleModuleAnchorSource;
66
67} // namespace tidy
68} // namespace clang