clang-tools 22.0.0git
CustomTidyModule.cpp
Go to the documentation of this file.
1#include "../ClangTidy.h"
5#include "QueryCheck.h"
6#include "llvm/ADT/SmallSet.h"
7#include "llvm/ADT/SmallString.h"
8#include "llvm/ADT/StringRef.h"
9#include <cassert>
10#include <memory>
11
12namespace clang::tidy {
13namespace custom {
14
16public:
17 void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {}
18};
19
20// We need to register the checks more flexibly than builtin modules. The checks
21// will changed dynamically when switching to different source file.
22extern void registerCustomChecks(const ClangTidyOptions &Options,
23 ClangTidyCheckFactories &Factories) {
24 static llvm::SmallSet<llvm::SmallString<32>, 8> CustomCheckNames{};
25 if (!Options.CustomChecks.has_value() || Options.CustomChecks->empty())
26 return;
27 for (const llvm::SmallString<32> &Name : CustomCheckNames)
28 Factories.eraseCheck(Name);
30 Options.CustomChecks.value()) {
31 llvm::SmallString<32> Name = llvm::StringRef{"custom-" + V.Name};
32 Factories.registerCheckFactory(
33 // add custom- prefix to avoid conflicts with builtin checks
34 Name, [&V](llvm::StringRef Name, ClangTidyContext *Context) {
35 return std::make_unique<custom::QueryCheck>(Name, V, Context);
36 });
37 CustomCheckNames.insert(std::move(Name));
38 }
39}
40
46
48
49} // namespace custom
50
51// Register the CustomTidyModule using this statically initialized variable.
52static ClangTidyModuleRegistry::Add<custom::CustomModule>
53 X("custom-module", "Adds custom query lint checks.");
54
55// This anchor is used to force the linker to link in the generated object file
56// and thus register the AlteraModule.
57volatile int CustomModuleAnchorSource = 0; // NOLINT (misc-use-internal-linkage)
58
59} // namespace clang::tidy
A collection of ClangTidyCheckFactory instances.
void registerCheckFactory(llvm::StringRef Name, CheckFactory Factory)
Registers check Factory with name Name.
void eraseCheck(llvm::StringRef CheckName)
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
A clang-tidy module groups a number of ClangTidyChecks and gives them a prefixed name.
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override
Implement this function in order to register all CheckFactories belonging to this module.
void(* RegisterCustomChecks)(const ClangTidyOptions &O, ClangTidyCheckFactories &Factories)
static CustomChecksRegisterInitializer Init
void registerCustomChecks(const ClangTidyOptions &Options, ClangTidyCheckFactories &Factories)
volatile int CustomModuleAnchorSource
static ClangTidyModuleRegistry::Add< altera::AlteraModule > X("altera-module", "Adds Altera FPGA OpenCL lint checks.")
Contains options for clang-tidy.
std::optional< CustomCheckValueList > CustomChecks