Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:21

0001 //===--- UseStdFormatCheck.h - clang-tidy -----------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USESTDFORMATCHECK_H
0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USESTDFORMATCHECK_H
0011 
0012 #include "../ClangTidyCheck.h"
0013 #include "../utils/IncludeInserter.h"
0014 
0015 namespace clang::tidy::modernize {
0016 
0017 /// Converts calls to absl::StrFormat, or other functions via configuration
0018 /// options, to C++20's std::format, or another function via a configuration
0019 /// option, modifying the format string appropriately and removing
0020 /// now-unnecessary calls to std::string::c_str() and std::string::data().
0021 ///
0022 /// For the user-facing documentation see:
0023 /// http://clang.llvm.org/extra/clang-tidy/checks/modernize/use-std-format.html
0024 class UseStdFormatCheck : public ClangTidyCheck {
0025 public:
0026   UseStdFormatCheck(StringRef Name, ClangTidyContext *Context);
0027   bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
0028     if (ReplacementFormatFunction == "std::format")
0029       return LangOpts.CPlusPlus20;
0030     return LangOpts.CPlusPlus;
0031   }
0032   void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
0033                            Preprocessor *ModuleExpanderPP) override;
0034   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
0035   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
0036   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
0037   std::optional<TraversalKind> getCheckTraversalKind() const override {
0038     return TK_IgnoreUnlessSpelledInSource;
0039   }
0040 
0041 private:
0042   bool StrictMode;
0043   std::vector<StringRef> StrFormatLikeFunctions;
0044   StringRef ReplacementFormatFunction;
0045   utils::IncludeInserter IncludeInserter;
0046   std::optional<StringRef> MaybeHeaderToInclude;
0047   Preprocessor *PP = nullptr;
0048 };
0049 
0050 } // namespace clang::tidy::modernize
0051 
0052 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USESTDFORMATCHECK_H