clang-tools  6.0.0
ClangTidyModule.cpp
Go to the documentation of this file.
1 //===--- tools/extra/clang-tidy/ClangTidyModule.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 Implements classes required to build clang-tidy modules.
11 ///
12 //===----------------------------------------------------------------------===//
13 
14 #include "ClangTidyModule.h"
15 
16 namespace clang {
17 namespace tidy {
18 
20  CheckFactory Factory) {
21  Factories[Name] = std::move(Factory);
22 }
23 
25  ClangTidyContext *Context,
26  std::vector<std::unique_ptr<ClangTidyCheck>> &Checks) {
27  for (const auto &Factory : Factories) {
28  if (Context->isCheckEnabled(Factory.first))
29  Checks.emplace_back(Factory.second(Factory.first, Context));
30  }
31 }
32 
34  return ClangTidyOptions();
35 }
36 
37 } // namespace tidy
38 } // namespace clang
StringHandle Name
void registerCheckFactory(StringRef Name, CheckFactory Factory)
Registers check Factory with name Name.
bool isCheckEnabled(StringRef CheckName) const
Returns true if the check is enabled for the CurrentFile.
Contains options for clang-tidy.
virtual ClangTidyOptions getModuleOptions()
Gets default options for checks defined in this module.
std::function< ClangTidyCheck *(StringRef Name, ClangTidyContext *Context)> CheckFactory
void createChecks(ClangTidyContext *Context, std::vector< std::unique_ptr< ClangTidyCheck >> &Checks)
Create instances of all checks matching CheckRegexString and store them in Checks.
static cl::opt< std::string > Checks("checks", cl::desc(R"( Comma-separated list of globs with optional '-' prefix. Globs are processed in order of appearance in the list. Globs without '-' prefix add checks with matching names to the set, globs with the '-' prefix remove checks with matching names from the set of enabled checks. This option's value is appended to the value of the 'Checks' option in .clang-tidy file, if any. )"), cl::init(""), cl::cat(ClangTidyCategory))
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.