/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/lib/Analysis/FormatStringParsing.h
Line | Count | Source |
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/Analysis/Analyses/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 | 211k | : ValueToUpdate(valueToUpdate), ValueToCopy(valueToCopy) {} |
19 | | |
20 | 211k | ~UpdateOnReturn() { |
21 | 211k | ValueToUpdate = ValueToCopy; |
22 | 211k | } |
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 | | /// Returns true if a LengthModifier was parsed and installed in the |
45 | | /// FormatSpecifier& argument, and false otherwise. |
46 | | bool ParseLengthModifier(FormatSpecifier &FS, const char *&Beg, const char *E, |
47 | | const LangOptions &LO, bool IsScanf = false); |
48 | | |
49 | | /// Returns true if the invalid specifier in \p SpecifierBegin is a UTF-8 |
50 | | /// string; check that it won't go further than \p FmtStrEnd and write |
51 | | /// up the total size in \p Len. |
52 | | bool ParseUTF8InvalidSpecifier(const char *SpecifierBegin, |
53 | | const char *FmtStrEnd, unsigned &Len); |
54 | | |
55 | | template <typename T> class SpecifierResult { |
56 | | T FS; |
57 | | const char *Start; |
58 | | bool Stop; |
59 | | public: |
60 | | SpecifierResult(bool stop = false) |
61 | 38.7k | : Start(nullptr), Stop(stop) {} clang::analyze_format_string::SpecifierResult<clang::analyze_printf::PrintfSpecifier>::SpecifierResult(bool) Line | Count | Source | 61 | 38.3k | : Start(nullptr), Stop(stop) {} |
clang::analyze_format_string::SpecifierResult<clang::analyze_scanf::ScanfSpecifier>::SpecifierResult(bool) Line | Count | Source | 61 | 412 | : Start(nullptr), Stop(stop) {} |
|
62 | | SpecifierResult(const char *start, |
63 | | const T &fs) |
64 | 56.9k | : FS(fs), Start(start), Stop(false) {} clang::analyze_format_string::SpecifierResult<clang::analyze_printf::PrintfSpecifier>::SpecifierResult(char const*, clang::analyze_printf::PrintfSpecifier const&) Line | Count | Source | 64 | 55.4k | : FS(fs), Start(start), Stop(false) {} |
clang::analyze_format_string::SpecifierResult<clang::analyze_scanf::ScanfSpecifier>::SpecifierResult(char const*, clang::analyze_scanf::ScanfSpecifier const&) Line | Count | Source | 64 | 1.47k | : FS(fs), Start(start), Stop(false) {} |
|
65 | | |
66 | 113k | const char *getStart() const { return Start; } clang::analyze_format_string::SpecifierResult<clang::analyze_printf::PrintfSpecifier>::getStart() const Line | Count | Source | 66 | 110k | const char *getStart() const { return Start; } |
clang::analyze_format_string::SpecifierResult<clang::analyze_scanf::ScanfSpecifier>::getStart() const Line | Count | Source | 66 | 2.95k | const char *getStart() const { return Start; } |
|
67 | 95.7k | bool shouldStop() const { return Stop; } clang::analyze_format_string::SpecifierResult<clang::analyze_printf::PrintfSpecifier>::shouldStop() const Line | Count | Source | 67 | 93.8k | bool shouldStop() const { return Stop; } |
clang::analyze_format_string::SpecifierResult<clang::analyze_scanf::ScanfSpecifier>::shouldStop() const Line | Count | Source | 67 | 1.88k | bool shouldStop() const { return Stop; } |
|
68 | 95.6k | bool hasValue() const { return Start != nullptr; } clang::analyze_format_string::SpecifierResult<clang::analyze_printf::PrintfSpecifier>::hasValue() const Line | Count | Source | 68 | 93.7k | bool hasValue() const { return Start != nullptr; } |
clang::analyze_format_string::SpecifierResult<clang::analyze_scanf::ScanfSpecifier>::hasValue() const Line | Count | Source | 68 | 1.87k | bool hasValue() const { return Start != nullptr; } |
|
69 | 56.9k | const T &getValue() const { |
70 | 56.9k | assert(hasValue()); |
71 | 56.9k | return FS; |
72 | 56.9k | } clang::analyze_format_string::SpecifierResult<clang::analyze_printf::PrintfSpecifier>::getValue() const Line | Count | Source | 69 | 55.4k | const T &getValue() const { | 70 | 55.4k | assert(hasValue()); | 71 | 55.4k | return FS; | 72 | 55.4k | } |
clang::analyze_format_string::SpecifierResult<clang::analyze_scanf::ScanfSpecifier>::getValue() const Line | Count | Source | 69 | 1.47k | const T &getValue() const { | 70 | 1.47k | assert(hasValue()); | 71 | 1.47k | return FS; | 72 | 1.47k | } |
|
73 | | const T &getValue() { return FS; } |
74 | | }; |
75 | | |
76 | | } // end analyze_format_string namespace |
77 | | } // end clang namespace |
78 | | |
79 | | #endif |