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" |
Manuel Klimek | 814f9bd | 2013-11-14 15:49:44 +0000 | [diff] [blame^] | 19 | #include "clang/Tooling/CommonOptionsParser.h" |
Daniel Jasper | d07c840 | 2013-07-29 08:19:24 +0000 | [diff] [blame] | 20 | #include "llvm/Support/CommandLine.h" |
| 21 | #include <vector> |
| 22 | |
| 23 | using namespace clang::ast_matchers; |
| 24 | using namespace clang::driver; |
| 25 | using namespace clang::tooling; |
| 26 | using namespace llvm; |
| 27 | |
| 28 | cl::OptionCategory ClangTidyCategory("clang-tidy options"); |
| 29 | |
Manuel Klimek | 814f9bd | 2013-11-14 15:49:44 +0000 | [diff] [blame^] | 30 | static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage); |
Daniel Jasper | d07c840 | 2013-07-29 08:19:24 +0000 | [diff] [blame] | 31 | |
| 32 | static 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)); |
| 36 | static 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 | |
| 41 | int main(int argc, const char **argv) { |
Manuel Klimek | 814f9bd | 2013-11-14 15:49:44 +0000 | [diff] [blame^] | 42 | CommonOptionsParser OptionsParser(argc, argv); |
Daniel Jasper | d07c840 | 2013-07-29 08:19:24 +0000 | [diff] [blame] | 43 | |
| 44 | SmallVector<clang::tidy::ClangTidyError, 16> Errors; |
Manuel Klimek | 814f9bd | 2013-11-14 15:49:44 +0000 | [diff] [blame^] | 45 | clang::tidy::runClangTidy(Checks, OptionsParser.getCompilations(), |
| 46 | OptionsParser.getSourcePathList(), &Errors); |
Daniel Jasper | d07c840 | 2013-07-29 08:19:24 +0000 | [diff] [blame] | 47 | clang::tidy::handleErrors(Errors, Fix); |
| 48 | |
| 49 | return 0; |
| 50 | } |
Daniel Jasper | 89bbab0 | 2013-08-04 15:56:30 +0000 | [diff] [blame] | 51 | |
| 52 | namespace clang { |
| 53 | namespace tidy { |
| 54 | |
| 55 | // This anchor is used to force the linker to link the LLVMModule. |
| 56 | extern volatile int LLVMModuleAnchorSource; |
| 57 | static int LLVMModuleAnchorDestination = LLVMModuleAnchorSource; |
| 58 | |
| 59 | // This anchor is used to force the linker to link the GoogleModule. |
| 60 | extern volatile int GoogleModuleAnchorSource; |
| 61 | static int GoogleModuleAnchorDestination = GoogleModuleAnchorSource; |
| 62 | |
| 63 | } // namespace tidy |
| 64 | } // namespace clang |