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")), @(random()) or @(view.frame)
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);
691 ObjCInterfaceDecl *getClassReceiver() const {
692 return Receiver.get<ObjCInterfaceDecl*>();
694 bool isObjectReceiver() const { return Receiver.is<Stmt*>(); }
695 bool isSuperReceiver() const { return Receiver.is<const Type*>(); }
696 bool isClassReceiver() const { return Receiver.is<ObjCInterfaceDecl*>(); }
698 /// Determine the type of the base, regardless of the kind of receiver.
699 QualType getReceiverType(const ASTContext &ctx) const;
701 SourceLocation getLocStart() const LLVM_READONLY {
702 return isObjectReceiver() ? getBase()->getLocStart() :getReceiverLocation();
704 SourceLocation getLocEnd() const LLVM_READONLY { return IdLoc; }
706 static bool classof(const Stmt *T) {
707 return T->getStmtClass() == ObjCPropertyRefExprClass;
711 child_range children() {
712 if (Receiver.is<Stmt*>()) {
713 Stmt **begin = reinterpret_cast<Stmt**>(&Receiver); // hack!
714 return child_range(begin, begin+1);
716 return child_range();
720 friend class ASTStmtReader;
721 friend class ASTStmtWriter;
722 void setExplicitProperty(ObjCPropertyDecl *D, unsigned methRefFlags) {
723 PropertyOrGetter.setPointer(D);
724 PropertyOrGetter.setInt(false);
725 SetterAndMethodRefFlags.setPointer(nullptr);
726 SetterAndMethodRefFlags.setInt(methRefFlags);
728 void setImplicitProperty(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter,
729 unsigned methRefFlags) {
730 PropertyOrGetter.setPointer(Getter);
731 PropertyOrGetter.setInt(true);
732 SetterAndMethodRefFlags.setPointer(Setter);
733 SetterAndMethodRefFlags.setInt(methRefFlags);
735 void setBase(Expr *Base) { Receiver = Base; }
736 void setSuperReceiver(QualType T) { Receiver = T.getTypePtr(); }
737 void setClassReceiver(ObjCInterfaceDecl *D) { Receiver = D; }
739 void setLocation(SourceLocation L) { IdLoc = L; }
740 void setReceiverLocation(SourceLocation Loc) { ReceiverLoc = Loc; }
742 void setMethodRefFlag(MethodRefFlags flag, bool val) {
743 unsigned f = SetterAndMethodRefFlags.getInt();
748 SetterAndMethodRefFlags.setInt(f);
752 /// ObjCSubscriptRefExpr - used for array and dictionary subscripting.
753 /// array[4] = array[3]; dictionary[key] = dictionary[alt_key];
755 class ObjCSubscriptRefExpr : public Expr {
756 // Location of ']' in an indexing expression.
757 SourceLocation RBracket;
758 // array/dictionary base expression.
759 // for arrays, this is a numeric expression. For dictionaries, this is
760 // an objective-c object pointer expression.
761 enum { BASE, KEY, END_EXPR };
762 Stmt* SubExprs[END_EXPR];
764 ObjCMethodDecl *GetAtIndexMethodDecl;
766 // For immutable objects this is null. When ObjCSubscriptRefExpr is to read
767 // an indexed object this is null too.
768 ObjCMethodDecl *SetAtIndexMethodDecl;
772 ObjCSubscriptRefExpr(Expr *base, Expr *key, QualType T,
773 ExprValueKind VK, ExprObjectKind OK,
774 ObjCMethodDecl *getMethod,
775 ObjCMethodDecl *setMethod, SourceLocation RB)
776 : Expr(ObjCSubscriptRefExprClass, T, VK, OK,
777 base->isTypeDependent() || key->isTypeDependent(),
778 base->isValueDependent() || key->isValueDependent(),
779 base->isInstantiationDependent() || key->isInstantiationDependent(),
780 (base->containsUnexpandedParameterPack() ||
781 key->containsUnexpandedParameterPack())),
783 GetAtIndexMethodDecl(getMethod),
784 SetAtIndexMethodDecl(setMethod)
785 {SubExprs[BASE] = base; SubExprs[KEY] = key;}
787 explicit ObjCSubscriptRefExpr(EmptyShell Empty)
788 : Expr(ObjCSubscriptRefExprClass, Empty) {}
790 static ObjCSubscriptRefExpr *Create(const ASTContext &C,
792 Expr *key, QualType T,
793 ObjCMethodDecl *getMethod,
794 ObjCMethodDecl *setMethod,
797 SourceLocation getRBracket() const { return RBracket; }
798 void setRBracket(SourceLocation RB) { RBracket = RB; }
800 SourceLocation getLocStart() const LLVM_READONLY {
801 return SubExprs[BASE]->getLocStart();
803 SourceLocation getLocEnd() const LLVM_READONLY { return RBracket; }
805 static bool classof(const Stmt *T) {
806 return T->getStmtClass() == ObjCSubscriptRefExprClass;
809 Expr *getBaseExpr() const { return cast<Expr>(SubExprs[BASE]); }
810 void setBaseExpr(Stmt *S) { SubExprs[BASE] = S; }
812 Expr *getKeyExpr() const { return cast<Expr>(SubExprs[KEY]); }
813 void setKeyExpr(Stmt *S) { SubExprs[KEY] = S; }
815 ObjCMethodDecl *getAtIndexMethodDecl() const {
816 return GetAtIndexMethodDecl;
819 ObjCMethodDecl *setAtIndexMethodDecl() const {
820 return SetAtIndexMethodDecl;
823 bool isArraySubscriptRefExpr() const {
824 return getKeyExpr()->getType()->isIntegralOrEnumerationType();
827 child_range children() {
828 return child_range(SubExprs, SubExprs+END_EXPR);
831 friend class ASTStmtReader;
835 /// \brief An expression that sends a message to the given Objective-C
838 /// The following contains two message send expressions:
841 /// [[NSString alloc] initWithString:@"Hello"]
844 /// The innermost message send invokes the "alloc" class method on the
845 /// NSString class, while the outermost message send invokes the
846 /// "initWithString" instance method on the object returned from
847 /// NSString's "alloc". In all, an Objective-C message send can take
848 /// on four different (although related) forms:
850 /// 1. Send to an object instance.
851 /// 2. Send to a class.
852 /// 3. Send to the superclass instance of the current class.
853 /// 4. Send to the superclass of the current class.
855 /// All four kinds of message sends are modeled by the ObjCMessageExpr
856 /// class, and can be distinguished via \c getReceiverKind(). Example:
858 class ObjCMessageExpr : public Expr {
859 /// \brief Stores either the selector that this message is sending
860 /// to (when \c HasMethod is zero) or an \c ObjCMethodDecl pointer
861 /// referring to the method that we type-checked against.
862 uintptr_t SelectorOrMethod;
864 enum { NumArgsBitWidth = 16 };
866 /// \brief The number of arguments in the message send, not
867 /// including the receiver.
868 unsigned NumArgs : NumArgsBitWidth;
870 void setNumArgs(unsigned Num) {
871 assert((Num >> NumArgsBitWidth) == 0 && "Num of args is out of range!");
875 /// \brief The kind of message send this is, which is one of the
876 /// ReceiverKind values.
878 /// We pad this out to a byte to avoid excessive masking and shifting.
881 /// \brief Whether we have an actual method prototype in \c
882 /// SelectorOrMethod.
884 /// When non-zero, we have a method declaration; otherwise, we just
886 unsigned HasMethod : 1;
888 /// \brief Whether this message send is a "delegate init call",
889 /// i.e. a call of an init method on self from within an init method.
890 unsigned IsDelegateInitCall : 1;
892 /// \brief Whether this message send was implicitly generated by
893 /// the implementation rather than explicitly written by the user.
894 unsigned IsImplicit : 1;
896 /// \brief Whether the locations of the selector identifiers are in a
897 /// "standard" position, a enum SelectorLocationsKind.
898 unsigned SelLocsKind : 2;
900 /// \brief When the message expression is a send to 'super', this is
901 /// the location of the 'super' keyword.
902 SourceLocation SuperLoc;
904 /// \brief The source locations of the open and close square
905 /// brackets ('[' and ']', respectively).
906 SourceLocation LBracLoc, RBracLoc;
908 ObjCMessageExpr(EmptyShell Empty, unsigned NumArgs)
909 : Expr(ObjCMessageExprClass, Empty), SelectorOrMethod(0), Kind(0),
910 HasMethod(0), IsDelegateInitCall(0), IsImplicit(0), SelLocsKind(0) {
914 ObjCMessageExpr(QualType T, ExprValueKind VK,
915 SourceLocation LBracLoc,
916 SourceLocation SuperLoc,
917 bool IsInstanceSuper,
920 ArrayRef<SourceLocation> SelLocs,
921 SelectorLocationsKind SelLocsK,
922 ObjCMethodDecl *Method,
923 ArrayRef<Expr *> Args,
924 SourceLocation RBracLoc,
926 ObjCMessageExpr(QualType T, ExprValueKind VK,
927 SourceLocation LBracLoc,
928 TypeSourceInfo *Receiver,
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,
940 ArrayRef<SourceLocation> SelLocs,
941 SelectorLocationsKind SelLocsK,
942 ObjCMethodDecl *Method,
943 ArrayRef<Expr *> Args,
944 SourceLocation RBracLoc,
947 void initArgsAndSelLocs(ArrayRef<Expr *> Args,
948 ArrayRef<SourceLocation> SelLocs,
949 SelectorLocationsKind SelLocsK);
951 /// \brief Retrieve the pointer value of the message receiver.
952 void *getReceiverPointer() const {
953 return *const_cast<void **>(
954 reinterpret_cast<const void * const*>(this + 1));
957 /// \brief Set the pointer value of the message receiver.
958 void setReceiverPointer(void *Value) {
959 *reinterpret_cast<void **>(this + 1) = Value;
962 SelectorLocationsKind getSelLocsKind() const {
963 return (SelectorLocationsKind)SelLocsKind;
965 bool hasStandardSelLocs() const {
966 return getSelLocsKind() != SelLoc_NonStandard;
969 /// \brief Get a pointer to the stored selector identifiers locations array.
970 /// No locations will be stored if HasStandardSelLocs is true.
971 SourceLocation *getStoredSelLocs() {
972 return reinterpret_cast<SourceLocation*>(getArgs() + getNumArgs());
974 const SourceLocation *getStoredSelLocs() const {
975 return reinterpret_cast<const SourceLocation*>(getArgs() + getNumArgs());
978 /// \brief Get the number of stored selector identifiers locations.
979 /// No locations will be stored if HasStandardSelLocs is true.
980 unsigned getNumStoredSelLocs() const {
981 if (hasStandardSelLocs())
983 return getNumSelectorLocs();
986 static ObjCMessageExpr *alloc(const ASTContext &C,
987 ArrayRef<Expr *> Args,
988 SourceLocation RBraceLoc,
989 ArrayRef<SourceLocation> SelLocs,
991 SelectorLocationsKind &SelLocsK);
992 static ObjCMessageExpr *alloc(const ASTContext &C,
994 unsigned NumStoredSelLocs);
997 /// \brief The kind of receiver this message is sending to.
999 /// \brief The receiver is a class.
1001 /// \brief The receiver is an object instance.
1003 /// \brief The receiver is a superclass.
1005 /// \brief The receiver is the instance of the superclass object.
1009 /// \brief Create a message send to super.
1011 /// \param Context The ASTContext in which this expression will be created.
1013 /// \param T The result type of this message.
1015 /// \param VK The value kind of this message. A message returning
1016 /// a l-value or r-value reference will be an l-value or x-value,
1019 /// \param LBracLoc The location of the open square bracket '['.
1021 /// \param SuperLoc The location of the "super" keyword.
1023 /// \param IsInstanceSuper Whether this is an instance "super"
1024 /// message (otherwise, it's a class "super" message).
1026 /// \param Sel The selector used to determine which method gets called.
1028 /// \param Method The Objective-C method against which this message
1029 /// send was type-checked. May be NULL.
1031 /// \param Args The message send arguments.
1033 /// \param RBracLoc The location of the closing square bracket ']'.
1034 static ObjCMessageExpr *Create(const ASTContext &Context, QualType T,
1036 SourceLocation LBracLoc,
1037 SourceLocation SuperLoc,
1038 bool IsInstanceSuper,
1041 ArrayRef<SourceLocation> SelLocs,
1042 ObjCMethodDecl *Method,
1043 ArrayRef<Expr *> Args,
1044 SourceLocation RBracLoc,
1047 /// \brief Create a class message send.
1049 /// \param Context The ASTContext in which this expression will be created.
1051 /// \param T The result type of this message.
1053 /// \param VK The value kind of this message. A message returning
1054 /// a l-value or r-value reference will be an l-value or x-value,
1057 /// \param LBracLoc The location of the open square bracket '['.
1059 /// \param Receiver The type of the receiver, including
1060 /// source-location information.
1062 /// \param Sel The selector used to determine which method gets called.
1064 /// \param Method The Objective-C method against which this message
1065 /// send was type-checked. May be NULL.
1067 /// \param Args The message send arguments.
1069 /// \param RBracLoc The location of the closing square bracket ']'.
1070 static ObjCMessageExpr *Create(const ASTContext &Context, QualType T,
1072 SourceLocation LBracLoc,
1073 TypeSourceInfo *Receiver,
1075 ArrayRef<SourceLocation> SelLocs,
1076 ObjCMethodDecl *Method,
1077 ArrayRef<Expr *> Args,
1078 SourceLocation RBracLoc,
1081 /// \brief Create an instance message send.
1083 /// \param Context The ASTContext in which this expression will be created.
1085 /// \param T The result type of this message.
1087 /// \param VK The value kind of this message. A message returning
1088 /// a l-value or r-value reference will be an l-value or x-value,
1091 /// \param LBracLoc The location of the open square bracket '['.
1093 /// \param Receiver The expression used to produce the object that
1094 /// will receive this message.
1096 /// \param Sel The selector used to determine which method gets called.
1098 /// \param Method The Objective-C method against which this message
1099 /// send was type-checked. May be NULL.
1101 /// \param Args The message send arguments.
1103 /// \param RBracLoc The location of the closing square bracket ']'.
1104 static ObjCMessageExpr *Create(const ASTContext &Context, QualType T,
1106 SourceLocation LBracLoc,
1109 ArrayRef<SourceLocation> SeLocs,
1110 ObjCMethodDecl *Method,
1111 ArrayRef<Expr *> Args,
1112 SourceLocation RBracLoc,
1115 /// \brief Create an empty Objective-C message expression, to be
1116 /// filled in by subsequent calls.
1118 /// \param Context The context in which the message send will be created.
1120 /// \param NumArgs The number of message arguments, not including
1122 static ObjCMessageExpr *CreateEmpty(const ASTContext &Context,
1124 unsigned NumStoredSelLocs);
1126 /// \brief Indicates whether the message send was implicitly
1127 /// generated by the implementation. If false, it was written explicitly
1128 /// in the source code.
1129 bool isImplicit() const { return IsImplicit; }
1131 /// \brief Determine the kind of receiver that this message is being
1133 ReceiverKind getReceiverKind() const { return (ReceiverKind)Kind; }
1135 /// \brief Source range of the receiver.
1136 SourceRange getReceiverRange() const;
1138 /// \brief Determine whether this is an instance message to either a
1139 /// computed object or to super.
1140 bool isInstanceMessage() const {
1141 return getReceiverKind() == Instance || getReceiverKind() == SuperInstance;
1144 /// \brief Determine whether this is an class message to either a
1145 /// specified class or to super.
1146 bool isClassMessage() const {
1147 return getReceiverKind() == Class || getReceiverKind() == SuperClass;
1150 /// \brief Returns the object expression (receiver) for an instance message,
1151 /// or null for a message that is not an instance message.
1152 Expr *getInstanceReceiver() {
1153 if (getReceiverKind() == Instance)
1154 return static_cast<Expr *>(getReceiverPointer());
1158 const Expr *getInstanceReceiver() const {
1159 return const_cast<ObjCMessageExpr*>(this)->getInstanceReceiver();
1162 /// \brief Turn this message send into an instance message that
1163 /// computes the receiver object with the given expression.
1164 void setInstanceReceiver(Expr *rec) {
1166 setReceiverPointer(rec);
1169 /// \brief Returns the type of a class message send, or NULL if the
1170 /// message is not a class message.
1171 QualType getClassReceiver() const {
1172 if (TypeSourceInfo *TSInfo = getClassReceiverTypeInfo())
1173 return TSInfo->getType();
1178 /// \brief Returns a type-source information of a class message
1179 /// send, or NULL if the message is not a class message.
1180 TypeSourceInfo *getClassReceiverTypeInfo() const {
1181 if (getReceiverKind() == Class)
1182 return reinterpret_cast<TypeSourceInfo *>(getReceiverPointer());
1186 void setClassReceiver(TypeSourceInfo *TSInfo) {
1188 setReceiverPointer(TSInfo);
1191 /// \brief Retrieve the location of the 'super' keyword for a class
1192 /// or instance message to 'super', otherwise an invalid source location.
1193 SourceLocation getSuperLoc() const {
1194 if (getReceiverKind() == SuperInstance || getReceiverKind() == SuperClass)
1197 return SourceLocation();
1200 /// \brief Retrieve the receiver type to which this message is being directed.
1202 /// This routine cross-cuts all of the different kinds of message
1203 /// sends to determine what the underlying (statically known) type
1204 /// of the receiver will be; use \c getReceiverKind() to determine
1205 /// whether the message is a class or an instance method, whether it
1206 /// is a send to super or not, etc.
1208 /// \returns The type of the receiver.
1209 QualType getReceiverType() const;
1211 /// \brief Retrieve the Objective-C interface to which this message
1212 /// is being directed, if known.
1214 /// This routine cross-cuts all of the different kinds of message
1215 /// sends to determine what the underlying (statically known) type
1216 /// of the receiver will be; use \c getReceiverKind() to determine
1217 /// whether the message is a class or an instance method, whether it
1218 /// is a send to super or not, etc.
1220 /// \returns The Objective-C interface if known, otherwise NULL.
1221 ObjCInterfaceDecl *getReceiverInterface() const;
1223 /// \brief Retrieve the type referred to by 'super'.
1225 /// The returned type will either be an ObjCInterfaceType (for an
1226 /// class message to super) or an ObjCObjectPointerType that refers
1227 /// to a class (for an instance message to super);
1228 QualType getSuperType() const {
1229 if (getReceiverKind() == SuperInstance || getReceiverKind() == SuperClass)
1230 return QualType::getFromOpaquePtr(getReceiverPointer());
1235 void setSuper(SourceLocation Loc, QualType T, bool IsInstanceSuper) {
1236 Kind = IsInstanceSuper? SuperInstance : SuperClass;
1238 setReceiverPointer(T.getAsOpaquePtr());
1241 Selector getSelector() const;
1243 void setSelector(Selector S) {
1245 SelectorOrMethod = reinterpret_cast<uintptr_t>(S.getAsOpaquePtr());
1248 const ObjCMethodDecl *getMethodDecl() const {
1250 return reinterpret_cast<const ObjCMethodDecl *>(SelectorOrMethod);
1255 ObjCMethodDecl *getMethodDecl() {
1257 return reinterpret_cast<ObjCMethodDecl *>(SelectorOrMethod);
1262 void setMethodDecl(ObjCMethodDecl *MD) {
1264 SelectorOrMethod = reinterpret_cast<uintptr_t>(MD);
1267 ObjCMethodFamily getMethodFamily() const {
1268 if (HasMethod) return getMethodDecl()->getMethodFamily();
1269 return getSelector().getMethodFamily();
1272 /// \brief Return the number of actual arguments in this message,
1273 /// not counting the receiver.
1274 unsigned getNumArgs() const { return NumArgs; }
1276 /// \brief Retrieve the arguments to this message, not including the
1279 return reinterpret_cast<Expr **>(this + 1) + 1;
1281 const Expr * const *getArgs() const {
1282 return reinterpret_cast<const Expr * const *>(this + 1) + 1;
1285 /// getArg - Return the specified argument.
1286 Expr *getArg(unsigned Arg) {
1287 assert(Arg < NumArgs && "Arg access out of range!");
1288 return cast<Expr>(getArgs()[Arg]);
1290 const Expr *getArg(unsigned Arg) const {
1291 assert(Arg < NumArgs && "Arg access out of range!");
1292 return cast<Expr>(getArgs()[Arg]);
1294 /// setArg - Set the specified argument.
1295 void setArg(unsigned Arg, Expr *ArgExpr) {
1296 assert(Arg < NumArgs && "Arg access out of range!");
1297 getArgs()[Arg] = ArgExpr;
1300 /// isDelegateInitCall - Answers whether this message send has been
1301 /// tagged as a "delegate init call", i.e. a call to a method in the
1302 /// -init family on self from within an -init method implementation.
1303 bool isDelegateInitCall() const { return IsDelegateInitCall; }
1304 void setDelegateInitCall(bool isDelegate) { IsDelegateInitCall = isDelegate; }
1306 SourceLocation getLeftLoc() const { return LBracLoc; }
1307 SourceLocation getRightLoc() const { return RBracLoc; }
1309 SourceLocation getSelectorStartLoc() const {
1311 return getLocStart();
1312 return getSelectorLoc(0);
1314 SourceLocation getSelectorLoc(unsigned Index) const {
1315 assert(Index < getNumSelectorLocs() && "Index out of range!");
1316 if (hasStandardSelLocs())
1317 return getStandardSelectorLoc(Index, getSelector(),
1318 getSelLocsKind() == SelLoc_StandardWithSpace,
1319 llvm::makeArrayRef(const_cast<Expr**>(getArgs()),
1322 return getStoredSelLocs()[Index];
1325 void getSelectorLocs(SmallVectorImpl<SourceLocation> &SelLocs) const;
1327 unsigned getNumSelectorLocs() const {
1330 Selector Sel = getSelector();
1331 if (Sel.isUnarySelector())
1333 return Sel.getNumArgs();
1336 void setSourceRange(SourceRange R) {
1337 LBracLoc = R.getBegin();
1338 RBracLoc = R.getEnd();
1340 SourceLocation getLocStart() const LLVM_READONLY { return LBracLoc; }
1341 SourceLocation getLocEnd() const LLVM_READONLY { return RBracLoc; }
1343 static bool classof(const Stmt *T) {
1344 return T->getStmtClass() == ObjCMessageExprClass;
1348 child_range children();
1350 typedef ExprIterator arg_iterator;
1351 typedef ConstExprIterator const_arg_iterator;
1353 arg_iterator arg_begin() { return reinterpret_cast<Stmt **>(getArgs()); }
1354 arg_iterator arg_end() {
1355 return reinterpret_cast<Stmt **>(getArgs() + NumArgs);
1357 const_arg_iterator arg_begin() const {
1358 return reinterpret_cast<Stmt const * const*>(getArgs());
1360 const_arg_iterator arg_end() const {
1361 return reinterpret_cast<Stmt const * const*>(getArgs() + NumArgs);
1364 friend class ASTStmtReader;
1365 friend class ASTStmtWriter;
1368 /// ObjCIsaExpr - Represent X->isa and X.isa when X is an ObjC 'id' type.
1369 /// (similar in spirit to MemberExpr).
1370 class ObjCIsaExpr : public Expr {
1371 /// Base - the expression for the base object pointer.
1374 /// IsaMemberLoc - This is the location of the 'isa'.
1375 SourceLocation IsaMemberLoc;
1377 /// OpLoc - This is the location of '.' or '->'
1378 SourceLocation OpLoc;
1380 /// IsArrow - True if this is "X->F", false if this is "X.F".
1383 ObjCIsaExpr(Expr *base, bool isarrow, SourceLocation l, SourceLocation oploc,
1385 : Expr(ObjCIsaExprClass, ty, VK_LValue, OK_Ordinary,
1386 /*TypeDependent=*/false, base->isValueDependent(),
1387 base->isInstantiationDependent(),
1388 /*ContainsUnexpandedParameterPack=*/false),
1389 Base(base), IsaMemberLoc(l), OpLoc(oploc), IsArrow(isarrow) {}
1391 /// \brief Build an empty expression.
1392 explicit ObjCIsaExpr(EmptyShell Empty) : Expr(ObjCIsaExprClass, Empty) { }
1394 void setBase(Expr *E) { Base = E; }
1395 Expr *getBase() const { return cast<Expr>(Base); }
1397 bool isArrow() const { return IsArrow; }
1398 void setArrow(bool A) { IsArrow = A; }
1400 /// getMemberLoc - Return the location of the "member", in X->F, it is the
1401 /// location of 'F'.
1402 SourceLocation getIsaMemberLoc() const { return IsaMemberLoc; }
1403 void setIsaMemberLoc(SourceLocation L) { IsaMemberLoc = L; }
1405 SourceLocation getOpLoc() const { return OpLoc; }
1406 void setOpLoc(SourceLocation L) { OpLoc = L; }
1408 SourceLocation getLocStart() const LLVM_READONLY {
1409 return getBase()->getLocStart();
1412 SourceLocation getBaseLocEnd() const LLVM_READONLY {
1413 return getBase()->getLocEnd();
1416 SourceLocation getLocEnd() const LLVM_READONLY { return IsaMemberLoc; }
1418 SourceLocation getExprLoc() const LLVM_READONLY { return IsaMemberLoc; }
1420 static bool classof(const Stmt *T) {
1421 return T->getStmtClass() == ObjCIsaExprClass;
1425 child_range children() { return child_range(&Base, &Base+1); }
1429 /// ObjCIndirectCopyRestoreExpr - Represents the passing of a function
1430 /// argument by indirect copy-restore in ARC. This is used to support
1431 /// passing indirect arguments with the wrong lifetime, e.g. when
1432 /// passing the address of a __strong local variable to an 'out'
1433 /// parameter. This expression kind is only valid in an "argument"
1434 /// position to some sort of call expression.
1436 /// The parameter must have type 'pointer to T', and the argument must
1437 /// have type 'pointer to U', where T and U agree except possibly in
1438 /// qualification. If the argument value is null, then a null pointer
1439 /// is passed; otherwise it points to an object A, and:
1440 /// 1. A temporary object B of type T is initialized, either by
1441 /// zero-initialization (used when initializing an 'out' parameter)
1442 /// or copy-initialization (used when initializing an 'inout'
1444 /// 2. The address of the temporary is passed to the function.
1445 /// 3. If the call completes normally, A is move-assigned from B.
1446 /// 4. Finally, A is destroyed immediately.
1448 /// Currently 'T' must be a retainable object lifetime and must be
1449 /// __autoreleasing; this qualifier is ignored when initializing
1451 class ObjCIndirectCopyRestoreExpr : public Expr {
1454 // unsigned ObjCIndirectCopyRestoreBits.ShouldCopy : 1;
1456 friend class ASTReader;
1457 friend class ASTStmtReader;
1459 void setShouldCopy(bool shouldCopy) {
1460 ObjCIndirectCopyRestoreExprBits.ShouldCopy = shouldCopy;
1463 explicit ObjCIndirectCopyRestoreExpr(EmptyShell Empty)
1464 : Expr(ObjCIndirectCopyRestoreExprClass, Empty) { }
1467 ObjCIndirectCopyRestoreExpr(Expr *operand, QualType type, bool shouldCopy)
1468 : Expr(ObjCIndirectCopyRestoreExprClass, type, VK_LValue, OK_Ordinary,
1469 operand->isTypeDependent(), operand->isValueDependent(),
1470 operand->isInstantiationDependent(),
1471 operand->containsUnexpandedParameterPack()),
1473 setShouldCopy(shouldCopy);
1476 Expr *getSubExpr() { return cast<Expr>(Operand); }
1477 const Expr *getSubExpr() const { return cast<Expr>(Operand); }
1479 /// shouldCopy - True if we should do the 'copy' part of the
1480 /// copy-restore. If false, the temporary will be zero-initialized.
1481 bool shouldCopy() const { return ObjCIndirectCopyRestoreExprBits.ShouldCopy; }
1483 child_range children() { return child_range(&Operand, &Operand+1); }
1485 // Source locations are determined by the subexpression.
1486 SourceLocation getLocStart() const LLVM_READONLY {
1487 return Operand->getLocStart();
1489 SourceLocation getLocEnd() const LLVM_READONLY { return Operand->getLocEnd();}
1491 SourceLocation getExprLoc() const LLVM_READONLY {
1492 return getSubExpr()->getExprLoc();
1495 static bool classof(const Stmt *s) {
1496 return s->getStmtClass() == ObjCIndirectCopyRestoreExprClass;
1500 /// \brief An Objective-C "bridged" cast expression, which casts between
1501 /// Objective-C pointers and C pointers, transferring ownership in the process.
1504 /// NSString *str = (__bridge_transfer NSString *)CFCreateString();
1506 class ObjCBridgedCastExpr : public ExplicitCastExpr {
1507 SourceLocation LParenLoc;
1508 SourceLocation BridgeKeywordLoc;
1511 friend class ASTStmtReader;
1512 friend class ASTStmtWriter;
1515 ObjCBridgedCastExpr(SourceLocation LParenLoc, ObjCBridgeCastKind Kind,
1516 CastKind CK, SourceLocation BridgeKeywordLoc,
1517 TypeSourceInfo *TSInfo, Expr *Operand)
1518 : ExplicitCastExpr(ObjCBridgedCastExprClass, TSInfo->getType(), VK_RValue,
1519 CK, Operand, 0, TSInfo),
1520 LParenLoc(LParenLoc), BridgeKeywordLoc(BridgeKeywordLoc), Kind(Kind) { }
1522 /// \brief Construct an empty Objective-C bridged cast.
1523 explicit ObjCBridgedCastExpr(EmptyShell Shell)
1524 : ExplicitCastExpr(ObjCBridgedCastExprClass, Shell, 0) { }
1526 SourceLocation getLParenLoc() const { return LParenLoc; }
1528 /// \brief Determine which kind of bridge is being performed via this cast.
1529 ObjCBridgeCastKind getBridgeKind() const {
1530 return static_cast<ObjCBridgeCastKind>(Kind);
1533 /// \brief Retrieve the kind of bridge being performed as a string.
1534 StringRef getBridgeKindName() const;
1536 /// \brief The location of the bridge keyword.
1537 SourceLocation getBridgeKeywordLoc() const { return BridgeKeywordLoc; }
1539 SourceLocation getLocStart() const LLVM_READONLY { return LParenLoc; }
1540 SourceLocation getLocEnd() const LLVM_READONLY {
1541 return getSubExpr()->getLocEnd();
1544 static bool classof(const Stmt *T) {
1545 return T->getStmtClass() == ObjCBridgedCastExprClass;
1549 } // end namespace clang