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() { return child_range(); }
88 /// ObjCBoxedExpr - used for generalized expression boxing.
89 /// as in: @(strdup("hello world")) or @(random())
90 /// Also used for boxing non-parenthesized numeric literals;
91 /// as in: @42 or \@true (c++/objc++) or \@__yes (c/objc).
92 class ObjCBoxedExpr : public Expr {
94 ObjCMethodDecl *BoxingMethod;
97 ObjCBoxedExpr(Expr *E, QualType T, ObjCMethodDecl *method,
99 : Expr(ObjCBoxedExprClass, T, VK_RValue, OK_Ordinary,
100 E->isTypeDependent(), E->isValueDependent(),
101 E->isInstantiationDependent(), E->containsUnexpandedParameterPack()),
102 SubExpr(E), BoxingMethod(method), Range(R) {}
103 explicit ObjCBoxedExpr(EmptyShell Empty)
104 : Expr(ObjCBoxedExprClass, Empty) {}
106 Expr *getSubExpr() { return cast<Expr>(SubExpr); }
107 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
109 ObjCMethodDecl *getBoxingMethod() const {
113 SourceLocation getAtLoc() const { return Range.getBegin(); }
115 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
116 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
117 SourceRange getSourceRange() const LLVM_READONLY {
121 static bool classof(const Stmt *T) {
122 return T->getStmtClass() == ObjCBoxedExprClass;
126 child_range children() { return child_range(&SubExpr, &SubExpr+1); }
128 typedef ConstExprIterator const_arg_iterator;
130 const_arg_iterator arg_begin() const {
131 return reinterpret_cast<Stmt const * const*>(&SubExpr);
133 const_arg_iterator arg_end() const {
134 return reinterpret_cast<Stmt const * const*>(&SubExpr + 1);
137 friend class ASTStmtReader;
140 /// ObjCArrayLiteral - used for objective-c array containers; as in:
141 /// @[@"Hello", NSApp, [NSNumber numberWithInt:42]];
142 class ObjCArrayLiteral : public Expr {
143 unsigned NumElements;
145 ObjCMethodDecl *ArrayWithObjectsMethod;
147 ObjCArrayLiteral(ArrayRef<Expr *> Elements,
148 QualType T, ObjCMethodDecl * Method,
151 explicit ObjCArrayLiteral(EmptyShell Empty, unsigned NumElements)
152 : Expr(ObjCArrayLiteralClass, Empty), NumElements(NumElements) {}
155 static ObjCArrayLiteral *Create(const ASTContext &C,
156 ArrayRef<Expr *> Elements,
157 QualType T, ObjCMethodDecl * Method,
160 static ObjCArrayLiteral *CreateEmpty(const ASTContext &C,
161 unsigned NumElements);
163 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
164 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
165 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
167 static bool classof(const Stmt *T) {
168 return T->getStmtClass() == ObjCArrayLiteralClass;
171 /// \brief Retrieve elements of array of literals.
172 Expr **getElements() { return reinterpret_cast<Expr **>(this + 1); }
174 /// \brief Retrieve elements of array of literals.
175 const Expr * const *getElements() const {
176 return reinterpret_cast<const Expr * const*>(this + 1);
179 /// getNumElements - Return number of elements of objective-c array literal.
180 unsigned getNumElements() const { return NumElements; }
182 /// getExpr - Return the Expr at the specified index.
183 Expr *getElement(unsigned Index) {
184 assert((Index < NumElements) && "Arg access out of range!");
185 return cast<Expr>(getElements()[Index]);
187 const Expr *getElement(unsigned Index) const {
188 assert((Index < NumElements) && "Arg access out of range!");
189 return cast<Expr>(getElements()[Index]);
192 ObjCMethodDecl *getArrayWithObjectsMethod() const {
193 return ArrayWithObjectsMethod;
197 child_range children() {
198 return child_range((Stmt **)getElements(),
199 (Stmt **)getElements() + NumElements);
202 friend class ASTStmtReader;
205 /// \brief An element in an Objective-C dictionary literal.
207 struct ObjCDictionaryElement {
208 /// \brief The key for the dictionary element.
211 /// \brief The value of the dictionary element.
214 /// \brief The location of the ellipsis, if this is a pack expansion.
215 SourceLocation EllipsisLoc;
217 /// \brief The number of elements this pack expansion will expand to, if
218 /// this is a pack expansion and is known.
219 Optional<unsigned> NumExpansions;
221 /// \brief Determines whether this dictionary element is a pack expansion.
222 bool isPackExpansion() const { return EllipsisLoc.isValid(); }
224 } // end namespace clang
227 template <> struct isPodLike<clang::ObjCDictionaryElement> : std::true_type {};
231 /// ObjCDictionaryLiteral - AST node to represent objective-c dictionary
232 /// literals; as in: @{@"name" : NSUserName(), @"date" : [NSDate date] };
233 class ObjCDictionaryLiteral : public Expr {
234 /// \brief Key/value pair used to store the key and value of a given element.
236 /// Objects of this type are stored directly after the expression.
237 struct KeyValuePair {
242 /// \brief Data that describes an element that is a pack expansion, used if any
243 /// of the elements in the dictionary literal are pack expansions.
244 struct ExpansionData {
245 /// \brief The location of the ellipsis, if this element is a pack
247 SourceLocation EllipsisLoc;
249 /// \brief If non-zero, the number of elements that this pack
250 /// expansion will expand to (+1).
251 unsigned NumExpansionsPlusOne;
254 /// \brief The number of elements in this dictionary literal.
255 unsigned NumElements : 31;
257 /// \brief Determine whether this dictionary literal has any pack expansions.
259 /// If the dictionary literal has pack expansions, then there will
260 /// be an array of pack expansion data following the array of
261 /// key/value pairs, which provide the locations of the ellipses (if
262 /// any) and number of elements in the expansion (if known). If
263 /// there are no pack expansions, we optimize away this storage.
264 unsigned HasPackExpansions : 1;
267 ObjCMethodDecl *DictWithObjectsMethod;
269 ObjCDictionaryLiteral(ArrayRef<ObjCDictionaryElement> VK,
270 bool HasPackExpansions,
271 QualType T, ObjCMethodDecl *method,
274 explicit ObjCDictionaryLiteral(EmptyShell Empty, unsigned NumElements,
275 bool HasPackExpansions)
276 : Expr(ObjCDictionaryLiteralClass, Empty), NumElements(NumElements),
277 HasPackExpansions(HasPackExpansions) {}
279 KeyValuePair *getKeyValues() {
280 return reinterpret_cast<KeyValuePair *>(this + 1);
283 const KeyValuePair *getKeyValues() const {
284 return reinterpret_cast<const KeyValuePair *>(this + 1);
287 ExpansionData *getExpansionData() {
288 if (!HasPackExpansions)
291 return reinterpret_cast<ExpansionData *>(getKeyValues() + NumElements);
294 const ExpansionData *getExpansionData() const {
295 if (!HasPackExpansions)
298 return reinterpret_cast<const ExpansionData *>(getKeyValues()+NumElements);
302 static ObjCDictionaryLiteral *Create(const ASTContext &C,
303 ArrayRef<ObjCDictionaryElement> VK,
304 bool HasPackExpansions,
305 QualType T, ObjCMethodDecl *method,
308 static ObjCDictionaryLiteral *CreateEmpty(const ASTContext &C,
309 unsigned NumElements,
310 bool HasPackExpansions);
312 /// getNumElements - Return number of elements of objective-c dictionary
314 unsigned getNumElements() const { return NumElements; }
316 ObjCDictionaryElement getKeyValueElement(unsigned Index) const {
317 assert((Index < NumElements) && "Arg access out of range!");
318 const KeyValuePair &KV = getKeyValues()[Index];
319 ObjCDictionaryElement Result = { KV.Key, KV.Value, SourceLocation(), None };
320 if (HasPackExpansions) {
321 const ExpansionData &Expansion = getExpansionData()[Index];
322 Result.EllipsisLoc = Expansion.EllipsisLoc;
323 if (Expansion.NumExpansionsPlusOne > 0)
324 Result.NumExpansions = Expansion.NumExpansionsPlusOne - 1;
329 ObjCMethodDecl *getDictWithObjectsMethod() const
330 { return DictWithObjectsMethod; }
332 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
333 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
334 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
336 static bool classof(const Stmt *T) {
337 return T->getStmtClass() == ObjCDictionaryLiteralClass;
341 child_range children() {
342 // Note: we're taking advantage of the layout of the KeyValuePair struct
343 // here. If that struct changes, this code will need to change as well.
344 return child_range(reinterpret_cast<Stmt **>(this + 1),
345 reinterpret_cast<Stmt **>(this + 1) + NumElements * 2);
348 friend class ASTStmtReader;
349 friend class ASTStmtWriter;
353 /// ObjCEncodeExpr, used for \@encode in Objective-C. \@encode has the same
354 /// type and behavior as StringLiteral except that the string initializer is
355 /// obtained from ASTContext with the encoding type as an argument.
356 class ObjCEncodeExpr : public Expr {
357 TypeSourceInfo *EncodedType;
358 SourceLocation AtLoc, RParenLoc;
360 ObjCEncodeExpr(QualType T, TypeSourceInfo *EncodedType,
361 SourceLocation at, SourceLocation rp)
362 : Expr(ObjCEncodeExprClass, T, VK_LValue, OK_Ordinary,
363 EncodedType->getType()->isDependentType(),
364 EncodedType->getType()->isDependentType(),
365 EncodedType->getType()->isInstantiationDependentType(),
366 EncodedType->getType()->containsUnexpandedParameterPack()),
367 EncodedType(EncodedType), AtLoc(at), RParenLoc(rp) {}
369 explicit ObjCEncodeExpr(EmptyShell Empty) : Expr(ObjCEncodeExprClass, Empty){}
372 SourceLocation getAtLoc() const { return AtLoc; }
373 void setAtLoc(SourceLocation L) { AtLoc = L; }
374 SourceLocation getRParenLoc() const { return RParenLoc; }
375 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
377 QualType getEncodedType() const { return EncodedType->getType(); }
379 TypeSourceInfo *getEncodedTypeSourceInfo() const { return EncodedType; }
380 void setEncodedTypeSourceInfo(TypeSourceInfo *EncType) {
381 EncodedType = EncType;
384 SourceLocation getLocStart() const LLVM_READONLY { return AtLoc; }
385 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
387 static bool classof(const Stmt *T) {
388 return T->getStmtClass() == ObjCEncodeExprClass;
392 child_range children() { return child_range(); }
395 /// ObjCSelectorExpr used for \@selector in Objective-C.
396 class ObjCSelectorExpr : public Expr {
398 SourceLocation AtLoc, RParenLoc;
400 ObjCSelectorExpr(QualType T, Selector selInfo,
401 SourceLocation at, SourceLocation rp)
402 : Expr(ObjCSelectorExprClass, T, VK_RValue, OK_Ordinary, false, false,
404 SelName(selInfo), AtLoc(at), RParenLoc(rp){}
405 explicit ObjCSelectorExpr(EmptyShell Empty)
406 : Expr(ObjCSelectorExprClass, Empty) {}
408 Selector getSelector() const { return SelName; }
409 void setSelector(Selector S) { SelName = S; }
411 SourceLocation getAtLoc() const { return AtLoc; }
412 SourceLocation getRParenLoc() const { return RParenLoc; }
413 void setAtLoc(SourceLocation L) { AtLoc = L; }
414 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
416 SourceLocation getLocStart() const LLVM_READONLY { return AtLoc; }
417 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
419 /// getNumArgs - Return the number of actual arguments to this call.
420 unsigned getNumArgs() const { return SelName.getNumArgs(); }
422 static bool classof(const Stmt *T) {
423 return T->getStmtClass() == ObjCSelectorExprClass;
427 child_range children() { return child_range(); }
430 /// ObjCProtocolExpr used for protocol expression in Objective-C.
432 /// This is used as: \@protocol(foo), as in:
434 /// [obj conformsToProtocol:@protocol(foo)]
437 /// The return type is "Protocol*".
438 class ObjCProtocolExpr : public Expr {
439 ObjCProtocolDecl *TheProtocol;
440 SourceLocation AtLoc, ProtoLoc, RParenLoc;
442 ObjCProtocolExpr(QualType T, ObjCProtocolDecl *protocol,
443 SourceLocation at, SourceLocation protoLoc, SourceLocation rp)
444 : Expr(ObjCProtocolExprClass, T, VK_RValue, OK_Ordinary, false, false,
446 TheProtocol(protocol), AtLoc(at), ProtoLoc(protoLoc), RParenLoc(rp) {}
447 explicit ObjCProtocolExpr(EmptyShell Empty)
448 : Expr(ObjCProtocolExprClass, Empty) {}
450 ObjCProtocolDecl *getProtocol() const { return TheProtocol; }
451 void setProtocol(ObjCProtocolDecl *P) { TheProtocol = P; }
453 SourceLocation getProtocolIdLoc() const { return ProtoLoc; }
454 SourceLocation getAtLoc() const { return AtLoc; }
455 SourceLocation getRParenLoc() const { return RParenLoc; }
456 void setAtLoc(SourceLocation L) { AtLoc = L; }
457 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
459 SourceLocation getLocStart() const LLVM_READONLY { return AtLoc; }
460 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
462 static bool classof(const Stmt *T) {
463 return T->getStmtClass() == ObjCProtocolExprClass;
467 child_range children() { return child_range(); }
469 friend class ASTStmtReader;
470 friend class ASTStmtWriter;
473 /// ObjCIvarRefExpr - A reference to an ObjC instance variable.
474 class ObjCIvarRefExpr : public Expr {
478 /// OpLoc - This is the location of '.' or '->'
479 SourceLocation OpLoc;
481 bool IsArrow:1; // True if this is "X->F", false if this is "X.F".
482 bool IsFreeIvar:1; // True if ivar reference has no base (self assumed).
485 ObjCIvarRefExpr(ObjCIvarDecl *d, QualType t,
486 SourceLocation l, SourceLocation oploc,
488 bool arrow = false, bool freeIvar = false) :
489 Expr(ObjCIvarRefExprClass, t, VK_LValue,
490 d->isBitField() ? OK_BitField : OK_Ordinary,
491 /*TypeDependent=*/false, base->isValueDependent(),
492 base->isInstantiationDependent(),
493 base->containsUnexpandedParameterPack()),
494 D(d), Base(base), Loc(l), OpLoc(oploc),
495 IsArrow(arrow), IsFreeIvar(freeIvar) {}
497 explicit ObjCIvarRefExpr(EmptyShell Empty)
498 : Expr(ObjCIvarRefExprClass, Empty) {}
500 ObjCIvarDecl *getDecl() { return D; }
501 const ObjCIvarDecl *getDecl() const { return D; }
502 void setDecl(ObjCIvarDecl *d) { D = d; }
504 const Expr *getBase() const { return cast<Expr>(Base); }
505 Expr *getBase() { return cast<Expr>(Base); }
506 void setBase(Expr * base) { Base = base; }
508 bool isArrow() const { return IsArrow; }
509 bool isFreeIvar() const { return IsFreeIvar; }
510 void setIsArrow(bool A) { IsArrow = A; }
511 void setIsFreeIvar(bool A) { IsFreeIvar = A; }
513 SourceLocation getLocation() const { return Loc; }
514 void setLocation(SourceLocation L) { Loc = L; }
516 SourceLocation getLocStart() const LLVM_READONLY {
517 return isFreeIvar() ? Loc : getBase()->getLocStart();
519 SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
521 SourceLocation getOpLoc() const { return OpLoc; }
522 void setOpLoc(SourceLocation L) { OpLoc = L; }
524 static bool classof(const Stmt *T) {
525 return T->getStmtClass() == ObjCIvarRefExprClass;
529 child_range children() { return child_range(&Base, &Base+1); }
532 /// ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC
534 class ObjCPropertyRefExpr : public Expr {
536 /// If the bool is true, this is an implicit property reference; the
537 /// pointer is an (optional) ObjCMethodDecl and Setter may be set.
538 /// if the bool is false, this is an explicit property reference;
539 /// the pointer is an ObjCPropertyDecl and Setter is always null.
540 llvm::PointerIntPair<NamedDecl*, 1, bool> PropertyOrGetter;
542 /// \brief Indicates whether the property reference will result in a message
543 /// to the getter, the setter, or both.
544 /// This applies to both implicit and explicit property references.
545 enum MethodRefFlags {
547 MethodRef_Getter = 0x1,
548 MethodRef_Setter = 0x2
551 /// \brief Contains the Setter method pointer and MethodRefFlags bit flags.
552 llvm::PointerIntPair<ObjCMethodDecl *, 2, unsigned> SetterAndMethodRefFlags;
554 // FIXME: Maybe we should store the property identifier here,
555 // because it's not rederivable from the other data when there's an
556 // implicit property with no getter (because the 'foo' -> 'setFoo:'
557 // transformation is lossy on the first character).
559 SourceLocation IdLoc;
561 /// \brief When the receiver in property access is 'super', this is
562 /// the location of the 'super' keyword. When it's an interface,
563 /// this is that interface.
564 SourceLocation ReceiverLoc;
565 llvm::PointerUnion3<Stmt*, const Type*, ObjCInterfaceDecl*> Receiver;
568 ObjCPropertyRefExpr(ObjCPropertyDecl *PD, QualType t,
569 ExprValueKind VK, ExprObjectKind OK,
570 SourceLocation l, Expr *base)
571 : Expr(ObjCPropertyRefExprClass, t, VK, OK,
572 /*TypeDependent=*/false, base->isValueDependent(),
573 base->isInstantiationDependent(),
574 base->containsUnexpandedParameterPack()),
575 PropertyOrGetter(PD, false), SetterAndMethodRefFlags(),
576 IdLoc(l), ReceiverLoc(), Receiver(base) {
577 assert(t->isSpecificPlaceholderType(BuiltinType::PseudoObject));
580 ObjCPropertyRefExpr(ObjCPropertyDecl *PD, QualType t,
581 ExprValueKind VK, ExprObjectKind OK,
582 SourceLocation l, SourceLocation sl, QualType st)
583 : Expr(ObjCPropertyRefExprClass, t, VK, OK,
584 /*TypeDependent=*/false, false, st->isInstantiationDependentType(),
585 st->containsUnexpandedParameterPack()),
586 PropertyOrGetter(PD, false), SetterAndMethodRefFlags(),
587 IdLoc(l), ReceiverLoc(sl), Receiver(st.getTypePtr()) {
588 assert(t->isSpecificPlaceholderType(BuiltinType::PseudoObject));
591 ObjCPropertyRefExpr(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter,
592 QualType T, ExprValueKind VK, ExprObjectKind OK,
593 SourceLocation IdLoc, Expr *Base)
594 : Expr(ObjCPropertyRefExprClass, T, VK, OK, false,
595 Base->isValueDependent(), Base->isInstantiationDependent(),
596 Base->containsUnexpandedParameterPack()),
597 PropertyOrGetter(Getter, true), SetterAndMethodRefFlags(Setter, 0),
598 IdLoc(IdLoc), ReceiverLoc(), Receiver(Base) {
599 assert(T->isSpecificPlaceholderType(BuiltinType::PseudoObject));
602 ObjCPropertyRefExpr(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter,
603 QualType T, ExprValueKind VK, ExprObjectKind OK,
604 SourceLocation IdLoc,
605 SourceLocation SuperLoc, QualType SuperTy)
606 : Expr(ObjCPropertyRefExprClass, T, VK, OK, false, false, false, false),
607 PropertyOrGetter(Getter, true), SetterAndMethodRefFlags(Setter, 0),
608 IdLoc(IdLoc), ReceiverLoc(SuperLoc), Receiver(SuperTy.getTypePtr()) {
609 assert(T->isSpecificPlaceholderType(BuiltinType::PseudoObject));
612 ObjCPropertyRefExpr(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter,
613 QualType T, ExprValueKind VK, ExprObjectKind OK,
614 SourceLocation IdLoc,
615 SourceLocation ReceiverLoc, ObjCInterfaceDecl *Receiver)
616 : Expr(ObjCPropertyRefExprClass, T, VK, OK, false, false, false, false),
617 PropertyOrGetter(Getter, true), SetterAndMethodRefFlags(Setter, 0),
618 IdLoc(IdLoc), ReceiverLoc(ReceiverLoc), Receiver(Receiver) {
619 assert(T->isSpecificPlaceholderType(BuiltinType::PseudoObject));
622 explicit ObjCPropertyRefExpr(EmptyShell Empty)
623 : Expr(ObjCPropertyRefExprClass, Empty) {}
625 bool isImplicitProperty() const { return PropertyOrGetter.getInt(); }
626 bool isExplicitProperty() const { return !PropertyOrGetter.getInt(); }
628 ObjCPropertyDecl *getExplicitProperty() const {
629 assert(!isImplicitProperty());
630 return cast<ObjCPropertyDecl>(PropertyOrGetter.getPointer());
633 ObjCMethodDecl *getImplicitPropertyGetter() const {
634 assert(isImplicitProperty());
635 return cast_or_null<ObjCMethodDecl>(PropertyOrGetter.getPointer());
638 ObjCMethodDecl *getImplicitPropertySetter() const {
639 assert(isImplicitProperty());
640 return SetterAndMethodRefFlags.getPointer();
643 Selector getGetterSelector() const {
644 if (isImplicitProperty())
645 return getImplicitPropertyGetter()->getSelector();
646 return getExplicitProperty()->getGetterName();
649 Selector getSetterSelector() const {
650 if (isImplicitProperty())
651 return getImplicitPropertySetter()->getSelector();
652 return getExplicitProperty()->getSetterName();
655 /// \brief True if the property reference will result in a message to the
657 /// This applies to both implicit and explicit property references.
658 bool isMessagingGetter() const {
659 return SetterAndMethodRefFlags.getInt() & MethodRef_Getter;
662 /// \brief True if the property reference will result in a message to the
664 /// This applies to both implicit and explicit property references.
665 bool isMessagingSetter() const {
666 return SetterAndMethodRefFlags.getInt() & MethodRef_Setter;
669 void setIsMessagingGetter(bool val = true) {
670 setMethodRefFlag(MethodRef_Getter, val);
673 void setIsMessagingSetter(bool val = true) {
674 setMethodRefFlag(MethodRef_Setter, val);
677 const Expr *getBase() const {
678 return cast<Expr>(Receiver.get<Stmt*>());
681 return cast<Expr>(Receiver.get<Stmt*>());
684 SourceLocation getLocation() const { return IdLoc; }
686 SourceLocation getReceiverLocation() const { return ReceiverLoc; }
687 QualType getSuperReceiverType() const {
688 return QualType(Receiver.get<const Type*>(), 0);
690 QualType getGetterResultType() const {
692 if (isExplicitProperty()) {
693 const ObjCPropertyDecl *PDecl = getExplicitProperty();
694 if (const ObjCMethodDecl *Getter = PDecl->getGetterMethodDecl())
695 ResultType = Getter->getReturnType();
697 ResultType = PDecl->getType();
699 const ObjCMethodDecl *Getter = getImplicitPropertyGetter();
701 ResultType = Getter->getReturnType(); // with reference!
706 QualType getSetterArgType() const {
708 if (isImplicitProperty()) {
709 const ObjCMethodDecl *Setter = getImplicitPropertySetter();
710 ObjCMethodDecl::param_const_iterator P = Setter->param_begin();
711 ArgType = (*P)->getType();
713 if (ObjCPropertyDecl *PDecl = getExplicitProperty())
714 if (const ObjCMethodDecl *Setter = PDecl->getSetterMethodDecl()) {
715 ObjCMethodDecl::param_const_iterator P = Setter->param_begin();
716 ArgType = (*P)->getType();
718 if (ArgType.isNull())
724 ObjCInterfaceDecl *getClassReceiver() const {
725 return Receiver.get<ObjCInterfaceDecl*>();
727 bool isObjectReceiver() const { return Receiver.is<Stmt*>(); }
728 bool isSuperReceiver() const { return Receiver.is<const Type*>(); }
729 bool isClassReceiver() const { return Receiver.is<ObjCInterfaceDecl*>(); }
731 SourceLocation getLocStart() const LLVM_READONLY {
732 return isObjectReceiver() ? getBase()->getLocStart() :getReceiverLocation();
734 SourceLocation getLocEnd() const LLVM_READONLY { return IdLoc; }
736 static bool classof(const Stmt *T) {
737 return T->getStmtClass() == ObjCPropertyRefExprClass;
741 child_range children() {
742 if (Receiver.is<Stmt*>()) {
743 Stmt **begin = reinterpret_cast<Stmt**>(&Receiver); // hack!
744 return child_range(begin, begin+1);
746 return child_range();
750 friend class ASTStmtReader;
751 friend class ASTStmtWriter;
752 void setExplicitProperty(ObjCPropertyDecl *D, unsigned methRefFlags) {
753 PropertyOrGetter.setPointer(D);
754 PropertyOrGetter.setInt(false);
755 SetterAndMethodRefFlags.setPointer(nullptr);
756 SetterAndMethodRefFlags.setInt(methRefFlags);
758 void setImplicitProperty(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter,
759 unsigned methRefFlags) {
760 PropertyOrGetter.setPointer(Getter);
761 PropertyOrGetter.setInt(true);
762 SetterAndMethodRefFlags.setPointer(Setter);
763 SetterAndMethodRefFlags.setInt(methRefFlags);
765 void setBase(Expr *Base) { Receiver = Base; }
766 void setSuperReceiver(QualType T) { Receiver = T.getTypePtr(); }
767 void setClassReceiver(ObjCInterfaceDecl *D) { Receiver = D; }
769 void setLocation(SourceLocation L) { IdLoc = L; }
770 void setReceiverLocation(SourceLocation Loc) { ReceiverLoc = Loc; }
772 void setMethodRefFlag(MethodRefFlags flag, bool val) {
773 unsigned f = SetterAndMethodRefFlags.getInt();
778 SetterAndMethodRefFlags.setInt(f);
782 /// ObjCSubscriptRefExpr - used for array and dictionary subscripting.
783 /// array[4] = array[3]; dictionary[key] = dictionary[alt_key];
785 class ObjCSubscriptRefExpr : public Expr {
786 // Location of ']' in an indexing expression.
787 SourceLocation RBracket;
788 // array/dictionary base expression.
789 // for arrays, this is a numeric expression. For dictionaries, this is
790 // an objective-c object pointer expression.
791 enum { BASE, KEY, END_EXPR };
792 Stmt* SubExprs[END_EXPR];
794 ObjCMethodDecl *GetAtIndexMethodDecl;
796 // For immutable objects this is null. When ObjCSubscriptRefExpr is to read
797 // an indexed object this is null too.
798 ObjCMethodDecl *SetAtIndexMethodDecl;
802 ObjCSubscriptRefExpr(Expr *base, Expr *key, QualType T,
803 ExprValueKind VK, ExprObjectKind OK,
804 ObjCMethodDecl *getMethod,
805 ObjCMethodDecl *setMethod, SourceLocation RB)
806 : Expr(ObjCSubscriptRefExprClass, T, VK, OK,
807 base->isTypeDependent() || key->isTypeDependent(),
808 base->isValueDependent() || key->isValueDependent(),
809 base->isInstantiationDependent() || key->isInstantiationDependent(),
810 (base->containsUnexpandedParameterPack() ||
811 key->containsUnexpandedParameterPack())),
813 GetAtIndexMethodDecl(getMethod),
814 SetAtIndexMethodDecl(setMethod)
815 {SubExprs[BASE] = base; SubExprs[KEY] = key;}
817 explicit ObjCSubscriptRefExpr(EmptyShell Empty)
818 : Expr(ObjCSubscriptRefExprClass, Empty) {}
820 static ObjCSubscriptRefExpr *Create(const ASTContext &C,
822 Expr *key, QualType T,
823 ObjCMethodDecl *getMethod,
824 ObjCMethodDecl *setMethod,
827 SourceLocation getRBracket() const { return RBracket; }
828 void setRBracket(SourceLocation RB) { RBracket = RB; }
830 SourceLocation getLocStart() const LLVM_READONLY {
831 return SubExprs[BASE]->getLocStart();
833 SourceLocation getLocEnd() const LLVM_READONLY { return RBracket; }
835 static bool classof(const Stmt *T) {
836 return T->getStmtClass() == ObjCSubscriptRefExprClass;
839 Expr *getBaseExpr() const { return cast<Expr>(SubExprs[BASE]); }
840 void setBaseExpr(Stmt *S) { SubExprs[BASE] = S; }
842 Expr *getKeyExpr() const { return cast<Expr>(SubExprs[KEY]); }
843 void setKeyExpr(Stmt *S) { SubExprs[KEY] = S; }
845 ObjCMethodDecl *getAtIndexMethodDecl() const {
846 return GetAtIndexMethodDecl;
849 ObjCMethodDecl *setAtIndexMethodDecl() const {
850 return SetAtIndexMethodDecl;
853 bool isArraySubscriptRefExpr() const {
854 return getKeyExpr()->getType()->isIntegralOrEnumerationType();
857 child_range children() {
858 return child_range(SubExprs, SubExprs+END_EXPR);
861 friend class ASTStmtReader;
865 /// \brief An expression that sends a message to the given Objective-C
868 /// The following contains two message send expressions:
871 /// [[NSString alloc] initWithString:@"Hello"]
874 /// The innermost message send invokes the "alloc" class method on the
875 /// NSString class, while the outermost message send invokes the
876 /// "initWithString" instance method on the object returned from
877 /// NSString's "alloc". In all, an Objective-C message send can take
878 /// on four different (although related) forms:
880 /// 1. Send to an object instance.
881 /// 2. Send to a class.
882 /// 3. Send to the superclass instance of the current class.
883 /// 4. Send to the superclass of the current class.
885 /// All four kinds of message sends are modeled by the ObjCMessageExpr
886 /// class, and can be distinguished via \c getReceiverKind(). Example:
888 class ObjCMessageExpr : public Expr {
889 /// \brief Stores either the selector that this message is sending
890 /// to (when \c HasMethod is zero) or an \c ObjCMethodDecl pointer
891 /// referring to the method that we type-checked against.
892 uintptr_t SelectorOrMethod;
894 enum { NumArgsBitWidth = 16 };
896 /// \brief The number of arguments in the message send, not
897 /// including the receiver.
898 unsigned NumArgs : NumArgsBitWidth;
900 void setNumArgs(unsigned Num) {
901 assert((Num >> NumArgsBitWidth) == 0 && "Num of args is out of range!");
905 /// \brief The kind of message send this is, which is one of the
906 /// ReceiverKind values.
908 /// We pad this out to a byte to avoid excessive masking and shifting.
911 /// \brief Whether we have an actual method prototype in \c
912 /// SelectorOrMethod.
914 /// When non-zero, we have a method declaration; otherwise, we just
916 unsigned HasMethod : 1;
918 /// \brief Whether this message send is a "delegate init call",
919 /// i.e. a call of an init method on self from within an init method.
920 unsigned IsDelegateInitCall : 1;
922 /// \brief Whether this message send was implicitly generated by
923 /// the implementation rather than explicitly written by the user.
924 unsigned IsImplicit : 1;
926 /// \brief Whether the locations of the selector identifiers are in a
927 /// "standard" position, a enum SelectorLocationsKind.
928 unsigned SelLocsKind : 2;
930 /// \brief When the message expression is a send to 'super', this is
931 /// the location of the 'super' keyword.
932 SourceLocation SuperLoc;
934 /// \brief The source locations of the open and close square
935 /// brackets ('[' and ']', respectively).
936 SourceLocation LBracLoc, RBracLoc;
938 ObjCMessageExpr(EmptyShell Empty, unsigned NumArgs)
939 : Expr(ObjCMessageExprClass, Empty), SelectorOrMethod(0), Kind(0),
940 HasMethod(0), IsDelegateInitCall(0), IsImplicit(0), SelLocsKind(0) {
944 ObjCMessageExpr(QualType T, ExprValueKind VK,
945 SourceLocation LBracLoc,
946 SourceLocation SuperLoc,
947 bool IsInstanceSuper,
950 ArrayRef<SourceLocation> SelLocs,
951 SelectorLocationsKind SelLocsK,
952 ObjCMethodDecl *Method,
953 ArrayRef<Expr *> Args,
954 SourceLocation RBracLoc,
956 ObjCMessageExpr(QualType T, ExprValueKind VK,
957 SourceLocation LBracLoc,
958 TypeSourceInfo *Receiver,
960 ArrayRef<SourceLocation> SelLocs,
961 SelectorLocationsKind SelLocsK,
962 ObjCMethodDecl *Method,
963 ArrayRef<Expr *> Args,
964 SourceLocation RBracLoc,
966 ObjCMessageExpr(QualType T, ExprValueKind VK,
967 SourceLocation LBracLoc,
970 ArrayRef<SourceLocation> SelLocs,
971 SelectorLocationsKind SelLocsK,
972 ObjCMethodDecl *Method,
973 ArrayRef<Expr *> Args,
974 SourceLocation RBracLoc,
977 void initArgsAndSelLocs(ArrayRef<Expr *> Args,
978 ArrayRef<SourceLocation> SelLocs,
979 SelectorLocationsKind SelLocsK);
981 /// \brief Retrieve the pointer value of the message receiver.
982 void *getReceiverPointer() const {
983 return *const_cast<void **>(
984 reinterpret_cast<const void * const*>(this + 1));
987 /// \brief Set the pointer value of the message receiver.
988 void setReceiverPointer(void *Value) {
989 *reinterpret_cast<void **>(this + 1) = Value;
992 SelectorLocationsKind getSelLocsKind() const {
993 return (SelectorLocationsKind)SelLocsKind;
995 bool hasStandardSelLocs() const {
996 return getSelLocsKind() != SelLoc_NonStandard;
999 /// \brief Get a pointer to the stored selector identifiers locations array.
1000 /// No locations will be stored if HasStandardSelLocs is true.
1001 SourceLocation *getStoredSelLocs() {
1002 return reinterpret_cast<SourceLocation*>(getArgs() + getNumArgs());
1004 const SourceLocation *getStoredSelLocs() const {
1005 return reinterpret_cast<const SourceLocation*>(getArgs() + getNumArgs());
1008 /// \brief Get the number of stored selector identifiers locations.
1009 /// No locations will be stored if HasStandardSelLocs is true.
1010 unsigned getNumStoredSelLocs() const {
1011 if (hasStandardSelLocs())
1013 return getNumSelectorLocs();
1016 static ObjCMessageExpr *alloc(const ASTContext &C,
1017 ArrayRef<Expr *> Args,
1018 SourceLocation RBraceLoc,
1019 ArrayRef<SourceLocation> SelLocs,
1021 SelectorLocationsKind &SelLocsK);
1022 static ObjCMessageExpr *alloc(const ASTContext &C,
1024 unsigned NumStoredSelLocs);
1027 /// \brief The kind of receiver this message is sending to.
1029 /// \brief The receiver is a class.
1031 /// \brief The receiver is an object instance.
1033 /// \brief The receiver is a superclass.
1035 /// \brief The receiver is the instance of the superclass object.
1039 /// \brief Create a message send to super.
1041 /// \param Context The ASTContext in which this expression will be created.
1043 /// \param T The result type of this message.
1045 /// \param VK The value kind of this message. A message returning
1046 /// a l-value or r-value reference will be an l-value or x-value,
1049 /// \param LBracLoc The location of the open square bracket '['.
1051 /// \param SuperLoc The location of the "super" keyword.
1053 /// \param IsInstanceSuper Whether this is an instance "super"
1054 /// message (otherwise, it's a class "super" message).
1056 /// \param Sel The selector used to determine which method gets called.
1058 /// \param Method The Objective-C method against which this message
1059 /// send was type-checked. May be NULL.
1061 /// \param Args The message send arguments.
1063 /// \param RBracLoc The location of the closing square bracket ']'.
1064 static ObjCMessageExpr *Create(const ASTContext &Context, QualType T,
1066 SourceLocation LBracLoc,
1067 SourceLocation SuperLoc,
1068 bool IsInstanceSuper,
1071 ArrayRef<SourceLocation> SelLocs,
1072 ObjCMethodDecl *Method,
1073 ArrayRef<Expr *> Args,
1074 SourceLocation RBracLoc,
1077 /// \brief Create a class message send.
1079 /// \param Context The ASTContext in which this expression will be created.
1081 /// \param T The result type of this message.
1083 /// \param VK The value kind of this message. A message returning
1084 /// a l-value or r-value reference will be an l-value or x-value,
1087 /// \param LBracLoc The location of the open square bracket '['.
1089 /// \param Receiver The type of the receiver, including
1090 /// source-location information.
1092 /// \param Sel The selector used to determine which method gets called.
1094 /// \param Method The Objective-C method against which this message
1095 /// send was type-checked. May be NULL.
1097 /// \param Args The message send arguments.
1099 /// \param RBracLoc The location of the closing square bracket ']'.
1100 static ObjCMessageExpr *Create(const ASTContext &Context, QualType T,
1102 SourceLocation LBracLoc,
1103 TypeSourceInfo *Receiver,
1105 ArrayRef<SourceLocation> SelLocs,
1106 ObjCMethodDecl *Method,
1107 ArrayRef<Expr *> Args,
1108 SourceLocation RBracLoc,
1111 /// \brief Create an instance message send.
1113 /// \param Context The ASTContext in which this expression will be created.
1115 /// \param T The result type of this message.
1117 /// \param VK The value kind of this message. A message returning
1118 /// a l-value or r-value reference will be an l-value or x-value,
1121 /// \param LBracLoc The location of the open square bracket '['.
1123 /// \param Receiver The expression used to produce the object that
1124 /// will receive this message.
1126 /// \param Sel The selector used to determine which method gets called.
1128 /// \param Method The Objective-C method against which this message
1129 /// send was type-checked. May be NULL.
1131 /// \param Args The message send arguments.
1133 /// \param RBracLoc The location of the closing square bracket ']'.
1134 static ObjCMessageExpr *Create(const ASTContext &Context, QualType T,
1136 SourceLocation LBracLoc,
1139 ArrayRef<SourceLocation> SeLocs,
1140 ObjCMethodDecl *Method,
1141 ArrayRef<Expr *> Args,
1142 SourceLocation RBracLoc,
1145 /// \brief Create an empty Objective-C message expression, to be
1146 /// filled in by subsequent calls.
1148 /// \param Context The context in which the message send will be created.
1150 /// \param NumArgs The number of message arguments, not including
1152 static ObjCMessageExpr *CreateEmpty(const ASTContext &Context,
1154 unsigned NumStoredSelLocs);
1156 /// \brief Indicates whether the message send was implicitly
1157 /// generated by the implementation. If false, it was written explicitly
1158 /// in the source code.
1159 bool isImplicit() const { return IsImplicit; }
1161 /// \brief Determine the kind of receiver that this message is being
1163 ReceiverKind getReceiverKind() const { return (ReceiverKind)Kind; }
1165 /// \brief Source range of the receiver.
1166 SourceRange getReceiverRange() const;
1168 /// \brief Determine whether this is an instance message to either a
1169 /// computed object or to super.
1170 bool isInstanceMessage() const {
1171 return getReceiverKind() == Instance || getReceiverKind() == SuperInstance;
1174 /// \brief Determine whether this is an class message to either a
1175 /// specified class or to super.
1176 bool isClassMessage() const {
1177 return getReceiverKind() == Class || getReceiverKind() == SuperClass;
1180 /// \brief Returns the object expression (receiver) for an instance message,
1181 /// or null for a message that is not an instance message.
1182 Expr *getInstanceReceiver() {
1183 if (getReceiverKind() == Instance)
1184 return static_cast<Expr *>(getReceiverPointer());
1188 const Expr *getInstanceReceiver() const {
1189 return const_cast<ObjCMessageExpr*>(this)->getInstanceReceiver();
1192 /// \brief Turn this message send into an instance message that
1193 /// computes the receiver object with the given expression.
1194 void setInstanceReceiver(Expr *rec) {
1196 setReceiverPointer(rec);
1199 /// \brief Returns the type of a class message send, or NULL if the
1200 /// message is not a class message.
1201 QualType getClassReceiver() const {
1202 if (TypeSourceInfo *TSInfo = getClassReceiverTypeInfo())
1203 return TSInfo->getType();
1208 /// \brief Returns a type-source information of a class message
1209 /// send, or NULL if the message is not a class message.
1210 TypeSourceInfo *getClassReceiverTypeInfo() const {
1211 if (getReceiverKind() == Class)
1212 return reinterpret_cast<TypeSourceInfo *>(getReceiverPointer());
1216 void setClassReceiver(TypeSourceInfo *TSInfo) {
1218 setReceiverPointer(TSInfo);
1221 /// \brief Retrieve the location of the 'super' keyword for a class
1222 /// or instance message to 'super', otherwise an invalid source location.
1223 SourceLocation getSuperLoc() const {
1224 if (getReceiverKind() == SuperInstance || getReceiverKind() == SuperClass)
1227 return SourceLocation();
1230 /// \brief Retrieve the receiver type to which this message is being directed.
1232 /// This routine cross-cuts all of the different kinds of message
1233 /// sends to determine what the underlying (statically known) type
1234 /// of the receiver will be; use \c getReceiverKind() to determine
1235 /// whether the message is a class or an instance method, whether it
1236 /// is a send to super or not, etc.
1238 /// \returns The type of the receiver.
1239 QualType getReceiverType() const;
1241 /// \brief Retrieve the Objective-C interface to which this message
1242 /// is being directed, if known.
1244 /// This routine cross-cuts all of the different kinds of message
1245 /// sends to determine what the underlying (statically known) type
1246 /// of the receiver will be; use \c getReceiverKind() to determine
1247 /// whether the message is a class or an instance method, whether it
1248 /// is a send to super or not, etc.
1250 /// \returns The Objective-C interface if known, otherwise NULL.
1251 ObjCInterfaceDecl *getReceiverInterface() const;
1253 /// \brief Retrieve the type referred to by 'super'.
1255 /// The returned type will either be an ObjCInterfaceType (for an
1256 /// class message to super) or an ObjCObjectPointerType that refers
1257 /// to a class (for an instance message to super);
1258 QualType getSuperType() const {
1259 if (getReceiverKind() == SuperInstance || getReceiverKind() == SuperClass)
1260 return QualType::getFromOpaquePtr(getReceiverPointer());
1265 void setSuper(SourceLocation Loc, QualType T, bool IsInstanceSuper) {
1266 Kind = IsInstanceSuper? SuperInstance : SuperClass;
1268 setReceiverPointer(T.getAsOpaquePtr());
1271 Selector getSelector() const;
1273 void setSelector(Selector S) {
1275 SelectorOrMethod = reinterpret_cast<uintptr_t>(S.getAsOpaquePtr());
1278 const ObjCMethodDecl *getMethodDecl() const {
1280 return reinterpret_cast<const ObjCMethodDecl *>(SelectorOrMethod);
1285 ObjCMethodDecl *getMethodDecl() {
1287 return reinterpret_cast<ObjCMethodDecl *>(SelectorOrMethod);
1292 void setMethodDecl(ObjCMethodDecl *MD) {
1294 SelectorOrMethod = reinterpret_cast<uintptr_t>(MD);
1297 ObjCMethodFamily getMethodFamily() const {
1298 if (HasMethod) return getMethodDecl()->getMethodFamily();
1299 return getSelector().getMethodFamily();
1302 /// \brief Return the number of actual arguments in this message,
1303 /// not counting the receiver.
1304 unsigned getNumArgs() const { return NumArgs; }
1306 /// \brief Retrieve the arguments to this message, not including the
1309 return reinterpret_cast<Expr **>(this + 1) + 1;
1311 const Expr * const *getArgs() const {
1312 return reinterpret_cast<const Expr * const *>(this + 1) + 1;
1315 /// getArg - Return the specified argument.
1316 Expr *getArg(unsigned Arg) {
1317 assert(Arg < NumArgs && "Arg access out of range!");
1318 return cast<Expr>(getArgs()[Arg]);
1320 const Expr *getArg(unsigned Arg) const {
1321 assert(Arg < NumArgs && "Arg access out of range!");
1322 return cast<Expr>(getArgs()[Arg]);
1324 /// setArg - Set the specified argument.
1325 void setArg(unsigned Arg, Expr *ArgExpr) {
1326 assert(Arg < NumArgs && "Arg access out of range!");
1327 getArgs()[Arg] = ArgExpr;
1330 /// isDelegateInitCall - Answers whether this message send has been
1331 /// tagged as a "delegate init call", i.e. a call to a method in the
1332 /// -init family on self from within an -init method implementation.
1333 bool isDelegateInitCall() const { return IsDelegateInitCall; }
1334 void setDelegateInitCall(bool isDelegate) { IsDelegateInitCall = isDelegate; }
1336 SourceLocation getLeftLoc() const { return LBracLoc; }
1337 SourceLocation getRightLoc() const { return RBracLoc; }
1339 SourceLocation getSelectorStartLoc() const {
1341 return getLocStart();
1342 return getSelectorLoc(0);
1344 SourceLocation getSelectorLoc(unsigned Index) const {
1345 assert(Index < getNumSelectorLocs() && "Index out of range!");
1346 if (hasStandardSelLocs())
1347 return getStandardSelectorLoc(Index, getSelector(),
1348 getSelLocsKind() == SelLoc_StandardWithSpace,
1349 llvm::makeArrayRef(const_cast<Expr**>(getArgs()),
1352 return getStoredSelLocs()[Index];
1355 void getSelectorLocs(SmallVectorImpl<SourceLocation> &SelLocs) const;
1357 unsigned getNumSelectorLocs() const {
1360 Selector Sel = getSelector();
1361 if (Sel.isUnarySelector())
1363 return Sel.getNumArgs();
1366 void setSourceRange(SourceRange R) {
1367 LBracLoc = R.getBegin();
1368 RBracLoc = R.getEnd();
1370 SourceLocation getLocStart() const LLVM_READONLY { return LBracLoc; }
1371 SourceLocation getLocEnd() const LLVM_READONLY { return RBracLoc; }
1373 static bool classof(const Stmt *T) {
1374 return T->getStmtClass() == ObjCMessageExprClass;
1378 child_range children();
1380 typedef ExprIterator arg_iterator;
1381 typedef ConstExprIterator const_arg_iterator;
1383 arg_iterator arg_begin() { return reinterpret_cast<Stmt **>(getArgs()); }
1384 arg_iterator arg_end() {
1385 return reinterpret_cast<Stmt **>(getArgs() + NumArgs);
1387 const_arg_iterator arg_begin() const {
1388 return reinterpret_cast<Stmt const * const*>(getArgs());
1390 const_arg_iterator arg_end() const {
1391 return reinterpret_cast<Stmt const * const*>(getArgs() + NumArgs);
1394 friend class ASTStmtReader;
1395 friend class ASTStmtWriter;
1398 /// ObjCIsaExpr - Represent X->isa and X.isa when X is an ObjC 'id' type.
1399 /// (similar in spirit to MemberExpr).
1400 class ObjCIsaExpr : public Expr {
1401 /// Base - the expression for the base object pointer.
1404 /// IsaMemberLoc - This is the location of the 'isa'.
1405 SourceLocation IsaMemberLoc;
1407 /// OpLoc - This is the location of '.' or '->'
1408 SourceLocation OpLoc;
1410 /// IsArrow - True if this is "X->F", false if this is "X.F".
1413 ObjCIsaExpr(Expr *base, bool isarrow, SourceLocation l, SourceLocation oploc,
1415 : Expr(ObjCIsaExprClass, ty, VK_LValue, OK_Ordinary,
1416 /*TypeDependent=*/false, base->isValueDependent(),
1417 base->isInstantiationDependent(),
1418 /*ContainsUnexpandedParameterPack=*/false),
1419 Base(base), IsaMemberLoc(l), OpLoc(oploc), IsArrow(isarrow) {}
1421 /// \brief Build an empty expression.
1422 explicit ObjCIsaExpr(EmptyShell Empty) : Expr(ObjCIsaExprClass, Empty) { }
1424 void setBase(Expr *E) { Base = E; }
1425 Expr *getBase() const { return cast<Expr>(Base); }
1427 bool isArrow() const { return IsArrow; }
1428 void setArrow(bool A) { IsArrow = A; }
1430 /// getMemberLoc - Return the location of the "member", in X->F, it is the
1431 /// location of 'F'.
1432 SourceLocation getIsaMemberLoc() const { return IsaMemberLoc; }
1433 void setIsaMemberLoc(SourceLocation L) { IsaMemberLoc = L; }
1435 SourceLocation getOpLoc() const { return OpLoc; }
1436 void setOpLoc(SourceLocation L) { OpLoc = L; }
1438 SourceLocation getLocStart() const LLVM_READONLY {
1439 return getBase()->getLocStart();
1442 SourceLocation getBaseLocEnd() const LLVM_READONLY {
1443 return getBase()->getLocEnd();
1446 SourceLocation getLocEnd() const LLVM_READONLY { return IsaMemberLoc; }
1448 SourceLocation getExprLoc() const LLVM_READONLY { return IsaMemberLoc; }
1450 static bool classof(const Stmt *T) {
1451 return T->getStmtClass() == ObjCIsaExprClass;
1455 child_range children() { return child_range(&Base, &Base+1); }
1459 /// ObjCIndirectCopyRestoreExpr - Represents the passing of a function
1460 /// argument by indirect copy-restore in ARC. This is used to support
1461 /// passing indirect arguments with the wrong lifetime, e.g. when
1462 /// passing the address of a __strong local variable to an 'out'
1463 /// parameter. This expression kind is only valid in an "argument"
1464 /// position to some sort of call expression.
1466 /// The parameter must have type 'pointer to T', and the argument must
1467 /// have type 'pointer to U', where T and U agree except possibly in
1468 /// qualification. If the argument value is null, then a null pointer
1469 /// is passed; otherwise it points to an object A, and:
1470 /// 1. A temporary object B of type T is initialized, either by
1471 /// zero-initialization (used when initializing an 'out' parameter)
1472 /// or copy-initialization (used when initializing an 'inout'
1474 /// 2. The address of the temporary is passed to the function.
1475 /// 3. If the call completes normally, A is move-assigned from B.
1476 /// 4. Finally, A is destroyed immediately.
1478 /// Currently 'T' must be a retainable object lifetime and must be
1479 /// __autoreleasing; this qualifier is ignored when initializing
1481 class ObjCIndirectCopyRestoreExpr : public Expr {
1484 // unsigned ObjCIndirectCopyRestoreBits.ShouldCopy : 1;
1486 friend class ASTReader;
1487 friend class ASTStmtReader;
1489 void setShouldCopy(bool shouldCopy) {
1490 ObjCIndirectCopyRestoreExprBits.ShouldCopy = shouldCopy;
1493 explicit ObjCIndirectCopyRestoreExpr(EmptyShell Empty)
1494 : Expr(ObjCIndirectCopyRestoreExprClass, Empty) { }
1497 ObjCIndirectCopyRestoreExpr(Expr *operand, QualType type, bool shouldCopy)
1498 : Expr(ObjCIndirectCopyRestoreExprClass, type, VK_LValue, OK_Ordinary,
1499 operand->isTypeDependent(), operand->isValueDependent(),
1500 operand->isInstantiationDependent(),
1501 operand->containsUnexpandedParameterPack()),
1503 setShouldCopy(shouldCopy);
1506 Expr *getSubExpr() { return cast<Expr>(Operand); }
1507 const Expr *getSubExpr() const { return cast<Expr>(Operand); }
1509 /// shouldCopy - True if we should do the 'copy' part of the
1510 /// copy-restore. If false, the temporary will be zero-initialized.
1511 bool shouldCopy() const { return ObjCIndirectCopyRestoreExprBits.ShouldCopy; }
1513 child_range children() { return child_range(&Operand, &Operand+1); }
1515 // Source locations are determined by the subexpression.
1516 SourceLocation getLocStart() const LLVM_READONLY {
1517 return Operand->getLocStart();
1519 SourceLocation getLocEnd() const LLVM_READONLY { return Operand->getLocEnd();}
1521 SourceLocation getExprLoc() const LLVM_READONLY {
1522 return getSubExpr()->getExprLoc();
1525 static bool classof(const Stmt *s) {
1526 return s->getStmtClass() == ObjCIndirectCopyRestoreExprClass;
1530 /// \brief An Objective-C "bridged" cast expression, which casts between
1531 /// Objective-C pointers and C pointers, transferring ownership in the process.
1534 /// NSString *str = (__bridge_transfer NSString *)CFCreateString();
1536 class ObjCBridgedCastExpr : public ExplicitCastExpr {
1537 SourceLocation LParenLoc;
1538 SourceLocation BridgeKeywordLoc;
1541 friend class ASTStmtReader;
1542 friend class ASTStmtWriter;
1545 ObjCBridgedCastExpr(SourceLocation LParenLoc, ObjCBridgeCastKind Kind,
1546 CastKind CK, SourceLocation BridgeKeywordLoc,
1547 TypeSourceInfo *TSInfo, Expr *Operand)
1548 : ExplicitCastExpr(ObjCBridgedCastExprClass, TSInfo->getType(), VK_RValue,
1549 CK, Operand, 0, TSInfo),
1550 LParenLoc(LParenLoc), BridgeKeywordLoc(BridgeKeywordLoc), Kind(Kind) { }
1552 /// \brief Construct an empty Objective-C bridged cast.
1553 explicit ObjCBridgedCastExpr(EmptyShell Shell)
1554 : ExplicitCastExpr(ObjCBridgedCastExprClass, Shell, 0) { }
1556 SourceLocation getLParenLoc() const { return LParenLoc; }
1558 /// \brief Determine which kind of bridge is being performed via this cast.
1559 ObjCBridgeCastKind getBridgeKind() const {
1560 return static_cast<ObjCBridgeCastKind>(Kind);
1563 /// \brief Retrieve the kind of bridge being performed as a string.
1564 StringRef getBridgeKindName() const;
1566 /// \brief The location of the bridge keyword.
1567 SourceLocation getBridgeKeywordLoc() const { return BridgeKeywordLoc; }
1569 SourceLocation getLocStart() const LLVM_READONLY { return LParenLoc; }
1570 SourceLocation getLocEnd() const LLVM_READONLY {
1571 return getSubExpr()->getLocEnd();
1574 static bool classof(const Stmt *T) {
1575 return T->getStmtClass() == ObjCBridgedCastExprClass;
1579 } // end namespace clang