blob: aed545697fbcdf4b02705401d675f6ebd82148ac [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"
19#include "clang/Driver/OptTable.h"
20#include "clang/Driver/Options.h"
21#include "llvm/Support/CommandLine.h"
22#include <vector>
23
24using namespace clang::ast_matchers;
25using namespace clang::driver;
26using namespace clang::tooling;
27using namespace llvm;
28
29cl::OptionCategory ClangTidyCategory("clang-tidy options");
30
31cl::list<std::string>
32Ranges(cl::Positional, cl::desc("<range0> [... <rangeN>]"), cl::OneOrMore);
33
34static cl::opt<std::string> Checks(
35 "checks",
36 cl::desc("Regular expression matching the names of the checks to be run."),
37 cl::init(".*"), cl::cat(ClangTidyCategory));
38static cl::opt<bool> Fix("fix", cl::desc("Fix detected errors if possible."),
39 cl::init(false), cl::cat(ClangTidyCategory));
40
41// FIXME: Add option to list name/description of all checks.
42
43int main(int argc, const char **argv) {
44 cl::ParseCommandLineOptions(argc, argv, "TBD\n");
45 OwningPtr<clang::tooling::CompilationDatabase> Compilations(
46 FixedCompilationDatabase::loadFromCommandLine(argc, argv));
47 if (!Compilations)
48 return 0;
49 // FIXME: Load other compilation databases.
50
51 SmallVector<clang::tidy::ClangTidyError, 16> Errors;
52 clang::tidy::runClangTidy(Checks, *Compilations, Ranges, &Errors);
53 clang::tidy::handleErrors(Errors, Fix);
54
55 return 0;
56}