1 //===--- ExprObjC.h - Classes for representing ObjC expressions -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the ExprObjC interface and subclasses.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_AST_EXPROBJC_H
15 #define LLVM_CLANG_AST_EXPROBJC_H
17 #include "clang/AST/DeclObjC.h"
18 #include "clang/AST/Expr.h"
19 #include "clang/AST/SelectorLocationsKind.h"
20 #include "clang/Basic/IdentifierTable.h"
21 #include "llvm/Support/Compiler.h"
27 /// ObjCStringLiteral, used for Objective-C string literals
29 class ObjCStringLiteral : public Expr {
33 ObjCStringLiteral(StringLiteral *SL, QualType T, SourceLocation L)
34 : Expr(ObjCStringLiteralClass, T, VK_RValue, OK_Ordinary, false, false,
36 String(SL), AtLoc(L) {}
37 explicit ObjCStringLiteral(EmptyShell Empty)
38 : Expr(ObjCStringLiteralClass, Empty) {}
40 StringLiteral *getString() { return cast<StringLiteral>(String); }
41 const StringLiteral *getString() const { return cast<StringLiteral>(String); }
42 void setString(StringLiteral *S) { String = S; }
44 SourceLocation getAtLoc() const { return AtLoc; }
45 void setAtLoc(SourceLocation L) { AtLoc = L; }
47 SourceLocation getLocStart() const LLVM_READONLY { return AtLoc; }
48 SourceLocation getLocEnd() const LLVM_READONLY { return String->getLocEnd(); }
50 static bool classof(const Stmt *T) {
51 return T->getStmtClass() == ObjCStringLiteralClass;
55 child_range children() { return child_range(&String, &String+1); }
58 /// ObjCBoolLiteralExpr - Objective-C Boolean Literal.
60 class ObjCBoolLiteralExpr : public Expr {
64 ObjCBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) :
65 Expr(ObjCBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
66 false, false), Value(val), Loc(l) {}
68 explicit ObjCBoolLiteralExpr(EmptyShell Empty)
69 : Expr(ObjCBoolLiteralExprClass, Empty) { }
71 bool getValue() const { return Value; }
72 void setValue(bool V) { Value = V; }
74 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
75 SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
77 SourceLocation getLocation() const { return Loc; }
78 void setLocation(SourceLocation L) { Loc = L; }
80 static bool classof(const Stmt *T) {
81 return T->getStmtClass() == ObjCBoolLiteralExprClass;
85 child_range children() {
86 return child_range(child_iterator(), child_iterator());
90 /// ObjCBoxedExpr - used for generalized expression boxing.
91 /// as in: @(strdup("hello world")), @(random()) or @(view.frame)
92 /// Also used for boxing non-parenthesized numeric literals;
93 /// as in: @42 or \@true (c++/objc++) or \@__objc_yes (c/objc).
94 class ObjCBoxedExpr : public Expr {
96 ObjCMethodDecl *BoxingMethod;
99 ObjCBoxedExpr(Expr *E, QualType T, ObjCMethodDecl *method,
101 : Expr(ObjCBoxedExprClass, T, VK_RValue, OK_Ordinary,
102 E->isTypeDependent(), E->isValueDependent(),
103 E->isInstantiationDependent(), E->containsUnexpandedParameterPack()),
104 SubExpr(E), BoxingMethod(method), Range(R) {}
105 explicit ObjCBoxedExpr(EmptyShell Empty)
106 : Expr(ObjCBoxedExprClass, Empty) {}
108 Expr *getSubExpr() { return cast<Expr>(SubExpr); }
109 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
111 ObjCMethodDecl *getBoxingMethod() const {
115 SourceLocation getAtLoc() const { return Range.getBegin(); }
117 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
118 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
119 SourceRange getSourceRange() const LLVM_READONLY {
123 static bool classof(const Stmt *T) {
124 return T->getStmtClass() == ObjCBoxedExprClass;
128 child_range children() { return child_range(&SubExpr, &SubExpr+1); }
130 typedef ConstExprIterator const_arg_iterator;
132 const_arg_iterator arg_begin() const {
133 return reinterpret_cast<Stmt const * const*>(&SubExpr);
135 const_arg_iterator arg_end() const {
136 return reinterpret_cast<Stmt const * const*>(&SubExpr + 1);
139 friend class ASTStmtReader;
142 /// ObjCArrayLiteral - used for objective-c array containers; as in:
143 /// @[@"Hello", NSApp, [NSNumber numberWithInt:42]];
144 class ObjCArrayLiteral final
146 private llvm::TrailingObjects<ObjCArrayLiteral, Expr *> {
147 unsigned NumElements;
149 ObjCMethodDecl *ArrayWithObjectsMethod;
151 ObjCArrayLiteral(ArrayRef<Expr *> Elements,
152 QualType T, ObjCMethodDecl * Method,
155 explicit ObjCArrayLiteral(EmptyShell Empty, unsigned NumElements)
156 : Expr(ObjCArrayLiteralClass, Empty), NumElements(NumElements) {}
159 static ObjCArrayLiteral *Create(const ASTContext &C,
160 ArrayRef<Expr *> Elements,
161 QualType T, ObjCMethodDecl * Method,
164 static ObjCArrayLiteral *CreateEmpty(const ASTContext &C,
165 unsigned NumElements);
167 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
168 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
169 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
171 static bool classof(const Stmt *T) {
172 return T->getStmtClass() == ObjCArrayLiteralClass;
175 /// \brief Retrieve elements of array of literals.
176 Expr **getElements() { return getTrailingObjects<Expr *>(); }
178 /// \brief Retrieve elements of array of literals.
179 const Expr * const *getElements() const {
180 return getTrailingObjects<Expr *>();
183 /// getNumElements - Return number of elements of objective-c array literal.
184 unsigned getNumElements() const { return NumElements; }
186 /// getExpr - Return the Expr at the specified index.
187 Expr *getElement(unsigned Index) {
188 assert((Index < NumElements) && "Arg access out of range!");
189 return cast<Expr>(getElements()[Index]);
191 const Expr *getElement(unsigned Index) const {
192 assert((Index < NumElements) && "Arg access out of range!");
193 return cast<Expr>(getElements()[Index]);
196 ObjCMethodDecl *getArrayWithObjectsMethod() const {
197 return ArrayWithObjectsMethod;
201 child_range children() {
202 return child_range(reinterpret_cast<Stmt **>(getElements()),
203 reinterpret_cast<Stmt **>(getElements()) + NumElements);
206 friend TrailingObjects;
207 friend class ASTStmtReader;
210 /// \brief An element in an Objective-C dictionary literal.
212 struct ObjCDictionaryElement {
213 /// \brief The key for the dictionary element.
216 /// \brief The value of the dictionary element.
219 /// \brief The location of the ellipsis, if this is a pack expansion.
220 SourceLocation EllipsisLoc;
222 /// \brief The number of elements this pack expansion will expand to, if
223 /// this is a pack expansion and is known.
224 Optional<unsigned> NumExpansions;
226 /// \brief Determines whether this dictionary element is a pack expansion.
227 bool isPackExpansion() const { return EllipsisLoc.isValid(); }
229 } // end namespace clang
232 template <> struct isPodLike<clang::ObjCDictionaryElement> : std::true_type {};
236 /// \brief Internal struct for storing Key/value pair.
237 struct ObjCDictionaryLiteral_KeyValuePair {
242 /// \brief Internal struct to describes an element that is a pack
243 /// expansion, used if any of the elements in the dictionary literal
244 /// are pack expansions.
245 struct ObjCDictionaryLiteral_ExpansionData {
246 /// \brief The location of the ellipsis, if this element is a pack
248 SourceLocation EllipsisLoc;
250 /// \brief If non-zero, the number of elements that this pack
251 /// expansion will expand to (+1).
252 unsigned NumExpansionsPlusOne;
255 /// ObjCDictionaryLiteral - AST node to represent objective-c dictionary
256 /// literals; as in: @{@"name" : NSUserName(), @"date" : [NSDate date] };
257 class ObjCDictionaryLiteral final
259 private llvm::TrailingObjects<ObjCDictionaryLiteral,
260 ObjCDictionaryLiteral_KeyValuePair,
261 ObjCDictionaryLiteral_ExpansionData> {
262 /// \brief The number of elements in this dictionary literal.
263 unsigned NumElements : 31;
265 /// \brief Determine whether this dictionary literal has any pack expansions.
267 /// If the dictionary literal has pack expansions, then there will
268 /// be an array of pack expansion data following the array of
269 /// key/value pairs, which provide the locations of the ellipses (if
270 /// any) and number of elements in the expansion (if known). If
271 /// there are no pack expansions, we optimize away this storage.
272 unsigned HasPackExpansions : 1;
275 ObjCMethodDecl *DictWithObjectsMethod;
277 typedef ObjCDictionaryLiteral_KeyValuePair KeyValuePair;
278 typedef ObjCDictionaryLiteral_ExpansionData ExpansionData;
280 size_t numTrailingObjects(OverloadToken<KeyValuePair>) const {
284 ObjCDictionaryLiteral(ArrayRef<ObjCDictionaryElement> VK,
285 bool HasPackExpansions,
286 QualType T, ObjCMethodDecl *method,
289 explicit ObjCDictionaryLiteral(EmptyShell Empty, unsigned NumElements,
290 bool HasPackExpansions)
291 : Expr(ObjCDictionaryLiteralClass, Empty), NumElements(NumElements),
292 HasPackExpansions(HasPackExpansions) {}
295 static ObjCDictionaryLiteral *Create(const ASTContext &C,
296 ArrayRef<ObjCDictionaryElement> VK,
297 bool HasPackExpansions,
298 QualType T, ObjCMethodDecl *method,
301 static ObjCDictionaryLiteral *CreateEmpty(const ASTContext &C,
302 unsigned NumElements,
303 bool HasPackExpansions);
305 /// getNumElements - Return number of elements of objective-c dictionary
307 unsigned getNumElements() const { return NumElements; }
309 ObjCDictionaryElement getKeyValueElement(unsigned Index) const {
310 assert((Index < NumElements) && "Arg access out of range!");
311 const KeyValuePair &KV = getTrailingObjects<KeyValuePair>()[Index];
312 ObjCDictionaryElement Result = { KV.Key, KV.Value, SourceLocation(), None };
313 if (HasPackExpansions) {
314 const ExpansionData &Expansion =
315 getTrailingObjects<ExpansionData>()[Index];
316 Result.EllipsisLoc = Expansion.EllipsisLoc;
317 if (Expansion.NumExpansionsPlusOne > 0)
318 Result.NumExpansions = Expansion.NumExpansionsPlusOne - 1;
323 ObjCMethodDecl *getDictWithObjectsMethod() const
324 { return DictWithObjectsMethod; }
326 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
327 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
328 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
330 static bool classof(const Stmt *T) {
331 return T->getStmtClass() == ObjCDictionaryLiteralClass;
335 child_range children() {
336 // Note: we're taking advantage of the layout of the KeyValuePair struct
337 // here. If that struct changes, this code will need to change as well.
338 static_assert(sizeof(KeyValuePair) == sizeof(Stmt *) * 2,
339 "KeyValuePair is expected size");
341 reinterpret_cast<Stmt **>(getTrailingObjects<KeyValuePair>()),
342 reinterpret_cast<Stmt **>(getTrailingObjects<KeyValuePair>()) +
346 friend class ASTStmtReader;
347 friend class ASTStmtWriter;
348 friend TrailingObjects;
352 /// ObjCEncodeExpr, used for \@encode in Objective-C. \@encode has the same
353 /// type and behavior as StringLiteral except that the string initializer is
354 /// obtained from ASTContext with the encoding type as an argument.
355 class ObjCEncodeExpr : public Expr {
356 TypeSourceInfo *EncodedType;
357 SourceLocation AtLoc, RParenLoc;
359 ObjCEncodeExpr(QualType T, TypeSourceInfo *EncodedType,
360 SourceLocation at, SourceLocation rp)
361 : Expr(ObjCEncodeExprClass, T, VK_LValue, OK_Ordinary,
362 EncodedType->getType()->isDependentType(),
363 EncodedType->getType()->isDependentType(),
364 EncodedType->getType()->isInstantiationDependentType(),
365 EncodedType->getType()->containsUnexpandedParameterPack()),
366 EncodedType(EncodedType), AtLoc(at), RParenLoc(rp) {}
368 explicit ObjCEncodeExpr(EmptyShell Empty) : Expr(ObjCEncodeExprClass, Empty){}
371 SourceLocation getAtLoc() const { return AtLoc; }
372 void setAtLoc(SourceLocation L) { AtLoc = L; }
373 SourceLocation getRParenLoc() const { return RParenLoc; }
374 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
376 QualType getEncodedType() const { return EncodedType->getType(); }
378 TypeSourceInfo *getEncodedTypeSourceInfo() const { return EncodedType; }
379 void setEncodedTypeSourceInfo(TypeSourceInfo *EncType) {
380 EncodedType = EncType;
383 SourceLocation getLocStart() const LLVM_READONLY { return AtLoc; }
384 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
386 static bool classof(const Stmt *T) {
387 return T->getStmtClass() == ObjCEncodeExprClass;
391 child_range children() {
392 return child_range(child_iterator(), child_iterator());
396 /// ObjCSelectorExpr used for \@selector in Objective-C.
397 class ObjCSelectorExpr : public Expr {
399 SourceLocation AtLoc, RParenLoc;
401 ObjCSelectorExpr(QualType T, Selector selInfo,
402 SourceLocation at, SourceLocation rp)
403 : Expr(ObjCSelectorExprClass, T, VK_RValue, OK_Ordinary, false, false,
405 SelName(selInfo), AtLoc(at), RParenLoc(rp){}
406 explicit ObjCSelectorExpr(EmptyShell Empty)
407 : Expr(ObjCSelectorExprClass, Empty) {}
409 Selector getSelector() const { return SelName; }
410 void setSelector(Selector S) { SelName = S; }
412 SourceLocation getAtLoc() const { return AtLoc; }
413 SourceLocation getRParenLoc() const { return RParenLoc; }
414 void setAtLoc(SourceLocation L) { AtLoc = L; }
415 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
417 SourceLocation getLocStart() const LLVM_READONLY { return AtLoc; }
418 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
420 /// getNumArgs - Return the number of actual arguments to this call.
421 unsigned getNumArgs() const { return SelName.getNumArgs(); }
423 static bool classof(const Stmt *T) {
424 return T->getStmtClass() == ObjCSelectorExprClass;
428 child_range children() {
429 return child_range(child_iterator(), child_iterator());
433 /// ObjCProtocolExpr used for protocol expression in Objective-C.
435 /// This is used as: \@protocol(foo), as in:
437 /// [obj conformsToProtocol:@protocol(foo)]
440 /// The return type is "Protocol*".
441 class ObjCProtocolExpr : public Expr {
442 ObjCProtocolDecl *TheProtocol;
443 SourceLocation AtLoc, ProtoLoc, RParenLoc;
445 ObjCProtocolExpr(QualType T, ObjCProtocolDecl *protocol,
446 SourceLocation at, SourceLocation protoLoc, SourceLocation rp)
447 : Expr(ObjCProtocolExprClass, T, VK_RValue, OK_Ordinary, false, false,
449 TheProtocol(protocol), AtLoc(at), ProtoLoc(protoLoc), RParenLoc(rp) {}
450 explicit ObjCProtocolExpr(EmptyShell Empty)
451 : Expr(ObjCProtocolExprClass, Empty) {}
453 ObjCProtocolDecl *getProtocol() const { return TheProtocol; }
454 void setProtocol(ObjCProtocolDecl *P) { TheProtocol = P; }
456 SourceLocation getProtocolIdLoc() const { return ProtoLoc; }
457 SourceLocation getAtLoc() const { return AtLoc; }
458 SourceLocation getRParenLoc() const { return RParenLoc; }
459 void setAtLoc(SourceLocation L) { AtLoc = L; }
460 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
462 SourceLocation getLocStart() const LLVM_READONLY { return AtLoc; }
463 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
465 static bool classof(const Stmt *T) {
466 return T->getStmtClass() == ObjCProtocolExprClass;
470 child_range children() {
471 return child_range(child_iterator(), child_iterator());
474 friend class ASTStmtReader;
475 friend class ASTStmtWriter;
478 /// ObjCIvarRefExpr - A reference to an ObjC instance variable.
479 class ObjCIvarRefExpr : public Expr {
483 /// OpLoc - This is the location of '.' or '->'
484 SourceLocation OpLoc;
486 bool IsArrow:1; // True if this is "X->F", false if this is "X.F".
487 bool IsFreeIvar:1; // True if ivar reference has no base (self assumed).
490 ObjCIvarRefExpr(ObjCIvarDecl *d, QualType t,
491 SourceLocation l, SourceLocation oploc,
493 bool arrow = false, bool freeIvar = false) :
494 Expr(ObjCIvarRefExprClass, t, VK_LValue,
495 d->isBitField() ? OK_BitField : OK_Ordinary,
496 /*TypeDependent=*/false, base->isValueDependent(),
497 base->isInstantiationDependent(),
498 base->containsUnexpandedParameterPack()),
499 D(d), Base(base), Loc(l), OpLoc(oploc),
500 IsArrow(arrow), IsFreeIvar(freeIvar) {}
502 explicit ObjCIvarRefExpr(EmptyShell Empty)
503 : Expr(ObjCIvarRefExprClass, Empty) {}
505 ObjCIvarDecl *getDecl() { return D; }
506 const ObjCIvarDecl *getDecl() const { return D; }
507 void setDecl(ObjCIvarDecl *d) { D = d; }
509 const Expr *getBase() const { return cast<Expr>(Base); }
510 Expr *getBase() { return cast<Expr>(Base); }
511 void setBase(Expr * base) { Base = base; }
513 bool isArrow() const { return IsArrow; }
514 bool isFreeIvar() const { return IsFreeIvar; }
515 void setIsArrow(bool A) { IsArrow = A; }
516 void setIsFreeIvar(bool A) { IsFreeIvar = A; }
518 SourceLocation getLocation() const { return Loc; }
519 void setLocation(SourceLocation L) { Loc = L; }
521 SourceLocation getLocStart() const LLVM_READONLY {
522 return isFreeIvar() ? Loc : getBase()->getLocStart();
524 SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
526 SourceLocation getOpLoc() const { return OpLoc; }
527 void setOpLoc(SourceLocation L) { OpLoc = L; }
529 static bool classof(const Stmt *T) {
530 return T->getStmtClass() == ObjCIvarRefExprClass;
534 child_range children() { return child_range(&Base, &Base+1); }
537 /// ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC
539 class ObjCPropertyRefExpr : public Expr {
541 /// If the bool is true, this is an implicit property reference; the
542 /// pointer is an (optional) ObjCMethodDecl and Setter may be set.
543 /// if the bool is false, this is an explicit property reference;
544 /// the pointer is an ObjCPropertyDecl and Setter is always null.
545 llvm::PointerIntPair<NamedDecl*, 1, bool> PropertyOrGetter;
547 /// \brief Indicates whether the property reference will result in a message
548 /// to the getter, the setter, or both.
549 /// This applies to both implicit and explicit property references.
550 enum MethodRefFlags {
552 MethodRef_Getter = 0x1,
553 MethodRef_Setter = 0x2
556 /// \brief Contains the Setter method pointer and MethodRefFlags bit flags.
557 llvm::PointerIntPair<ObjCMethodDecl *, 2, unsigned> SetterAndMethodRefFlags;
559 // FIXME: Maybe we should store the property identifier here,
560 // because it's not rederivable from the other data when there's an
561 // implicit property with no getter (because the 'foo' -> 'setFoo:'
562 // transformation is lossy on the first character).
564 SourceLocation IdLoc;
566 /// \brief When the receiver in property access is 'super', this is
567 /// the location of the 'super' keyword. When it's an interface,
568 /// this is that interface.
569 SourceLocation ReceiverLoc;
570 llvm::PointerUnion3<Stmt*, const Type*, ObjCInterfaceDecl*> Receiver;
573 ObjCPropertyRefExpr(ObjCPropertyDecl *PD, QualType t,
574 ExprValueKind VK, ExprObjectKind OK,
575 SourceLocation l, Expr *base)
576 : Expr(ObjCPropertyRefExprClass, t, VK, OK,
577 /*TypeDependent=*/false, base->isValueDependent(),
578 base->isInstantiationDependent(),
579 base->containsUnexpandedParameterPack()),
580 PropertyOrGetter(PD, false), SetterAndMethodRefFlags(),
581 IdLoc(l), ReceiverLoc(), Receiver(base) {
582 assert(t->isSpecificPlaceholderType(BuiltinType::PseudoObject));
585 ObjCPropertyRefExpr(ObjCPropertyDecl *PD, QualType t,
586 ExprValueKind VK, ExprObjectKind OK,
587 SourceLocation l, SourceLocation sl, QualType st)
588 : Expr(ObjCPropertyRefExprClass, t, VK, OK,
589 /*TypeDependent=*/false, false, st->isInstantiationDependentType(),
590 st->containsUnexpandedParameterPack()),
591 PropertyOrGetter(PD, false), SetterAndMethodRefFlags(),
592 IdLoc(l), ReceiverLoc(sl), Receiver(st.getTypePtr()) {
593 assert(t->isSpecificPlaceholderType(BuiltinType::PseudoObject));
596 ObjCPropertyRefExpr(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter,
597 QualType T, ExprValueKind VK, ExprObjectKind OK,
598 SourceLocation IdLoc, Expr *Base)
599 : Expr(ObjCPropertyRefExprClass, T, VK, OK, false,
600 Base->isValueDependent(), Base->isInstantiationDependent(),
601 Base->containsUnexpandedParameterPack()),
602 PropertyOrGetter(Getter, true), SetterAndMethodRefFlags(Setter, 0),
603 IdLoc(IdLoc), ReceiverLoc(), Receiver(Base) {
604 assert(T->isSpecificPlaceholderType(BuiltinType::PseudoObject));
607 ObjCPropertyRefExpr(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter,
608 QualType T, ExprValueKind VK, ExprObjectKind OK,
609 SourceLocation IdLoc,
610 SourceLocation SuperLoc, QualType SuperTy)
611 : Expr(ObjCPropertyRefExprClass, T, VK, OK, false, false, false, false),
612 PropertyOrGetter(Getter, true), SetterAndMethodRefFlags(Setter, 0),
613 IdLoc(IdLoc), ReceiverLoc(SuperLoc), Receiver(SuperTy.getTypePtr()) {
614 assert(T->isSpecificPlaceholderType(BuiltinType::PseudoObject));
617 ObjCPropertyRefExpr(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter,
618 QualType T, ExprValueKind VK, ExprObjectKind OK,
619 SourceLocation IdLoc,
620 SourceLocation ReceiverLoc, ObjCInterfaceDecl *Receiver)
621 : Expr(ObjCPropertyRefExprClass, T, VK, OK, false, false, false, false),
622 PropertyOrGetter(Getter, true), SetterAndMethodRefFlags(Setter, 0),
623 IdLoc(IdLoc), ReceiverLoc(ReceiverLoc), Receiver(Receiver) {
624 assert(T->isSpecificPlaceholderType(BuiltinType::PseudoObject));
627 explicit ObjCPropertyRefExpr(EmptyShell Empty)
628 : Expr(ObjCPropertyRefExprClass, Empty) {}
630 bool isImplicitProperty() const { return PropertyOrGetter.getInt(); }
631 bool isExplicitProperty() const { return !PropertyOrGetter.getInt(); }
633 ObjCPropertyDecl *getExplicitProperty() const {
634 assert(!isImplicitProperty());
635 return cast<ObjCPropertyDecl>(PropertyOrGetter.getPointer());
638 ObjCMethodDecl *getImplicitPropertyGetter() const {
639 assert(isImplicitProperty());
640 return cast_or_null<ObjCMethodDecl>(PropertyOrGetter.getPointer());
643 ObjCMethodDecl *getImplicitPropertySetter() const {
644 assert(isImplicitProperty());
645 return SetterAndMethodRefFlags.getPointer();
648 Selector getGetterSelector() const {
649 if (isImplicitProperty())
650 return getImplicitPropertyGetter()->getSelector();
651 return getExplicitProperty()->getGetterName();
654 Selector getSetterSelector() const {
655 if (isImplicitProperty())
656 return getImplicitPropertySetter()->getSelector();
657 return getExplicitProperty()->getSetterName();
660 /// \brief True if the property reference will result in a message to the
662 /// This applies to both implicit and explicit property references.
663 bool isMessagingGetter() const {
664 return SetterAndMethodRefFlags.getInt() & MethodRef_Getter;
667 /// \brief True if the property reference will result in a message to the
669 /// This applies to both implicit and explicit property references.
670 bool isMessagingSetter() const {
671 return SetterAndMethodRefFlags.getInt() & MethodRef_Setter;
674 void setIsMessagingGetter(bool val = true) {
675 setMethodRefFlag(MethodRef_Getter, val);
678 void setIsMessagingSetter(bool val = true) {
679 setMethodRefFlag(MethodRef_Setter, val);
682 const Expr *getBase() const {
683 return cast<Expr>(Receiver.get<Stmt*>());
686 return cast<Expr>(Receiver.get<Stmt*>());
689 SourceLocation getLocation() const { return IdLoc; }
691 SourceLocation getReceiverLocation() const { return ReceiverLoc; }
692 QualType getSuperReceiverType() const {
693 return QualType(Receiver.get<const Type*>(), 0);
696 ObjCInterfaceDecl *getClassReceiver() const {
697 return Receiver.get<ObjCInterfaceDecl*>();
699 bool isObjectReceiver() const { return Receiver.is<Stmt*>(); }
700 bool isSuperReceiver() const { return Receiver.is<const Type*>(); }
701 bool isClassReceiver() const { return Receiver.is<ObjCInterfaceDecl*>(); }
703 /// Determine the type of the base, regardless of the kind of receiver.
704 QualType getReceiverType(const ASTContext &ctx) const;
706 SourceLocation getLocStart() const LLVM_READONLY {
707 return isObjectReceiver() ? getBase()->getLocStart() :getReceiverLocation();
709 SourceLocation getLocEnd() const LLVM_READONLY { return IdLoc; }
711 static bool classof(const Stmt *T) {
712 return T->getStmtClass() == ObjCPropertyRefExprClass;
716 child_range children() {
717 if (Receiver.is<Stmt*>()) {
718 Stmt **begin = reinterpret_cast<Stmt**>(&Receiver); // hack!
719 return child_range(begin, begin+1);
721 return child_range(child_iterator(), child_iterator());
725 friend class ASTStmtReader;
726 friend class ASTStmtWriter;
727 void setExplicitProperty(ObjCPropertyDecl *D, unsigned methRefFlags) {
728 PropertyOrGetter.setPointer(D);
729 PropertyOrGetter.setInt(false);
730 SetterAndMethodRefFlags.setPointer(nullptr);
731 SetterAndMethodRefFlags.setInt(methRefFlags);
733 void setImplicitProperty(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter,
734 unsigned methRefFlags) {
735 PropertyOrGetter.setPointer(Getter);
736 PropertyOrGetter.setInt(true);
737 SetterAndMethodRefFlags.setPointer(Setter);
738 SetterAndMethodRefFlags.setInt(methRefFlags);
740 void setBase(Expr *Base) { Receiver = Base; }
741 void setSuperReceiver(QualType T) { Receiver = T.getTypePtr(); }
742 void setClassReceiver(ObjCInterfaceDecl *D) { Receiver = D; }
744 void setLocation(SourceLocation L) { IdLoc = L; }
745 void setReceiverLocation(SourceLocation Loc) { ReceiverLoc = Loc; }
747 void setMethodRefFlag(MethodRefFlags flag, bool val) {
748 unsigned f = SetterAndMethodRefFlags.getInt();
753 SetterAndMethodRefFlags.setInt(f);
757 /// ObjCSubscriptRefExpr - used for array and dictionary subscripting.
758 /// array[4] = array[3]; dictionary[key] = dictionary[alt_key];
760 class ObjCSubscriptRefExpr : public Expr {
761 // Location of ']' in an indexing expression.
762 SourceLocation RBracket;
763 // array/dictionary base expression.
764 // for arrays, this is a numeric expression. For dictionaries, this is
765 // an objective-c object pointer expression.
766 enum { BASE, KEY, END_EXPR };
767 Stmt* SubExprs[END_EXPR];
769 ObjCMethodDecl *GetAtIndexMethodDecl;
771 // For immutable objects this is null. When ObjCSubscriptRefExpr is to read
772 // an indexed object this is null too.
773 ObjCMethodDecl *SetAtIndexMethodDecl;
777 ObjCSubscriptRefExpr(Expr *base, Expr *key, QualType T,
778 ExprValueKind VK, ExprObjectKind OK,
779 ObjCMethodDecl *getMethod,
780 ObjCMethodDecl *setMethod, SourceLocation RB)
781 : Expr(ObjCSubscriptRefExprClass, T, VK, OK,
782 base->isTypeDependent() || key->isTypeDependent(),
783 base->isValueDependent() || key->isValueDependent(),
784 base->isInstantiationDependent() || key->isInstantiationDependent(),
785 (base->containsUnexpandedParameterPack() ||
786 key->containsUnexpandedParameterPack())),
788 GetAtIndexMethodDecl(getMethod),
789 SetAtIndexMethodDecl(setMethod)
790 {SubExprs[BASE] = base; SubExprs[KEY] = key;}
792 explicit ObjCSubscriptRefExpr(EmptyShell Empty)
793 : Expr(ObjCSubscriptRefExprClass, Empty) {}
795 SourceLocation getRBracket() const { return RBracket; }
796 void setRBracket(SourceLocation RB) { RBracket = RB; }
798 SourceLocation getLocStart() const LLVM_READONLY {
799 return SubExprs[BASE]->getLocStart();
801 SourceLocation getLocEnd() const LLVM_READONLY { return RBracket; }
803 static bool classof(const Stmt *T) {
804 return T->getStmtClass() == ObjCSubscriptRefExprClass;
807 Expr *getBaseExpr() const { return cast<Expr>(SubExprs[BASE]); }
808 void setBaseExpr(Stmt *S) { SubExprs[BASE] = S; }
810 Expr *getKeyExpr() const { return cast<Expr>(SubExprs[KEY]); }
811 void setKeyExpr(Stmt *S) { SubExprs[KEY] = S; }
813 ObjCMethodDecl *getAtIndexMethodDecl() const {
814 return GetAtIndexMethodDecl;
817 ObjCMethodDecl *setAtIndexMethodDecl() const {
818 return SetAtIndexMethodDecl;
821 bool isArraySubscriptRefExpr() const {
822 return getKeyExpr()->getType()->isIntegralOrEnumerationType();
825 child_range children() {
826 return child_range(SubExprs, SubExprs+END_EXPR);
829 friend class ASTStmtReader;
833 /// \brief An expression that sends a message to the given Objective-C
836 /// The following contains two message send expressions:
839 /// [[NSString alloc] initWithString:@"Hello"]
842 /// The innermost message send invokes the "alloc" class method on the
843 /// NSString class, while the outermost message send invokes the
844 /// "initWithString" instance method on the object returned from
845 /// NSString's "alloc". In all, an Objective-C message send can take
846 /// on four different (although related) forms:
848 /// 1. Send to an object instance.
849 /// 2. Send to a class.
850 /// 3. Send to the superclass instance of the current class.
851 /// 4. Send to the superclass of the current class.
853 /// All four kinds of message sends are modeled by the ObjCMessageExpr
854 /// class, and can be distinguished via \c getReceiverKind(). Example:
856 /// The "void *" trailing objects are actually ONE void * (the
857 /// receiver pointer), and NumArgs Expr *. But due to the
858 /// implementation of children(), these must be together contiguously.
860 class ObjCMessageExpr final
862 private llvm::TrailingObjects<ObjCMessageExpr, void *, SourceLocation> {
863 /// \brief Stores either the selector that this message is sending
864 /// to (when \c HasMethod is zero) or an \c ObjCMethodDecl pointer
865 /// referring to the method that we type-checked against.
866 uintptr_t SelectorOrMethod;
868 enum { NumArgsBitWidth = 16 };
870 /// \brief The number of arguments in the message send, not
871 /// including the receiver.
872 unsigned NumArgs : NumArgsBitWidth;
874 /// \brief The kind of message send this is, which is one of the
875 /// ReceiverKind values.
877 /// We pad this out to a byte to avoid excessive masking and shifting.
880 /// \brief Whether we have an actual method prototype in \c
881 /// SelectorOrMethod.
883 /// When non-zero, we have a method declaration; otherwise, we just
885 unsigned HasMethod : 1;
887 /// \brief Whether this message send is a "delegate init call",
888 /// i.e. a call of an init method on self from within an init method.
889 unsigned IsDelegateInitCall : 1;
891 /// \brief Whether this message send was implicitly generated by
892 /// the implementation rather than explicitly written by the user.
893 unsigned IsImplicit : 1;
895 /// \brief Whether the locations of the selector identifiers are in a
896 /// "standard" position, a enum SelectorLocationsKind.
897 unsigned SelLocsKind : 2;
899 /// \brief When the message expression is a send to 'super', this is
900 /// the location of the 'super' keyword.
901 SourceLocation SuperLoc;
903 /// \brief The source locations of the open and close square
904 /// brackets ('[' and ']', respectively).
905 SourceLocation LBracLoc, RBracLoc;
907 size_t numTrailingObjects(OverloadToken<void *>) const { return NumArgs + 1; }
909 void setNumArgs(unsigned Num) {
910 assert((Num >> NumArgsBitWidth) == 0 && "Num of args is out of range!");
914 ObjCMessageExpr(EmptyShell Empty, unsigned NumArgs)
915 : Expr(ObjCMessageExprClass, Empty), SelectorOrMethod(0), Kind(0),
916 HasMethod(0), IsDelegateInitCall(0), IsImplicit(0), SelLocsKind(0) {
920 ObjCMessageExpr(QualType T, ExprValueKind VK,
921 SourceLocation LBracLoc,
922 SourceLocation SuperLoc,
923 bool IsInstanceSuper,
926 ArrayRef<SourceLocation> SelLocs,
927 SelectorLocationsKind SelLocsK,
928 ObjCMethodDecl *Method,
929 ArrayRef<Expr *> Args,
930 SourceLocation RBracLoc,
932 ObjCMessageExpr(QualType T, ExprValueKind VK,
933 SourceLocation LBracLoc,
934 TypeSourceInfo *Receiver,
936 ArrayRef<SourceLocation> SelLocs,
937 SelectorLocationsKind SelLocsK,
938 ObjCMethodDecl *Method,
939 ArrayRef<Expr *> Args,
940 SourceLocation RBracLoc,
942 ObjCMessageExpr(QualType T, ExprValueKind VK,
943 SourceLocation LBracLoc,
946 ArrayRef<SourceLocation> SelLocs,
947 SelectorLocationsKind SelLocsK,
948 ObjCMethodDecl *Method,
949 ArrayRef<Expr *> Args,
950 SourceLocation RBracLoc,
953 void initArgsAndSelLocs(ArrayRef<Expr *> Args,
954 ArrayRef<SourceLocation> SelLocs,
955 SelectorLocationsKind SelLocsK);
957 /// \brief Retrieve the pointer value of the message receiver.
958 void *getReceiverPointer() const { return *getTrailingObjects<void *>(); }
960 /// \brief Set the pointer value of the message receiver.
961 void setReceiverPointer(void *Value) {
962 *getTrailingObjects<void *>() = Value;
965 SelectorLocationsKind getSelLocsKind() const {
966 return (SelectorLocationsKind)SelLocsKind;
968 bool hasStandardSelLocs() const {
969 return getSelLocsKind() != SelLoc_NonStandard;
972 /// \brief Get a pointer to the stored selector identifiers locations array.
973 /// No locations will be stored if HasStandardSelLocs is true.
974 SourceLocation *getStoredSelLocs() {
975 return getTrailingObjects<SourceLocation>();
977 const SourceLocation *getStoredSelLocs() const {
978 return getTrailingObjects<SourceLocation>();
981 /// \brief Get the number of stored selector identifiers locations.
982 /// No locations will be stored if HasStandardSelLocs is true.
983 unsigned getNumStoredSelLocs() const {
984 if (hasStandardSelLocs())
986 return getNumSelectorLocs();
989 static ObjCMessageExpr *alloc(const ASTContext &C,
990 ArrayRef<Expr *> Args,
991 SourceLocation RBraceLoc,
992 ArrayRef<SourceLocation> SelLocs,
994 SelectorLocationsKind &SelLocsK);
995 static ObjCMessageExpr *alloc(const ASTContext &C,
997 unsigned NumStoredSelLocs);
1000 /// \brief The kind of receiver this message is sending to.
1002 /// \brief The receiver is a class.
1004 /// \brief The receiver is an object instance.
1006 /// \brief The receiver is a superclass.
1008 /// \brief The receiver is the instance of the superclass object.
1012 /// \brief Create a message send to super.
1014 /// \param Context The ASTContext in which this expression will be created.
1016 /// \param T The result type of this message.
1018 /// \param VK The value kind of this message. A message returning
1019 /// a l-value or r-value reference will be an l-value or x-value,
1022 /// \param LBracLoc The location of the open square bracket '['.
1024 /// \param SuperLoc The location of the "super" keyword.
1026 /// \param IsInstanceSuper Whether this is an instance "super"
1027 /// message (otherwise, it's a class "super" message).
1029 /// \param Sel The selector used to determine which method gets called.
1031 /// \param Method The Objective-C method against which this message
1032 /// send was type-checked. May be NULL.
1034 /// \param Args The message send arguments.
1036 /// \param RBracLoc The location of the closing square bracket ']'.
1037 static ObjCMessageExpr *Create(const ASTContext &Context, QualType T,
1039 SourceLocation LBracLoc,
1040 SourceLocation SuperLoc,
1041 bool IsInstanceSuper,
1044 ArrayRef<SourceLocation> SelLocs,
1045 ObjCMethodDecl *Method,
1046 ArrayRef<Expr *> Args,
1047 SourceLocation RBracLoc,
1050 /// \brief Create a class message send.
1052 /// \param Context The ASTContext in which this expression will be created.
1054 /// \param T The result type of this message.
1056 /// \param VK The value kind of this message. A message returning
1057 /// a l-value or r-value reference will be an l-value or x-value,
1060 /// \param LBracLoc The location of the open square bracket '['.
1062 /// \param Receiver The type of the receiver, including
1063 /// source-location information.
1065 /// \param Sel The selector used to determine which method gets called.
1067 /// \param Method The Objective-C method against which this message
1068 /// send was type-checked. May be NULL.
1070 /// \param Args The message send arguments.
1072 /// \param RBracLoc The location of the closing square bracket ']'.
1073 static ObjCMessageExpr *Create(const ASTContext &Context, QualType T,
1075 SourceLocation LBracLoc,
1076 TypeSourceInfo *Receiver,
1078 ArrayRef<SourceLocation> SelLocs,
1079 ObjCMethodDecl *Method,
1080 ArrayRef<Expr *> Args,
1081 SourceLocation RBracLoc,
1084 /// \brief Create an instance message send.
1086 /// \param Context The ASTContext in which this expression will be created.
1088 /// \param T The result type of this message.
1090 /// \param VK The value kind of this message. A message returning
1091 /// a l-value or r-value reference will be an l-value or x-value,
1094 /// \param LBracLoc The location of the open square bracket '['.
1096 /// \param Receiver The expression used to produce the object that
1097 /// will receive this message.
1099 /// \param Sel The selector used to determine which method gets called.
1101 /// \param Method The Objective-C method against which this message
1102 /// send was type-checked. May be NULL.
1104 /// \param Args The message send arguments.
1106 /// \param RBracLoc The location of the closing square bracket ']'.
1107 static ObjCMessageExpr *Create(const ASTContext &Context, QualType T,
1109 SourceLocation LBracLoc,
1112 ArrayRef<SourceLocation> SeLocs,
1113 ObjCMethodDecl *Method,
1114 ArrayRef<Expr *> Args,
1115 SourceLocation RBracLoc,
1118 /// \brief Create an empty Objective-C message expression, to be
1119 /// filled in by subsequent calls.
1121 /// \param Context The context in which the message send will be created.
1123 /// \param NumArgs The number of message arguments, not including
1125 static ObjCMessageExpr *CreateEmpty(const ASTContext &Context,
1127 unsigned NumStoredSelLocs);
1129 /// \brief Indicates whether the message send was implicitly
1130 /// generated by the implementation. If false, it was written explicitly
1131 /// in the source code.
1132 bool isImplicit() const { return IsImplicit; }
1134 /// \brief Determine the kind of receiver that this message is being
1136 ReceiverKind getReceiverKind() const { return (ReceiverKind)Kind; }
1138 /// \brief Source range of the receiver.
1139 SourceRange getReceiverRange() const;
1141 /// \brief Determine whether this is an instance message to either a
1142 /// computed object or to super.
1143 bool isInstanceMessage() const {
1144 return getReceiverKind() == Instance || getReceiverKind() == SuperInstance;
1147 /// \brief Determine whether this is an class message to either a
1148 /// specified class or to super.
1149 bool isClassMessage() const {
1150 return getReceiverKind() == Class || getReceiverKind() == SuperClass;
1153 /// \brief Returns the object expression (receiver) for an instance message,
1154 /// or null for a message that is not an instance message.
1155 Expr *getInstanceReceiver() {
1156 if (getReceiverKind() == Instance)
1157 return static_cast<Expr *>(getReceiverPointer());
1161 const Expr *getInstanceReceiver() const {
1162 return const_cast<ObjCMessageExpr*>(this)->getInstanceReceiver();
1165 /// \brief Turn this message send into an instance message that
1166 /// computes the receiver object with the given expression.
1167 void setInstanceReceiver(Expr *rec) {
1169 setReceiverPointer(rec);
1172 /// \brief Returns the type of a class message send, or NULL if the
1173 /// message is not a class message.
1174 QualType getClassReceiver() const {
1175 if (TypeSourceInfo *TSInfo = getClassReceiverTypeInfo())
1176 return TSInfo->getType();
1181 /// \brief Returns a type-source information of a class message
1182 /// send, or NULL if the message is not a class message.
1183 TypeSourceInfo *getClassReceiverTypeInfo() const {
1184 if (getReceiverKind() == Class)
1185 return reinterpret_cast<TypeSourceInfo *>(getReceiverPointer());
1189 void setClassReceiver(TypeSourceInfo *TSInfo) {
1191 setReceiverPointer(TSInfo);
1194 /// \brief Retrieve the location of the 'super' keyword for a class
1195 /// or instance message to 'super', otherwise an invalid source location.
1196 SourceLocation getSuperLoc() const {
1197 if (getReceiverKind() == SuperInstance || getReceiverKind() == SuperClass)
1200 return SourceLocation();
1203 /// \brief Retrieve the receiver type to which this message is being directed.
1205 /// This routine cross-cuts all of the different kinds of message
1206 /// sends to determine what the underlying (statically known) type
1207 /// of the receiver will be; use \c getReceiverKind() to determine
1208 /// whether the message is a class or an instance method, whether it
1209 /// is a send to super or not, etc.
1211 /// \returns The type of the receiver.
1212 QualType getReceiverType() const;
1214 /// \brief Retrieve the Objective-C interface to which this message
1215 /// is being directed, if known.
1217 /// This routine cross-cuts all of the different kinds of message
1218 /// sends to determine what the underlying (statically known) type
1219 /// of the receiver will be; use \c getReceiverKind() to determine
1220 /// whether the message is a class or an instance method, whether it
1221 /// is a send to super or not, etc.
1223 /// \returns The Objective-C interface if known, otherwise NULL.
1224 ObjCInterfaceDecl *getReceiverInterface() const;
1226 /// \brief Retrieve the type referred to by 'super'.
1228 /// The returned type will either be an ObjCInterfaceType (for an
1229 /// class message to super) or an ObjCObjectPointerType that refers
1230 /// to a class (for an instance message to super);
1231 QualType getSuperType() const {
1232 if (getReceiverKind() == SuperInstance || getReceiverKind() == SuperClass)
1233 return QualType::getFromOpaquePtr(getReceiverPointer());
1238 void setSuper(SourceLocation Loc, QualType T, bool IsInstanceSuper) {
1239 Kind = IsInstanceSuper? SuperInstance : SuperClass;
1241 setReceiverPointer(T.getAsOpaquePtr());
1244 Selector getSelector() const;
1246 void setSelector(Selector S) {
1248 SelectorOrMethod = reinterpret_cast<uintptr_t>(S.getAsOpaquePtr());
1251 const ObjCMethodDecl *getMethodDecl() const {
1253 return reinterpret_cast<const ObjCMethodDecl *>(SelectorOrMethod);
1258 ObjCMethodDecl *getMethodDecl() {
1260 return reinterpret_cast<ObjCMethodDecl *>(SelectorOrMethod);
1265 void setMethodDecl(ObjCMethodDecl *MD) {
1267 SelectorOrMethod = reinterpret_cast<uintptr_t>(MD);
1270 ObjCMethodFamily getMethodFamily() const {
1271 if (HasMethod) return getMethodDecl()->getMethodFamily();
1272 return getSelector().getMethodFamily();
1275 /// \brief Return the number of actual arguments in this message,
1276 /// not counting the receiver.
1277 unsigned getNumArgs() const { return NumArgs; }
1279 /// \brief Retrieve the arguments to this message, not including the
1282 return reinterpret_cast<Expr **>(getTrailingObjects<void *>() + 1);
1284 const Expr * const *getArgs() const {
1285 return reinterpret_cast<const Expr *const *>(getTrailingObjects<void *>() +
1289 /// getArg - Return the specified argument.
1290 Expr *getArg(unsigned Arg) {
1291 assert(Arg < NumArgs && "Arg access out of range!");
1292 return getArgs()[Arg];
1294 const Expr *getArg(unsigned Arg) const {
1295 assert(Arg < NumArgs && "Arg access out of range!");
1296 return getArgs()[Arg];
1298 /// setArg - Set the specified argument.
1299 void setArg(unsigned Arg, Expr *ArgExpr) {
1300 assert(Arg < NumArgs && "Arg access out of range!");
1301 getArgs()[Arg] = ArgExpr;
1304 /// isDelegateInitCall - Answers whether this message send has been
1305 /// tagged as a "delegate init call", i.e. a call to a method in the
1306 /// -init family on self from within an -init method implementation.
1307 bool isDelegateInitCall() const { return IsDelegateInitCall; }
1308 void setDelegateInitCall(bool isDelegate) { IsDelegateInitCall = isDelegate; }
1310 SourceLocation getLeftLoc() const { return LBracLoc; }
1311 SourceLocation getRightLoc() const { return RBracLoc; }
1313 SourceLocation getSelectorStartLoc() const {
1315 return getLocStart();
1316 return getSelectorLoc(0);
1318 SourceLocation getSelectorLoc(unsigned Index) const {
1319 assert(Index < getNumSelectorLocs() && "Index out of range!");
1320 if (hasStandardSelLocs())
1321 return getStandardSelectorLoc(Index, getSelector(),
1322 getSelLocsKind() == SelLoc_StandardWithSpace,
1323 llvm::makeArrayRef(const_cast<Expr**>(getArgs()),
1326 return getStoredSelLocs()[Index];
1329 void getSelectorLocs(SmallVectorImpl<SourceLocation> &SelLocs) const;
1331 unsigned getNumSelectorLocs() const {
1334 Selector Sel = getSelector();
1335 if (Sel.isUnarySelector())
1337 return Sel.getNumArgs();
1340 void setSourceRange(SourceRange R) {
1341 LBracLoc = R.getBegin();
1342 RBracLoc = R.getEnd();
1344 SourceLocation getLocStart() const LLVM_READONLY { return LBracLoc; }
1345 SourceLocation getLocEnd() const LLVM_READONLY { return RBracLoc; }
1347 static bool classof(const Stmt *T) {
1348 return T->getStmtClass() == ObjCMessageExprClass;
1352 child_range children();
1354 typedef ExprIterator arg_iterator;
1355 typedef ConstExprIterator const_arg_iterator;
1357 llvm::iterator_range<arg_iterator> arguments() {
1358 return llvm::make_range(arg_begin(), arg_end());
1361 llvm::iterator_range<const_arg_iterator> arguments() const {
1362 return llvm::make_range(arg_begin(), arg_end());
1365 arg_iterator arg_begin() { return reinterpret_cast<Stmt **>(getArgs()); }
1366 arg_iterator arg_end() {
1367 return reinterpret_cast<Stmt **>(getArgs() + NumArgs);
1369 const_arg_iterator arg_begin() const {
1370 return reinterpret_cast<Stmt const * const*>(getArgs());
1372 const_arg_iterator arg_end() const {
1373 return reinterpret_cast<Stmt const * const*>(getArgs() + NumArgs);
1376 friend TrailingObjects;
1377 friend class ASTStmtReader;
1378 friend class ASTStmtWriter;
1381 /// ObjCIsaExpr - Represent X->isa and X.isa when X is an ObjC 'id' type.
1382 /// (similar in spirit to MemberExpr).
1383 class ObjCIsaExpr : public Expr {
1384 /// Base - the expression for the base object pointer.
1387 /// IsaMemberLoc - This is the location of the 'isa'.
1388 SourceLocation IsaMemberLoc;
1390 /// OpLoc - This is the location of '.' or '->'
1391 SourceLocation OpLoc;
1393 /// IsArrow - True if this is "X->F", false if this is "X.F".
1396 ObjCIsaExpr(Expr *base, bool isarrow, SourceLocation l, SourceLocation oploc,
1398 : Expr(ObjCIsaExprClass, ty, VK_LValue, OK_Ordinary,
1399 /*TypeDependent=*/false, base->isValueDependent(),
1400 base->isInstantiationDependent(),
1401 /*ContainsUnexpandedParameterPack=*/false),
1402 Base(base), IsaMemberLoc(l), OpLoc(oploc), IsArrow(isarrow) {}
1404 /// \brief Build an empty expression.
1405 explicit ObjCIsaExpr(EmptyShell Empty) : Expr(ObjCIsaExprClass, Empty) { }
1407 void setBase(Expr *E) { Base = E; }
1408 Expr *getBase() const { return cast<Expr>(Base); }
1410 bool isArrow() const { return IsArrow; }
1411 void setArrow(bool A) { IsArrow = A; }
1413 /// getMemberLoc - Return the location of the "member", in X->F, it is the
1414 /// location of 'F'.
1415 SourceLocation getIsaMemberLoc() const { return IsaMemberLoc; }
1416 void setIsaMemberLoc(SourceLocation L) { IsaMemberLoc = L; }
1418 SourceLocation getOpLoc() const { return OpLoc; }
1419 void setOpLoc(SourceLocation L) { OpLoc = L; }
1421 SourceLocation getLocStart() const LLVM_READONLY {
1422 return getBase()->getLocStart();
1425 SourceLocation getBaseLocEnd() const LLVM_READONLY {
1426 return getBase()->getLocEnd();
1429 SourceLocation getLocEnd() const LLVM_READONLY { return IsaMemberLoc; }
1431 SourceLocation getExprLoc() const LLVM_READONLY { return IsaMemberLoc; }
1433 static bool classof(const Stmt *T) {
1434 return T->getStmtClass() == ObjCIsaExprClass;
1438 child_range children() { return child_range(&Base, &Base+1); }
1442 /// ObjCIndirectCopyRestoreExpr - Represents the passing of a function
1443 /// argument by indirect copy-restore in ARC. This is used to support
1444 /// passing indirect arguments with the wrong lifetime, e.g. when
1445 /// passing the address of a __strong local variable to an 'out'
1446 /// parameter. This expression kind is only valid in an "argument"
1447 /// position to some sort of call expression.
1449 /// The parameter must have type 'pointer to T', and the argument must
1450 /// have type 'pointer to U', where T and U agree except possibly in
1451 /// qualification. If the argument value is null, then a null pointer
1452 /// is passed; otherwise it points to an object A, and:
1453 /// 1. A temporary object B of type T is initialized, either by
1454 /// zero-initialization (used when initializing an 'out' parameter)
1455 /// or copy-initialization (used when initializing an 'inout'
1457 /// 2. The address of the temporary is passed to the function.
1458 /// 3. If the call completes normally, A is move-assigned from B.
1459 /// 4. Finally, A is destroyed immediately.
1461 /// Currently 'T' must be a retainable object lifetime and must be
1462 /// __autoreleasing; this qualifier is ignored when initializing
1464 class ObjCIndirectCopyRestoreExpr : public Expr {
1467 // unsigned ObjCIndirectCopyRestoreBits.ShouldCopy : 1;
1469 friend class ASTReader;
1470 friend class ASTStmtReader;
1472 void setShouldCopy(bool shouldCopy) {
1473 ObjCIndirectCopyRestoreExprBits.ShouldCopy = shouldCopy;
1476 explicit ObjCIndirectCopyRestoreExpr(EmptyShell Empty)
1477 : Expr(ObjCIndirectCopyRestoreExprClass, Empty) { }
1480 ObjCIndirectCopyRestoreExpr(Expr *operand, QualType type, bool shouldCopy)
1481 : Expr(ObjCIndirectCopyRestoreExprClass, type, VK_LValue, OK_Ordinary,
1482 operand->isTypeDependent(), operand->isValueDependent(),
1483 operand->isInstantiationDependent(),
1484 operand->containsUnexpandedParameterPack()),
1486 setShouldCopy(shouldCopy);
1489 Expr *getSubExpr() { return cast<Expr>(Operand); }
1490 const Expr *getSubExpr() const { return cast<Expr>(Operand); }
1492 /// shouldCopy - True if we should do the 'copy' part of the
1493 /// copy-restore. If false, the temporary will be zero-initialized.
1494 bool shouldCopy() const { return ObjCIndirectCopyRestoreExprBits.ShouldCopy; }
1496 child_range children() { return child_range(&Operand, &Operand+1); }
1498 // Source locations are determined by the subexpression.
1499 SourceLocation getLocStart() const LLVM_READONLY {
1500 return Operand->getLocStart();
1502 SourceLocation getLocEnd() const LLVM_READONLY { return Operand->getLocEnd();}
1504 SourceLocation getExprLoc() const LLVM_READONLY {
1505 return getSubExpr()->getExprLoc();
1508 static bool classof(const Stmt *s) {
1509 return s->getStmtClass() == ObjCIndirectCopyRestoreExprClass;
1513 /// \brief An Objective-C "bridged" cast expression, which casts between
1514 /// Objective-C pointers and C pointers, transferring ownership in the process.
1517 /// NSString *str = (__bridge_transfer NSString *)CFCreateString();
1519 class ObjCBridgedCastExpr final
1520 : public ExplicitCastExpr,
1521 private llvm::TrailingObjects<ObjCBridgedCastExpr, CXXBaseSpecifier *> {
1522 SourceLocation LParenLoc;
1523 SourceLocation BridgeKeywordLoc;
1526 friend TrailingObjects;
1527 friend class CastExpr;
1528 friend class ASTStmtReader;
1529 friend class ASTStmtWriter;
1532 ObjCBridgedCastExpr(SourceLocation LParenLoc, ObjCBridgeCastKind Kind,
1533 CastKind CK, SourceLocation BridgeKeywordLoc,
1534 TypeSourceInfo *TSInfo, Expr *Operand)
1535 : ExplicitCastExpr(ObjCBridgedCastExprClass, TSInfo->getType(), VK_RValue,
1536 CK, Operand, 0, TSInfo),
1537 LParenLoc(LParenLoc), BridgeKeywordLoc(BridgeKeywordLoc), Kind(Kind) { }
1539 /// \brief Construct an empty Objective-C bridged cast.
1540 explicit ObjCBridgedCastExpr(EmptyShell Shell)
1541 : ExplicitCastExpr(ObjCBridgedCastExprClass, Shell, 0) { }
1543 SourceLocation getLParenLoc() const { return LParenLoc; }
1545 /// \brief Determine which kind of bridge is being performed via this cast.
1546 ObjCBridgeCastKind getBridgeKind() const {
1547 return static_cast<ObjCBridgeCastKind>(Kind);
1550 /// \brief Retrieve the kind of bridge being performed as a string.
1551 StringRef getBridgeKindName() const;
1553 /// \brief The location of the bridge keyword.
1554 SourceLocation getBridgeKeywordLoc() const { return BridgeKeywordLoc; }
1556 SourceLocation getLocStart() const LLVM_READONLY { return LParenLoc; }
1557 SourceLocation getLocEnd() const LLVM_READONLY {
1558 return getSubExpr()->getLocEnd();
1561 static bool classof(const Stmt *T) {
1562 return T->getStmtClass() == ObjCBridgedCastExprClass;
1566 /// \brief A runtime availability query.
1568 /// There are 2 ways to spell this node:
1570 /// @available(macos 10.10, ios 8, *); // Objective-C
1571 /// __builtin_available(macos 10.10, ios 8, *); // C, C++, and Objective-C
1574 /// Note that we only need to keep track of one \c VersionTuple here, which is
1575 /// the one that corresponds to the current deployment target. This is meant to
1576 /// be used in the condition of an \c if, but it is also usable as top level
1579 class ObjCAvailabilityCheckExpr : public Expr {
1580 VersionTuple VersionToCheck;
1581 SourceLocation AtLoc, RParen;
1583 friend class ASTStmtReader;
1585 ObjCAvailabilityCheckExpr(VersionTuple VersionToCheck, SourceLocation AtLoc,
1586 SourceLocation RParen, QualType Ty)
1587 : Expr(ObjCAvailabilityCheckExprClass, Ty, VK_RValue, OK_Ordinary, false,
1588 false, false, false),
1589 VersionToCheck(VersionToCheck), AtLoc(AtLoc), RParen(RParen) {}
1591 explicit ObjCAvailabilityCheckExpr(EmptyShell Shell)
1592 : Expr(ObjCAvailabilityCheckExprClass, Shell) {}
1594 SourceLocation getLocStart() const { return AtLoc; }
1595 SourceLocation getLocEnd() const { return RParen; }
1596 SourceRange getSourceRange() const { return {AtLoc, RParen}; }
1598 /// \brief This may be '*', in which case this should fold to true.
1599 bool hasVersion() const { return !VersionToCheck.empty(); }
1600 VersionTuple getVersion() { return VersionToCheck; }
1602 child_range children() {
1603 return child_range(child_iterator(), child_iterator());
1606 static bool classof(const Stmt *T) {
1607 return T->getStmtClass() == ObjCAvailabilityCheckExprClass;
1611 } // end namespace clang