clang-tools 20.0.0git
UseStdNumbersCheck.h
Go to the documentation of this file.
1//===--- UseStdNumbersCheck.h - clang-tidy ----------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USESTDNUMBERSCHECK_H
10#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USESTDNUMBERSCHECK_H
11
12#include "../ClangTidyCheck.h"
13#include "../utils/IncludeInserter.h"
14
15namespace clang::tidy::modernize {
16
17/// Finds constants and function calls to math functions that can be replaced
18/// with c++20's mathematical constants from the ``numbers`` header and
19/// offers fix-it hints.
20/// Does not match the use of variables with that value, and instead,
21/// offers a replacement at the definition of those variables.
22///
23/// For the user-facing documentation see:
24/// http://clang.llvm.org/extra/clang-tidy/checks/modernize/use-std-numbers.html
26public:
27 UseStdNumbersCheck(StringRef Name, ClangTidyContext *Context);
28
29 bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
30 return LangOpts.CPlusPlus20;
31 }
32 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
33 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
34 void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
35 Preprocessor *ModuleExpanderPP) override;
36 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
37 std::optional<TraversalKind> getCheckTraversalKind() const override {
38 return TK_IgnoreUnlessSpelledInSource;
39 }
40
41private:
42 utils::IncludeInserter IncludeInserter;
43 StringRef DiffThresholdString;
44 double DiffThreshold;
45};
46
47} // namespace clang::tidy::modernize
48
49#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USESTDNUMBERSCHECK_H
llvm::SmallString< 256U > Name
Base class for all clang-tidy checks.
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Finds constants and function calls to math functions that can be replaced with c++20's mathematical c...
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) override
Override this to register PPCallbacks in the preprocessor.
std::optional< TraversalKind > getCheckTraversalKind() const override
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override
Override this to disable registering matchers and PP callbacks if an invalid language version is bein...
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Produces fixes to insert specified includes to source files, if not yet present.
llvm::StringMap< ClangTidyValue > OptionMap