brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.1 KiB · 7dad065 Raw
53 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_USESTDFORMATCHECK_H10#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USESTDFORMATCHECK_H11 12#include "../ClangTidyCheck.h"13#include "../utils/IncludeInserter.h"14 15namespace clang::tidy::modernize {16 17/// Converts calls to absl::StrFormat, or other functions via configuration18/// options, to C++20's std::format, or another function via a configuration19/// option, modifying the format string appropriately and removing20/// now-unnecessary calls to std::string::c_str() and std::string::data().21///22/// For the user-facing documentation see:23/// https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-std-format.html24class UseStdFormatCheck : public ClangTidyCheck {25public:26  UseStdFormatCheck(StringRef Name, ClangTidyContext *Context);27  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {28    if (ReplacementFormatFunction == "std::format")29      return LangOpts.CPlusPlus20;30    return LangOpts.CPlusPlus;31  }32  void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,33                           Preprocessor *ModuleExpanderPP) override;34  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;35  void registerMatchers(ast_matchers::MatchFinder *Finder) override;36  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;37  std::optional<TraversalKind> getCheckTraversalKind() const override {38    return TK_IgnoreUnlessSpelledInSource;39  }40 41private:42  bool StrictMode;43  std::vector<StringRef> StrFormatLikeFunctions;44  StringRef ReplacementFormatFunction;45  utils::IncludeInserter IncludeInserter;46  std::optional<StringRef> MaybeHeaderToInclude;47  Preprocessor *PP = nullptr;48};49 50} // namespace clang::tidy::modernize51 52#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USESTDFORMATCHECK_H53