1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | #ifndef LLVM_CLANG_ANALYSIS_ANALYSES_OSLOG_H |
15 | #define LLVM_CLANG_ANALYSIS_ANALYSES_OSLOG_H |
16 | |
17 | #include "clang/AST/ASTContext.h" |
18 | #include "clang/AST/Expr.h" |
19 | |
20 | namespace clang { |
21 | namespace analyze_os_log { |
22 | |
23 | |
24 | |
25 | class OSLogBufferItem { |
26 | public: |
27 | enum Kind { |
28 | |
29 | |
30 | ScalarKind = 0, |
31 | |
32 | |
33 | |
34 | |
35 | CountKind, |
36 | |
37 | |
38 | |
39 | StringKind, |
40 | |
41 | |
42 | |
43 | PointerKind, |
44 | |
45 | |
46 | |
47 | ObjCObjKind, |
48 | |
49 | |
50 | WideStringKind, |
51 | |
52 | |
53 | |
54 | ErrnoKind, |
55 | |
56 | |
57 | MaskKind |
58 | }; |
59 | |
60 | enum { |
61 | |
62 | IsPrivate = 0x1, |
63 | |
64 | |
65 | IsPublic = 0x2, |
66 | |
67 | |
68 | IsSensitive = 0x4 | IsPrivate |
69 | }; |
70 | |
71 | private: |
72 | Kind TheKind = ScalarKind; |
73 | const Expr *TheExpr = nullptr; |
74 | CharUnits ConstValue; |
75 | CharUnits Size; |
76 | unsigned Flags = 0; |
77 | StringRef MaskType; |
78 | |
79 | public: |
80 | OSLogBufferItem(Kind kind, const Expr *expr, CharUnits size, unsigned flags, |
81 | StringRef maskType = StringRef()) |
82 | : TheKind(kind), TheExpr(expr), Size(size), Flags(flags), |
83 | MaskType(maskType) { |
84 | (0) . __assert_fail ("((Flags == 0) || (Flags == IsPrivate) || (Flags == IsPublic) || (Flags == IsSensitive)) && \"unexpected privacy flag\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/OSLog.h", 86, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(((Flags == 0) || (Flags == IsPrivate) || (Flags == IsPublic) || |
85 | (0) . __assert_fail ("((Flags == 0) || (Flags == IsPrivate) || (Flags == IsPublic) || (Flags == IsSensitive)) && \"unexpected privacy flag\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/OSLog.h", 86, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> (Flags == IsSensitive)) && |
86 | (0) . __assert_fail ("((Flags == 0) || (Flags == IsPrivate) || (Flags == IsPublic) || (Flags == IsSensitive)) && \"unexpected privacy flag\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/OSLog.h", 86, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "unexpected privacy flag"); |
87 | } |
88 | |
89 | OSLogBufferItem(ASTContext &Ctx, CharUnits value, unsigned flags) |
90 | : TheKind(CountKind), ConstValue(value), |
91 | Size(Ctx.getTypeSizeInChars(Ctx.IntTy)), Flags(flags) {} |
92 | |
93 | unsigned char getDescriptorByte() const { |
94 | unsigned char result = Flags; |
95 | result |= ((unsigned)getKind()) << 4; |
96 | return result; |
97 | } |
98 | |
99 | unsigned char getSizeByte() const { return size().getQuantity(); } |
100 | |
101 | Kind getKind() const { return TheKind; } |
102 | bool getIsPrivate() const { return (Flags & IsPrivate) != 0; } |
103 | |
104 | const Expr *getExpr() const { return TheExpr; } |
105 | CharUnits getConstValue() const { return ConstValue; } |
106 | CharUnits size() const { return Size; } |
107 | |
108 | StringRef getMaskType() const { return MaskType; } |
109 | }; |
110 | |
111 | class OSLogBufferLayout { |
112 | public: |
113 | SmallVector<OSLogBufferItem, 4> Items; |
114 | |
115 | enum Flags { HasPrivateItems = 1, HasNonScalarItems = 1 << 1 }; |
116 | |
117 | CharUnits size() const { |
118 | CharUnits result; |
119 | result += CharUnits::fromQuantity(2); |
120 | for (auto &item : Items) { |
121 | |
122 | result += item.size() + CharUnits::fromQuantity(2); |
123 | } |
124 | return result; |
125 | } |
126 | |
127 | bool hasPrivateItems() const { |
128 | return llvm::any_of( |
129 | Items, [](const OSLogBufferItem &Item) { return Item.getIsPrivate(); }); |
130 | } |
131 | |
132 | bool hasNonScalarOrMask() const { |
133 | return llvm::any_of(Items, [](const OSLogBufferItem &Item) { |
134 | return Item.getKind() != OSLogBufferItem::ScalarKind || |
135 | !Item.getMaskType().empty(); |
136 | }); |
137 | } |
138 | |
139 | unsigned char getSummaryByte() const { |
140 | unsigned char result = 0; |
141 | if (hasPrivateItems()) |
142 | result |= HasPrivateItems; |
143 | if (hasNonScalarOrMask()) |
144 | result |= HasNonScalarItems; |
145 | return result; |
146 | } |
147 | |
148 | unsigned char getNumArgsByte() const { return Items.size(); } |
149 | }; |
150 | |
151 | |
152 | |
153 | |
154 | |
155 | bool computeOSLogBufferLayout(clang::ASTContext &Ctx, const clang::CallExpr *E, |
156 | OSLogBufferLayout &layout); |
157 | |
158 | } |
159 | } |
160 | #endif |
161 | |