1 #ifndef LLVM_CLANG_LIB_ANALYSIS_FORMATSTRINGPARSING_H
2 #define LLVM_CLANG_LIB_ANALYSIS_FORMATSTRINGPARSING_H
4 #include "clang/AST/ASTContext.h"
5 #include "clang/AST/Type.h"
6 #include "clang/AST/FormatString.h"
13 class UpdateOnReturn {
17 UpdateOnReturn(T &valueToUpdate, const T &valueToCopy)
18 : ValueToUpdate(valueToUpdate), ValueToCopy(valueToCopy) {}
21 ValueToUpdate = ValueToCopy;
25 namespace analyze_format_string {
27 OptionalAmount ParseAmount(const char *&Beg, const char *E);
28 OptionalAmount ParseNonPositionAmount(const char *&Beg, const char *E,
31 OptionalAmount ParsePositionAmount(FormatStringHandler &H,
32 const char *Start, const char *&Beg,
33 const char *E, PositionContext p);
35 bool ParseFieldWidth(FormatStringHandler &H,
37 const char *Start, const char *&Beg, const char *E,
40 bool ParseArgPosition(FormatStringHandler &H,
41 FormatSpecifier &CS, const char *Start,
42 const char *&Beg, const char *E);
44 bool ParseVectorModifier(FormatStringHandler &H,
45 FormatSpecifier &FS, const char *&Beg, const char *E,
46 const LangOptions &LO);
48 /// Returns true if a LengthModifier was parsed and installed in the
49 /// FormatSpecifier& argument, and false otherwise.
50 bool ParseLengthModifier(FormatSpecifier &FS, const char *&Beg, const char *E,
51 const LangOptions &LO, bool IsScanf = false);
53 /// Returns true if the invalid specifier in \p SpecifierBegin is a UTF-8
54 /// string; check that it won't go further than \p FmtStrEnd and write
55 /// up the total size in \p Len.
56 bool ParseUTF8InvalidSpecifier(const char *SpecifierBegin,
57 const char *FmtStrEnd, unsigned &Len);
59 template <typename T> class SpecifierResult {
64 SpecifierResult(bool stop = false)
65 : Start(nullptr), Stop(stop) {}
66 SpecifierResult(const char *start,
68 : FS(fs), Start(start), Stop(false) {}
70 const char *getStart() const { return Start; }
71 bool shouldStop() const { return Stop; }
72 bool hasValue() const { return Start != nullptr; }
73 const T &getValue() const {
77 const T &getValue() { return FS; }
80 } // end analyze_format_string namespace
81 } // end clang namespace