Daniel Jasper | d07c840 | 2013-07-29 08:19:24 +0000 | [diff] [blame^] | 1 | //===--- 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 | |
| 24 | using namespace clang::ast_matchers; |
| 25 | using namespace clang::driver; |
| 26 | using namespace clang::tooling; |
| 27 | using namespace llvm; |
| 28 | |
| 29 | cl::OptionCategory ClangTidyCategory("clang-tidy options"); |
| 30 | |
| 31 | cl::list<std::string> |
| 32 | Ranges(cl::Positional, cl::desc("<range0> [... <rangeN>]"), cl::OneOrMore); |
| 33 | |
| 34 | static 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)); |
| 38 | static 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 | |
| 43 | int 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 | } |