183f875dcSMike Crowe //===--- UseStdPrintCheck.h - clang-tidy-------------------------*- C++ -*-===// 283f875dcSMike Crowe // 383f875dcSMike Crowe // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 483f875dcSMike Crowe // See https://llvm.org/LICENSE.txt for license information. 583f875dcSMike Crowe // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 683f875dcSMike Crowe // 783f875dcSMike Crowe //===----------------------------------------------------------------------===// 883f875dcSMike Crowe 983f875dcSMike Crowe #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_USESTDPRINTCHECK_H 1083f875dcSMike Crowe #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_USESTDPRINTCHECK_H 1183f875dcSMike Crowe 1283f875dcSMike Crowe #include "../ClangTidyCheck.h" 1383f875dcSMike Crowe #include "../utils/IncludeInserter.h" 1483f875dcSMike Crowe 1583f875dcSMike Crowe namespace clang::tidy::modernize { 1683f875dcSMike Crowe /// Convert calls to printf-like functions to std::print and std::println 1783f875dcSMike Crowe /// 1883f875dcSMike Crowe /// For the user-facing documentation see: 1983f875dcSMike Crowe /// http://clang.llvm.org/extra/clang-tidy/checks/modernize/use-std-print.html 2083f875dcSMike Crowe class UseStdPrintCheck : public ClangTidyCheck { 2183f875dcSMike Crowe public: 2283f875dcSMike Crowe UseStdPrintCheck(StringRef Name, ClangTidyContext *Context); 2383f875dcSMike Crowe bool isLanguageVersionSupported(const LangOptions &LangOpts) const override { 2483f875dcSMike Crowe if (ReplacementPrintFunction == "std::print" || 2583f875dcSMike Crowe ReplacementPrintlnFunction == "std::println") 2683f875dcSMike Crowe return LangOpts.CPlusPlus23; 2783f875dcSMike Crowe return LangOpts.CPlusPlus; 2883f875dcSMike Crowe } 2983f875dcSMike Crowe void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, 3083f875dcSMike Crowe Preprocessor *ModuleExpanderPP) override; 3183f875dcSMike Crowe void storeOptions(ClangTidyOptions::OptionMap &Opts) override; 3283f875dcSMike Crowe void registerMatchers(ast_matchers::MatchFinder *Finder) override; 3383f875dcSMike Crowe void check(const ast_matchers::MatchFinder::MatchResult &Result) override; 3483f875dcSMike Crowe std::optional<TraversalKind> getCheckTraversalKind() const override { 3583f875dcSMike Crowe return TK_IgnoreUnlessSpelledInSource; 3683f875dcSMike Crowe } 3783f875dcSMike Crowe 3883f875dcSMike Crowe private: 39*a199fb12SMike Crowe Preprocessor *PP; 4083f875dcSMike Crowe bool StrictMode; 4183f875dcSMike Crowe std::vector<StringRef> PrintfLikeFunctions; 4283f875dcSMike Crowe std::vector<StringRef> FprintfLikeFunctions; 4383f875dcSMike Crowe StringRef ReplacementPrintFunction; 4483f875dcSMike Crowe StringRef ReplacementPrintlnFunction; 4583f875dcSMike Crowe utils::IncludeInserter IncludeInserter; 4683f875dcSMike Crowe std::optional<StringRef> MaybeHeaderToInclude; 4783f875dcSMike Crowe }; 4883f875dcSMike Crowe 4983f875dcSMike Crowe } // namespace clang::tidy::modernize 5083f875dcSMike Crowe 5183f875dcSMike Crowe #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_USESTDPRINTCHECK_H 52