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"
36 unsigned FormatArgOffset,
bool StrictMode,
37 const LangOptions &LO);
39 bool canApply()
const {
return ConversionNotPossibleReason.empty(); }
41 return ConversionNotPossibleReason;
43 void applyFixes(DiagnosticBuilder &Diag, SourceManager &SM);
48 const bool CastMismatchedIntegerTypes;
49 const Expr *
const *Args;
50 const unsigned NumArgs;
52 const LangOptions &LangOpts;
53 std::string ConversionNotPossibleReason;
54 bool FormatStringNeededRewriting =
false;
55 bool UsePrintNewlineFunction =
false;
56 size_t PrintfFormatStringPos = 0U;
57 StringRef PrintfFormatString;
60 std::optional<clang::ast_matchers::StatementMatcher>
61 StringCStrCallExprMatcher;
63 const StringLiteral *FormatExpr;
64 std::string StandardFormatString;
72 explicit ArgumentFix(
unsigned ArgIndex, std::string Fix)
73 : ArgIndex(ArgIndex), Fix(std::move(Fix)) {}
76 std::vector<ArgumentFix> ArgFixes;
77 std::vector<clang::ast_matchers::BoundNodes> ArgCStrRemovals;
82 std::vector<std::tuple<unsigned, unsigned>> ArgRotates;
86 void emitAlternativeForm(
const PrintfSpecifier &FS, std::string &FormatSpec);
87 void emitFieldWidth(
const PrintfSpecifier &FS, std::string &FormatSpec);
89 void emitStringArgument(
unsigned ArgIndex,
const Expr *Arg);
90 bool emitIntegerArgument(ConversionSpecifier::Kind ArgKind,
const Expr *Arg,
91 unsigned ArgIndex, std::string &FormatSpec);
94 std::string &FormatSpec);
96 std::string &StandardFormatString);
101 const char *StartSpecifier,
unsigned SpecifierLen,
102 const TargetInfo &Target)
override;
104 void appendFormatText(StringRef
Text);
105 void finalizeFormatText();
106 bool conversionNotPossible(std::string Reason) {
107 ConversionNotPossibleReason = std::move(Reason);