10#include "llvm/ADT/SmallBitVector.h"
19class OSLogFormatStringHandler
23 const Expr *
E =
nullptr;
24 std::optional<OSLogBufferItem::Kind>
Kind;
25 std::optional<unsigned>
Size;
26 std::optional<const Expr *> Count;
27 std::optional<const Expr *> Precision;
28 std::optional<const Expr *> FieldWidth;
29 unsigned char Flags = 0;
39 return OSLogBufferItem::StringKind;
41 return OSLogBufferItem::WideStringKind;
43 return OSLogBufferItem::PointerKind;
45 return OSLogBufferItem::ObjCObjKind;
47 return OSLogBufferItem::ErrnoKind;
49 return OSLogBufferItem::ScalarKind;
56 ArgsData.reserve(Args.size());
60 const char *StartSpecifier,
unsigned SpecifierLen,
62 if (!FS.consumesDataArgument() &&
63 FS.getConversionSpecifier().getKind() !=
67 ArgsData.emplace_back();
68 unsigned ArgIndex = FS.getArgIndex();
69 if (ArgIndex < Args.size())
70 ArgsData.back().E = Args[ArgIndex];
73 ArgsData.back().Kind =
getKind(FS.getConversionSpecifier().getKind());
74 if (ArgsData.back().Kind != OSLogBufferItem::ErrnoKind &&
81 switch (FS.getConversionSpecifier().getKind()) {
84 auto &precision = FS.getPrecision();
85 switch (precision.getHowSpecified()) {
89 ArgsData.back().Size = precision.getConstantAmount();
92 ArgsData.back().Count = Args[precision.getArgIndex()];
100 auto &precision = FS.getPrecision();
101 switch (precision.getHowSpecified()) {
105 ArgsData.back().Size = precision.getConstantAmount();
108 ArgsData.back().Count = Args[precision.getArgIndex()];
116 if (FS.getPrecision().hasDataArgument()) {
117 ArgsData.back().Precision = Args[FS.getPrecision().getArgIndex()];
121 if (FS.getFieldWidth().hasDataArgument()) {
122 ArgsData.back().FieldWidth = Args[FS.getFieldWidth().getArgIndex()];
125 if (FS.isSensitive())
126 ArgsData.back().Flags |= OSLogBufferItem::IsSensitive;
127 else if (FS.isPrivate())
128 ArgsData.back().Flags |= OSLogBufferItem::IsPrivate;
129 else if (FS.isPublic())
130 ArgsData.back().Flags |= OSLogBufferItem::IsPublic;
132 ArgsData.back().MaskType = FS.getMaskType();
137 Layout.
Items.clear();
138 for (
auto &
Data : ArgsData) {
139 if (!
Data.MaskType.empty()) {
141 Layout.
Items.emplace_back(OSLogBufferItem::MaskKind,
nullptr,
142 Size, 0,
Data.MaskType);
145 if (
Data.FieldWidth) {
147 Layout.
Items.emplace_back(OSLogBufferItem::ScalarKind, *
Data.FieldWidth,
150 if (
Data.Precision) {
152 Layout.
Items.emplace_back(OSLogBufferItem::ScalarKind, *
Data.Precision,
158 Layout.
Items.emplace_back(OSLogBufferItem::CountKind, *
Data.Count, Size,
166 if (*
Data.Kind == OSLogBufferItem::ErrnoKind)
173 Layout.
Items.emplace_back(OSLogBufferItem::ScalarKind,
Data.E, Size,
185 const Expr *StringArg;
187 switch (
E->getBuiltinCallee()) {
188 case Builtin::BI__builtin_os_log_format_buffer_size:
189 assert(
E->getNumArgs() >= 1 &&
190 "__builtin_os_log_format_buffer_size takes at least 1 argument");
191 StringArg =
E->getArg(0);
192 VarArgs = Args.slice(1);
194 case Builtin::BI__builtin_os_log_format:
195 assert(
E->getNumArgs() >= 2 &&
196 "__builtin_os_log_format takes at least 2 arguments");
197 StringArg =
E->getArg(1);
198 VarArgs = Args.slice(2);
201 llvm_unreachable(
"non-os_log builtin passed to computeOSLogBufferLayout");
207 OSLogFormatStringHandler H(VarArgs);
211 H.computeLayout(Ctx, Layout);
Defines enum values for all the target-independent builtin functions.
static Decl::Kind getKind(const Decl *D)
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
const LangOptions & getLangOpts() const
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
const TargetInfo & getTargetInfo() const
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
CharUnits - This is an opaque type for sizes expressed in character units.
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
This represents one expression.
Expr * IgnoreParenCasts() LLVM_READONLY
Skip past any parentheses and casts which might surround this expression until reaching a fixed point...
StringLiteral - This represents a string literal expression, e.g.
StringRef getString() const
Exposes information about the current target.
An OSLogBufferItem represents a single item in the data written by a call to os_log() or os_trace().
SmallVector< OSLogBufferItem, 4 > Items
bool computeOSLogBufferLayout(clang::ASTContext &Ctx, const clang::CallExpr *E, OSLogBufferLayout &layout)
The JSON file list parser is used to communicate input to InstallAPI.