10 #include "llvm/ADT/SmallBitVector.h" 12 using namespace clang;
18 class OSLogFormatStringHandler
22 const Expr *E =
nullptr;
28 unsigned char Flags = 0;
37 return OSLogBufferItem::StringKind;
39 return OSLogBufferItem::WideStringKind;
41 return OSLogBufferItem::PointerKind;
43 return OSLogBufferItem::ObjCObjKind;
45 return OSLogBufferItem::ErrnoKind;
47 return OSLogBufferItem::ScalarKind;
54 ArgsData.reserve(Args.size());
58 const char *StartSpecifier,
59 unsigned SpecifierLen) {
65 ArgsData.emplace_back();
67 if (ArgIndex < Args.size())
68 ArgsData.back().E = Args[ArgIndex];
72 if (ArgsData.back().Kind != OSLogBufferItem::ErrnoKind &&
83 switch (precision.getHowSpecified()) {
87 ArgsData.back().Size = precision.getConstantAmount();
90 ArgsData.back().Count = Args[precision.getArgIndex()];
99 switch (precision.getHowSpecified()) {
103 ArgsData.back().Size = precision.getConstantAmount();
106 ArgsData.back().Count = Args[precision.getArgIndex()];
124 ArgsData.back().Flags |= OSLogBufferItem::IsPrivate;
127 ArgsData.back().Flags |= OSLogBufferItem::IsPublic;
133 Layout.
Items.clear();
134 for (
auto &Data : ArgsData) {
135 if (Data.FieldWidth) {
137 Layout.
Items.emplace_back(OSLogBufferItem::ScalarKind, *Data.FieldWidth,
140 if (Data.Precision) {
142 Layout.
Items.emplace_back(OSLogBufferItem::ScalarKind, *Data.Precision,
148 Layout.
Items.emplace_back(OSLogBufferItem::CountKind, *Data.Count, Size,
156 if (*Data.Kind == OSLogBufferItem::ErrnoKind)
160 Layout.
Items.emplace_back(*Data.Kind, Data.E, Size, Data.Flags);
163 Layout.
Items.emplace_back(OSLogBufferItem::ScalarKind, Data.E, Size,
175 const Expr *StringArg;
178 case Builtin::BI__builtin_os_log_format_buffer_size:
180 "__builtin_os_log_format_buffer_size takes at least 1 argument");
182 VarArgs = Args.slice(1);
184 case Builtin::BI__builtin_os_log_format:
186 "__builtin_os_log_format takes at least 2 arguments");
188 VarArgs = Args.slice(2);
191 llvm_unreachable(
"non-os_log builtin passed to computeOSLogBufferLayout");
194 const StringLiteral *Lit = cast<StringLiteral>(StringArg->IgnoreParenCasts());
197 OSLogFormatStringHandler H(VarArgs);
201 H.computeLayout(Ctx, Layout);
Expr ** getArgs()
Retrieve the call arguments.
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
bool consumesDataArgument() const
const TargetInfo & getTargetInfo() const
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
CharUnits - This is an opaque type for sizes expressed in character units.
bool computeOSLogBufferLayout(clang::ASTContext &Ctx, const clang::CallExpr *E, OSLogBufferLayout &layout)
StringRef getString() const
An OSLogBufferItem represents a single item in the data written by a call to os_log() or os_trace()...
Expr - This represents one expression.
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
unsigned getBuiltinCallee() const
getBuiltinCallee - If this is a call to a builtin, return the builtin ID of the callee.
const PrintfConversionSpecifier & getConversionSpecifier() const
Dataflow Directional Tag Classes.
const OptionalFlag & isPrivate() const
SmallVector< OSLogBufferItem, 4 > Items
const OptionalAmount & getPrecision() const
const OptionalFlag & isPublic() const
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
StringLiteral - This represents a string literal expression, e.g.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
static Decl::Kind getKind(const Decl *D)
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
const LangOptions & getLangOpts() const
Defines enum values for all the target-independent builtin functions.