]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/AST/ExprObjC.h
Update llvm, clang and lldb to 3.7.0 release.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / AST / ExprObjC.h
1 //===--- ExprObjC.h - Classes for representing ObjC expressions -*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 //  This file defines the ExprObjC interface and subclasses.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_CLANG_AST_EXPROBJC_H
15 #define LLVM_CLANG_AST_EXPROBJC_H
16
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"
22
23 namespace clang {
24   class IdentifierInfo;
25   class ASTContext;
26
27 /// ObjCStringLiteral, used for Objective-C string literals
28 /// i.e. @"foo".
29 class ObjCStringLiteral : public Expr {
30   Stmt *String;
31   SourceLocation AtLoc;
32 public:
33   ObjCStringLiteral(StringLiteral *SL, QualType T, SourceLocation L)
34     : Expr(ObjCStringLiteralClass, T, VK_RValue, OK_Ordinary, false, false,
35            false, false),
36       String(SL), AtLoc(L) {}
37   explicit ObjCStringLiteral(EmptyShell Empty)
38     : Expr(ObjCStringLiteralClass, Empty) {}
39
40   StringLiteral *getString() { return cast<StringLiteral>(String); }
41   const StringLiteral *getString() const { return cast<StringLiteral>(String); }
42   void setString(StringLiteral *S) { String = S; }
43
44   SourceLocation getAtLoc() const { return AtLoc; }
45   void setAtLoc(SourceLocation L) { AtLoc = L; }
46
47   SourceLocation getLocStart() const LLVM_READONLY { return AtLoc; }
48   SourceLocation getLocEnd() const LLVM_READONLY { return String->getLocEnd(); }
49
50   static bool classof(const Stmt *T) {
51     return T->getStmtClass() == ObjCStringLiteralClass;
52   }
53
54   // Iterators
55   child_range children() { return child_range(&String, &String+1); }
56 };
57
58 /// ObjCBoolLiteralExpr - Objective-C Boolean Literal.
59 ///
60 class ObjCBoolLiteralExpr : public Expr {
61   bool Value;
62   SourceLocation Loc;
63 public:
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) {}
67     
68   explicit ObjCBoolLiteralExpr(EmptyShell Empty)
69   : Expr(ObjCBoolLiteralExprClass, Empty) { }
70     
71   bool getValue() const { return Value; }
72   void setValue(bool V) { Value = V; }
73     
74   SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
75   SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
76
77   SourceLocation getLocation() const { return Loc; }
78   void setLocation(SourceLocation L) { Loc = L; }
79     
80   static bool classof(const Stmt *T) {
81     return T->getStmtClass() == ObjCBoolLiteralExprClass;
82   }
83     
84   // Iterators
85   child_range children() { return child_range(); }
86 };
87
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 {
93   Stmt *SubExpr;
94   ObjCMethodDecl *BoxingMethod;
95   SourceRange Range;
96 public:
97   ObjCBoxedExpr(Expr *E, QualType T, ObjCMethodDecl *method,
98                      SourceRange R)
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) {}
105   
106   Expr *getSubExpr() { return cast<Expr>(SubExpr); }
107   const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
108   
109   ObjCMethodDecl *getBoxingMethod() const {
110     return BoxingMethod; 
111   }
112   
113   SourceLocation getAtLoc() const { return Range.getBegin(); }
114   
115   SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
116   SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
117   SourceRange getSourceRange() const LLVM_READONLY {
118     return Range;
119   }
120   
121   static bool classof(const Stmt *T) {
122     return T->getStmtClass() == ObjCBoxedExprClass;
123   }
124   
125   // Iterators
126   child_range children() { return child_range(&SubExpr, &SubExpr+1); }
127
128   typedef ConstExprIterator const_arg_iterator;
129
130   const_arg_iterator arg_begin() const {
131     return reinterpret_cast<Stmt const * const*>(&SubExpr);
132   }
133   const_arg_iterator arg_end() const {
134     return reinterpret_cast<Stmt const * const*>(&SubExpr + 1);
135   }
136   
137   friend class ASTStmtReader;
138 };
139
140 /// ObjCArrayLiteral - used for objective-c array containers; as in:
141 /// @[@"Hello", NSApp, [NSNumber numberWithInt:42]];
142 class ObjCArrayLiteral : public Expr {
143   unsigned NumElements;
144   SourceRange Range;
145   ObjCMethodDecl *ArrayWithObjectsMethod;
146   
147   ObjCArrayLiteral(ArrayRef<Expr *> Elements,
148                    QualType T, ObjCMethodDecl * Method,
149                    SourceRange SR);
150   
151   explicit ObjCArrayLiteral(EmptyShell Empty, unsigned NumElements)
152     : Expr(ObjCArrayLiteralClass, Empty), NumElements(NumElements) {}
153
154 public:
155   static ObjCArrayLiteral *Create(const ASTContext &C,
156                                   ArrayRef<Expr *> Elements,
157                                   QualType T, ObjCMethodDecl * Method,
158                                   SourceRange SR);
159
160   static ObjCArrayLiteral *CreateEmpty(const ASTContext &C,
161                                        unsigned NumElements);
162
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; }
166
167   static bool classof(const Stmt *T) {
168       return T->getStmtClass() == ObjCArrayLiteralClass;
169   }
170
171   /// \brief Retrieve elements of array of literals.
172   Expr **getElements() { return reinterpret_cast<Expr **>(this + 1); }
173
174   /// \brief Retrieve elements of array of literals.
175   const Expr * const *getElements() const { 
176     return reinterpret_cast<const Expr * const*>(this + 1); 
177   }
178
179   /// getNumElements - Return number of elements of objective-c array literal.
180   unsigned getNumElements() const { return NumElements; }
181     
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]);
186   }
187   const Expr *getElement(unsigned Index) const {
188     assert((Index < NumElements) && "Arg access out of range!");
189     return cast<Expr>(getElements()[Index]);
190   }
191     
192   ObjCMethodDecl *getArrayWithObjectsMethod() const {
193     return ArrayWithObjectsMethod; 
194   }
195     
196   // Iterators
197   child_range children() { 
198     return child_range((Stmt **)getElements(), 
199                        (Stmt **)getElements() + NumElements);
200   }
201     
202   friend class ASTStmtReader;
203 };
204
205 /// \brief An element in an Objective-C dictionary literal.
206 ///
207 struct ObjCDictionaryElement {
208   /// \brief The key for the dictionary element.
209   Expr *Key;
210   
211   /// \brief The value of the dictionary element.
212   Expr *Value;
213   
214   /// \brief The location of the ellipsis, if this is a pack expansion.
215   SourceLocation EllipsisLoc;
216   
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;
220
221   /// \brief Determines whether this dictionary element is a pack expansion.
222   bool isPackExpansion() const { return EllipsisLoc.isValid(); }
223 };
224 } // end namespace clang
225
226 namespace llvm {
227 template <> struct isPodLike<clang::ObjCDictionaryElement> : std::true_type {};
228 }
229
230 namespace clang {
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.
235   ///
236   /// Objects of this type are stored directly after the expression.
237   struct KeyValuePair {
238     Expr *Key;
239     Expr *Value;
240   };
241   
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
246     /// expansion.
247     SourceLocation EllipsisLoc;
248
249     /// \brief If non-zero, the number of elements that this pack
250     /// expansion will expand to (+1).
251     unsigned NumExpansionsPlusOne;
252   };
253
254   /// \brief The number of elements in this dictionary literal.
255   unsigned NumElements : 31;
256   
257   /// \brief Determine whether this dictionary literal has any pack expansions.
258   ///
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;
265   
266   SourceRange Range;
267   ObjCMethodDecl *DictWithObjectsMethod;
268     
269   ObjCDictionaryLiteral(ArrayRef<ObjCDictionaryElement> VK, 
270                         bool HasPackExpansions,
271                         QualType T, ObjCMethodDecl *method,
272                         SourceRange SR);
273
274   explicit ObjCDictionaryLiteral(EmptyShell Empty, unsigned NumElements,
275                                  bool HasPackExpansions)
276     : Expr(ObjCDictionaryLiteralClass, Empty), NumElements(NumElements),
277       HasPackExpansions(HasPackExpansions) {}
278
279   KeyValuePair *getKeyValues() {
280     return reinterpret_cast<KeyValuePair *>(this + 1);
281   }
282   
283   const KeyValuePair *getKeyValues() const {
284     return reinterpret_cast<const KeyValuePair *>(this + 1);
285   }
286
287   ExpansionData *getExpansionData() {
288     if (!HasPackExpansions)
289       return nullptr;
290     
291     return reinterpret_cast<ExpansionData *>(getKeyValues() + NumElements);
292   }
293
294   const ExpansionData *getExpansionData() const {
295     if (!HasPackExpansions)
296       return nullptr;
297     
298     return reinterpret_cast<const ExpansionData *>(getKeyValues()+NumElements);
299   }
300
301 public:
302   static ObjCDictionaryLiteral *Create(const ASTContext &C,
303                                        ArrayRef<ObjCDictionaryElement> VK, 
304                                        bool HasPackExpansions,
305                                        QualType T, ObjCMethodDecl *method,
306                                        SourceRange SR);
307   
308   static ObjCDictionaryLiteral *CreateEmpty(const ASTContext &C,
309                                             unsigned NumElements,
310                                             bool HasPackExpansions);
311   
312   /// getNumElements - Return number of elements of objective-c dictionary 
313   /// literal.
314   unsigned getNumElements() const { return NumElements; }
315
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;
325     }
326     return Result;
327   }
328     
329   ObjCMethodDecl *getDictWithObjectsMethod() const
330     { return DictWithObjectsMethod; }
331
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; }
335   
336   static bool classof(const Stmt *T) {
337       return T->getStmtClass() == ObjCDictionaryLiteralClass;
338   }
339     
340   // Iterators
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);
346   }
347     
348   friend class ASTStmtReader;
349   friend class ASTStmtWriter;
350 };
351
352
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;
359 public:
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) {}
368
369   explicit ObjCEncodeExpr(EmptyShell Empty) : Expr(ObjCEncodeExprClass, Empty){}
370
371
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; }
376
377   QualType getEncodedType() const { return EncodedType->getType(); }
378
379   TypeSourceInfo *getEncodedTypeSourceInfo() const { return EncodedType; }
380   void setEncodedTypeSourceInfo(TypeSourceInfo *EncType) { 
381     EncodedType = EncType; 
382   }
383
384   SourceLocation getLocStart() const LLVM_READONLY { return AtLoc; }
385   SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
386
387   static bool classof(const Stmt *T) {
388     return T->getStmtClass() == ObjCEncodeExprClass;
389   }
390
391   // Iterators
392   child_range children() { return child_range(); }
393 };
394
395 /// ObjCSelectorExpr used for \@selector in Objective-C.
396 class ObjCSelectorExpr : public Expr {
397   Selector SelName;
398   SourceLocation AtLoc, RParenLoc;
399 public:
400   ObjCSelectorExpr(QualType T, Selector selInfo,
401                    SourceLocation at, SourceLocation rp)
402     : Expr(ObjCSelectorExprClass, T, VK_RValue, OK_Ordinary, false, false, 
403            false, false),
404     SelName(selInfo), AtLoc(at), RParenLoc(rp){}
405   explicit ObjCSelectorExpr(EmptyShell Empty)
406    : Expr(ObjCSelectorExprClass, Empty) {}
407
408   Selector getSelector() const { return SelName; }
409   void setSelector(Selector S) { SelName = S; }
410
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; }
415
416   SourceLocation getLocStart() const LLVM_READONLY { return AtLoc; }
417   SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
418
419   /// getNumArgs - Return the number of actual arguments to this call.
420   unsigned getNumArgs() const { return SelName.getNumArgs(); }
421
422   static bool classof(const Stmt *T) {
423     return T->getStmtClass() == ObjCSelectorExprClass;
424   }
425
426   // Iterators
427   child_range children() { return child_range(); }
428 };
429
430 /// ObjCProtocolExpr used for protocol expression in Objective-C.
431 ///
432 /// This is used as: \@protocol(foo), as in:
433 /// \code
434 ///   [obj conformsToProtocol:@protocol(foo)]
435 /// \endcode
436 ///
437 /// The return type is "Protocol*".
438 class ObjCProtocolExpr : public Expr {
439   ObjCProtocolDecl *TheProtocol;
440   SourceLocation AtLoc, ProtoLoc, RParenLoc;
441 public:
442   ObjCProtocolExpr(QualType T, ObjCProtocolDecl *protocol,
443                  SourceLocation at, SourceLocation protoLoc, SourceLocation rp)
444     : Expr(ObjCProtocolExprClass, T, VK_RValue, OK_Ordinary, false, false,
445            false, false),
446       TheProtocol(protocol), AtLoc(at), ProtoLoc(protoLoc), RParenLoc(rp) {}
447   explicit ObjCProtocolExpr(EmptyShell Empty)
448     : Expr(ObjCProtocolExprClass, Empty) {}
449
450   ObjCProtocolDecl *getProtocol() const { return TheProtocol; }
451   void setProtocol(ObjCProtocolDecl *P) { TheProtocol = P; }
452
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; }
458
459   SourceLocation getLocStart() const LLVM_READONLY { return AtLoc; }
460   SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
461
462   static bool classof(const Stmt *T) {
463     return T->getStmtClass() == ObjCProtocolExprClass;
464   }
465
466   // Iterators
467   child_range children() { return child_range(); }
468
469   friend class ASTStmtReader;
470   friend class ASTStmtWriter;
471 };
472
473 /// ObjCIvarRefExpr - A reference to an ObjC instance variable.
474 class ObjCIvarRefExpr : public Expr {
475   ObjCIvarDecl *D;
476   Stmt *Base;
477   SourceLocation Loc;
478   /// OpLoc - This is the location of '.' or '->'
479   SourceLocation OpLoc;
480   
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).
483
484 public:
485   ObjCIvarRefExpr(ObjCIvarDecl *d, QualType t,
486                   SourceLocation l, SourceLocation oploc,
487                   Expr *base,
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) {}
496
497   explicit ObjCIvarRefExpr(EmptyShell Empty)
498     : Expr(ObjCIvarRefExprClass, Empty) {}
499
500   ObjCIvarDecl *getDecl() { return D; }
501   const ObjCIvarDecl *getDecl() const { return D; }
502   void setDecl(ObjCIvarDecl *d) { D = d; }
503
504   const Expr *getBase() const { return cast<Expr>(Base); }
505   Expr *getBase() { return cast<Expr>(Base); }
506   void setBase(Expr * base) { Base = base; }
507
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; }
512
513   SourceLocation getLocation() const { return Loc; }
514   void setLocation(SourceLocation L) { Loc = L; }
515
516   SourceLocation getLocStart() const LLVM_READONLY {
517     return isFreeIvar() ? Loc : getBase()->getLocStart();
518   }
519   SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
520   
521   SourceLocation getOpLoc() const { return OpLoc; }
522   void setOpLoc(SourceLocation L) { OpLoc = L; }
523
524   static bool classof(const Stmt *T) {
525     return T->getStmtClass() == ObjCIvarRefExprClass;
526   }
527
528   // Iterators
529   child_range children() { return child_range(&Base, &Base+1); }
530 };
531
532 /// ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC
533 /// property.
534 class ObjCPropertyRefExpr : public Expr {
535 private:
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;
541
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 {
546     MethodRef_None = 0,
547     MethodRef_Getter = 0x1,
548     MethodRef_Setter = 0x2
549   };
550
551   /// \brief Contains the Setter method pointer and MethodRefFlags bit flags.
552   llvm::PointerIntPair<ObjCMethodDecl *, 2, unsigned> SetterAndMethodRefFlags;
553
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).
558
559   SourceLocation IdLoc;
560   
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;
566   
567 public:
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));
578   }
579   
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));
589   }
590
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));
600   }
601
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));
610   }
611
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));
620   }
621
622   explicit ObjCPropertyRefExpr(EmptyShell Empty)
623     : Expr(ObjCPropertyRefExprClass, Empty) {}
624
625   bool isImplicitProperty() const { return PropertyOrGetter.getInt(); }
626   bool isExplicitProperty() const { return !PropertyOrGetter.getInt(); }
627
628   ObjCPropertyDecl *getExplicitProperty() const {
629     assert(!isImplicitProperty());
630     return cast<ObjCPropertyDecl>(PropertyOrGetter.getPointer());
631   }
632
633   ObjCMethodDecl *getImplicitPropertyGetter() const {
634     assert(isImplicitProperty());
635     return cast_or_null<ObjCMethodDecl>(PropertyOrGetter.getPointer());
636   }
637
638   ObjCMethodDecl *getImplicitPropertySetter() const {
639     assert(isImplicitProperty());
640     return SetterAndMethodRefFlags.getPointer();
641   }
642
643   Selector getGetterSelector() const {
644     if (isImplicitProperty())
645       return getImplicitPropertyGetter()->getSelector();
646     return getExplicitProperty()->getGetterName();
647   }
648
649   Selector getSetterSelector() const {
650     if (isImplicitProperty())
651       return getImplicitPropertySetter()->getSelector();
652     return getExplicitProperty()->getSetterName();
653   }
654
655   /// \brief True if the property reference will result in a message to the
656   /// getter.
657   /// This applies to both implicit and explicit property references.
658   bool isMessagingGetter() const {
659     return SetterAndMethodRefFlags.getInt() & MethodRef_Getter;
660   }
661
662   /// \brief True if the property reference will result in a message to the
663   /// setter.
664   /// This applies to both implicit and explicit property references.
665   bool isMessagingSetter() const {
666     return SetterAndMethodRefFlags.getInt() & MethodRef_Setter;
667   }
668
669   void setIsMessagingGetter(bool val = true) {
670     setMethodRefFlag(MethodRef_Getter, val);
671   }
672
673   void setIsMessagingSetter(bool val = true) {
674     setMethodRefFlag(MethodRef_Setter, val);
675   }
676
677   const Expr *getBase() const { 
678     return cast<Expr>(Receiver.get<Stmt*>()); 
679   }
680   Expr *getBase() { 
681     return cast<Expr>(Receiver.get<Stmt*>()); 
682   }
683
684   SourceLocation getLocation() const { return IdLoc; }
685   
686   SourceLocation getReceiverLocation() const { return ReceiverLoc; }
687   QualType getSuperReceiverType() const { 
688     return QualType(Receiver.get<const Type*>(), 0); 
689   }
690
691   ObjCInterfaceDecl *getClassReceiver() const {
692     return Receiver.get<ObjCInterfaceDecl*>();
693   }
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*>(); }
697
698   /// Determine the type of the base, regardless of the kind of receiver.
699   QualType getReceiverType(const ASTContext &ctx) const;
700
701   SourceLocation getLocStart() const LLVM_READONLY {
702     return isObjectReceiver() ? getBase()->getLocStart() :getReceiverLocation();
703   }
704   SourceLocation getLocEnd() const LLVM_READONLY { return IdLoc; }
705
706   static bool classof(const Stmt *T) {
707     return T->getStmtClass() == ObjCPropertyRefExprClass;
708   }
709
710   // Iterators
711   child_range children() {
712     if (Receiver.is<Stmt*>()) {
713       Stmt **begin = reinterpret_cast<Stmt**>(&Receiver); // hack!
714       return child_range(begin, begin+1);
715     }
716     return child_range();
717   }
718
719 private:
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);
727   }
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);
734   }
735   void setBase(Expr *Base) { Receiver = Base; }
736   void setSuperReceiver(QualType T) { Receiver = T.getTypePtr(); }
737   void setClassReceiver(ObjCInterfaceDecl *D) { Receiver = D; }
738
739   void setLocation(SourceLocation L) { IdLoc = L; }
740   void setReceiverLocation(SourceLocation Loc) { ReceiverLoc = Loc; }
741
742   void setMethodRefFlag(MethodRefFlags flag, bool val) {
743     unsigned f = SetterAndMethodRefFlags.getInt();
744     if (val)
745       f |= flag;
746     else
747       f &= ~flag;
748     SetterAndMethodRefFlags.setInt(f);
749   }
750 };
751   
752 /// ObjCSubscriptRefExpr - used for array and dictionary subscripting.
753 /// array[4] = array[3]; dictionary[key] = dictionary[alt_key];
754 ///
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];
763   
764   ObjCMethodDecl *GetAtIndexMethodDecl;
765   
766   // For immutable objects this is null. When ObjCSubscriptRefExpr is to read
767   // an indexed object this is null too.
768   ObjCMethodDecl *SetAtIndexMethodDecl;
769   
770 public:
771   
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())),
782       RBracket(RB), 
783   GetAtIndexMethodDecl(getMethod), 
784   SetAtIndexMethodDecl(setMethod) 
785     {SubExprs[BASE] = base; SubExprs[KEY] = key;}
786
787   explicit ObjCSubscriptRefExpr(EmptyShell Empty)
788     : Expr(ObjCSubscriptRefExprClass, Empty) {}
789   
790   static ObjCSubscriptRefExpr *Create(const ASTContext &C,
791                                       Expr *base,
792                                       Expr *key, QualType T, 
793                                       ObjCMethodDecl *getMethod,
794                                       ObjCMethodDecl *setMethod, 
795                                       SourceLocation RB);
796   
797   SourceLocation getRBracket() const { return RBracket; }
798   void setRBracket(SourceLocation RB) { RBracket = RB; }
799
800   SourceLocation getLocStart() const LLVM_READONLY {
801     return SubExprs[BASE]->getLocStart();
802   }
803   SourceLocation getLocEnd() const LLVM_READONLY { return RBracket; }
804
805   static bool classof(const Stmt *T) {
806     return T->getStmtClass() == ObjCSubscriptRefExprClass;
807   }
808   
809   Expr *getBaseExpr() const { return cast<Expr>(SubExprs[BASE]); }
810   void setBaseExpr(Stmt *S) { SubExprs[BASE] = S; }
811   
812   Expr *getKeyExpr() const { return cast<Expr>(SubExprs[KEY]); }
813   void setKeyExpr(Stmt *S) { SubExprs[KEY] = S; }
814   
815   ObjCMethodDecl *getAtIndexMethodDecl() const {
816     return GetAtIndexMethodDecl;
817   }
818  
819   ObjCMethodDecl *setAtIndexMethodDecl() const {
820     return SetAtIndexMethodDecl;
821   }
822   
823   bool isArraySubscriptRefExpr() const {
824     return getKeyExpr()->getType()->isIntegralOrEnumerationType();
825   }
826   
827   child_range children() {
828     return child_range(SubExprs, SubExprs+END_EXPR);
829   }
830 private:
831   friend class ASTStmtReader;
832 };
833   
834
835 /// \brief An expression that sends a message to the given Objective-C
836 /// object or class.
837 ///
838 /// The following contains two message send expressions:
839 ///
840 /// \code
841 ///   [[NSString alloc] initWithString:@"Hello"]
842 /// \endcode
843 ///
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:
849 ///
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.
854 ///
855 /// All four kinds of message sends are modeled by the ObjCMessageExpr
856 /// class, and can be distinguished via \c getReceiverKind(). Example:
857 ///
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;
863
864   enum { NumArgsBitWidth = 16 };
865
866   /// \brief The number of arguments in the message send, not
867   /// including the receiver.
868   unsigned NumArgs : NumArgsBitWidth;
869   
870   void setNumArgs(unsigned Num) {
871     assert((Num >> NumArgsBitWidth) == 0 && "Num of args is out of range!");
872     NumArgs = Num;
873   }
874
875   /// \brief The kind of message send this is, which is one of the
876   /// ReceiverKind values.
877   ///
878   /// We pad this out to a byte to avoid excessive masking and shifting.
879   unsigned Kind : 8;
880
881   /// \brief Whether we have an actual method prototype in \c
882   /// SelectorOrMethod.
883   ///
884   /// When non-zero, we have a method declaration; otherwise, we just
885   /// have a selector.
886   unsigned HasMethod : 1;
887
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;
891
892   /// \brief Whether this message send was implicitly generated by
893   /// the implementation rather than explicitly written by the user.
894   unsigned IsImplicit : 1;
895
896   /// \brief Whether the locations of the selector identifiers are in a
897   /// "standard" position, a enum SelectorLocationsKind.
898   unsigned SelLocsKind : 2;
899
900   /// \brief When the message expression is a send to 'super', this is
901   /// the location of the 'super' keyword.
902   SourceLocation SuperLoc;
903
904   /// \brief The source locations of the open and close square
905   /// brackets ('[' and ']', respectively).
906   SourceLocation LBracLoc, RBracLoc;
907
908   ObjCMessageExpr(EmptyShell Empty, unsigned NumArgs)
909     : Expr(ObjCMessageExprClass, Empty), SelectorOrMethod(0), Kind(0), 
910       HasMethod(0), IsDelegateInitCall(0), IsImplicit(0), SelLocsKind(0) {
911     setNumArgs(NumArgs);
912   }
913
914   ObjCMessageExpr(QualType T, ExprValueKind VK,
915                   SourceLocation LBracLoc,
916                   SourceLocation SuperLoc,
917                   bool IsInstanceSuper,
918                   QualType SuperType,
919                   Selector Sel, 
920                   ArrayRef<SourceLocation> SelLocs,
921                   SelectorLocationsKind SelLocsK,
922                   ObjCMethodDecl *Method,
923                   ArrayRef<Expr *> Args,
924                   SourceLocation RBracLoc,
925                   bool isImplicit);
926   ObjCMessageExpr(QualType T, ExprValueKind VK,
927                   SourceLocation LBracLoc,
928                   TypeSourceInfo *Receiver,
929                   Selector Sel, 
930                   ArrayRef<SourceLocation> SelLocs,
931                   SelectorLocationsKind SelLocsK,
932                   ObjCMethodDecl *Method,
933                   ArrayRef<Expr *> Args,
934                   SourceLocation RBracLoc,
935                   bool isImplicit);
936   ObjCMessageExpr(QualType T, ExprValueKind VK,
937                   SourceLocation LBracLoc,
938                   Expr *Receiver,
939                   Selector Sel, 
940                   ArrayRef<SourceLocation> SelLocs,
941                   SelectorLocationsKind SelLocsK,
942                   ObjCMethodDecl *Method,
943                   ArrayRef<Expr *> Args,
944                   SourceLocation RBracLoc,
945                   bool isImplicit);
946
947   void initArgsAndSelLocs(ArrayRef<Expr *> Args,
948                           ArrayRef<SourceLocation> SelLocs,
949                           SelectorLocationsKind SelLocsK);
950
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));
955   }
956
957   /// \brief Set the pointer value of the message receiver.
958   void setReceiverPointer(void *Value) {
959     *reinterpret_cast<void **>(this + 1) = Value;
960   }
961
962   SelectorLocationsKind getSelLocsKind() const {
963     return (SelectorLocationsKind)SelLocsKind;
964   }
965   bool hasStandardSelLocs() const {
966     return getSelLocsKind() != SelLoc_NonStandard;
967   }
968
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());
973   }
974   const SourceLocation *getStoredSelLocs() const {
975     return reinterpret_cast<const SourceLocation*>(getArgs() + getNumArgs());
976   }
977
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())
982       return 0;
983     return getNumSelectorLocs();
984   }
985
986   static ObjCMessageExpr *alloc(const ASTContext &C,
987                                 ArrayRef<Expr *> Args,
988                                 SourceLocation RBraceLoc,
989                                 ArrayRef<SourceLocation> SelLocs,
990                                 Selector Sel,
991                                 SelectorLocationsKind &SelLocsK);
992   static ObjCMessageExpr *alloc(const ASTContext &C,
993                                 unsigned NumArgs,
994                                 unsigned NumStoredSelLocs);
995
996 public:
997   /// \brief The kind of receiver this message is sending to.
998   enum ReceiverKind {
999     /// \brief The receiver is a class.
1000     Class = 0,
1001     /// \brief The receiver is an object instance.
1002     Instance,
1003     /// \brief The receiver is a superclass.
1004     SuperClass,
1005     /// \brief The receiver is the instance of the superclass object.
1006     SuperInstance
1007   };
1008
1009   /// \brief Create a message send to super.
1010   ///
1011   /// \param Context The ASTContext in which this expression will be created.
1012   ///
1013   /// \param T The result type of this message.
1014   ///
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,
1017   /// respectively.
1018   ///
1019   /// \param LBracLoc The location of the open square bracket '['.
1020   ///
1021   /// \param SuperLoc The location of the "super" keyword.
1022   ///
1023   /// \param IsInstanceSuper Whether this is an instance "super"
1024   /// message (otherwise, it's a class "super" message).
1025   ///
1026   /// \param Sel The selector used to determine which method gets called.
1027   ///
1028   /// \param Method The Objective-C method against which this message
1029   /// send was type-checked. May be NULL.
1030   ///
1031   /// \param Args The message send arguments.
1032   ///
1033   /// \param RBracLoc The location of the closing square bracket ']'.
1034   static ObjCMessageExpr *Create(const ASTContext &Context, QualType T,
1035                                  ExprValueKind VK,
1036                                  SourceLocation LBracLoc,
1037                                  SourceLocation SuperLoc,
1038                                  bool IsInstanceSuper,
1039                                  QualType SuperType,
1040                                  Selector Sel, 
1041                                  ArrayRef<SourceLocation> SelLocs,
1042                                  ObjCMethodDecl *Method,
1043                                  ArrayRef<Expr *> Args,
1044                                  SourceLocation RBracLoc,
1045                                  bool isImplicit);
1046
1047   /// \brief Create a class message send.
1048   ///
1049   /// \param Context The ASTContext in which this expression will be created.
1050   ///
1051   /// \param T The result type of this message.
1052   ///
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,
1055   /// respectively.
1056   ///
1057   /// \param LBracLoc The location of the open square bracket '['.
1058   ///
1059   /// \param Receiver The type of the receiver, including
1060   /// source-location information.
1061   ///
1062   /// \param Sel The selector used to determine which method gets called.
1063   ///
1064   /// \param Method The Objective-C method against which this message
1065   /// send was type-checked. May be NULL.
1066   ///
1067   /// \param Args The message send arguments.
1068   ///
1069   /// \param RBracLoc The location of the closing square bracket ']'.
1070   static ObjCMessageExpr *Create(const ASTContext &Context, QualType T,
1071                                  ExprValueKind VK,
1072                                  SourceLocation LBracLoc,
1073                                  TypeSourceInfo *Receiver,
1074                                  Selector Sel, 
1075                                  ArrayRef<SourceLocation> SelLocs,
1076                                  ObjCMethodDecl *Method,
1077                                  ArrayRef<Expr *> Args,
1078                                  SourceLocation RBracLoc,
1079                                  bool isImplicit);
1080
1081   /// \brief Create an instance message send.
1082   ///
1083   /// \param Context The ASTContext in which this expression will be created.
1084   ///
1085   /// \param T The result type of this message.
1086   ///
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,
1089   /// respectively.
1090   ///
1091   /// \param LBracLoc The location of the open square bracket '['.
1092   ///
1093   /// \param Receiver The expression used to produce the object that
1094   /// will receive this message.
1095   ///
1096   /// \param Sel The selector used to determine which method gets called.
1097   ///
1098   /// \param Method The Objective-C method against which this message
1099   /// send was type-checked. May be NULL.
1100   ///
1101   /// \param Args The message send arguments.
1102   ///
1103   /// \param RBracLoc The location of the closing square bracket ']'.
1104   static ObjCMessageExpr *Create(const ASTContext &Context, QualType T,
1105                                  ExprValueKind VK,
1106                                  SourceLocation LBracLoc,
1107                                  Expr *Receiver,
1108                                  Selector Sel, 
1109                                  ArrayRef<SourceLocation> SeLocs,
1110                                  ObjCMethodDecl *Method,
1111                                  ArrayRef<Expr *> Args,
1112                                  SourceLocation RBracLoc,
1113                                  bool isImplicit);
1114
1115   /// \brief Create an empty Objective-C message expression, to be
1116   /// filled in by subsequent calls.
1117   ///
1118   /// \param Context The context in which the message send will be created.
1119   ///
1120   /// \param NumArgs The number of message arguments, not including
1121   /// the receiver.
1122   static ObjCMessageExpr *CreateEmpty(const ASTContext &Context,
1123                                       unsigned NumArgs,
1124                                       unsigned NumStoredSelLocs);
1125
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; }
1130
1131   /// \brief Determine the kind of receiver that this message is being
1132   /// sent to.
1133   ReceiverKind getReceiverKind() const { return (ReceiverKind)Kind; }
1134
1135   /// \brief Source range of the receiver.
1136   SourceRange getReceiverRange() const;
1137
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;
1142   }
1143
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;
1148   }
1149
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());
1155
1156     return nullptr;
1157   }
1158   const Expr *getInstanceReceiver() const {
1159     return const_cast<ObjCMessageExpr*>(this)->getInstanceReceiver();
1160   }
1161
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) { 
1165     Kind = Instance;
1166     setReceiverPointer(rec);
1167   }
1168   
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();
1174
1175     return QualType();
1176   }
1177
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());
1183     return nullptr;
1184   }
1185
1186   void setClassReceiver(TypeSourceInfo *TSInfo) {
1187     Kind = Class;
1188     setReceiverPointer(TSInfo);
1189   }
1190
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)
1195       return SuperLoc;
1196
1197     return SourceLocation();
1198   }
1199
1200   /// \brief Retrieve the receiver type to which this message is being directed.
1201   ///
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.
1207   ///
1208   /// \returns The type of the receiver.
1209   QualType getReceiverType() const;
1210
1211   /// \brief Retrieve the Objective-C interface to which this message
1212   /// is being directed, if known.
1213   ///
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.
1219   ///
1220   /// \returns The Objective-C interface if known, otherwise NULL.
1221   ObjCInterfaceDecl *getReceiverInterface() const;
1222
1223   /// \brief Retrieve the type referred to by 'super'. 
1224   ///
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());
1231
1232     return QualType();
1233   }
1234
1235   void setSuper(SourceLocation Loc, QualType T, bool IsInstanceSuper) {
1236     Kind = IsInstanceSuper? SuperInstance : SuperClass;
1237     SuperLoc = Loc;
1238     setReceiverPointer(T.getAsOpaquePtr());
1239   }
1240
1241   Selector getSelector() const;
1242
1243   void setSelector(Selector S) { 
1244     HasMethod = false;
1245     SelectorOrMethod = reinterpret_cast<uintptr_t>(S.getAsOpaquePtr());
1246   }
1247
1248   const ObjCMethodDecl *getMethodDecl() const { 
1249     if (HasMethod)
1250       return reinterpret_cast<const ObjCMethodDecl *>(SelectorOrMethod);
1251
1252     return nullptr;
1253   }
1254
1255   ObjCMethodDecl *getMethodDecl() { 
1256     if (HasMethod)
1257       return reinterpret_cast<ObjCMethodDecl *>(SelectorOrMethod);
1258
1259     return nullptr;
1260   }
1261
1262   void setMethodDecl(ObjCMethodDecl *MD) { 
1263     HasMethod = true;
1264     SelectorOrMethod = reinterpret_cast<uintptr_t>(MD);
1265   }
1266
1267   ObjCMethodFamily getMethodFamily() const {
1268     if (HasMethod) return getMethodDecl()->getMethodFamily();
1269     return getSelector().getMethodFamily();
1270   }
1271
1272   /// \brief Return the number of actual arguments in this message,
1273   /// not counting the receiver.
1274   unsigned getNumArgs() const { return NumArgs; }
1275
1276   /// \brief Retrieve the arguments to this message, not including the
1277   /// receiver.
1278   Expr **getArgs() {
1279     return reinterpret_cast<Expr **>(this + 1) + 1;
1280   }
1281   const Expr * const *getArgs() const {
1282     return reinterpret_cast<const Expr * const *>(this + 1) + 1;
1283   }
1284
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]);
1289   }
1290   const Expr *getArg(unsigned Arg) const {
1291     assert(Arg < NumArgs && "Arg access out of range!");
1292     return cast<Expr>(getArgs()[Arg]);
1293   }
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;
1298   }
1299
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; }
1305
1306   SourceLocation getLeftLoc() const { return LBracLoc; }
1307   SourceLocation getRightLoc() const { return RBracLoc; }
1308
1309   SourceLocation getSelectorStartLoc() const {
1310     if (isImplicit())
1311       return getLocStart();
1312     return getSelectorLoc(0);
1313   }
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()),
1320                                                   getNumArgs()),
1321                                    RBracLoc);
1322     return getStoredSelLocs()[Index];
1323   }
1324
1325   void getSelectorLocs(SmallVectorImpl<SourceLocation> &SelLocs) const;
1326
1327   unsigned getNumSelectorLocs() const {
1328     if (isImplicit())
1329       return 0;
1330     Selector Sel = getSelector();
1331     if (Sel.isUnarySelector())
1332       return 1;
1333     return Sel.getNumArgs();
1334   }
1335
1336   void setSourceRange(SourceRange R) {
1337     LBracLoc = R.getBegin();
1338     RBracLoc = R.getEnd();
1339   }
1340   SourceLocation getLocStart() const LLVM_READONLY { return LBracLoc; }
1341   SourceLocation getLocEnd() const LLVM_READONLY { return RBracLoc; }
1342
1343   static bool classof(const Stmt *T) {
1344     return T->getStmtClass() == ObjCMessageExprClass;
1345   }
1346
1347   // Iterators
1348   child_range children();
1349
1350   typedef ExprIterator arg_iterator;
1351   typedef ConstExprIterator const_arg_iterator;
1352
1353   arg_iterator arg_begin() { return reinterpret_cast<Stmt **>(getArgs()); }
1354   arg_iterator arg_end()   { 
1355     return reinterpret_cast<Stmt **>(getArgs() + NumArgs); 
1356   }
1357   const_arg_iterator arg_begin() const { 
1358     return reinterpret_cast<Stmt const * const*>(getArgs()); 
1359   }
1360   const_arg_iterator arg_end() const { 
1361     return reinterpret_cast<Stmt const * const*>(getArgs() + NumArgs); 
1362   }
1363
1364   friend class ASTStmtReader;
1365   friend class ASTStmtWriter;
1366 };
1367
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.
1372   Stmt *Base;
1373
1374   /// IsaMemberLoc - This is the location of the 'isa'.
1375   SourceLocation IsaMemberLoc;
1376   
1377   /// OpLoc - This is the location of '.' or '->'
1378   SourceLocation OpLoc;
1379
1380   /// IsArrow - True if this is "X->F", false if this is "X.F".
1381   bool IsArrow;
1382 public:
1383   ObjCIsaExpr(Expr *base, bool isarrow, SourceLocation l, SourceLocation oploc,
1384               QualType ty)
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) {}
1390
1391   /// \brief Build an empty expression.
1392   explicit ObjCIsaExpr(EmptyShell Empty) : Expr(ObjCIsaExprClass, Empty) { }
1393
1394   void setBase(Expr *E) { Base = E; }
1395   Expr *getBase() const { return cast<Expr>(Base); }
1396
1397   bool isArrow() const { return IsArrow; }
1398   void setArrow(bool A) { IsArrow = A; }
1399
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; }
1404   
1405   SourceLocation getOpLoc() const { return OpLoc; }
1406   void setOpLoc(SourceLocation L) { OpLoc = L; }
1407
1408   SourceLocation getLocStart() const LLVM_READONLY {
1409     return getBase()->getLocStart();
1410   }
1411   
1412   SourceLocation getBaseLocEnd() const LLVM_READONLY {
1413     return getBase()->getLocEnd();
1414   }
1415   
1416   SourceLocation getLocEnd() const LLVM_READONLY { return IsaMemberLoc; }
1417
1418   SourceLocation getExprLoc() const LLVM_READONLY { return IsaMemberLoc; }
1419
1420   static bool classof(const Stmt *T) {
1421     return T->getStmtClass() == ObjCIsaExprClass;
1422   }
1423
1424   // Iterators
1425   child_range children() { return child_range(&Base, &Base+1); }
1426 };
1427
1428
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.
1435 ///
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'
1443 ///    parameter).
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.
1447 ///
1448 /// Currently 'T' must be a retainable object lifetime and must be
1449 /// __autoreleasing;  this qualifier is ignored when initializing
1450 /// the value.
1451 class ObjCIndirectCopyRestoreExpr : public Expr {
1452   Stmt *Operand;
1453
1454   // unsigned ObjCIndirectCopyRestoreBits.ShouldCopy : 1;
1455
1456   friend class ASTReader;
1457   friend class ASTStmtReader;
1458
1459   void setShouldCopy(bool shouldCopy) {
1460     ObjCIndirectCopyRestoreExprBits.ShouldCopy = shouldCopy;
1461   }
1462
1463   explicit ObjCIndirectCopyRestoreExpr(EmptyShell Empty)
1464     : Expr(ObjCIndirectCopyRestoreExprClass, Empty) { }
1465
1466 public:
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()),
1472       Operand(operand) {
1473     setShouldCopy(shouldCopy);
1474   }
1475
1476   Expr *getSubExpr() { return cast<Expr>(Operand); }
1477   const Expr *getSubExpr() const { return cast<Expr>(Operand); }
1478
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; }
1482
1483   child_range children() { return child_range(&Operand, &Operand+1); }  
1484
1485   // Source locations are determined by the subexpression.
1486   SourceLocation getLocStart() const LLVM_READONLY {
1487     return Operand->getLocStart();
1488   }
1489   SourceLocation getLocEnd() const LLVM_READONLY { return Operand->getLocEnd();}
1490
1491   SourceLocation getExprLoc() const LLVM_READONLY {
1492     return getSubExpr()->getExprLoc();
1493   }
1494
1495   static bool classof(const Stmt *s) {
1496     return s->getStmtClass() == ObjCIndirectCopyRestoreExprClass;
1497   }
1498 };
1499
1500 /// \brief An Objective-C "bridged" cast expression, which casts between
1501 /// Objective-C pointers and C pointers, transferring ownership in the process.
1502 ///
1503 /// \code
1504 /// NSString *str = (__bridge_transfer NSString *)CFCreateString();
1505 /// \endcode
1506 class ObjCBridgedCastExpr : public ExplicitCastExpr {
1507   SourceLocation LParenLoc;
1508   SourceLocation BridgeKeywordLoc;
1509   unsigned Kind : 2;
1510   
1511   friend class ASTStmtReader;
1512   friend class ASTStmtWriter;
1513   
1514 public:
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) { }
1521   
1522   /// \brief Construct an empty Objective-C bridged cast.
1523   explicit ObjCBridgedCastExpr(EmptyShell Shell)
1524     : ExplicitCastExpr(ObjCBridgedCastExprClass, Shell, 0) { }
1525
1526   SourceLocation getLParenLoc() const { return LParenLoc; }
1527
1528   /// \brief Determine which kind of bridge is being performed via this cast.
1529   ObjCBridgeCastKind getBridgeKind() const { 
1530     return static_cast<ObjCBridgeCastKind>(Kind); 
1531   }
1532   
1533   /// \brief Retrieve the kind of bridge being performed as a string.
1534   StringRef getBridgeKindName() const;
1535   
1536   /// \brief The location of the bridge keyword.
1537   SourceLocation getBridgeKeywordLoc() const { return BridgeKeywordLoc; }
1538   
1539   SourceLocation getLocStart() const LLVM_READONLY { return LParenLoc; }
1540   SourceLocation getLocEnd() const LLVM_READONLY {
1541     return getSubExpr()->getLocEnd();
1542   }
1543   
1544   static bool classof(const Stmt *T) {
1545     return T->getStmtClass() == ObjCBridgedCastExprClass;
1546   }
1547 };
1548   
1549 }  // end namespace clang
1550
1551 #endif