clang: lib/AST/ExprObjC.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
19#include "llvm/Support/ErrorHandling.h"
20#include
21#include
22#include
23
24using namespace clang;
25
29 NumElements(Elements.size()), Range(SR), ArrayWithObjectsMethod(Method) {
30 Expr **SaveElements = getElements();
31 for (unsigned I = 0, N = Elements.size(); I != N; ++I)
32 SaveElements[I] = Elements[I];
33
35}
36
41 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(Elements.size()));
43}
44
46 unsigned NumElements) {
47 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumElements));
49}
50
52 bool HasPackExpansions, QualType T,
56 NumElements(VK.size()), HasPackExpansions(HasPackExpansions), Range(SR),
57 DictWithObjectsMethod(method) {
58 KeyValuePair *KeyValues = getTrailingObjects();
59 ExpansionData *Expansions =
60 HasPackExpansions ? getTrailingObjects() : nullptr;
61 for (unsigned I = 0; I < NumElements; I++) {
62 KeyValues[I].Key = VK[I].Key;
63 KeyValues[I].Value = VK[I].Value;
64 if (Expansions) {
65 Expansions[I].EllipsisLoc = VK[I].EllipsisLoc;
66 if (VK[I].NumExpansions)
67 Expansions[I].NumExpansionsPlusOne = *VK[I].NumExpansions + 1;
68 else
69 Expansions[I].NumExpansionsPlusOne = 0;
70 }
71 }
73}
74
78 bool HasPackExpansions, QualType T,
80 void *Mem = C.Allocate(totalSizeToAlloc<KeyValuePair, ExpansionData>(
81 VK.size(), HasPackExpansions ? VK.size() : 0));
83}
84
87 bool HasPackExpansions) {
88 void *Mem = C.Allocate(totalSizeToAlloc<KeyValuePair, ExpansionData>(
89 NumElements, HasPackExpansions ? NumElements : 0));
90 return new (Mem)
92}
93
97
100
102}
103
113 SelectorOrMethod(
114 reinterpret_cast<uintptr_t>(Method ? Method : Sel.getAsOpaquePtr())),
115 Kind(IsInstanceSuper ? SuperInstance : SuperClass),
116 HasMethod(Method != nullptr), IsDelegateInitCall(false),
117 IsImplicit(isImplicit), SuperLoc(SuperLoc), LBracLoc(LBracLoc),
118 RBracLoc(RBracLoc) {
119 initArgsAndSelLocs(Args, SelLocs, SelLocsK);
122}
123
132 SelectorOrMethod(
133 reinterpret_cast<uintptr_t>(Method ? Method : Sel.getAsOpaquePtr())),
134 Kind(Class), HasMethod(Method != nullptr), IsDelegateInitCall(false),
135 IsImplicit(isImplicit), LBracLoc(LBracLoc), RBracLoc(RBracLoc) {
136 initArgsAndSelLocs(Args, SelLocs, SelLocsK);
137 setReceiverPointer(Receiver);
139}
140
148 SelectorOrMethod(
149 reinterpret_cast<uintptr_t>(Method ? Method : Sel.getAsOpaquePtr())),
150 Kind(Instance), HasMethod(Method != nullptr), IsDelegateInitCall(false),
151 IsImplicit(isImplicit), LBracLoc(LBracLoc), RBracLoc(RBracLoc) {
152 initArgsAndSelLocs(Args, SelLocs, SelLocsK);
153 setReceiverPointer(Receiver);
155}
156
157void ObjCMessageExpr::initArgsAndSelLocs(ArrayRef<Expr *> Args,
160 setNumArgs(Args.size());
162 for (unsigned I = 0; I != Args.size(); ++I)
163 MyArgs[I] = Args[I];
164
165 SelLocsKind = SelLocsK;
168 std::copy(SelLocs.begin(), SelLocs.end(), getStoredSelLocs());
169 }
170}
171
179 assert((!SelLocs.empty() || isImplicit) &&
180 "No selector locs for non-implicit message");
184 Mem = alloc(Context, Args.size(), 0);
185 else
186 Mem = alloc(Context, Args, RBracLoc, SelLocs, Sel, SelLocsK);
187 return new (Mem) ObjCMessageExpr(T, VK, LBracLoc, SuperLoc, IsInstanceSuper,
188 SuperType, Sel, SelLocs, SelLocsK, Method,
190}
191
198 assert((!SelLocs.empty() || isImplicit) &&
199 "No selector locs for non-implicit message");
203 Mem = alloc(Context, Args.size(), 0);
204 else
205 Mem = alloc(Context, Args, RBracLoc, SelLocs, Sel, SelLocsK);
206 return new (Mem)
207 ObjCMessageExpr(T, VK, LBracLoc, Receiver, Sel, SelLocs, SelLocsK, Method,
209}
210
217 assert((!SelLocs.empty() || isImplicit) &&
218 "No selector locs for non-implicit message");
222 Mem = alloc(Context, Args.size(), 0);
223 else
224 Mem = alloc(Context, Args, RBracLoc, SelLocs, Sel, SelLocsK);
225 return new (Mem)
226 ObjCMessageExpr(T, VK, LBracLoc, Receiver, Sel, SelLocs, SelLocsK, Method,
228}
229
231 unsigned NumArgs,
232 unsigned NumStoredSelLocs) {
233 ObjCMessageExpr *Mem = alloc(Context, NumArgs, NumStoredSelLocs);
235}
236
244 unsigned NumStoredSelLocs =
246 return alloc(C, Args.size(), NumStoredSelLocs);
247}
248
250 unsigned NumStoredSelLocs) {
252 totalSizeToAlloc<void *, SourceLocation>(NumArgs + 1, NumStoredSelLocs),
254}
255
260}
261
262
265 QualType QT = MD->getReturnType();
267
269 }
270 return QT;
271 }
273}
274
279
282
286 }
287
288 llvm_unreachable("Invalid ReceiverKind!");
289}
290
292 if (HasMethod)
293 return reinterpret_cast<const ObjCMethodDecl *>(SelectorOrMethod)
295 return Selector(SelectorOrMethod);
296}
297
307 }
308
309 llvm_unreachable("unexpected receiver kind");
310}
311
314
316 return Ptr->getInterfaceDecl();
317
319 return Ty->getInterface();
320
321 return nullptr;
322}
323
325 Stmt **begin;
327 begin = reinterpret_cast<Stmt **>(getTrailingObjects<void *>());
328 else
329 begin = reinterpret_cast<Stmt **>(getArgs());
332}
333
337}
338
342 return "__bridge";
344 return "__bridge_transfer";
346 return "__bridge_retained";
347 }
348
349 llvm_unreachable("Invalid BridgeKind!");
350}
Defines the clang::ASTContext interface.
Defines the clang::TypeLoc interface and its subclasses.
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl, ObjCInterfaceDecl *PrevDecl=nullptr) const
getObjCInterfaceType - Return the unique reference to the type for the specified ObjC interface decl.
QualType getReferenceQualifiedType(const Expr *e) const
getReferenceQualifiedType - Given an expr, will return the type for that expression,...
QualType getObjCInstanceType()
Retrieve the Objective-C "instancetype" type, if already known; otherwise, returns a NULL type;.
This represents one expression.
void setDependence(ExprDependence Deps)
Each concrete expr subclass is expected to compute its dependence and call this in the constructor.
ObjCArrayLiteral - used for objective-c array containers; as in: @["Hello", NSApp,...
static ObjCArrayLiteral * CreateEmpty(const ASTContext &C, unsigned NumElements)
static ObjCArrayLiteral * Create(const ASTContext &C, ArrayRef< Expr * > Elements, QualType T, ObjCMethodDecl *Method, SourceRange SR)
StringRef getBridgeKindName() const
Retrieve the kind of bridge being performed as a string.
ObjCBridgeCastKind getBridgeKind() const
Determine which kind of bridge is being performed via this cast.
ObjCDictionaryLiteral - AST node to represent objective-c dictionary literals; as in:"name" : NSUserN...
static ObjCDictionaryLiteral * Create(const ASTContext &C, ArrayRef< ObjCDictionaryElement > VK, bool HasPackExpansions, QualType T, ObjCMethodDecl *method, SourceRange SR)
static ObjCDictionaryLiteral * CreateEmpty(const ASTContext &C, unsigned NumElements, bool HasPackExpansions)
Represents an ObjC class declaration.
An expression that sends a message to the given Objective-C object or class.
static ObjCMessageExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, SourceLocation LBracLoc, SourceLocation SuperLoc, bool IsInstanceSuper, QualType SuperType, Selector Sel, ArrayRef< SourceLocation > SelLocs, ObjCMethodDecl *Method, ArrayRef< Expr * > Args, SourceLocation RBracLoc, bool isImplicit)
Create a message send to super.
void getSelectorLocs(SmallVectorImpl< SourceLocation > &SelLocs) const
bool isImplicit() const
Indicates whether the message send was implicitly generated by the implementation.
static ObjCMessageExpr * CreateEmpty(const ASTContext &Context, unsigned NumArgs, unsigned NumStoredSelLocs)
Create an empty Objective-C message expression, to be filled in by subsequent calls.
Expr ** getArgs()
Retrieve the arguments to this message, not including the receiver.
Expr * getInstanceReceiver()
Returns the object expression (receiver) for an instance message, or null for a message that is not a...
QualType getCallReturnType(ASTContext &Ctx) const
SourceLocation getSuperLoc() const
Retrieve the location of the 'super' keyword for a class or instance message to 'super',...
Selector getSelector() const
@ SuperInstance
The receiver is the instance of the superclass object.
@ Instance
The receiver is an object instance.
@ SuperClass
The receiver is a superclass.
@ Class
The receiver is a class.
TypeSourceInfo * getClassReceiverTypeInfo() const
Returns a type-source information of a class message send, or nullptr if the message is not a class m...
QualType getClassReceiver() const
Returns the type of a class message send, or NULL if the message is not a class message.
ObjCInterfaceDecl * getReceiverInterface() const
Retrieve the Objective-C interface to which this message is being directed, if known.
QualType getSuperType() const
Retrieve the type referred to by 'super'.
const ObjCMethodDecl * getMethodDecl() const
SourceRange getReceiverRange() const
Source range of the receiver.
unsigned getNumSelectorLocs() const
ReceiverKind getReceiverKind() const
Determine the kind of receiver that this message is being sent to.
QualType getReceiverType() const
Retrieve the receiver type to which this message is being directed.
SourceLocation getSelectorLoc(unsigned Index) const
unsigned getNumArgs() const
Return the number of actual arguments in this message, not counting the receiver.
ObjCMethodDecl - Represents an instance or class method declaration.
Represents a pointer to an Objective C object.
Represents a class type in Objective C.
const Expr * getBase() const
QualType getSuperReceiverType() const
ObjCInterfaceDecl * getClassReceiver() const
QualType getReceiverType(const ASTContext &ctx) const
Determine the type of the base, regardless of the kind of receiver.
bool isClassReceiver() const
bool isSuperReceiver() const
A (possibly-)qualified type.
void * getAsOpaquePtr() const
Smart pointer class that efficiently represents Objective-C method names.
Encodes a location in the source.
A trivial tuple used to represent a source range.
Stmt - This represents one statement.
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
llvm::iterator_range< child_iterator > child_range
llvm::iterator_range< const_child_iterator > const_child_range
SourceRange getSourceRange() const LLVM_READONLY
Get the full source range.
A container of type source information.
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
const T * getAs() const
Member-template getAs'.
The JSON file list parser is used to communicate input to InstallAPI.
SelectorLocationsKind
Whether all locations of the selector identifiers are in a "standard" position.
@ SelLoc_NonStandard
Non-standard.
@ OK_Ordinary
An ordinary object is located at an address in memory.
ExprDependence computeDependence(FullExpr *E)
SelectorLocationsKind hasStandardSelectorLocs(Selector Sel, ArrayRef< SourceLocation > SelLocs, ArrayRef< Expr * > Args, SourceLocation EndLoc)
Returns true if all SelLocs are in a "standard" location.
@ OBC_Bridge
Bridging via __bridge, which does nothing but reinterpret the bits.
@ OBC_BridgeTransfer
Bridging via __bridge_transfer, which transfers ownership of an Objective-C pointer into ARC.
@ OBC_BridgeRetained
Bridging via __bridge_retain, which makes an ARC object available as a +1 C pointer.
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
const FunctionProtoType * T
@ Class
The "class" keyword introduces the elaborated-type-specifier.
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
A placeholder type used to construct an empty shell of a type, that will be filled in later (e....