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 \@__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 : public Expr {
145 unsigned NumElements;
147 ObjCMethodDecl *ArrayWithObjectsMethod;
149 ObjCArrayLiteral(ArrayRef<Expr *> Elements,
150 QualType T, ObjCMethodDecl * Method,
153 explicit ObjCArrayLiteral(EmptyShell Empty, unsigned NumElements)
154 : Expr(ObjCArrayLiteralClass, Empty), NumElements(NumElements) {}
157 static ObjCArrayLiteral *Create(const ASTContext &C,
158 ArrayRef<Expr *> Elements,
159 QualType T, ObjCMethodDecl * Method,
162 static ObjCArrayLiteral *CreateEmpty(const ASTContext &C,
163 unsigned NumElements);
165 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
166 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
167 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
169 static bool classof(const Stmt *T) {
170 return T->getStmtClass() == ObjCArrayLiteralClass;
173 /// \brief Retrieve elements of array of literals.
174 Expr **getElements() { return reinterpret_cast<Expr **>(this + 1); }
176 /// \brief Retrieve elements of array of literals.
177 const Expr * const *getElements() const {
178 return reinterpret_cast<const Expr * const*>(this + 1);
181 /// getNumElements - Return number of elements of objective-c array literal.
182 unsigned getNumElements() const { return NumElements; }
184 /// getExpr - Return the Expr at the specified index.
185 Expr *getElement(unsigned Index) {
186 assert((Index < NumElements) && "Arg access out of range!");
187 return cast<Expr>(getElements()[Index]);
189 const Expr *getElement(unsigned Index) const {
190 assert((Index < NumElements) && "Arg access out of range!");
191 return cast<Expr>(getElements()[Index]);
194 ObjCMethodDecl *getArrayWithObjectsMethod() const {
195 return ArrayWithObjectsMethod;
199 child_range children() {
200 return child_range((Stmt **)getElements(),
201 (Stmt **)getElements() + NumElements);
204 friend class ASTStmtReader;
207 /// \brief An element in an Objective-C dictionary literal.
209 struct ObjCDictionaryElement {
210 /// \brief The key for the dictionary element.
213 /// \brief The value of the dictionary element.
216 /// \brief The location of the ellipsis, if this is a pack expansion.
217 SourceLocation EllipsisLoc;
219 /// \brief The number of elements this pack expansion will expand to, if
220 /// this is a pack expansion and is known.
221 Optional<unsigned> NumExpansions;
223 /// \brief Determines whether this dictionary element is a pack expansion.
224 bool isPackExpansion() const { return EllipsisLoc.isValid(); }
226 } // end namespace clang
229 template <> struct isPodLike<clang::ObjCDictionaryElement> : std::true_type {};
233 /// ObjCDictionaryLiteral - AST node to represent objective-c dictionary
234 /// literals; as in: @{@"name" : NSUserName(), @"date" : [NSDate date] };
235 class ObjCDictionaryLiteral : public Expr {
236 /// \brief Key/value pair used to store the key and value of a given element.
238 /// Objects of this type are stored directly after the expression.
239 struct KeyValuePair {
244 /// \brief Data that describes an element that is a pack expansion, used if any
245 /// of the elements in the dictionary literal are pack expansions.
246 struct ExpansionData {
247 /// \brief The location of the ellipsis, if this element is a pack
249 SourceLocation EllipsisLoc;
251 /// \brief If non-zero, the number of elements that this pack
252 /// expansion will expand to (+1).
253 unsigned NumExpansionsPlusOne;
256 /// \brief The number of elements in this dictionary literal.
257 unsigned NumElements : 31;
259 /// \brief Determine whether this dictionary literal has any pack expansions.
261 /// If the dictionary literal has pack expansions, then there will
262 /// be an array of pack expansion data following the array of
263 /// key/value pairs, which provide the locations of the ellipses (if
264 /// any) and number of elements in the expansion (if known). If
265 /// there are no pack expansions, we optimize away this storage.
266 unsigned HasPackExpansions : 1;
269 ObjCMethodDecl *DictWithObjectsMethod;
271 ObjCDictionaryLiteral(ArrayRef<ObjCDictionaryElement> VK,
272 bool HasPackExpansions,
273 QualType T, ObjCMethodDecl *method,
276 explicit ObjCDictionaryLiteral(EmptyShell Empty, unsigned NumElements,
277 bool HasPackExpansions)
278 : Expr(ObjCDictionaryLiteralClass, Empty), NumElements(NumElements),
279 HasPackExpansions(HasPackExpansions) {}
281 KeyValuePair *getKeyValues() {
282 return reinterpret_cast<KeyValuePair *>(this + 1);
285 const KeyValuePair *getKeyValues() const {
286 return reinterpret_cast<const KeyValuePair *>(this + 1);
289 ExpansionData *getExpansionData() {
290 if (!HasPackExpansions)
293 return reinterpret_cast<ExpansionData *>(getKeyValues() + NumElements);
296 const ExpansionData *getExpansionData() const {
297 if (!HasPackExpansions)
300 return reinterpret_cast<const ExpansionData *>(getKeyValues()+NumElements);
304 static ObjCDictionaryLiteral *Create(const ASTContext &C,
305 ArrayRef<ObjCDictionaryElement> VK,
306 bool HasPackExpansions,
307 QualType T, ObjCMethodDecl *method,
310 static ObjCDictionaryLiteral *CreateEmpty(const ASTContext &C,
311 unsigned NumElements,
312 bool HasPackExpansions);
314 /// getNumElements - Return number of elements of objective-c dictionary
316 unsigned getNumElements() const { return NumElements; }
318 ObjCDictionaryElement getKeyValueElement(unsigned Index) const {
319 assert((Index < NumElements) && "Arg access out of range!");
320 const KeyValuePair &KV = getKeyValues()[Index];
321 ObjCDictionaryElement Result = { KV.Key, KV.Value, SourceLocation(), None };
322 if (HasPackExpansions) {
323 const ExpansionData &Expansion = getExpansionData()[Index];
324 Result.EllipsisLoc = Expansion.EllipsisLoc;
325 if (Expansion.NumExpansionsPlusOne > 0)
326 Result.NumExpansions = Expansion.NumExpansionsPlusOne - 1;
331 ObjCMethodDecl *getDictWithObjectsMethod() const
332 { return DictWithObjectsMethod; }
334 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
335 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
336 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
338 static bool classof(const Stmt *T) {
339 return T->getStmtClass() == ObjCDictionaryLiteralClass;
343 child_range children() {
344 // Note: we're taking advantage of the layout of the KeyValuePair struct
345 // here. If that struct changes, this code will need to change as well.
346 static_assert(sizeof(KeyValuePair) == sizeof(Stmt *) * 2,
347 "KeyValuePair is expected size");
348 return child_range(reinterpret_cast<Stmt **>(this + 1),
349 reinterpret_cast<Stmt **>(this + 1) + NumElements * 2);
352 friend class ASTStmtReader;
353 friend class ASTStmtWriter;
357 /// ObjCEncodeExpr, used for \@encode in Objective-C. \@encode has the same
358 /// type and behavior as StringLiteral except that the string initializer is
359 /// obtained from ASTContext with the encoding type as an argument.
360 class ObjCEncodeExpr : public Expr {
361 TypeSourceInfo *EncodedType;
362 SourceLocation AtLoc, RParenLoc;
364 ObjCEncodeExpr(QualType T, TypeSourceInfo *EncodedType,
365 SourceLocation at, SourceLocation rp)
366 : Expr(ObjCEncodeExprClass, T, VK_LValue, OK_Ordinary,
367 EncodedType->getType()->isDependentType(),
368 EncodedType->getType()->isDependentType(),
369 EncodedType->getType()->isInstantiationDependentType(),
370 EncodedType->getType()->containsUnexpandedParameterPack()),
371 EncodedType(EncodedType), AtLoc(at), RParenLoc(rp) {}
373 explicit ObjCEncodeExpr(EmptyShell Empty) : Expr(ObjCEncodeExprClass, Empty){}
376 SourceLocation getAtLoc() const { return AtLoc; }
377 void setAtLoc(SourceLocation L) { AtLoc = L; }
378 SourceLocation getRParenLoc() const { return RParenLoc; }
379 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
381 QualType getEncodedType() const { return EncodedType->getType(); }
383 TypeSourceInfo *getEncodedTypeSourceInfo() const { return EncodedType; }
384 void setEncodedTypeSourceInfo(TypeSourceInfo *EncType) {
385 EncodedType = EncType;
388 SourceLocation getLocStart() const LLVM_READONLY { return AtLoc; }
389 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
391 static bool classof(const Stmt *T) {
392 return T->getStmtClass() == ObjCEncodeExprClass;
396 child_range children() {
397 return child_range(child_iterator(), child_iterator());
401 /// ObjCSelectorExpr used for \@selector in Objective-C.
402 class ObjCSelectorExpr : public Expr {
404 SourceLocation AtLoc, RParenLoc;
406 ObjCSelectorExpr(QualType T, Selector selInfo,
407 SourceLocation at, SourceLocation rp)
408 : Expr(ObjCSelectorExprClass, T, VK_RValue, OK_Ordinary, false, false,
410 SelName(selInfo), AtLoc(at), RParenLoc(rp){}
411 explicit ObjCSelectorExpr(EmptyShell Empty)
412 : Expr(ObjCSelectorExprClass, Empty) {}
414 Selector getSelector() const { return SelName; }
415 void setSelector(Selector S) { SelName = S; }
417 SourceLocation getAtLoc() const { return AtLoc; }
418 SourceLocation getRParenLoc() const { return RParenLoc; }
419 void setAtLoc(SourceLocation L) { AtLoc = L; }
420 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
422 SourceLocation getLocStart() const LLVM_READONLY { return AtLoc; }
423 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
425 /// getNumArgs - Return the number of actual arguments to this call.
426 unsigned getNumArgs() const { return SelName.getNumArgs(); }
428 static bool classof(const Stmt *T) {
429 return T->getStmtClass() == ObjCSelectorExprClass;
433 child_range children() {
434 return child_range(child_iterator(), child_iterator());
438 /// ObjCProtocolExpr used for protocol expression in Objective-C.
440 /// This is used as: \@protocol(foo), as in:
442 /// [obj conformsToProtocol:@protocol(foo)]
445 /// The return type is "Protocol*".
446 class ObjCProtocolExpr : public Expr {
447 ObjCProtocolDecl *TheProtocol;
448 SourceLocation AtLoc, ProtoLoc, RParenLoc;
450 ObjCProtocolExpr(QualType T, ObjCProtocolDecl *protocol,
451 SourceLocation at, SourceLocation protoLoc, SourceLocation rp)
452 : Expr(ObjCProtocolExprClass, T, VK_RValue, OK_Ordinary, false, false,
454 TheProtocol(protocol), AtLoc(at), ProtoLoc(protoLoc), RParenLoc(rp) {}
455 explicit ObjCProtocolExpr(EmptyShell Empty)
456 : Expr(ObjCProtocolExprClass, Empty) {}
458 ObjCProtocolDecl *getProtocol() const { return TheProtocol; }
459 void setProtocol(ObjCProtocolDecl *P) { TheProtocol = P; }
461 SourceLocation getProtocolIdLoc() const { return ProtoLoc; }
462 SourceLocation getAtLoc() const { return AtLoc; }
463 SourceLocation getRParenLoc() const { return RParenLoc; }
464 void setAtLoc(SourceLocation L) { AtLoc = L; }
465 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
467 SourceLocation getLocStart() const LLVM_READONLY { return AtLoc; }
468 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
470 static bool classof(const Stmt *T) {
471 return T->getStmtClass() == ObjCProtocolExprClass;
475 child_range children() {
476 return child_range(child_iterator(), child_iterator());
479 friend class ASTStmtReader;
480 friend class ASTStmtWriter;
483 /// ObjCIvarRefExpr - A reference to an ObjC instance variable.
484 class ObjCIvarRefExpr : public Expr {
488 /// OpLoc - This is the location of '.' or '->'
489 SourceLocation OpLoc;
491 bool IsArrow:1; // True if this is "X->F", false if this is "X.F".
492 bool IsFreeIvar:1; // True if ivar reference has no base (self assumed).
495 ObjCIvarRefExpr(ObjCIvarDecl *d, QualType t,
496 SourceLocation l, SourceLocation oploc,
498 bool arrow = false, bool freeIvar = false) :
499 Expr(ObjCIvarRefExprClass, t, VK_LValue,
500 d->isBitField() ? OK_BitField : OK_Ordinary,
501 /*TypeDependent=*/false, base->isValueDependent(),
502 base->isInstantiationDependent(),
503 base->containsUnexpandedParameterPack()),
504 D(d), Base(base), Loc(l), OpLoc(oploc),
505 IsArrow(arrow), IsFreeIvar(freeIvar) {}
507 explicit ObjCIvarRefExpr(EmptyShell Empty)
508 : Expr(ObjCIvarRefExprClass, Empty) {}
510 ObjCIvarDecl *getDecl() { return D; }
511 const ObjCIvarDecl *getDecl() const { return D; }
512 void setDecl(ObjCIvarDecl *d) { D = d; }
514 const Expr *getBase() const { return cast<Expr>(Base); }
515 Expr *getBase() { return cast<Expr>(Base); }
516 void setBase(Expr * base) { Base = base; }
518 bool isArrow() const { return IsArrow; }
519 bool isFreeIvar() const { return IsFreeIvar; }
520 void setIsArrow(bool A) { IsArrow = A; }
521 void setIsFreeIvar(bool A) { IsFreeIvar = A; }
523 SourceLocation getLocation() const { return Loc; }
524 void setLocation(SourceLocation L) { Loc = L; }
526 SourceLocation getLocStart() const LLVM_READONLY {
527 return isFreeIvar() ? Loc : getBase()->getLocStart();
529 SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
531 SourceLocation getOpLoc() const { return OpLoc; }
532 void setOpLoc(SourceLocation L) { OpLoc = L; }
534 static bool classof(const Stmt *T) {
535 return T->getStmtClass() == ObjCIvarRefExprClass;
539 child_range children() { return child_range(&Base, &Base+1); }
542 /// ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC
544 class ObjCPropertyRefExpr : public Expr {
546 /// If the bool is true, this is an implicit property reference; the
547 /// pointer is an (optional) ObjCMethodDecl and Setter may be set.
548 /// if the bool is false, this is an explicit property reference;
549 /// the pointer is an ObjCPropertyDecl and Setter is always null.
550 llvm::PointerIntPair<NamedDecl*, 1, bool> PropertyOrGetter;
552 /// \brief Indicates whether the property reference will result in a message
553 /// to the getter, the setter, or both.
554 /// This applies to both implicit and explicit property references.
555 enum MethodRefFlags {
557 MethodRef_Getter = 0x1,
558 MethodRef_Setter = 0x2
561 /// \brief Contains the Setter method pointer and MethodRefFlags bit flags.
562 llvm::PointerIntPair<ObjCMethodDecl *, 2, unsigned> SetterAndMethodRefFlags;
564 // FIXME: Maybe we should store the property identifier here,
565 // because it's not rederivable from the other data when there's an
566 // implicit property with no getter (because the 'foo' -> 'setFoo:'
567 // transformation is lossy on the first character).
569 SourceLocation IdLoc;
571 /// \brief When the receiver in property access is 'super', this is
572 /// the location of the 'super' keyword. When it's an interface,
573 /// this is that interface.
574 SourceLocation ReceiverLoc;
575 llvm::PointerUnion3<Stmt*, const Type*, ObjCInterfaceDecl*> Receiver;
578 ObjCPropertyRefExpr(ObjCPropertyDecl *PD, QualType t,
579 ExprValueKind VK, ExprObjectKind OK,
580 SourceLocation l, Expr *base)
581 : Expr(ObjCPropertyRefExprClass, t, VK, OK,
582 /*TypeDependent=*/false, base->isValueDependent(),
583 base->isInstantiationDependent(),
584 base->containsUnexpandedParameterPack()),
585 PropertyOrGetter(PD, false), SetterAndMethodRefFlags(),
586 IdLoc(l), ReceiverLoc(), Receiver(base) {
587 assert(t->isSpecificPlaceholderType(BuiltinType::PseudoObject));
590 ObjCPropertyRefExpr(ObjCPropertyDecl *PD, QualType t,
591 ExprValueKind VK, ExprObjectKind OK,
592 SourceLocation l, SourceLocation sl, QualType st)
593 : Expr(ObjCPropertyRefExprClass, t, VK, OK,
594 /*TypeDependent=*/false, false, st->isInstantiationDependentType(),
595 st->containsUnexpandedParameterPack()),
596 PropertyOrGetter(PD, false), SetterAndMethodRefFlags(),
597 IdLoc(l), ReceiverLoc(sl), Receiver(st.getTypePtr()) {
598 assert(t->isSpecificPlaceholderType(BuiltinType::PseudoObject));
601 ObjCPropertyRefExpr(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter,
602 QualType T, ExprValueKind VK, ExprObjectKind OK,
603 SourceLocation IdLoc, Expr *Base)
604 : Expr(ObjCPropertyRefExprClass, T, VK, OK, false,
605 Base->isValueDependent(), Base->isInstantiationDependent(),
606 Base->containsUnexpandedParameterPack()),
607 PropertyOrGetter(Getter, true), SetterAndMethodRefFlags(Setter, 0),
608 IdLoc(IdLoc), ReceiverLoc(), Receiver(Base) {
609 assert(T->isSpecificPlaceholderType(BuiltinType::PseudoObject));
612 ObjCPropertyRefExpr(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter,
613 QualType T, ExprValueKind VK, ExprObjectKind OK,
614 SourceLocation IdLoc,
615 SourceLocation SuperLoc, QualType SuperTy)
616 : Expr(ObjCPropertyRefExprClass, T, VK, OK, false, false, false, false),
617 PropertyOrGetter(Getter, true), SetterAndMethodRefFlags(Setter, 0),
618 IdLoc(IdLoc), ReceiverLoc(SuperLoc), Receiver(SuperTy.getTypePtr()) {
619 assert(T->isSpecificPlaceholderType(BuiltinType::PseudoObject));
622 ObjCPropertyRefExpr(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter,
623 QualType T, ExprValueKind VK, ExprObjectKind OK,
624 SourceLocation IdLoc,
625 SourceLocation ReceiverLoc, ObjCInterfaceDecl *Receiver)
626 : Expr(ObjCPropertyRefExprClass, T, VK, OK, false, false, false, false),
627 PropertyOrGetter(Getter, true), SetterAndMethodRefFlags(Setter, 0),
628 IdLoc(IdLoc), ReceiverLoc(ReceiverLoc), Receiver(Receiver) {
629 assert(T->isSpecificPlaceholderType(BuiltinType::PseudoObject));
632 explicit ObjCPropertyRefExpr(EmptyShell Empty)
633 : Expr(ObjCPropertyRefExprClass, Empty) {}
635 bool isImplicitProperty() const { return PropertyOrGetter.getInt(); }
636 bool isExplicitProperty() const { return !PropertyOrGetter.getInt(); }
638 ObjCPropertyDecl *getExplicitProperty() const {
639 assert(!isImplicitProperty());
640 return cast<ObjCPropertyDecl>(PropertyOrGetter.getPointer());
643 ObjCMethodDecl *getImplicitPropertyGetter() const {
644 assert(isImplicitProperty());
645 return cast_or_null<ObjCMethodDecl>(PropertyOrGetter.getPointer());
648 ObjCMethodDecl *getImplicitPropertySetter() const {
649 assert(isImplicitProperty());
650 return SetterAndMethodRefFlags.getPointer();
653 Selector getGetterSelector() const {
654 if (isImplicitProperty())
655 return getImplicitPropertyGetter()->getSelector();
656 return getExplicitProperty()->getGetterName();
659 Selector getSetterSelector() const {
660 if (isImplicitProperty())
661 return getImplicitPropertySetter()->getSelector();
662 return getExplicitProperty()->getSetterName();
665 /// \brief True if the property reference will result in a message to the
667 /// This applies to both implicit and explicit property references.
668 bool isMessagingGetter() const {
669 return SetterAndMethodRefFlags.getInt() & MethodRef_Getter;
672 /// \brief True if the property reference will result in a message to the
674 /// This applies to both implicit and explicit property references.
675 bool isMessagingSetter() const {
676 return SetterAndMethodRefFlags.getInt() & MethodRef_Setter;
679 void setIsMessagingGetter(bool val = true) {
680 setMethodRefFlag(MethodRef_Getter, val);
683 void setIsMessagingSetter(bool val = true) {
684 setMethodRefFlag(MethodRef_Setter, val);
687 const Expr *getBase() const {
688 return cast<Expr>(Receiver.get<Stmt*>());
691 return cast<Expr>(Receiver.get<Stmt*>());
694 SourceLocation getLocation() const { return IdLoc; }
696 SourceLocation getReceiverLocation() const { return ReceiverLoc; }
697 QualType getSuperReceiverType() const {
698 return QualType(Receiver.get<const Type*>(), 0);
701 ObjCInterfaceDecl *getClassReceiver() const {
702 return Receiver.get<ObjCInterfaceDecl*>();
704 bool isObjectReceiver() const { return Receiver.is<Stmt*>(); }
705 bool isSuperReceiver() const { return Receiver.is<const Type*>(); }
706 bool isClassReceiver() const { return Receiver.is<ObjCInterfaceDecl*>(); }
708 /// Determine the type of the base, regardless of the kind of receiver.
709 QualType getReceiverType(const ASTContext &ctx) const;
711 SourceLocation getLocStart() const LLVM_READONLY {
712 return isObjectReceiver() ? getBase()->getLocStart() :getReceiverLocation();
714 SourceLocation getLocEnd() const LLVM_READONLY { return IdLoc; }
716 static bool classof(const Stmt *T) {
717 return T->getStmtClass() == ObjCPropertyRefExprClass;
721 child_range children() {
722 if (Receiver.is<Stmt*>()) {
723 Stmt **begin = reinterpret_cast<Stmt**>(&Receiver); // hack!
724 return child_range(begin, begin+1);
726 return child_range(child_iterator(), child_iterator());
730 friend class ASTStmtReader;
731 friend class ASTStmtWriter;
732 void setExplicitProperty(ObjCPropertyDecl *D, unsigned methRefFlags) {
733 PropertyOrGetter.setPointer(D);
734 PropertyOrGetter.setInt(false);
735 SetterAndMethodRefFlags.setPointer(nullptr);
736 SetterAndMethodRefFlags.setInt(methRefFlags);
738 void setImplicitProperty(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter,
739 unsigned methRefFlags) {
740 PropertyOrGetter.setPointer(Getter);
741 PropertyOrGetter.setInt(true);
742 SetterAndMethodRefFlags.setPointer(Setter);
743 SetterAndMethodRefFlags.setInt(methRefFlags);
745 void setBase(Expr *Base) { Receiver = Base; }
746 void setSuperReceiver(QualType T) { Receiver = T.getTypePtr(); }
747 void setClassReceiver(ObjCInterfaceDecl *D) { Receiver = D; }
749 void setLocation(SourceLocation L) { IdLoc = L; }
750 void setReceiverLocation(SourceLocation Loc) { ReceiverLoc = Loc; }
752 void setMethodRefFlag(MethodRefFlags flag, bool val) {
753 unsigned f = SetterAndMethodRefFlags.getInt();
758 SetterAndMethodRefFlags.setInt(f);
762 /// ObjCSubscriptRefExpr - used for array and dictionary subscripting.
763 /// array[4] = array[3]; dictionary[key] = dictionary[alt_key];
765 class ObjCSubscriptRefExpr : public Expr {
766 // Location of ']' in an indexing expression.
767 SourceLocation RBracket;
768 // array/dictionary base expression.
769 // for arrays, this is a numeric expression. For dictionaries, this is
770 // an objective-c object pointer expression.
771 enum { BASE, KEY, END_EXPR };
772 Stmt* SubExprs[END_EXPR];
774 ObjCMethodDecl *GetAtIndexMethodDecl;
776 // For immutable objects this is null. When ObjCSubscriptRefExpr is to read
777 // an indexed object this is null too.
778 ObjCMethodDecl *SetAtIndexMethodDecl;
782 ObjCSubscriptRefExpr(Expr *base, Expr *key, QualType T,
783 ExprValueKind VK, ExprObjectKind OK,
784 ObjCMethodDecl *getMethod,
785 ObjCMethodDecl *setMethod, SourceLocation RB)
786 : Expr(ObjCSubscriptRefExprClass, T, VK, OK,
787 base->isTypeDependent() || key->isTypeDependent(),
788 base->isValueDependent() || key->isValueDependent(),
789 base->isInstantiationDependent() || key->isInstantiationDependent(),
790 (base->containsUnexpandedParameterPack() ||
791 key->containsUnexpandedParameterPack())),
793 GetAtIndexMethodDecl(getMethod),
794 SetAtIndexMethodDecl(setMethod)
795 {SubExprs[BASE] = base; SubExprs[KEY] = key;}
797 explicit ObjCSubscriptRefExpr(EmptyShell Empty)
798 : Expr(ObjCSubscriptRefExprClass, Empty) {}
800 static ObjCSubscriptRefExpr *Create(const ASTContext &C,
802 Expr *key, QualType T,
803 ObjCMethodDecl *getMethod,
804 ObjCMethodDecl *setMethod,
807 SourceLocation getRBracket() const { return RBracket; }
808 void setRBracket(SourceLocation RB) { RBracket = RB; }
810 SourceLocation getLocStart() const LLVM_READONLY {
811 return SubExprs[BASE]->getLocStart();
813 SourceLocation getLocEnd() const LLVM_READONLY { return RBracket; }
815 static bool classof(const Stmt *T) {
816 return T->getStmtClass() == ObjCSubscriptRefExprClass;
819 Expr *getBaseExpr() const { return cast<Expr>(SubExprs[BASE]); }
820 void setBaseExpr(Stmt *S) { SubExprs[BASE] = S; }
822 Expr *getKeyExpr() const { return cast<Expr>(SubExprs[KEY]); }
823 void setKeyExpr(Stmt *S) { SubExprs[KEY] = S; }
825 ObjCMethodDecl *getAtIndexMethodDecl() const {
826 return GetAtIndexMethodDecl;
829 ObjCMethodDecl *setAtIndexMethodDecl() const {
830 return SetAtIndexMethodDecl;
833 bool isArraySubscriptRefExpr() const {
834 return getKeyExpr()->getType()->isIntegralOrEnumerationType();
837 child_range children() {
838 return child_range(SubExprs, SubExprs+END_EXPR);
841 friend class ASTStmtReader;
845 /// \brief An expression that sends a message to the given Objective-C
848 /// The following contains two message send expressions:
851 /// [[NSString alloc] initWithString:@"Hello"]
854 /// The innermost message send invokes the "alloc" class method on the
855 /// NSString class, while the outermost message send invokes the
856 /// "initWithString" instance method on the object returned from
857 /// NSString's "alloc". In all, an Objective-C message send can take
858 /// on four different (although related) forms:
860 /// 1. Send to an object instance.
861 /// 2. Send to a class.
862 /// 3. Send to the superclass instance of the current class.
863 /// 4. Send to the superclass of the current class.
865 /// All four kinds of message sends are modeled by the ObjCMessageExpr
866 /// class, and can be distinguished via \c getReceiverKind(). Example:
868 class ObjCMessageExpr : public Expr {
869 /// \brief Stores either the selector that this message is sending
870 /// to (when \c HasMethod is zero) or an \c ObjCMethodDecl pointer
871 /// referring to the method that we type-checked against.
872 uintptr_t SelectorOrMethod;
874 enum { NumArgsBitWidth = 16 };
876 /// \brief The number of arguments in the message send, not
877 /// including the receiver.
878 unsigned NumArgs : NumArgsBitWidth;
880 void setNumArgs(unsigned Num) {
881 assert((Num >> NumArgsBitWidth) == 0 && "Num of args is out of range!");
885 /// \brief The kind of message send this is, which is one of the
886 /// ReceiverKind values.
888 /// We pad this out to a byte to avoid excessive masking and shifting.
891 /// \brief Whether we have an actual method prototype in \c
892 /// SelectorOrMethod.
894 /// When non-zero, we have a method declaration; otherwise, we just
896 unsigned HasMethod : 1;
898 /// \brief Whether this message send is a "delegate init call",
899 /// i.e. a call of an init method on self from within an init method.
900 unsigned IsDelegateInitCall : 1;
902 /// \brief Whether this message send was implicitly generated by
903 /// the implementation rather than explicitly written by the user.
904 unsigned IsImplicit : 1;
906 /// \brief Whether the locations of the selector identifiers are in a
907 /// "standard" position, a enum SelectorLocationsKind.
908 unsigned SelLocsKind : 2;
910 /// \brief When the message expression is a send to 'super', this is
911 /// the location of the 'super' keyword.
912 SourceLocation SuperLoc;
914 /// \brief The source locations of the open and close square
915 /// brackets ('[' and ']', respectively).
916 SourceLocation LBracLoc, RBracLoc;
918 ObjCMessageExpr(EmptyShell Empty, unsigned NumArgs)
919 : Expr(ObjCMessageExprClass, Empty), SelectorOrMethod(0), Kind(0),
920 HasMethod(0), IsDelegateInitCall(0), IsImplicit(0), SelLocsKind(0) {
924 ObjCMessageExpr(QualType T, ExprValueKind VK,
925 SourceLocation LBracLoc,
926 SourceLocation SuperLoc,
927 bool IsInstanceSuper,
930 ArrayRef<SourceLocation> SelLocs,
931 SelectorLocationsKind SelLocsK,
932 ObjCMethodDecl *Method,
933 ArrayRef<Expr *> Args,
934 SourceLocation RBracLoc,
936 ObjCMessageExpr(QualType T, ExprValueKind VK,
937 SourceLocation LBracLoc,
938 TypeSourceInfo *Receiver,
940 ArrayRef<SourceLocation> SelLocs,
941 SelectorLocationsKind SelLocsK,
942 ObjCMethodDecl *Method,
943 ArrayRef<Expr *> Args,
944 SourceLocation RBracLoc,
946 ObjCMessageExpr(QualType T, ExprValueKind VK,
947 SourceLocation LBracLoc,
950 ArrayRef<SourceLocation> SelLocs,
951 SelectorLocationsKind SelLocsK,
952 ObjCMethodDecl *Method,
953 ArrayRef<Expr *> Args,
954 SourceLocation RBracLoc,
957 void initArgsAndSelLocs(ArrayRef<Expr *> Args,
958 ArrayRef<SourceLocation> SelLocs,
959 SelectorLocationsKind SelLocsK);
961 /// \brief Retrieve the pointer value of the message receiver.
962 void *getReceiverPointer() const {
963 return *const_cast<void **>(
964 reinterpret_cast<const void * const*>(this + 1));
967 /// \brief Set the pointer value of the message receiver.
968 void setReceiverPointer(void *Value) {
969 *reinterpret_cast<void **>(this + 1) = Value;
972 SelectorLocationsKind getSelLocsKind() const {
973 return (SelectorLocationsKind)SelLocsKind;
975 bool hasStandardSelLocs() const {
976 return getSelLocsKind() != SelLoc_NonStandard;
979 /// \brief Get a pointer to the stored selector identifiers locations array.
980 /// No locations will be stored if HasStandardSelLocs is true.
981 SourceLocation *getStoredSelLocs() {
982 return reinterpret_cast<SourceLocation*>(getArgs() + getNumArgs());
984 const SourceLocation *getStoredSelLocs() const {
985 return reinterpret_cast<const SourceLocation*>(getArgs() + getNumArgs());
988 /// \brief Get the number of stored selector identifiers locations.
989 /// No locations will be stored if HasStandardSelLocs is true.
990 unsigned getNumStoredSelLocs() const {
991 if (hasStandardSelLocs())
993 return getNumSelectorLocs();
996 static ObjCMessageExpr *alloc(const ASTContext &C,
997 ArrayRef<Expr *> Args,
998 SourceLocation RBraceLoc,
999 ArrayRef<SourceLocation> SelLocs,
1001 SelectorLocationsKind &SelLocsK);
1002 static ObjCMessageExpr *alloc(const ASTContext &C,
1004 unsigned NumStoredSelLocs);
1007 /// \brief The kind of receiver this message is sending to.
1009 /// \brief The receiver is a class.
1011 /// \brief The receiver is an object instance.
1013 /// \brief The receiver is a superclass.
1015 /// \brief The receiver is the instance of the superclass object.
1019 /// \brief Create a message send to super.
1021 /// \param Context The ASTContext in which this expression will be created.
1023 /// \param T The result type of this message.
1025 /// \param VK The value kind of this message. A message returning
1026 /// a l-value or r-value reference will be an l-value or x-value,
1029 /// \param LBracLoc The location of the open square bracket '['.
1031 /// \param SuperLoc The location of the "super" keyword.
1033 /// \param IsInstanceSuper Whether this is an instance "super"
1034 /// message (otherwise, it's a class "super" message).
1036 /// \param Sel The selector used to determine which method gets called.
1038 /// \param Method The Objective-C method against which this message
1039 /// send was type-checked. May be NULL.
1041 /// \param Args The message send arguments.
1043 /// \param RBracLoc The location of the closing square bracket ']'.
1044 static ObjCMessageExpr *Create(const ASTContext &Context, QualType T,
1046 SourceLocation LBracLoc,
1047 SourceLocation SuperLoc,
1048 bool IsInstanceSuper,
1051 ArrayRef<SourceLocation> SelLocs,
1052 ObjCMethodDecl *Method,
1053 ArrayRef<Expr *> Args,
1054 SourceLocation RBracLoc,
1057 /// \brief Create a class message send.
1059 /// \param Context The ASTContext in which this expression will be created.
1061 /// \param T The result type of this message.
1063 /// \param VK The value kind of this message. A message returning
1064 /// a l-value or r-value reference will be an l-value or x-value,
1067 /// \param LBracLoc The location of the open square bracket '['.
1069 /// \param Receiver The type of the receiver, including
1070 /// source-location information.
1072 /// \param Sel The selector used to determine which method gets called.
1074 /// \param Method The Objective-C method against which this message
1075 /// send was type-checked. May be NULL.
1077 /// \param Args The message send arguments.
1079 /// \param RBracLoc The location of the closing square bracket ']'.
1080 static ObjCMessageExpr *Create(const ASTContext &Context, QualType T,
1082 SourceLocation LBracLoc,
1083 TypeSourceInfo *Receiver,
1085 ArrayRef<SourceLocation> SelLocs,
1086 ObjCMethodDecl *Method,
1087 ArrayRef<Expr *> Args,
1088 SourceLocation RBracLoc,
1091 /// \brief Create an instance message send.
1093 /// \param Context The ASTContext in which this expression will be created.
1095 /// \param T The result type of this message.
1097 /// \param VK The value kind of this message. A message returning
1098 /// a l-value or r-value reference will be an l-value or x-value,
1101 /// \param LBracLoc The location of the open square bracket '['.
1103 /// \param Receiver The expression used to produce the object that
1104 /// will receive this message.
1106 /// \param Sel The selector used to determine which method gets called.
1108 /// \param Method The Objective-C method against which this message
1109 /// send was type-checked. May be NULL.
1111 /// \param Args The message send arguments.
1113 /// \param RBracLoc The location of the closing square bracket ']'.
1114 static ObjCMessageExpr *Create(const ASTContext &Context, QualType T,
1116 SourceLocation LBracLoc,
1119 ArrayRef<SourceLocation> SeLocs,
1120 ObjCMethodDecl *Method,
1121 ArrayRef<Expr *> Args,
1122 SourceLocation RBracLoc,
1125 /// \brief Create an empty Objective-C message expression, to be
1126 /// filled in by subsequent calls.
1128 /// \param Context The context in which the message send will be created.
1130 /// \param NumArgs The number of message arguments, not including
1132 static ObjCMessageExpr *CreateEmpty(const ASTContext &Context,
1134 unsigned NumStoredSelLocs);
1136 /// \brief Indicates whether the message send was implicitly
1137 /// generated by the implementation. If false, it was written explicitly
1138 /// in the source code.
1139 bool isImplicit() const { return IsImplicit; }
1141 /// \brief Determine the kind of receiver that this message is being
1143 ReceiverKind getReceiverKind() const { return (ReceiverKind)Kind; }
1145 /// \brief Source range of the receiver.
1146 SourceRange getReceiverRange() const;
1148 /// \brief Determine whether this is an instance message to either a
1149 /// computed object or to super.
1150 bool isInstanceMessage() const {
1151 return getReceiverKind() == Instance || getReceiverKind() == SuperInstance;
1154 /// \brief Determine whether this is an class message to either a
1155 /// specified class or to super.
1156 bool isClassMessage() const {
1157 return getReceiverKind() == Class || getReceiverKind() == SuperClass;
1160 /// \brief Returns the object expression (receiver) for an instance message,
1161 /// or null for a message that is not an instance message.
1162 Expr *getInstanceReceiver() {
1163 if (getReceiverKind() == Instance)
1164 return static_cast<Expr *>(getReceiverPointer());
1168 const Expr *getInstanceReceiver() const {
1169 return const_cast<ObjCMessageExpr*>(this)->getInstanceReceiver();
1172 /// \brief Turn this message send into an instance message that
1173 /// computes the receiver object with the given expression.
1174 void setInstanceReceiver(Expr *rec) {
1176 setReceiverPointer(rec);
1179 /// \brief Returns the type of a class message send, or NULL if the
1180 /// message is not a class message.
1181 QualType getClassReceiver() const {
1182 if (TypeSourceInfo *TSInfo = getClassReceiverTypeInfo())
1183 return TSInfo->getType();
1188 /// \brief Returns a type-source information of a class message
1189 /// send, or NULL if the message is not a class message.
1190 TypeSourceInfo *getClassReceiverTypeInfo() const {
1191 if (getReceiverKind() == Class)
1192 return reinterpret_cast<TypeSourceInfo *>(getReceiverPointer());
1196 void setClassReceiver(TypeSourceInfo *TSInfo) {
1198 setReceiverPointer(TSInfo);
1201 /// \brief Retrieve the location of the 'super' keyword for a class
1202 /// or instance message to 'super', otherwise an invalid source location.
1203 SourceLocation getSuperLoc() const {
1204 if (getReceiverKind() == SuperInstance || getReceiverKind() == SuperClass)
1207 return SourceLocation();
1210 /// \brief Retrieve the receiver type to which this message is being directed.
1212 /// This routine cross-cuts all of the different kinds of message
1213 /// sends to determine what the underlying (statically known) type
1214 /// of the receiver will be; use \c getReceiverKind() to determine
1215 /// whether the message is a class or an instance method, whether it
1216 /// is a send to super or not, etc.
1218 /// \returns The type of the receiver.
1219 QualType getReceiverType() const;
1221 /// \brief Retrieve the Objective-C interface to which this message
1222 /// is being directed, if known.
1224 /// This routine cross-cuts all of the different kinds of message
1225 /// sends to determine what the underlying (statically known) type
1226 /// of the receiver will be; use \c getReceiverKind() to determine
1227 /// whether the message is a class or an instance method, whether it
1228 /// is a send to super or not, etc.
1230 /// \returns The Objective-C interface if known, otherwise NULL.
1231 ObjCInterfaceDecl *getReceiverInterface() const;
1233 /// \brief Retrieve the type referred to by 'super'.
1235 /// The returned type will either be an ObjCInterfaceType (for an
1236 /// class message to super) or an ObjCObjectPointerType that refers
1237 /// to a class (for an instance message to super);
1238 QualType getSuperType() const {
1239 if (getReceiverKind() == SuperInstance || getReceiverKind() == SuperClass)
1240 return QualType::getFromOpaquePtr(getReceiverPointer());
1245 void setSuper(SourceLocation Loc, QualType T, bool IsInstanceSuper) {
1246 Kind = IsInstanceSuper? SuperInstance : SuperClass;
1248 setReceiverPointer(T.getAsOpaquePtr());
1251 Selector getSelector() const;
1253 void setSelector(Selector S) {
1255 SelectorOrMethod = reinterpret_cast<uintptr_t>(S.getAsOpaquePtr());
1258 const ObjCMethodDecl *getMethodDecl() const {
1260 return reinterpret_cast<const ObjCMethodDecl *>(SelectorOrMethod);
1265 ObjCMethodDecl *getMethodDecl() {
1267 return reinterpret_cast<ObjCMethodDecl *>(SelectorOrMethod);
1272 void setMethodDecl(ObjCMethodDecl *MD) {
1274 SelectorOrMethod = reinterpret_cast<uintptr_t>(MD);
1277 ObjCMethodFamily getMethodFamily() const {
1278 if (HasMethod) return getMethodDecl()->getMethodFamily();
1279 return getSelector().getMethodFamily();
1282 /// \brief Return the number of actual arguments in this message,
1283 /// not counting the receiver.
1284 unsigned getNumArgs() const { return NumArgs; }
1286 /// \brief Retrieve the arguments to this message, not including the
1289 return reinterpret_cast<Expr **>(this + 1) + 1;
1291 const Expr * const *getArgs() const {
1292 return reinterpret_cast<const Expr * const *>(this + 1) + 1;
1295 /// getArg - Return the specified argument.
1296 Expr *getArg(unsigned Arg) {
1297 assert(Arg < NumArgs && "Arg access out of range!");
1298 return cast<Expr>(getArgs()[Arg]);
1300 const Expr *getArg(unsigned Arg) const {
1301 assert(Arg < NumArgs && "Arg access out of range!");
1302 return cast<Expr>(getArgs()[Arg]);
1304 /// setArg - Set the specified argument.
1305 void setArg(unsigned Arg, Expr *ArgExpr) {
1306 assert(Arg < NumArgs && "Arg access out of range!");
1307 getArgs()[Arg] = ArgExpr;
1310 /// isDelegateInitCall - Answers whether this message send has been
1311 /// tagged as a "delegate init call", i.e. a call to a method in the
1312 /// -init family on self from within an -init method implementation.
1313 bool isDelegateInitCall() const { return IsDelegateInitCall; }
1314 void setDelegateInitCall(bool isDelegate) { IsDelegateInitCall = isDelegate; }
1316 SourceLocation getLeftLoc() const { return LBracLoc; }
1317 SourceLocation getRightLoc() const { return RBracLoc; }
1319 SourceLocation getSelectorStartLoc() const {
1321 return getLocStart();
1322 return getSelectorLoc(0);
1324 SourceLocation getSelectorLoc(unsigned Index) const {
1325 assert(Index < getNumSelectorLocs() && "Index out of range!");
1326 if (hasStandardSelLocs())
1327 return getStandardSelectorLoc(Index, getSelector(),
1328 getSelLocsKind() == SelLoc_StandardWithSpace,
1329 llvm::makeArrayRef(const_cast<Expr**>(getArgs()),
1332 return getStoredSelLocs()[Index];
1335 void getSelectorLocs(SmallVectorImpl<SourceLocation> &SelLocs) const;
1337 unsigned getNumSelectorLocs() const {
1340 Selector Sel = getSelector();
1341 if (Sel.isUnarySelector())
1343 return Sel.getNumArgs();
1346 void setSourceRange(SourceRange R) {
1347 LBracLoc = R.getBegin();
1348 RBracLoc = R.getEnd();
1350 SourceLocation getLocStart() const LLVM_READONLY { return LBracLoc; }
1351 SourceLocation getLocEnd() const LLVM_READONLY { return RBracLoc; }
1353 static bool classof(const Stmt *T) {
1354 return T->getStmtClass() == ObjCMessageExprClass;
1358 child_range children();
1360 typedef ExprIterator arg_iterator;
1361 typedef ConstExprIterator const_arg_iterator;
1363 llvm::iterator_range<arg_iterator> arguments() {
1364 return llvm::make_range(arg_begin(), arg_end());
1367 llvm::iterator_range<const_arg_iterator> arguments() const {
1368 return llvm::make_range(arg_begin(), arg_end());
1371 arg_iterator arg_begin() { return reinterpret_cast<Stmt **>(getArgs()); }
1372 arg_iterator arg_end() {
1373 return reinterpret_cast<Stmt **>(getArgs() + NumArgs);
1375 const_arg_iterator arg_begin() const {
1376 return reinterpret_cast<Stmt const * const*>(getArgs());
1378 const_arg_iterator arg_end() const {
1379 return reinterpret_cast<Stmt const * const*>(getArgs() + NumArgs);
1382 friend class ASTStmtReader;
1383 friend class ASTStmtWriter;
1386 /// ObjCIsaExpr - Represent X->isa and X.isa when X is an ObjC 'id' type.
1387 /// (similar in spirit to MemberExpr).
1388 class ObjCIsaExpr : public Expr {
1389 /// Base - the expression for the base object pointer.
1392 /// IsaMemberLoc - This is the location of the 'isa'.
1393 SourceLocation IsaMemberLoc;
1395 /// OpLoc - This is the location of '.' or '->'
1396 SourceLocation OpLoc;
1398 /// IsArrow - True if this is "X->F", false if this is "X.F".
1401 ObjCIsaExpr(Expr *base, bool isarrow, SourceLocation l, SourceLocation oploc,
1403 : Expr(ObjCIsaExprClass, ty, VK_LValue, OK_Ordinary,
1404 /*TypeDependent=*/false, base->isValueDependent(),
1405 base->isInstantiationDependent(),
1406 /*ContainsUnexpandedParameterPack=*/false),
1407 Base(base), IsaMemberLoc(l), OpLoc(oploc), IsArrow(isarrow) {}
1409 /// \brief Build an empty expression.
1410 explicit ObjCIsaExpr(EmptyShell Empty) : Expr(ObjCIsaExprClass, Empty) { }
1412 void setBase(Expr *E) { Base = E; }
1413 Expr *getBase() const { return cast<Expr>(Base); }
1415 bool isArrow() const { return IsArrow; }
1416 void setArrow(bool A) { IsArrow = A; }
1418 /// getMemberLoc - Return the location of the "member", in X->F, it is the
1419 /// location of 'F'.
1420 SourceLocation getIsaMemberLoc() const { return IsaMemberLoc; }
1421 void setIsaMemberLoc(SourceLocation L) { IsaMemberLoc = L; }
1423 SourceLocation getOpLoc() const { return OpLoc; }
1424 void setOpLoc(SourceLocation L) { OpLoc = L; }
1426 SourceLocation getLocStart() const LLVM_READONLY {
1427 return getBase()->getLocStart();
1430 SourceLocation getBaseLocEnd() const LLVM_READONLY {
1431 return getBase()->getLocEnd();
1434 SourceLocation getLocEnd() const LLVM_READONLY { return IsaMemberLoc; }
1436 SourceLocation getExprLoc() const LLVM_READONLY { return IsaMemberLoc; }
1438 static bool classof(const Stmt *T) {
1439 return T->getStmtClass() == ObjCIsaExprClass;
1443 child_range children() { return child_range(&Base, &Base+1); }
1447 /// ObjCIndirectCopyRestoreExpr - Represents the passing of a function
1448 /// argument by indirect copy-restore in ARC. This is used to support
1449 /// passing indirect arguments with the wrong lifetime, e.g. when
1450 /// passing the address of a __strong local variable to an 'out'
1451 /// parameter. This expression kind is only valid in an "argument"
1452 /// position to some sort of call expression.
1454 /// The parameter must have type 'pointer to T', and the argument must
1455 /// have type 'pointer to U', where T and U agree except possibly in
1456 /// qualification. If the argument value is null, then a null pointer
1457 /// is passed; otherwise it points to an object A, and:
1458 /// 1. A temporary object B of type T is initialized, either by
1459 /// zero-initialization (used when initializing an 'out' parameter)
1460 /// or copy-initialization (used when initializing an 'inout'
1462 /// 2. The address of the temporary is passed to the function.
1463 /// 3. If the call completes normally, A is move-assigned from B.
1464 /// 4. Finally, A is destroyed immediately.
1466 /// Currently 'T' must be a retainable object lifetime and must be
1467 /// __autoreleasing; this qualifier is ignored when initializing
1469 class ObjCIndirectCopyRestoreExpr : public Expr {
1472 // unsigned ObjCIndirectCopyRestoreBits.ShouldCopy : 1;
1474 friend class ASTReader;
1475 friend class ASTStmtReader;
1477 void setShouldCopy(bool shouldCopy) {
1478 ObjCIndirectCopyRestoreExprBits.ShouldCopy = shouldCopy;
1481 explicit ObjCIndirectCopyRestoreExpr(EmptyShell Empty)
1482 : Expr(ObjCIndirectCopyRestoreExprClass, Empty) { }
1485 ObjCIndirectCopyRestoreExpr(Expr *operand, QualType type, bool shouldCopy)
1486 : Expr(ObjCIndirectCopyRestoreExprClass, type, VK_LValue, OK_Ordinary,
1487 operand->isTypeDependent(), operand->isValueDependent(),
1488 operand->isInstantiationDependent(),
1489 operand->containsUnexpandedParameterPack()),
1491 setShouldCopy(shouldCopy);
1494 Expr *getSubExpr() { return cast<Expr>(Operand); }
1495 const Expr *getSubExpr() const { return cast<Expr>(Operand); }
1497 /// shouldCopy - True if we should do the 'copy' part of the
1498 /// copy-restore. If false, the temporary will be zero-initialized.
1499 bool shouldCopy() const { return ObjCIndirectCopyRestoreExprBits.ShouldCopy; }
1501 child_range children() { return child_range(&Operand, &Operand+1); }
1503 // Source locations are determined by the subexpression.
1504 SourceLocation getLocStart() const LLVM_READONLY {
1505 return Operand->getLocStart();
1507 SourceLocation getLocEnd() const LLVM_READONLY { return Operand->getLocEnd();}
1509 SourceLocation getExprLoc() const LLVM_READONLY {
1510 return getSubExpr()->getExprLoc();
1513 static bool classof(const Stmt *s) {
1514 return s->getStmtClass() == ObjCIndirectCopyRestoreExprClass;
1518 /// \brief An Objective-C "bridged" cast expression, which casts between
1519 /// Objective-C pointers and C pointers, transferring ownership in the process.
1522 /// NSString *str = (__bridge_transfer NSString *)CFCreateString();
1524 class ObjCBridgedCastExpr final
1525 : public ExplicitCastExpr,
1526 private llvm::TrailingObjects<ObjCBridgedCastExpr, CXXBaseSpecifier *> {
1527 SourceLocation LParenLoc;
1528 SourceLocation BridgeKeywordLoc;
1531 friend TrailingObjects;
1532 friend class CastExpr;
1533 friend class ASTStmtReader;
1534 friend class ASTStmtWriter;
1537 ObjCBridgedCastExpr(SourceLocation LParenLoc, ObjCBridgeCastKind Kind,
1538 CastKind CK, SourceLocation BridgeKeywordLoc,
1539 TypeSourceInfo *TSInfo, Expr *Operand)
1540 : ExplicitCastExpr(ObjCBridgedCastExprClass, TSInfo->getType(), VK_RValue,
1541 CK, Operand, 0, TSInfo),
1542 LParenLoc(LParenLoc), BridgeKeywordLoc(BridgeKeywordLoc), Kind(Kind) { }
1544 /// \brief Construct an empty Objective-C bridged cast.
1545 explicit ObjCBridgedCastExpr(EmptyShell Shell)
1546 : ExplicitCastExpr(ObjCBridgedCastExprClass, Shell, 0) { }
1548 SourceLocation getLParenLoc() const { return LParenLoc; }
1550 /// \brief Determine which kind of bridge is being performed via this cast.
1551 ObjCBridgeCastKind getBridgeKind() const {
1552 return static_cast<ObjCBridgeCastKind>(Kind);
1555 /// \brief Retrieve the kind of bridge being performed as a string.
1556 StringRef getBridgeKindName() const;
1558 /// \brief The location of the bridge keyword.
1559 SourceLocation getBridgeKeywordLoc() const { return BridgeKeywordLoc; }
1561 SourceLocation getLocStart() const LLVM_READONLY { return LParenLoc; }
1562 SourceLocation getLocEnd() const LLVM_READONLY {
1563 return getSubExpr()->getLocEnd();
1566 static bool classof(const Stmt *T) {
1567 return T->getStmtClass() == ObjCBridgedCastExprClass;
1571 } // end namespace clang