50 lines · c
1//===----------------------------------------------------------------------===//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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USESTDNUMBERSCHECK_H10#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USESTDNUMBERSCHECK_H11 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 replaced18/// with c++20's mathematical constants from the ``numbers`` header and19/// 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/// https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-std-numbers.html25class UseStdNumbersCheck : public ClangTidyCheck {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::modernize48 49#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USESTDNUMBERSCHECK_H50