]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/llvm/tools/clang/include/clang/AST/ExprObjC.h
MFC r234353:
[FreeBSD/stable/9.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   SourceRange getSourceRange() const LLVM_READONLY {
48     return SourceRange(AtLoc, String->getLocEnd());
49   }
50
51   static bool classof(const Stmt *T) {
52     return T->getStmtClass() == ObjCStringLiteralClass;
53   }
54   static bool classof(const ObjCStringLiteral *) { return true; }
55
56   // Iterators
57   child_range children() { return child_range(&String, &String+1); }
58 };
59
60 /// ObjCBoolLiteralExpr - Objective-C Boolean Literal.
61 ///
62 class ObjCBoolLiteralExpr : public Expr {
63   bool Value;
64   SourceLocation Loc;
65 public:
66   ObjCBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) :
67   Expr(ObjCBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
68        false, false), Value(val), Loc(l) {}
69     
70   explicit ObjCBoolLiteralExpr(EmptyShell Empty)
71   : Expr(ObjCBoolLiteralExprClass, Empty) { }
72     
73   bool getValue() const { return Value; }
74   void setValue(bool V) { Value = V; }
75     
76   SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); }
77     
78   SourceLocation getLocation() const { return Loc; }
79   void setLocation(SourceLocation L) { Loc = L; }
80     
81   static bool classof(const Stmt *T) {
82     return T->getStmtClass() == ObjCBoolLiteralExprClass;
83   }
84   static bool classof(const ObjCBoolLiteralExpr *) { return true; }
85     
86   // Iterators
87   child_range children() { return child_range(); }
88 };
89
90 /// ObjCNumericLiteral - used for objective-c numeric literals;
91 /// as in: @42 or @true (c++/objc++) or @__yes (c/objc)
92 class ObjCNumericLiteral : public Expr {
93   /// Number - expression AST node for the numeric literal
94   Stmt *Number;
95   ObjCMethodDecl *ObjCNumericLiteralMethod;
96   SourceLocation AtLoc;
97 public:
98   ObjCNumericLiteral(Stmt *NL, QualType T, ObjCMethodDecl *method,
99                      SourceLocation L)
100   : Expr(ObjCNumericLiteralClass, T, VK_RValue, OK_Ordinary, 
101          false, false, false, false), Number(NL), 
102     ObjCNumericLiteralMethod(method), AtLoc(L) {}
103   explicit ObjCNumericLiteral(EmptyShell Empty)
104   : Expr(ObjCNumericLiteralClass, Empty) {}
105   
106   Expr *getNumber() { return cast<Expr>(Number); }
107   const Expr *getNumber() const { return cast<Expr>(Number); }
108   
109   ObjCMethodDecl *getObjCNumericLiteralMethod() const {
110     return ObjCNumericLiteralMethod; 
111   }
112     
113   SourceLocation getAtLoc() const { return AtLoc; }
114   
115   SourceRange getSourceRange() const LLVM_READONLY {
116     return SourceRange(AtLoc, Number->getSourceRange().getEnd());
117   }
118
119   static bool classof(const Stmt *T) {
120       return T->getStmtClass() == ObjCNumericLiteralClass;
121   }
122   static bool classof(const ObjCNumericLiteral *) { return true; }
123   
124   // Iterators
125   child_range children() { return child_range(&Number, &Number+1); }
126     
127   friend class ASTStmtReader;
128 };
129
130 /// ObjCArrayLiteral - used for objective-c array containers; as in:
131 /// @[@"Hello", NSApp, [NSNumber numberWithInt:42]];
132 class ObjCArrayLiteral : public Expr {
133   unsigned NumElements;
134   SourceRange Range;
135   ObjCMethodDecl *ArrayWithObjectsMethod;
136   
137   ObjCArrayLiteral(llvm::ArrayRef<Expr *> Elements,
138                    QualType T, ObjCMethodDecl * Method,
139                    SourceRange SR);
140   
141   explicit ObjCArrayLiteral(EmptyShell Empty, unsigned NumElements)
142     : Expr(ObjCArrayLiteralClass, Empty), NumElements(NumElements) {}
143
144 public:
145   static ObjCArrayLiteral *Create(ASTContext &C, 
146                                   llvm::ArrayRef<Expr *> Elements,
147                                   QualType T, ObjCMethodDecl * Method,
148                                   SourceRange SR);
149
150   static ObjCArrayLiteral *CreateEmpty(ASTContext &C, unsigned NumElements);
151
152   SourceRange getSourceRange() const LLVM_READONLY { return Range; }
153
154   static bool classof(const Stmt *T) {
155       return T->getStmtClass() == ObjCArrayLiteralClass;
156   }
157   static bool classof(const ObjCArrayLiteral *) { return true; }
158
159   /// \brief Retrieve elements of array of literals.
160   Expr **getElements() { return reinterpret_cast<Expr **>(this + 1); }
161
162   /// \brief Retrieve elements of array of literals.
163   const Expr * const *getElements() const { 
164     return reinterpret_cast<const Expr * const*>(this + 1); 
165   }
166
167   /// getNumElements - Return number of elements of objective-c array literal.
168   unsigned getNumElements() const { return NumElements; }
169     
170     /// getExpr - Return the Expr at the specified index.
171   Expr *getElement(unsigned Index) {
172     assert((Index < NumElements) && "Arg access out of range!");
173     return cast<Expr>(getElements()[Index]);
174   }
175   const Expr *getElement(unsigned Index) const {
176     assert((Index < NumElements) && "Arg access out of range!");
177     return cast<Expr>(getElements()[Index]);
178   }
179     
180   ObjCMethodDecl *getArrayWithObjectsMethod() const {
181     return ArrayWithObjectsMethod; 
182   }
183     
184   // Iterators
185   child_range children() { 
186     return child_range((Stmt **)getElements(), 
187                        (Stmt **)getElements() + NumElements);
188   }
189     
190   friend class ASTStmtReader;
191 };
192
193 /// \brief An element in an Objective-C dictionary literal.
194 ///
195 struct ObjCDictionaryElement {
196   /// \brief The key for the dictionary element.
197   Expr *Key;
198   
199   /// \brief The value of the dictionary element.
200   Expr *Value;
201   
202   /// \brief The location of the ellipsis, if this is a pack expansion.
203   SourceLocation EllipsisLoc;
204   
205   /// \brief The number of elements this pack expansion will expand to, if
206   /// this is a pack expansion and is known.
207   llvm::Optional<unsigned> NumExpansions;
208
209   /// \brief Determines whether this dictionary element is a pack expansion.
210   bool isPackExpansion() const { return EllipsisLoc.isValid(); }
211 };
212
213 /// ObjCDictionaryLiteral - AST node to represent objective-c dictionary 
214 /// literals; as in:  @{@"name" : NSUserName(), @"date" : [NSDate date] };
215 class ObjCDictionaryLiteral : public Expr {
216   /// \brief Key/value pair used to store the key and value of a given element.
217   ///
218   /// Objects of this type are stored directly after the expression.
219   struct KeyValuePair {
220     Expr *Key;
221     Expr *Value;
222   };
223   
224   /// \brief Data that describes an element that is a pack expansion, used if any
225   /// of the elements in the dictionary literal are pack expansions.
226   struct ExpansionData {
227     /// \brief The location of the ellipsis, if this element is a pack
228     /// expansion.
229     SourceLocation EllipsisLoc;
230
231     /// \brief If non-zero, the number of elements that this pack
232     /// expansion will expand to (+1).
233     unsigned NumExpansionsPlusOne;
234   };
235
236   /// \brief The number of elements in this dictionary literal.
237   unsigned NumElements : 31;
238   
239   /// \brief Determine whether this dictionary literal has any pack expansions.
240   ///
241   /// If the dictionary literal has pack expansions, then there will
242   /// be an array of pack expansion data following the array of
243   /// key/value pairs, which provide the locations of the ellipses (if
244   /// any) and number of elements in the expansion (if known). If
245   /// there are no pack expansions, we optimize away this storage.
246   unsigned HasPackExpansions : 1;
247   
248   SourceRange Range;
249   ObjCMethodDecl *DictWithObjectsMethod;
250     
251   ObjCDictionaryLiteral(ArrayRef<ObjCDictionaryElement> VK, 
252                         bool HasPackExpansions,
253                         QualType T, ObjCMethodDecl *method,
254                         SourceRange SR);
255
256   explicit ObjCDictionaryLiteral(EmptyShell Empty, unsigned NumElements,
257                                  bool HasPackExpansions)
258     : Expr(ObjCDictionaryLiteralClass, Empty), NumElements(NumElements),
259       HasPackExpansions(HasPackExpansions) {}
260
261   KeyValuePair *getKeyValues() {
262     return reinterpret_cast<KeyValuePair *>(this + 1);
263   }
264   
265   const KeyValuePair *getKeyValues() const {
266     return reinterpret_cast<const KeyValuePair *>(this + 1);
267   }
268
269   ExpansionData *getExpansionData() {
270     if (!HasPackExpansions)
271       return 0;
272     
273     return reinterpret_cast<ExpansionData *>(getKeyValues() + NumElements);
274   }
275
276   const ExpansionData *getExpansionData() const {
277     if (!HasPackExpansions)
278       return 0;
279     
280     return reinterpret_cast<const ExpansionData *>(getKeyValues()+NumElements);
281   }
282
283 public:
284   static ObjCDictionaryLiteral *Create(ASTContext &C,
285                                        ArrayRef<ObjCDictionaryElement> VK, 
286                                        bool HasPackExpansions,
287                                        QualType T, ObjCMethodDecl *method,
288                                        SourceRange SR);
289   
290   static ObjCDictionaryLiteral *CreateEmpty(ASTContext &C, 
291                                             unsigned NumElements,
292                                             bool HasPackExpansions);
293   
294   /// getNumElements - Return number of elements of objective-c dictionary 
295   /// literal.
296   unsigned getNumElements() const { return NumElements; }
297
298   ObjCDictionaryElement getKeyValueElement(unsigned Index) const {
299     assert((Index < NumElements) && "Arg access out of range!");
300     const KeyValuePair &KV = getKeyValues()[Index];
301     ObjCDictionaryElement Result = { KV.Key, KV.Value, SourceLocation(),
302                                      llvm::Optional<unsigned>() };
303     if (HasPackExpansions) {
304       const ExpansionData &Expansion = getExpansionData()[Index];
305       Result.EllipsisLoc = Expansion.EllipsisLoc;
306       if (Expansion.NumExpansionsPlusOne > 0)
307         Result.NumExpansions = Expansion.NumExpansionsPlusOne - 1;
308     }
309     return Result;
310   }
311     
312   ObjCMethodDecl *getDictWithObjectsMethod() const
313     { return DictWithObjectsMethod; }
314
315   SourceRange getSourceRange() const LLVM_READONLY { return Range; }
316   
317   static bool classof(const Stmt *T) {
318       return T->getStmtClass() == ObjCDictionaryLiteralClass;
319   }
320   static bool classof(const ObjCDictionaryLiteral *) { return true; }
321     
322   // Iterators
323   child_range children() { 
324     // Note: we're taking advantage of the layout of the KeyValuePair struct
325     // here. If that struct changes, this code will need to change as well.
326     return child_range(reinterpret_cast<Stmt **>(this + 1),
327                        reinterpret_cast<Stmt **>(this + 1) + NumElements * 2);
328   }
329     
330   friend class ASTStmtReader;
331   friend class ASTStmtWriter;
332 };
333
334
335 /// ObjCEncodeExpr, used for @encode in Objective-C.  @encode has the same type
336 /// and behavior as StringLiteral except that the string initializer is obtained
337 /// from ASTContext with the encoding type as an argument.
338 class ObjCEncodeExpr : public Expr {
339   TypeSourceInfo *EncodedType;
340   SourceLocation AtLoc, RParenLoc;
341 public:
342   ObjCEncodeExpr(QualType T, TypeSourceInfo *EncodedType,
343                  SourceLocation at, SourceLocation rp)
344     : Expr(ObjCEncodeExprClass, T, VK_LValue, OK_Ordinary,
345            EncodedType->getType()->isDependentType(),
346            EncodedType->getType()->isDependentType(),
347            EncodedType->getType()->isInstantiationDependentType(),
348            EncodedType->getType()->containsUnexpandedParameterPack()), 
349       EncodedType(EncodedType), AtLoc(at), RParenLoc(rp) {}
350
351   explicit ObjCEncodeExpr(EmptyShell Empty) : Expr(ObjCEncodeExprClass, Empty){}
352
353
354   SourceLocation getAtLoc() const { return AtLoc; }
355   void setAtLoc(SourceLocation L) { AtLoc = L; }
356   SourceLocation getRParenLoc() const { return RParenLoc; }
357   void setRParenLoc(SourceLocation L) { RParenLoc = L; }
358
359   QualType getEncodedType() const { return EncodedType->getType(); }
360
361   TypeSourceInfo *getEncodedTypeSourceInfo() const { return EncodedType; }
362   void setEncodedTypeSourceInfo(TypeSourceInfo *EncType) { 
363     EncodedType = EncType; 
364   }
365
366   SourceRange getSourceRange() const LLVM_READONLY {
367     return SourceRange(AtLoc, RParenLoc);
368   }
369
370   static bool classof(const Stmt *T) {
371     return T->getStmtClass() == ObjCEncodeExprClass;
372   }
373   static bool classof(const ObjCEncodeExpr *) { return true; }
374
375   // Iterators
376   child_range children() { return child_range(); }
377 };
378
379 /// ObjCSelectorExpr used for @selector in Objective-C.
380 class ObjCSelectorExpr : public Expr {
381   Selector SelName;
382   SourceLocation AtLoc, RParenLoc;
383 public:
384   ObjCSelectorExpr(QualType T, Selector selInfo,
385                    SourceLocation at, SourceLocation rp)
386     : Expr(ObjCSelectorExprClass, T, VK_RValue, OK_Ordinary, false, false, 
387            false, false),
388     SelName(selInfo), AtLoc(at), RParenLoc(rp){}
389   explicit ObjCSelectorExpr(EmptyShell Empty)
390    : Expr(ObjCSelectorExprClass, Empty) {}
391
392   Selector getSelector() const { return SelName; }
393   void setSelector(Selector S) { SelName = S; }
394
395   SourceLocation getAtLoc() const { return AtLoc; }
396   SourceLocation getRParenLoc() const { return RParenLoc; }
397   void setAtLoc(SourceLocation L) { AtLoc = L; }
398   void setRParenLoc(SourceLocation L) { RParenLoc = L; }
399
400   SourceRange getSourceRange() const LLVM_READONLY {
401     return SourceRange(AtLoc, RParenLoc);
402   }
403
404   /// getNumArgs - Return the number of actual arguments to this call.
405   unsigned getNumArgs() const { return SelName.getNumArgs(); }
406
407   static bool classof(const Stmt *T) {
408     return T->getStmtClass() == ObjCSelectorExprClass;
409   }
410   static bool classof(const ObjCSelectorExpr *) { return true; }
411
412   // Iterators
413   child_range children() { return child_range(); }
414 };
415
416 /// ObjCProtocolExpr used for protocol expression in Objective-C.  This is used
417 /// as: @protocol(foo), as in:
418 ///   obj conformsToProtocol:@protocol(foo)]
419 /// The return type is "Protocol*".
420 class ObjCProtocolExpr : public Expr {
421   ObjCProtocolDecl *TheProtocol;
422   SourceLocation AtLoc, RParenLoc;
423 public:
424   ObjCProtocolExpr(QualType T, ObjCProtocolDecl *protocol,
425                    SourceLocation at, SourceLocation rp)
426     : Expr(ObjCProtocolExprClass, T, VK_RValue, OK_Ordinary, false, false,
427            false, false),
428       TheProtocol(protocol), AtLoc(at), RParenLoc(rp) {}
429   explicit ObjCProtocolExpr(EmptyShell Empty)
430     : Expr(ObjCProtocolExprClass, Empty) {}
431
432   ObjCProtocolDecl *getProtocol() const { return TheProtocol; }
433   void setProtocol(ObjCProtocolDecl *P) { TheProtocol = P; }
434
435   SourceLocation getAtLoc() const { return AtLoc; }
436   SourceLocation getRParenLoc() const { return RParenLoc; }
437   void setAtLoc(SourceLocation L) { AtLoc = L; }
438   void setRParenLoc(SourceLocation L) { RParenLoc = L; }
439
440   SourceRange getSourceRange() const LLVM_READONLY {
441     return SourceRange(AtLoc, RParenLoc);
442   }
443
444   static bool classof(const Stmt *T) {
445     return T->getStmtClass() == ObjCProtocolExprClass;
446   }
447   static bool classof(const ObjCProtocolExpr *) { return true; }
448
449   // Iterators
450   child_range children() { return child_range(); }
451 };
452
453 /// ObjCIvarRefExpr - A reference to an ObjC instance variable.
454 class ObjCIvarRefExpr : public Expr {
455   ObjCIvarDecl *D;
456   Stmt *Base;
457   SourceLocation Loc;
458   bool IsArrow:1;      // True if this is "X->F", false if this is "X.F".
459   bool IsFreeIvar:1;   // True if ivar reference has no base (self assumed).
460
461 public:
462   ObjCIvarRefExpr(ObjCIvarDecl *d, QualType t,
463                   SourceLocation l, Expr *base,
464                   bool arrow = false, bool freeIvar = false) :
465     Expr(ObjCIvarRefExprClass, t, VK_LValue, OK_Ordinary,
466          /*TypeDependent=*/false, base->isValueDependent(), 
467          base->isInstantiationDependent(),
468          base->containsUnexpandedParameterPack()), 
469     D(d), Base(base), Loc(l), IsArrow(arrow), IsFreeIvar(freeIvar) {}
470
471   explicit ObjCIvarRefExpr(EmptyShell Empty)
472     : Expr(ObjCIvarRefExprClass, Empty) {}
473
474   ObjCIvarDecl *getDecl() { return D; }
475   const ObjCIvarDecl *getDecl() const { return D; }
476   void setDecl(ObjCIvarDecl *d) { D = d; }
477
478   const Expr *getBase() const { return cast<Expr>(Base); }
479   Expr *getBase() { return cast<Expr>(Base); }
480   void setBase(Expr * base) { Base = base; }
481
482   bool isArrow() const { return IsArrow; }
483   bool isFreeIvar() const { return IsFreeIvar; }
484   void setIsArrow(bool A) { IsArrow = A; }
485   void setIsFreeIvar(bool A) { IsFreeIvar = A; }
486
487   SourceLocation getLocation() const { return Loc; }
488   void setLocation(SourceLocation L) { Loc = L; }
489
490   SourceRange getSourceRange() const LLVM_READONLY {
491     return isFreeIvar() ? SourceRange(Loc)
492     : SourceRange(getBase()->getLocStart(), Loc);
493   }
494
495   static bool classof(const Stmt *T) {
496     return T->getStmtClass() == ObjCIvarRefExprClass;
497   }
498   static bool classof(const ObjCIvarRefExpr *) { return true; }
499
500   // Iterators
501   child_range children() { return child_range(&Base, &Base+1); }
502 };
503
504 /// ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC
505 /// property.
506 class ObjCPropertyRefExpr : public Expr {
507 private:
508   /// If the bool is true, this is an implicit property reference; the
509   /// pointer is an (optional) ObjCMethodDecl and Setter may be set.
510   /// if the bool is false, this is an explicit property reference;
511   /// the pointer is an ObjCPropertyDecl and Setter is always null.
512   llvm::PointerIntPair<NamedDecl*, 1, bool> PropertyOrGetter;
513
514   /// \brief Indicates whether the property reference will result in a message
515   /// to the getter, the setter, or both.
516   /// This applies to both implicit and explicit property references.
517   enum MethodRefFlags {
518     MethodRef_None = 0,
519     MethodRef_Getter = 0x1,
520     MethodRef_Setter = 0x2
521   };
522
523   /// \brief Contains the Setter method pointer and MethodRefFlags bit flags.
524   llvm::PointerIntPair<ObjCMethodDecl *, 2, unsigned> SetterAndMethodRefFlags;
525
526   // FIXME: Maybe we should store the property identifier here,
527   // because it's not rederivable from the other data when there's an
528   // implicit property with no getter (because the 'foo' -> 'setFoo:'
529   // transformation is lossy on the first character).
530
531   SourceLocation IdLoc;
532   
533   /// \brief When the receiver in property access is 'super', this is
534   /// the location of the 'super' keyword.  When it's an interface,
535   /// this is that interface.
536   SourceLocation ReceiverLoc;
537   llvm::PointerUnion3<Stmt*, const Type*, ObjCInterfaceDecl*> Receiver;
538   
539 public:
540   ObjCPropertyRefExpr(ObjCPropertyDecl *PD, QualType t,
541                       ExprValueKind VK, ExprObjectKind OK,
542                       SourceLocation l, Expr *base)
543     : Expr(ObjCPropertyRefExprClass, t, VK, OK,
544            /*TypeDependent=*/false, base->isValueDependent(),
545            base->isInstantiationDependent(),
546            base->containsUnexpandedParameterPack()),
547       PropertyOrGetter(PD, false), SetterAndMethodRefFlags(),
548       IdLoc(l), ReceiverLoc(), Receiver(base) {
549     assert(t->isSpecificPlaceholderType(BuiltinType::PseudoObject));
550   }
551   
552   ObjCPropertyRefExpr(ObjCPropertyDecl *PD, QualType t,
553                       ExprValueKind VK, ExprObjectKind OK,
554                       SourceLocation l, SourceLocation sl, QualType st)
555     : Expr(ObjCPropertyRefExprClass, t, VK, OK,
556            /*TypeDependent=*/false, false, st->isInstantiationDependentType(),
557            st->containsUnexpandedParameterPack()),
558       PropertyOrGetter(PD, false), SetterAndMethodRefFlags(),
559       IdLoc(l), ReceiverLoc(sl), Receiver(st.getTypePtr()) {
560     assert(t->isSpecificPlaceholderType(BuiltinType::PseudoObject));
561   }
562
563   ObjCPropertyRefExpr(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter,
564                       QualType T, ExprValueKind VK, ExprObjectKind OK,
565                       SourceLocation IdLoc, Expr *Base)
566     : Expr(ObjCPropertyRefExprClass, T, VK, OK, false,
567            Base->isValueDependent(), Base->isInstantiationDependent(),
568            Base->containsUnexpandedParameterPack()),
569       PropertyOrGetter(Getter, true), SetterAndMethodRefFlags(Setter, 0),
570       IdLoc(IdLoc), ReceiverLoc(), Receiver(Base) {
571     assert(T->isSpecificPlaceholderType(BuiltinType::PseudoObject));
572   }
573
574   ObjCPropertyRefExpr(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter,
575                       QualType T, ExprValueKind VK, ExprObjectKind OK,
576                       SourceLocation IdLoc,
577                       SourceLocation SuperLoc, QualType SuperTy)
578     : Expr(ObjCPropertyRefExprClass, T, VK, OK, false, false, false, false),
579       PropertyOrGetter(Getter, true), SetterAndMethodRefFlags(Setter, 0),
580       IdLoc(IdLoc), ReceiverLoc(SuperLoc), Receiver(SuperTy.getTypePtr()) {
581     assert(T->isSpecificPlaceholderType(BuiltinType::PseudoObject));
582   }
583
584   ObjCPropertyRefExpr(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter,
585                       QualType T, ExprValueKind VK, ExprObjectKind OK,
586                       SourceLocation IdLoc,
587                       SourceLocation ReceiverLoc, ObjCInterfaceDecl *Receiver)
588     : Expr(ObjCPropertyRefExprClass, T, VK, OK, false, false, false, false),
589       PropertyOrGetter(Getter, true), SetterAndMethodRefFlags(Setter, 0),
590       IdLoc(IdLoc), ReceiverLoc(ReceiverLoc), Receiver(Receiver) {
591     assert(T->isSpecificPlaceholderType(BuiltinType::PseudoObject));
592   }
593
594   explicit ObjCPropertyRefExpr(EmptyShell Empty)
595     : Expr(ObjCPropertyRefExprClass, Empty) {}
596
597   bool isImplicitProperty() const { return PropertyOrGetter.getInt(); }
598   bool isExplicitProperty() const { return !PropertyOrGetter.getInt(); }
599
600   ObjCPropertyDecl *getExplicitProperty() const {
601     assert(!isImplicitProperty());
602     return cast<ObjCPropertyDecl>(PropertyOrGetter.getPointer());
603   }
604
605   ObjCMethodDecl *getImplicitPropertyGetter() const {
606     assert(isImplicitProperty());
607     return cast_or_null<ObjCMethodDecl>(PropertyOrGetter.getPointer());
608   }
609
610   ObjCMethodDecl *getImplicitPropertySetter() const {
611     assert(isImplicitProperty());
612     return SetterAndMethodRefFlags.getPointer();
613   }
614
615   Selector getGetterSelector() const {
616     if (isImplicitProperty())
617       return getImplicitPropertyGetter()->getSelector();
618     return getExplicitProperty()->getGetterName();
619   }
620
621   Selector getSetterSelector() const {
622     if (isImplicitProperty())
623       return getImplicitPropertySetter()->getSelector();
624     return getExplicitProperty()->getSetterName();
625   }
626
627   /// \brief True if the property reference will result in a message to the
628   /// getter.
629   /// This applies to both implicit and explicit property references.
630   bool isMessagingGetter() const {
631     return SetterAndMethodRefFlags.getInt() & MethodRef_Getter;
632   }
633
634   /// \brief True if the property reference will result in a message to the
635   /// setter.
636   /// This applies to both implicit and explicit property references.
637   bool isMessagingSetter() const {
638     return SetterAndMethodRefFlags.getInt() & MethodRef_Setter;
639   }
640
641   void setIsMessagingGetter(bool val = true) {
642     setMethodRefFlag(MethodRef_Getter, val);
643   }
644
645   void setIsMessagingSetter(bool val = true) {
646     setMethodRefFlag(MethodRef_Setter, val);
647   }
648
649   const Expr *getBase() const { 
650     return cast<Expr>(Receiver.get<Stmt*>()); 
651   }
652   Expr *getBase() { 
653     return cast<Expr>(Receiver.get<Stmt*>()); 
654   }
655
656   SourceLocation getLocation() const { return IdLoc; }
657   
658   SourceLocation getReceiverLocation() const { return ReceiverLoc; }
659   QualType getSuperReceiverType() const { 
660     return QualType(Receiver.get<const Type*>(), 0); 
661   }
662   QualType getGetterResultType() const {
663     QualType ResultType;
664     if (isExplicitProperty()) {
665       const ObjCPropertyDecl *PDecl = getExplicitProperty();
666       if (const ObjCMethodDecl *Getter = PDecl->getGetterMethodDecl())
667         ResultType = Getter->getResultType();
668       else
669         ResultType = PDecl->getType();
670     } else {
671       const ObjCMethodDecl *Getter = getImplicitPropertyGetter();
672       if (Getter)
673         ResultType = Getter->getResultType(); // with reference!
674     }
675     return ResultType;
676   }
677
678   QualType getSetterArgType() const {
679     QualType ArgType;
680     if (isImplicitProperty()) {
681       const ObjCMethodDecl *Setter = getImplicitPropertySetter();
682       ObjCMethodDecl::param_const_iterator P = Setter->param_begin(); 
683       ArgType = (*P)->getType();
684     } else {
685       if (ObjCPropertyDecl *PDecl = getExplicitProperty())
686         if (const ObjCMethodDecl *Setter = PDecl->getSetterMethodDecl()) {
687           ObjCMethodDecl::param_const_iterator P = Setter->param_begin(); 
688           ArgType = (*P)->getType();
689         }
690       if (ArgType.isNull())
691         ArgType = getType();
692     }
693     return ArgType;
694   }
695   
696   ObjCInterfaceDecl *getClassReceiver() const {
697     return Receiver.get<ObjCInterfaceDecl*>();
698   }
699   bool isObjectReceiver() const { return Receiver.is<Stmt*>(); }
700   bool isSuperReceiver() const { return Receiver.is<const Type*>(); }
701   bool isClassReceiver() const { return Receiver.is<ObjCInterfaceDecl*>(); }
702
703   SourceRange getSourceRange() const LLVM_READONLY {
704     return SourceRange((isObjectReceiver() ? getBase()->getLocStart()
705                                            : getReceiverLocation()), 
706                        IdLoc);
707   }
708
709   static bool classof(const Stmt *T) {
710     return T->getStmtClass() == ObjCPropertyRefExprClass;
711   }
712   static bool classof(const ObjCPropertyRefExpr *) { return true; }
713
714   // Iterators
715   child_range children() {
716     if (Receiver.is<Stmt*>()) {
717       Stmt **begin = reinterpret_cast<Stmt**>(&Receiver); // hack!
718       return child_range(begin, begin+1);
719     }
720     return child_range();
721   }
722
723 private:
724   friend class ASTStmtReader;
725   friend class ASTStmtWriter;
726   void setExplicitProperty(ObjCPropertyDecl *D, unsigned methRefFlags) {
727     PropertyOrGetter.setPointer(D);
728     PropertyOrGetter.setInt(false);
729     SetterAndMethodRefFlags.setPointer(0);
730     SetterAndMethodRefFlags.setInt(methRefFlags);
731   }
732   void setImplicitProperty(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter,
733                            unsigned methRefFlags) {
734     PropertyOrGetter.setPointer(Getter);
735     PropertyOrGetter.setInt(true);
736     SetterAndMethodRefFlags.setPointer(Setter);
737     SetterAndMethodRefFlags.setInt(methRefFlags);
738   }
739   void setBase(Expr *Base) { Receiver = Base; }
740   void setSuperReceiver(QualType T) { Receiver = T.getTypePtr(); }
741   void setClassReceiver(ObjCInterfaceDecl *D) { Receiver = D; }
742
743   void setLocation(SourceLocation L) { IdLoc = L; }
744   void setReceiverLocation(SourceLocation Loc) { ReceiverLoc = Loc; }
745
746   void setMethodRefFlag(MethodRefFlags flag, bool val) {
747     unsigned f = SetterAndMethodRefFlags.getInt();
748     if (val)
749       f |= flag;
750     else
751       f &= ~flag;
752     SetterAndMethodRefFlags.setInt(f);
753   }
754 };
755   
756 /// ObjCSubscriptRefExpr - used for array and dictionary subscripting.
757 /// array[4] = array[3]; dictionary[key] = dictionary[alt_key];
758 ///
759 class ObjCSubscriptRefExpr : public Expr {
760   // Location of ']' in an indexing expression.
761   SourceLocation RBracket;
762   // array/dictionary base expression.
763   // for arrays, this is a numeric expression. For dictionaries, this is
764   // an objective-c object pointer expression.
765   enum { BASE, KEY, END_EXPR };
766   Stmt* SubExprs[END_EXPR];
767   
768   ObjCMethodDecl *GetAtIndexMethodDecl;
769   
770   // For immutable objects this is null. When ObjCSubscriptRefExpr is to read
771   // an indexed object this is null too.
772   ObjCMethodDecl *SetAtIndexMethodDecl;
773   
774 public:
775   
776   ObjCSubscriptRefExpr(Expr *base, Expr *key, QualType T,
777                        ExprValueKind VK, ExprObjectKind OK,
778                        ObjCMethodDecl *getMethod,
779                        ObjCMethodDecl *setMethod, SourceLocation RB)
780     : Expr(ObjCSubscriptRefExprClass, T, VK, OK, 
781            base->isTypeDependent() || key->isTypeDependent(), 
782            base->isValueDependent() || key->isValueDependent(),
783            base->isInstantiationDependent() || key->isInstantiationDependent(),
784            (base->containsUnexpandedParameterPack() ||
785             key->containsUnexpandedParameterPack())),
786       RBracket(RB), 
787   GetAtIndexMethodDecl(getMethod), 
788   SetAtIndexMethodDecl(setMethod) 
789     {SubExprs[BASE] = base; SubExprs[KEY] = key;}
790
791   explicit ObjCSubscriptRefExpr(EmptyShell Empty)
792     : Expr(ObjCSubscriptRefExprClass, Empty) {}
793   
794   static ObjCSubscriptRefExpr *Create(ASTContext &C,
795                                       Expr *base,
796                                       Expr *key, QualType T, 
797                                       ObjCMethodDecl *getMethod,
798                                       ObjCMethodDecl *setMethod, 
799                                       SourceLocation RB);
800   
801   SourceLocation getRBracket() const { return RBracket; }
802   void setRBracket(SourceLocation RB) { RBracket = RB; }
803   SourceRange getSourceRange() const LLVM_READONLY {
804     return SourceRange(SubExprs[BASE]->getLocStart(), RBracket);
805   }
806   
807   static bool classof(const Stmt *T) {
808     return T->getStmtClass() == ObjCSubscriptRefExprClass;
809   }
810   static bool classof(const ObjCSubscriptRefExpr *) { return true; }
811   
812   Expr *getBaseExpr() const { return cast<Expr>(SubExprs[BASE]); }
813   void setBaseExpr(Stmt *S) { SubExprs[BASE] = S; }
814   
815   Expr *getKeyExpr() const { return cast<Expr>(SubExprs[KEY]); }
816   void setKeyExpr(Stmt *S) { SubExprs[KEY] = S; }
817   
818   ObjCMethodDecl *getAtIndexMethodDecl() const {
819     return GetAtIndexMethodDecl;
820   }
821  
822   ObjCMethodDecl *setAtIndexMethodDecl() const {
823     return SetAtIndexMethodDecl;
824   }
825   
826   bool isArraySubscriptRefExpr() const {
827     return getKeyExpr()->getType()->isIntegralOrEnumerationType();
828   }
829   
830   child_range children() {
831     return child_range(SubExprs, SubExprs+END_EXPR);
832   }
833 private:
834   friend class ASTStmtReader;
835 };
836   
837
838 /// \brief An expression that sends a message to the given Objective-C
839 /// object or class.
840 ///
841 /// The following contains two message send expressions:
842 ///
843 /// \code
844 ///   [[NSString alloc] initWithString:@"Hello"]
845 /// \endcode
846 ///
847 /// The innermost message send invokes the "alloc" class method on the
848 /// NSString class, while the outermost message send invokes the
849 /// "initWithString" instance method on the object returned from
850 /// NSString's "alloc". In all, an Objective-C message send can take
851 /// on four different (although related) forms:
852 ///
853 ///   1. Send to an object instance.
854 ///   2. Send to a class.
855 ///   3. Send to the superclass instance of the current class.
856 ///   4. Send to the superclass of the current class.
857 ///
858 /// All four kinds of message sends are modeled by the ObjCMessageExpr
859 /// class, and can be distinguished via \c getReceiverKind(). Example:
860 ///
861 class ObjCMessageExpr : public Expr {
862   /// \brief Stores either the selector that this message is sending
863   /// to (when \c HasMethod is zero) or an \c ObjCMethodDecl pointer
864   /// referring to the method that we type-checked against.
865   uintptr_t SelectorOrMethod;
866
867   enum { NumArgsBitWidth = 16 };
868
869   /// \brief The number of arguments in the message send, not
870   /// including the receiver.
871   unsigned NumArgs : NumArgsBitWidth;
872   
873   void setNumArgs(unsigned Num) {
874     assert((Num >> NumArgsBitWidth) == 0 && "Num of args is out of range!");
875     NumArgs = Num;
876   }
877
878   /// \brief The kind of message send this is, which is one of the
879   /// ReceiverKind values.
880   ///
881   /// We pad this out to a byte to avoid excessive masking and shifting.
882   unsigned Kind : 8;
883
884   /// \brief Whether we have an actual method prototype in \c
885   /// SelectorOrMethod.
886   ///
887   /// When non-zero, we have a method declaration; otherwise, we just
888   /// have a selector.
889   unsigned HasMethod : 1;
890
891   /// \brief Whether this message send is a "delegate init call",
892   /// i.e. a call of an init method on self from within an init method.
893   unsigned IsDelegateInitCall : 1;
894
895   /// \brief Whether this message send was implicitly generated by
896   /// the implementation rather than explicitly written by the user.
897   unsigned IsImplicit : 1;
898
899   /// \brief Whether the locations of the selector identifiers are in a
900   /// "standard" position, a enum SelectorLocationsKind.
901   unsigned SelLocsKind : 2;
902
903   /// \brief When the message expression is a send to 'super', this is
904   /// the location of the 'super' keyword.
905   SourceLocation SuperLoc;
906
907   /// \brief The source locations of the open and close square
908   /// brackets ('[' and ']', respectively).
909   SourceLocation LBracLoc, RBracLoc;
910
911   ObjCMessageExpr(EmptyShell Empty, unsigned NumArgs)
912     : Expr(ObjCMessageExprClass, Empty), SelectorOrMethod(0), Kind(0), 
913       HasMethod(0), IsDelegateInitCall(0), IsImplicit(0), SelLocsKind(0) {
914     setNumArgs(NumArgs);
915   }
916
917   ObjCMessageExpr(QualType T, ExprValueKind VK,
918                   SourceLocation LBracLoc,
919                   SourceLocation SuperLoc,
920                   bool IsInstanceSuper,
921                   QualType SuperType,
922                   Selector Sel, 
923                   ArrayRef<SourceLocation> SelLocs,
924                   SelectorLocationsKind SelLocsK,
925                   ObjCMethodDecl *Method,
926                   ArrayRef<Expr *> Args,
927                   SourceLocation RBracLoc,
928                   bool isImplicit);
929   ObjCMessageExpr(QualType T, ExprValueKind VK,
930                   SourceLocation LBracLoc,
931                   TypeSourceInfo *Receiver,
932                   Selector Sel, 
933                   ArrayRef<SourceLocation> SelLocs,
934                   SelectorLocationsKind SelLocsK,
935                   ObjCMethodDecl *Method,
936                   ArrayRef<Expr *> Args,
937                   SourceLocation RBracLoc,
938                   bool isImplicit);
939   ObjCMessageExpr(QualType T, ExprValueKind VK,
940                   SourceLocation LBracLoc,
941                   Expr *Receiver,
942                   Selector Sel, 
943                   ArrayRef<SourceLocation> SelLocs,
944                   SelectorLocationsKind SelLocsK,
945                   ObjCMethodDecl *Method,
946                   ArrayRef<Expr *> Args,
947                   SourceLocation RBracLoc,
948                   bool isImplicit);
949
950   void initArgsAndSelLocs(ArrayRef<Expr *> Args,
951                           ArrayRef<SourceLocation> SelLocs,
952                           SelectorLocationsKind SelLocsK);
953
954   /// \brief Retrieve the pointer value of the message receiver.
955   void *getReceiverPointer() const {
956     return *const_cast<void **>(
957                              reinterpret_cast<const void * const*>(this + 1));
958   }
959
960   /// \brief Set the pointer value of the message receiver.
961   void setReceiverPointer(void *Value) {
962     *reinterpret_cast<void **>(this + 1) = Value;
963   }
964
965   SelectorLocationsKind getSelLocsKind() const {
966     return (SelectorLocationsKind)SelLocsKind;
967   }
968   bool hasStandardSelLocs() const {
969     return getSelLocsKind() != SelLoc_NonStandard;
970   }
971
972   /// \brief Get a pointer to the stored selector identifiers locations array.
973   /// No locations will be stored if HasStandardSelLocs is true.
974   SourceLocation *getStoredSelLocs() {
975     return reinterpret_cast<SourceLocation*>(getArgs() + getNumArgs());
976   }
977   const SourceLocation *getStoredSelLocs() const {
978     return reinterpret_cast<const SourceLocation*>(getArgs() + getNumArgs());
979   }
980
981   /// \brief Get the number of stored selector identifiers locations.
982   /// No locations will be stored if HasStandardSelLocs is true.
983   unsigned getNumStoredSelLocs() const {
984     if (hasStandardSelLocs())
985       return 0;
986     return getNumSelectorLocs();
987   }
988
989   static ObjCMessageExpr *alloc(ASTContext &C,
990                                 ArrayRef<Expr *> Args,
991                                 SourceLocation RBraceLoc,
992                                 ArrayRef<SourceLocation> SelLocs,
993                                 Selector Sel,
994                                 SelectorLocationsKind &SelLocsK);
995   static ObjCMessageExpr *alloc(ASTContext &C,
996                                 unsigned NumArgs,
997                                 unsigned NumStoredSelLocs);
998
999 public:
1000   /// \brief The kind of receiver this message is sending to.
1001   enum ReceiverKind {
1002     /// \brief The receiver is a class.
1003     Class = 0,
1004     /// \brief The receiver is an object instance.
1005     Instance,
1006     /// \brief The receiver is a superclass.
1007     SuperClass,
1008     /// \brief The receiver is the instance of the superclass object.
1009     SuperInstance
1010   };
1011
1012   /// \brief Create a message send to super.
1013   ///
1014   /// \param Context The ASTContext in which this expression will be created.
1015   ///
1016   /// \param T The result type of this message.
1017   ///
1018   /// \param VK The value kind of this message.  A message returning
1019   /// a l-value or r-value reference will be an l-value or x-value,
1020   /// respectively.
1021   ///
1022   /// \param LBrac The location of the open square bracket '['.
1023   ///
1024   /// \param SuperLoc The location of the "super" keyword.
1025   ///
1026   /// \param IsInstanceSuper Whether this is an instance "super"
1027   /// message (otherwise, it's a class "super" message).
1028   ///
1029   /// \param Sel The selector used to determine which method gets called.
1030   ///
1031   /// \param Method The Objective-C method against which this message
1032   /// send was type-checked. May be NULL.
1033   ///
1034   /// \param Args The message send arguments.
1035   ///
1036   /// \param NumArgs The number of arguments.
1037   ///
1038   /// \param RBracLoc The location of the closing square bracket ']'.
1039   static ObjCMessageExpr *Create(ASTContext &Context, QualType T, 
1040                                  ExprValueKind VK,
1041                                  SourceLocation LBracLoc,
1042                                  SourceLocation SuperLoc,
1043                                  bool IsInstanceSuper,
1044                                  QualType SuperType,
1045                                  Selector Sel, 
1046                                  ArrayRef<SourceLocation> SelLocs,
1047                                  ObjCMethodDecl *Method,
1048                                  ArrayRef<Expr *> Args,
1049                                  SourceLocation RBracLoc,
1050                                  bool isImplicit);
1051
1052   /// \brief Create a class message send.
1053   ///
1054   /// \param Context The ASTContext in which this expression will be created.
1055   ///
1056   /// \param T The result type of this message.
1057   ///
1058   /// \param VK The value kind of this message.  A message returning
1059   /// a l-value or r-value reference will be an l-value or x-value,
1060   /// respectively.
1061   ///
1062   /// \param LBrac The location of the open square bracket '['.
1063   ///
1064   /// \param Receiver The type of the receiver, including
1065   /// source-location information.
1066   ///
1067   /// \param Sel The selector used to determine which method gets called.
1068   ///
1069   /// \param Method The Objective-C method against which this message
1070   /// send was type-checked. May be NULL.
1071   ///
1072   /// \param Args The message send arguments.
1073   ///
1074   /// \param NumArgs The number of arguments.
1075   ///
1076   /// \param RBracLoc The location of the closing square bracket ']'.
1077   static ObjCMessageExpr *Create(ASTContext &Context, QualType T,
1078                                  ExprValueKind VK,
1079                                  SourceLocation LBracLoc,
1080                                  TypeSourceInfo *Receiver,
1081                                  Selector Sel, 
1082                                  ArrayRef<SourceLocation> SelLocs,
1083                                  ObjCMethodDecl *Method,
1084                                  ArrayRef<Expr *> Args,
1085                                  SourceLocation RBracLoc,
1086                                  bool isImplicit);
1087
1088   /// \brief Create an instance message send.
1089   ///
1090   /// \param Context The ASTContext in which this expression will be created.
1091   ///
1092   /// \param T The result type of this message.
1093   ///
1094   /// \param VK The value kind of this message.  A message returning
1095   /// a l-value or r-value reference will be an l-value or x-value,
1096   /// respectively.
1097   ///
1098   /// \param LBrac The location of the open square bracket '['.
1099   ///
1100   /// \param Receiver The expression used to produce the object that
1101   /// will receive this message.
1102   ///
1103   /// \param Sel The selector used to determine which method gets called.
1104   ///
1105   /// \param Method The Objective-C method against which this message
1106   /// send was type-checked. May be NULL.
1107   ///
1108   /// \param Args The message send arguments.
1109   ///
1110   /// \param NumArgs The number of arguments.
1111   ///
1112   /// \param RBracLoc The location of the closing square bracket ']'.
1113   static ObjCMessageExpr *Create(ASTContext &Context, QualType T,
1114                                  ExprValueKind VK,
1115                                  SourceLocation LBracLoc,
1116                                  Expr *Receiver,
1117                                  Selector Sel, 
1118                                  ArrayRef<SourceLocation> SeLocs,
1119                                  ObjCMethodDecl *Method,
1120                                  ArrayRef<Expr *> Args,
1121                                  SourceLocation RBracLoc,
1122                                  bool isImplicit);
1123
1124   /// \brief Create an empty Objective-C message expression, to be
1125   /// filled in by subsequent calls.
1126   ///
1127   /// \param Context The context in which the message send will be created.
1128   ///
1129   /// \param NumArgs The number of message arguments, not including
1130   /// the receiver.
1131   static ObjCMessageExpr *CreateEmpty(ASTContext &Context,
1132                                       unsigned NumArgs,
1133                                       unsigned NumStoredSelLocs);
1134
1135   /// \brief Indicates whether the message send was implicitly
1136   /// generated by the implementation. If false, it was written explicitly
1137   /// in the source code.
1138   bool isImplicit() const { return IsImplicit; }
1139
1140   /// \brief Determine the kind of receiver that this message is being
1141   /// sent to.
1142   ReceiverKind getReceiverKind() const { return (ReceiverKind)Kind; }
1143
1144   /// \brief Source range of the receiver.
1145   SourceRange getReceiverRange() const;
1146
1147   /// \brief Determine whether this is an instance message to either a
1148   /// computed object or to super.
1149   bool isInstanceMessage() const {
1150     return getReceiverKind() == Instance || getReceiverKind() == SuperInstance;
1151   }
1152
1153   /// \brief Determine whether this is an class message to either a
1154   /// specified class or to super.
1155   bool isClassMessage() const {
1156     return getReceiverKind() == Class || getReceiverKind() == SuperClass;
1157   }
1158
1159   /// \brief Returns the receiver of an instance message.
1160   ///
1161   /// \brief Returns the object expression for an instance message, or
1162   /// NULL for a message that is not an instance message.
1163   Expr *getInstanceReceiver() {
1164     if (getReceiverKind() == Instance)
1165       return static_cast<Expr *>(getReceiverPointer());
1166
1167     return 0;
1168   }
1169   const Expr *getInstanceReceiver() const {
1170     return const_cast<ObjCMessageExpr*>(this)->getInstanceReceiver();
1171   }
1172
1173   /// \brief Turn this message send into an instance message that
1174   /// computes the receiver object with the given expression.
1175   void setInstanceReceiver(Expr *rec) { 
1176     Kind = Instance;
1177     setReceiverPointer(rec);
1178   }
1179   
1180   /// \brief Returns the type of a class message send, or NULL if the
1181   /// message is not a class message.
1182   QualType getClassReceiver() const { 
1183     if (TypeSourceInfo *TSInfo = getClassReceiverTypeInfo())
1184       return TSInfo->getType();
1185
1186     return QualType();
1187   }
1188
1189   /// \brief Returns a type-source information of a class message
1190   /// send, or NULL if the message is not a class message.
1191   TypeSourceInfo *getClassReceiverTypeInfo() const {
1192     if (getReceiverKind() == Class)
1193       return reinterpret_cast<TypeSourceInfo *>(getReceiverPointer());
1194     return 0;
1195   }
1196
1197   void setClassReceiver(TypeSourceInfo *TSInfo) {
1198     Kind = Class;
1199     setReceiverPointer(TSInfo);
1200   }
1201
1202   /// \brief Retrieve the location of the 'super' keyword for a class
1203   /// or instance message to 'super', otherwise an invalid source location.
1204   SourceLocation getSuperLoc() const { 
1205     if (getReceiverKind() == SuperInstance || getReceiverKind() == SuperClass)
1206       return SuperLoc;
1207
1208     return SourceLocation();
1209   }
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 0;
1253   }
1254
1255   ObjCMethodDecl *getMethodDecl() { 
1256     if (HasMethod)
1257       return reinterpret_cast<ObjCMethodDecl *>(SelectorOrMethod);
1258
1259     return 0;
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   SourceRange getSourceRange() const LLVM_READONLY {
1341     return SourceRange(LBracLoc, RBracLoc);
1342   }
1343
1344   static bool classof(const Stmt *T) {
1345     return T->getStmtClass() == ObjCMessageExprClass;
1346   }
1347   static bool classof(const ObjCMessageExpr *) { return true; }
1348
1349   // Iterators
1350   child_range children();
1351
1352   typedef ExprIterator arg_iterator;
1353   typedef ConstExprIterator const_arg_iterator;
1354
1355   arg_iterator arg_begin() { return reinterpret_cast<Stmt **>(getArgs()); }
1356   arg_iterator arg_end()   { 
1357     return reinterpret_cast<Stmt **>(getArgs() + NumArgs); 
1358   }
1359   const_arg_iterator arg_begin() const { 
1360     return reinterpret_cast<Stmt const * const*>(getArgs()); 
1361   }
1362   const_arg_iterator arg_end() const { 
1363     return reinterpret_cast<Stmt const * const*>(getArgs() + NumArgs); 
1364   }
1365
1366   friend class ASTStmtReader;
1367   friend class ASTStmtWriter;
1368 };
1369
1370 /// ObjCIsaExpr - Represent X->isa and X.isa when X is an ObjC 'id' type.
1371 /// (similar in spirit to MemberExpr).
1372 class ObjCIsaExpr : public Expr {
1373   /// Base - the expression for the base object pointer.
1374   Stmt *Base;
1375
1376   /// IsaMemberLoc - This is the location of the 'isa'.
1377   SourceLocation IsaMemberLoc;
1378
1379   /// IsArrow - True if this is "X->F", false if this is "X.F".
1380   bool IsArrow;
1381 public:
1382   ObjCIsaExpr(Expr *base, bool isarrow, SourceLocation l, QualType ty)
1383     : Expr(ObjCIsaExprClass, ty, VK_LValue, OK_Ordinary,
1384            /*TypeDependent=*/false, base->isValueDependent(),
1385            base->isInstantiationDependent(),
1386            /*ContainsUnexpandedParameterPack=*/false),
1387       Base(base), IsaMemberLoc(l), IsArrow(isarrow) {}
1388
1389   /// \brief Build an empty expression.
1390   explicit ObjCIsaExpr(EmptyShell Empty) : Expr(ObjCIsaExprClass, Empty) { }
1391
1392   void setBase(Expr *E) { Base = E; }
1393   Expr *getBase() const { return cast<Expr>(Base); }
1394
1395   bool isArrow() const { return IsArrow; }
1396   void setArrow(bool A) { IsArrow = A; }
1397
1398   /// getMemberLoc - Return the location of the "member", in X->F, it is the
1399   /// location of 'F'.
1400   SourceLocation getIsaMemberLoc() const { return IsaMemberLoc; }
1401   void setIsaMemberLoc(SourceLocation L) { IsaMemberLoc = L; }
1402
1403   SourceRange getSourceRange() const LLVM_READONLY {
1404     return SourceRange(getBase()->getLocStart(), IsaMemberLoc);
1405   }
1406
1407   SourceLocation getExprLoc() const LLVM_READONLY { return IsaMemberLoc; }
1408
1409   static bool classof(const Stmt *T) {
1410     return T->getStmtClass() == ObjCIsaExprClass;
1411   }
1412   static bool classof(const ObjCIsaExpr *) { return true; }
1413
1414   // Iterators
1415   child_range children() { return child_range(&Base, &Base+1); }
1416 };
1417
1418
1419 /// ObjCIndirectCopyRestoreExpr - Represents the passing of a function
1420 /// argument by indirect copy-restore in ARC.  This is used to support
1421 /// passing indirect arguments with the wrong lifetime, e.g. when
1422 /// passing the address of a __strong local variable to an 'out'
1423 /// parameter.  This expression kind is only valid in an "argument"
1424 /// position to some sort of call expression.
1425 ///
1426 /// The parameter must have type 'pointer to T', and the argument must
1427 /// have type 'pointer to U', where T and U agree except possibly in
1428 /// qualification.  If the argument value is null, then a null pointer
1429 /// is passed;  otherwise it points to an object A, and:
1430 /// 1. A temporary object B of type T is initialized, either by
1431 ///    zero-initialization (used when initializing an 'out' parameter)
1432 ///    or copy-initialization (used when initializing an 'inout'
1433 ///    parameter).
1434 /// 2. The address of the temporary is passed to the function.
1435 /// 3. If the call completes normally, A is move-assigned from B.
1436 /// 4. Finally, A is destroyed immediately.
1437 ///
1438 /// Currently 'T' must be a retainable object lifetime and must be
1439 /// __autoreleasing;  this qualifier is ignored when initializing
1440 /// the value.
1441 class ObjCIndirectCopyRestoreExpr : public Expr {
1442   Stmt *Operand;
1443
1444   // unsigned ObjCIndirectCopyRestoreBits.ShouldCopy : 1;
1445
1446   friend class ASTReader;
1447   friend class ASTStmtReader;
1448
1449   void setShouldCopy(bool shouldCopy) {
1450     ObjCIndirectCopyRestoreExprBits.ShouldCopy = shouldCopy;
1451   }
1452
1453   explicit ObjCIndirectCopyRestoreExpr(EmptyShell Empty)
1454     : Expr(ObjCIndirectCopyRestoreExprClass, Empty) { }
1455
1456 public:
1457   ObjCIndirectCopyRestoreExpr(Expr *operand, QualType type, bool shouldCopy)
1458     : Expr(ObjCIndirectCopyRestoreExprClass, type, VK_LValue, OK_Ordinary,
1459            operand->isTypeDependent(), operand->isValueDependent(),
1460            operand->isInstantiationDependent(),
1461            operand->containsUnexpandedParameterPack()),
1462       Operand(operand) {
1463     setShouldCopy(shouldCopy);
1464   }
1465
1466   Expr *getSubExpr() { return cast<Expr>(Operand); }
1467   const Expr *getSubExpr() const { return cast<Expr>(Operand); }
1468
1469   /// shouldCopy - True if we should do the 'copy' part of the
1470   /// copy-restore.  If false, the temporary will be zero-initialized.
1471   bool shouldCopy() const { return ObjCIndirectCopyRestoreExprBits.ShouldCopy; }
1472
1473   child_range children() { return child_range(&Operand, &Operand+1); }  
1474
1475   // Source locations are determined by the subexpression.
1476   SourceRange getSourceRange() const LLVM_READONLY {
1477     return Operand->getSourceRange();
1478   }
1479   SourceLocation getExprLoc() const LLVM_READONLY {
1480     return getSubExpr()->getExprLoc();
1481   }
1482
1483   static bool classof(const Stmt *s) {
1484     return s->getStmtClass() == ObjCIndirectCopyRestoreExprClass;
1485   }
1486   static bool classof(const ObjCIndirectCopyRestoreExpr *) { return true; }
1487 };
1488
1489 /// \brief An Objective-C "bridged" cast expression, which casts between
1490 /// Objective-C pointers and C pointers, transferring ownership in the process.
1491 ///
1492 /// \code
1493 /// NSString *str = (__bridge_transfer NSString *)CFCreateString();
1494 /// \endcode
1495 class ObjCBridgedCastExpr : public ExplicitCastExpr {
1496   SourceLocation LParenLoc;
1497   SourceLocation BridgeKeywordLoc;
1498   unsigned Kind : 2;
1499   
1500   friend class ASTStmtReader;
1501   friend class ASTStmtWriter;
1502   
1503 public:
1504   ObjCBridgedCastExpr(SourceLocation LParenLoc, ObjCBridgeCastKind Kind,
1505                       CastKind CK, SourceLocation BridgeKeywordLoc,
1506                       TypeSourceInfo *TSInfo, Expr *Operand)
1507     : ExplicitCastExpr(ObjCBridgedCastExprClass, TSInfo->getType(), VK_RValue,
1508                        CK, Operand, 0, TSInfo),
1509       LParenLoc(LParenLoc), BridgeKeywordLoc(BridgeKeywordLoc), Kind(Kind) { }
1510   
1511   /// \brief Construct an empty Objective-C bridged cast.
1512   explicit ObjCBridgedCastExpr(EmptyShell Shell)
1513     : ExplicitCastExpr(ObjCBridgedCastExprClass, Shell, 0) { }
1514
1515   SourceLocation getLParenLoc() const { return LParenLoc; }
1516
1517   /// \brief Determine which kind of bridge is being performed via this cast.
1518   ObjCBridgeCastKind getBridgeKind() const { 
1519     return static_cast<ObjCBridgeCastKind>(Kind); 
1520   }
1521   
1522   /// \brief Retrieve the kind of bridge being performed as a string.
1523   StringRef getBridgeKindName() const;
1524   
1525   /// \brief The location of the bridge keyword.
1526   SourceLocation getBridgeKeywordLoc() const { return BridgeKeywordLoc; }
1527   
1528   SourceRange getSourceRange() const LLVM_READONLY {
1529     return SourceRange(LParenLoc, getSubExpr()->getLocEnd());
1530   }
1531   
1532   static bool classof(const Stmt *T) {
1533     return T->getStmtClass() == ObjCBridgedCastExprClass;
1534   }
1535   static bool classof(const ObjCBridgedCastExpr *) { return true; }
1536  
1537 };
1538   
1539 }  // end namespace clang
1540
1541 #endif