clang 8.0.0

FormatStringParsing.h
Go to the documentation of this file.
1 #ifndef LLVM_CLANG_LIB_ANALYSIS_FORMATSTRINGPARSING_H
2 #define LLVM_CLANG_LIB_ANALYSIS_FORMATSTRINGPARSING_H
3
4 #include "clang/AST/ASTContext.h"
5 #include "clang/AST/Type.h"
6 #include "clang/AST/FormatString.h"
7
8 namespace clang {
9
10 class LangOptions;
11
12 template <typename T>
13 class UpdateOnReturn {
14 T &ValueToUpdate;
15 const T &ValueToCopy;
16 public:
17 UpdateOnReturn(T &valueToUpdate, const T &valueToCopy)
18 : ValueToUpdate(valueToUpdate), ValueToCopy(valueToCopy) {}
19
20 ~UpdateOnReturn() {
21 ValueToUpdate = ValueToCopy;
22 }
23 };
24
25 namespace analyze_format_string {
26
27 OptionalAmount ParseAmount(const char *&Beg, const char *E);
28 OptionalAmount ParseNonPositionAmount(const char *&Beg, const char *E,
29 unsigned &argIndex);
30
31 OptionalAmount ParsePositionAmount(FormatStringHandler &H,
32 const char *Start, const char *&Beg,
33 const char *E, PositionContext p);
34
35 bool ParseFieldWidth(FormatStringHandler &H,
36 FormatSpecifier &CS,
37 const char *Start, const char *&Beg, const char *E,
38 unsigned *argIndex);
39
40 bool ParseArgPosition(FormatStringHandler &H,
41 FormatSpecifier &CS, const char *Start,
42 const char *&Beg, const char *E);
43
44 bool ParseVectorModifier(FormatStringHandler &H,
45 FormatSpecifier &FS, const char *&Beg, const char *E,
46 const LangOptions &LO);
47
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);
52
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);
58
59 template <typename T> class SpecifierResult {
60 T FS;
61 const char *Start;
62 bool Stop;
63 public:
64 SpecifierResult(bool stop = false)
65 : Start(nullptr), Stop(stop) {}
66 SpecifierResult(const char *start,
67 const T &fs)
68 : FS(fs), Start(start), Stop(false) {}
69
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 {
74 assert(hasValue());
75 return FS;
76 }
77 const T &getValue() { return FS; }
78 };
79
80 } // end analyze_format_string namespace
81 } // end clang namespace
82
83 #endif
ASTContext.h
Defines the clang::ASTContext interface.
clang::analyze_format_string::SpecifierResult::hasValue
bool hasValue() const
Definition: FormatStringParsing.h:72
clang::analyze_format_string::SpecifierResult::getValue
const T & getValue()
Definition: FormatStringParsing.h:77
clang::analyze_format_string::SpecifierResult::getStart
const char * getStart() const
Definition: FormatStringParsing.h:70
clang::analyze_format_string::ParseVectorModifier
bool ParseVectorModifier(FormatStringHandler &H, FormatSpecifier &FS, const char *&Beg, const char *E, const LangOptions &LO)
Definition: FormatString.cpp:182
Type.h
C Language Family Type Representation.
clang::analyze_format_string::ParseArgPosition
bool ParseArgPosition(FormatStringHandler &H, FormatSpecifier &CS, const char *Start, const char *&Beg, const char *E)
Definition: FormatString.cpp:145
clang::LangOptions
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:50
clang::UpdateOnReturn::~UpdateOnReturn
~UpdateOnReturn()
Definition: FormatStringParsing.h:20
clang::analyze_format_string::ParseNonPositionAmount
OptionalAmount ParseNonPositionAmount(const char *&Beg, const char *E, unsigned &argIndex)
Definition: FormatString.cpp:64
clang::analyze_format_string::SpecifierResult::getValue
const T & getValue() const
Definition: FormatStringParsing.h:73
clang::analyze_format_string::SpecifierResult::SpecifierResult
SpecifierResult(const char *start, const T &fs)
Definition: FormatStringParsing.h:66
false
#define false
Definition: stdbool.h:33
clang::analyze_format_string::SpecifierResult::SpecifierResult
SpecifierResult(bool stop=false)
Definition: FormatStringParsing.h:64
clang::analyze_format_string::ParseFieldWidth
bool ParseFieldWidth(FormatStringHandler &H, FormatSpecifier &CS, const char *Start, const char *&Beg, const char *E, unsigned *argIndex)
Definition: FormatString.cpp:123
FormatString.h
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
clang::UpdateOnReturn::UpdateOnReturn
UpdateOnReturn(T &valueToUpdate, const T &valueToCopy)
Definition: FormatStringParsing.h:17
clang::analyze_format_string::ParseUTF8InvalidSpecifier
bool ParseUTF8InvalidSpecifier(const char *SpecifierBegin, const char *FmtStrEnd, unsigned &Len)
Returns true if the invalid specifier in SpecifierBegin is a UTF-8 string; check that it won&#39;t go fur...
Definition: FormatString.cpp:294
clang::analyze_format_string::ParseLengthModifier
bool ParseLengthModifier(FormatSpecifier &FS, const char *&Beg, const char *E, const LangOptions &LO, bool IsScanf=false)
Returns true if a LengthModifier was parsed and installed in the FormatSpecifier& argument...
Definition: FormatString.cpp:212
clang::analyze_format_string::PositionContext
PositionContext
Definition: FormatString.h:675
clang::analyze_format_string::SpecifierResult
Definition: FormatStringParsing.h:59
clang::analyze_format_string::ParseAmount
OptionalAmount ParseAmount(const char *&Beg, const char *E)
Definition: FormatString.cpp:38
clang::analyze_format_string::SpecifierResult::shouldStop
bool shouldStop() const
Definition: FormatStringParsing.h:71
clang::analyze_format_string::ParsePositionAmount
OptionalAmount ParsePositionAmount(FormatStringHandler &H, const char *Start, const char *&Beg, const char *E, PositionContext p)
Definition: FormatString.cpp:76
clang::UpdateOnReturn
Definition: FormatStringParsing.h:13