15#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_FORMATSTRINGCONVERTER_H
16#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_FORMATSTRINGCONVERTER_H
18#include "clang/AST/ASTContext.h"
19#include "clang/AST/FormatString.h"
20#include "clang/ASTMatchers/ASTMatchers.h"
43 const LangOptions &LO);
45 bool canApply()
const {
return ConversionNotPossibleReason.empty(); }
47 return ConversionNotPossibleReason;
49 void applyFixes(DiagnosticBuilder &Diag, SourceManager &SM);
54 const Configuration Config;
55 const bool CastMismatchedIntegerTypes;
56 const Expr *
const *Args;
57 const unsigned NumArgs;
59 const LangOptions &LangOpts;
60 std::string ConversionNotPossibleReason;
61 bool FormatStringNeededRewriting =
false;
62 bool UsePrintNewlineFunction =
false;
63 size_t PrintfFormatStringPos = 0U;
64 StringRef PrintfFormatString;
67 std::optional<clang::ast_matchers::StatementMatcher>
68 StringCStrCallExprMatcher;
70 const StringLiteral *FormatExpr;
71 std::string StandardFormatString;
79 explicit ArgumentFix(
unsigned ArgIndex, std::string Fix)
80 : ArgIndex(ArgIndex), Fix(std::move(Fix)) {}
83 std::vector<ArgumentFix> ArgFixes;
84 std::vector<clang::ast_matchers::BoundNodes> ArgCStrRemovals;
89 std::vector<std::tuple<unsigned, unsigned>> ArgRotates;
93 void emitAlternativeForm(
const PrintfSpecifier &FS, std::string &FormatSpec);
94 void emitFieldWidth(
const PrintfSpecifier &FS, std::string &FormatSpec);
96 void emitStringArgument(
unsigned ArgIndex,
const Expr *Arg);
97 bool emitIntegerArgument(ConversionSpecifier::Kind ArgKind,
const Expr *Arg,
98 unsigned ArgIndex, std::string &FormatSpec);
101 std::string &FormatSpec);
103 std::string &StandardFormatString);
108 const char *StartSpecifier,
unsigned SpecifierLen,
109 const TargetInfo &Target)
override;
111 void appendFormatText(StringRef
Text);
112 void finalizeFormatText();
113 bool conversionNotPossible(std::string Reason) {
114 ConversionNotPossibleReason = std::move(Reason);