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 | |
| 21 | using namespace clang::ast_matchers; |
| 22 | using namespace clang::driver; |
| 23 | using namespace clang::tooling; |
| 24 | using namespace llvm; |
| 25 | |
Alexander Kornienko | 99c9d6a | 2014-02-05 13:43:27 +0000 | [diff] [blame] | 26 | static cl::OptionCategory ClangTidyCategory("clang-tidy options"); |
Daniel Jasper | d07c840 | 2013-07-29 08:19:24 +0000 | [diff] [blame] | 27 | |
Manuel Klimek | 814f9bd | 2013-11-14 15:49:44 +0000 | [diff] [blame] | 28 | static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage); |
Daniel Jasper | d07c840 | 2013-07-29 08:19:24 +0000 | [diff] [blame] | 29 | |
| 30 | static cl::opt<std::string> Checks( |
| 31 | "checks", |
| 32 | cl::desc("Regular expression matching the names of the checks to be run."), |
| 33 | cl::init(".*"), cl::cat(ClangTidyCategory)); |
Alexander Kornienko | fb9e92b | 2013-12-19 19:57:05 +0000 | [diff] [blame] | 34 | static cl::opt<std::string> DisableChecks( |
| 35 | "disable-checks", |
| 36 | cl::desc("Regular expression matching the names of the checks to disable."), |
| 37 | cl::init("clang-analyzer-alpha.*"), cl::cat(ClangTidyCategory)); |
Daniel Jasper | d07c840 | 2013-07-29 08:19:24 +0000 | [diff] [blame] | 38 | static cl::opt<bool> Fix("fix", cl::desc("Fix detected errors if possible."), |
| 39 | cl::init(false), cl::cat(ClangTidyCategory)); |
| 40 | |
Alexander Kornienko | fb9e92b | 2013-12-19 19:57:05 +0000 | [diff] [blame] | 41 | static cl::opt<bool> ListChecks("list-checks", |
| 42 | cl::desc("List all enabled checks and exit."), |
| 43 | cl::init(false), cl::cat(ClangTidyCategory)); |
Daniel Jasper | d07c840 | 2013-07-29 08:19:24 +0000 | [diff] [blame] | 44 | |
| 45 | int main(int argc, const char **argv) { |
Alexander Kornienko | 06ff5a7 | 2013-12-12 10:01:39 +0000 | [diff] [blame] | 46 | CommonOptionsParser OptionsParser(argc, argv, ClangTidyCategory); |
Daniel Jasper | d07c840 | 2013-07-29 08:19:24 +0000 | [diff] [blame] | 47 | |
Alexander Kornienko | fb9e92b | 2013-12-19 19:57:05 +0000 | [diff] [blame] | 48 | // FIXME: Allow using --list-checks without positional arguments. |
| 49 | if (ListChecks) { |
Alexander Kornienko | fb9e92b | 2013-12-19 19:57:05 +0000 | [diff] [blame] | 50 | llvm::outs() << "Enabled checks:"; |
Alexander Kornienko | 16ac6ce | 2014-03-05 13:14:32 +0000 | [diff] [blame] | 51 | for (auto CheckName : clang::tidy::getCheckNames(Checks, DisableChecks)) |
| 52 | llvm::outs() << "\n " << CheckName; |
Alexander Kornienko | fb9e92b | 2013-12-19 19:57:05 +0000 | [diff] [blame] | 53 | llvm::outs() << "\n\n"; |
| 54 | return 0; |
| 55 | } |
| 56 | |
Daniel Jasper | d07c840 | 2013-07-29 08:19:24 +0000 | [diff] [blame] | 57 | SmallVector<clang::tidy::ClangTidyError, 16> Errors; |
Alexander Kornienko | fb9e92b | 2013-12-19 19:57:05 +0000 | [diff] [blame] | 58 | clang::tidy::runClangTidy(Checks, DisableChecks, |
| 59 | OptionsParser.getCompilations(), |
Manuel Klimek | 814f9bd | 2013-11-14 15:49:44 +0000 | [diff] [blame] | 60 | OptionsParser.getSourcePathList(), &Errors); |
Daniel Jasper | d07c840 | 2013-07-29 08:19:24 +0000 | [diff] [blame] | 61 | clang::tidy::handleErrors(Errors, Fix); |
| 62 | |
| 63 | return 0; |
| 64 | } |
Daniel Jasper | 89bbab0 | 2013-08-04 15:56:30 +0000 | [diff] [blame] | 65 | |
| 66 | namespace clang { |
| 67 | namespace tidy { |
| 68 | |
| 69 | // This anchor is used to force the linker to link the LLVMModule. |
| 70 | extern volatile int LLVMModuleAnchorSource; |
| 71 | static int LLVMModuleAnchorDestination = LLVMModuleAnchorSource; |
| 72 | |
| 73 | // This anchor is used to force the linker to link the GoogleModule. |
| 74 | extern volatile int GoogleModuleAnchorSource; |
| 75 | static int GoogleModuleAnchorDestination = GoogleModuleAnchorSource; |
| 76 | |
Alexander Kornienko | 16ac6ce | 2014-03-05 13:14:32 +0000 | [diff] [blame] | 77 | // This anchor is used to force the linker to link the MiscModule. |
| 78 | extern volatile int MiscModuleAnchorSource; |
| 79 | static int MiscModuleAnchorDestination = MiscModuleAnchorSource; |
| 80 | |
Daniel Jasper | 89bbab0 | 2013-08-04 15:56:30 +0000 | [diff] [blame] | 81 | } // namespace tidy |
| 82 | } // namespace clang |