clang API Documentation

ExprObjC.h
Go to the documentation of this file.
00001 //===--- ExprObjC.h - Classes for representing ObjC expressions -*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 //  This file defines the ExprObjC interface and subclasses.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_CLANG_AST_EXPROBJC_H
00015 #define LLVM_CLANG_AST_EXPROBJC_H
00016 
00017 #include "clang/AST/DeclObjC.h"
00018 #include "clang/AST/Expr.h"
00019 #include "clang/AST/SelectorLocationsKind.h"
00020 #include "clang/Basic/IdentifierTable.h"
00021 #include "llvm/Support/Compiler.h"
00022 
00023 namespace clang {
00024   class IdentifierInfo;
00025   class ASTContext;
00026 
00027 /// ObjCStringLiteral, used for Objective-C string literals
00028 /// i.e. @"foo".
00029 class ObjCStringLiteral : public Expr {
00030   Stmt *String;
00031   SourceLocation AtLoc;
00032 public:
00033   ObjCStringLiteral(StringLiteral *SL, QualType T, SourceLocation L)
00034     : Expr(ObjCStringLiteralClass, T, VK_RValue, OK_Ordinary, false, false,
00035            false, false),
00036       String(SL), AtLoc(L) {}
00037   explicit ObjCStringLiteral(EmptyShell Empty)
00038     : Expr(ObjCStringLiteralClass, Empty) {}
00039 
00040   StringLiteral *getString() { return cast<StringLiteral>(String); }
00041   const StringLiteral *getString() const { return cast<StringLiteral>(String); }
00042   void setString(StringLiteral *S) { String = S; }
00043 
00044   SourceLocation getAtLoc() const { return AtLoc; }
00045   void setAtLoc(SourceLocation L) { AtLoc = L; }
00046 
00047   SourceLocation getLocStart() const LLVM_READONLY { return AtLoc; }
00048   SourceLocation getLocEnd() const LLVM_READONLY { return String->getLocEnd(); }
00049 
00050   static bool classof(const Stmt *T) {
00051     return T->getStmtClass() == ObjCStringLiteralClass;
00052   }
00053 
00054   // Iterators
00055   child_range children() { return child_range(&String, &String+1); }
00056 };
00057 
00058 /// ObjCBoolLiteralExpr - Objective-C Boolean Literal.
00059 ///
00060 class ObjCBoolLiteralExpr : public Expr {
00061   bool Value;
00062   SourceLocation Loc;
00063 public:
00064   ObjCBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) :
00065   Expr(ObjCBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
00066        false, false), Value(val), Loc(l) {}
00067     
00068   explicit ObjCBoolLiteralExpr(EmptyShell Empty)
00069   : Expr(ObjCBoolLiteralExprClass, Empty) { }
00070     
00071   bool getValue() const { return Value; }
00072   void setValue(bool V) { Value = V; }
00073     
00074   SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
00075   SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
00076 
00077   SourceLocation getLocation() const { return Loc; }
00078   void setLocation(SourceLocation L) { Loc = L; }
00079     
00080   static bool classof(const Stmt *T) {
00081     return T->getStmtClass() == ObjCBoolLiteralExprClass;
00082   }
00083     
00084   // Iterators
00085   child_range children() { return child_range(); }
00086 };
00087 
00088 /// ObjCBoxedExpr - used for generalized expression boxing.
00089 /// as in: @(strdup("hello world")) or @(random())
00090 /// Also used for boxing non-parenthesized numeric literals;
00091 /// as in: @42 or \@true (c++/objc++) or \@__yes (c/objc).
00092 class ObjCBoxedExpr : public Expr {
00093   Stmt *SubExpr;
00094   ObjCMethodDecl *BoxingMethod;
00095   SourceRange Range;
00096 public:
00097   ObjCBoxedExpr(Expr *E, QualType T, ObjCMethodDecl *method,
00098                      SourceRange R)
00099   : Expr(ObjCBoxedExprClass, T, VK_RValue, OK_Ordinary, 
00100          E->isTypeDependent(), E->isValueDependent(), 
00101          E->isInstantiationDependent(), E->containsUnexpandedParameterPack()), 
00102          SubExpr(E), BoxingMethod(method), Range(R) {}
00103   explicit ObjCBoxedExpr(EmptyShell Empty)
00104   : Expr(ObjCBoxedExprClass, Empty) {}
00105   
00106   Expr *getSubExpr() { return cast<Expr>(SubExpr); }
00107   const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
00108   
00109   ObjCMethodDecl *getBoxingMethod() const {
00110     return BoxingMethod; 
00111   }
00112   
00113   SourceLocation getAtLoc() const { return Range.getBegin(); }
00114   
00115   SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
00116   SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
00117   SourceRange getSourceRange() const LLVM_READONLY {
00118     return Range;
00119   }
00120   
00121   static bool classof(const Stmt *T) {
00122     return T->getStmtClass() == ObjCBoxedExprClass;
00123   }
00124   
00125   // Iterators
00126   child_range children() { return child_range(&SubExpr, &SubExpr+1); }
00127   
00128   friend class ASTStmtReader;
00129 };
00130 
00131 /// ObjCArrayLiteral - used for objective-c array containers; as in:
00132 /// @[@"Hello", NSApp, [NSNumber numberWithInt:42]];
00133 class ObjCArrayLiteral : public Expr {
00134   unsigned NumElements;
00135   SourceRange Range;
00136   ObjCMethodDecl *ArrayWithObjectsMethod;
00137   
00138   ObjCArrayLiteral(ArrayRef<Expr *> Elements,
00139                    QualType T, ObjCMethodDecl * Method,
00140                    SourceRange SR);
00141   
00142   explicit ObjCArrayLiteral(EmptyShell Empty, unsigned NumElements)
00143     : Expr(ObjCArrayLiteralClass, Empty), NumElements(NumElements) {}
00144 
00145 public:
00146   static ObjCArrayLiteral *Create(const ASTContext &C,
00147                                   ArrayRef<Expr *> Elements,
00148                                   QualType T, ObjCMethodDecl * Method,
00149                                   SourceRange SR);
00150 
00151   static ObjCArrayLiteral *CreateEmpty(const ASTContext &C,
00152                                        unsigned NumElements);
00153 
00154   SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
00155   SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
00156   SourceRange getSourceRange() const LLVM_READONLY { return Range; }
00157 
00158   static bool classof(const Stmt *T) {
00159       return T->getStmtClass() == ObjCArrayLiteralClass;
00160   }
00161 
00162   /// \brief Retrieve elements of array of literals.
00163   Expr **getElements() { return reinterpret_cast<Expr **>(this + 1); }
00164 
00165   /// \brief Retrieve elements of array of literals.
00166   const Expr * const *getElements() const { 
00167     return reinterpret_cast<const Expr * const*>(this + 1); 
00168   }
00169 
00170   /// getNumElements - Return number of elements of objective-c array literal.
00171   unsigned getNumElements() const { return NumElements; }
00172     
00173     /// getExpr - Return the Expr at the specified index.
00174   Expr *getElement(unsigned Index) {
00175     assert((Index < NumElements) && "Arg access out of range!");
00176     return cast<Expr>(getElements()[Index]);
00177   }
00178   const Expr *getElement(unsigned Index) const {
00179     assert((Index < NumElements) && "Arg access out of range!");
00180     return cast<Expr>(getElements()[Index]);
00181   }
00182     
00183   ObjCMethodDecl *getArrayWithObjectsMethod() const {
00184     return ArrayWithObjectsMethod; 
00185   }
00186     
00187   // Iterators
00188   child_range children() { 
00189     return child_range((Stmt **)getElements(), 
00190                        (Stmt **)getElements() + NumElements);
00191   }
00192     
00193   friend class ASTStmtReader;
00194 };
00195 
00196 /// \brief An element in an Objective-C dictionary literal.
00197 ///
00198 struct ObjCDictionaryElement {
00199   /// \brief The key for the dictionary element.
00200   Expr *Key;
00201   
00202   /// \brief The value of the dictionary element.
00203   Expr *Value;
00204   
00205   /// \brief The location of the ellipsis, if this is a pack expansion.
00206   SourceLocation EllipsisLoc;
00207   
00208   /// \brief The number of elements this pack expansion will expand to, if
00209   /// this is a pack expansion and is known.
00210   Optional<unsigned> NumExpansions;
00211 
00212   /// \brief Determines whether this dictionary element is a pack expansion.
00213   bool isPackExpansion() const { return EllipsisLoc.isValid(); }
00214 };
00215 } // end namespace clang
00216 
00217 namespace llvm {
00218 template <> struct isPodLike<clang::ObjCDictionaryElement> : std::true_type {};
00219 }
00220 
00221 namespace clang {
00222 /// ObjCDictionaryLiteral - AST node to represent objective-c dictionary 
00223 /// literals; as in:  @{@"name" : NSUserName(), @"date" : [NSDate date] };
00224 class ObjCDictionaryLiteral : public Expr {
00225   /// \brief Key/value pair used to store the key and value of a given element.
00226   ///
00227   /// Objects of this type are stored directly after the expression.
00228   struct KeyValuePair {
00229     Expr *Key;
00230     Expr *Value;
00231   };
00232   
00233   /// \brief Data that describes an element that is a pack expansion, used if any
00234   /// of the elements in the dictionary literal are pack expansions.
00235   struct ExpansionData {
00236     /// \brief The location of the ellipsis, if this element is a pack
00237     /// expansion.
00238     SourceLocation EllipsisLoc;
00239 
00240     /// \brief If non-zero, the number of elements that this pack
00241     /// expansion will expand to (+1).
00242     unsigned NumExpansionsPlusOne;
00243   };
00244 
00245   /// \brief The number of elements in this dictionary literal.
00246   unsigned NumElements : 31;
00247   
00248   /// \brief Determine whether this dictionary literal has any pack expansions.
00249   ///
00250   /// If the dictionary literal has pack expansions, then there will
00251   /// be an array of pack expansion data following the array of
00252   /// key/value pairs, which provide the locations of the ellipses (if
00253   /// any) and number of elements in the expansion (if known). If
00254   /// there are no pack expansions, we optimize away this storage.
00255   unsigned HasPackExpansions : 1;
00256   
00257   SourceRange Range;
00258   ObjCMethodDecl *DictWithObjectsMethod;
00259     
00260   ObjCDictionaryLiteral(ArrayRef<ObjCDictionaryElement> VK, 
00261                         bool HasPackExpansions,
00262                         QualType T, ObjCMethodDecl *method,
00263                         SourceRange SR);
00264 
00265   explicit ObjCDictionaryLiteral(EmptyShell Empty, unsigned NumElements,
00266                                  bool HasPackExpansions)
00267     : Expr(ObjCDictionaryLiteralClass, Empty), NumElements(NumElements),
00268       HasPackExpansions(HasPackExpansions) {}
00269 
00270   KeyValuePair *getKeyValues() {
00271     return reinterpret_cast<KeyValuePair *>(this + 1);
00272   }
00273   
00274   const KeyValuePair *getKeyValues() const {
00275     return reinterpret_cast<const KeyValuePair *>(this + 1);
00276   }
00277 
00278   ExpansionData *getExpansionData() {
00279     if (!HasPackExpansions)
00280       return nullptr;
00281     
00282     return reinterpret_cast<ExpansionData *>(getKeyValues() + NumElements);
00283   }
00284 
00285   const ExpansionData *getExpansionData() const {
00286     if (!HasPackExpansions)
00287       return nullptr;
00288     
00289     return reinterpret_cast<const ExpansionData *>(getKeyValues()+NumElements);
00290   }
00291 
00292 public:
00293   static ObjCDictionaryLiteral *Create(const ASTContext &C,
00294                                        ArrayRef<ObjCDictionaryElement> VK, 
00295                                        bool HasPackExpansions,
00296                                        QualType T, ObjCMethodDecl *method,
00297                                        SourceRange SR);
00298   
00299   static ObjCDictionaryLiteral *CreateEmpty(const ASTContext &C,
00300                                             unsigned NumElements,
00301                                             bool HasPackExpansions);
00302   
00303   /// getNumElements - Return number of elements of objective-c dictionary 
00304   /// literal.
00305   unsigned getNumElements() const { return NumElements; }
00306 
00307   ObjCDictionaryElement getKeyValueElement(unsigned Index) const {
00308     assert((Index < NumElements) && "Arg access out of range!");
00309     const KeyValuePair &KV = getKeyValues()[Index];
00310     ObjCDictionaryElement Result = { KV.Key, KV.Value, SourceLocation(), None };
00311     if (HasPackExpansions) {
00312       const ExpansionData &Expansion = getExpansionData()[Index];
00313       Result.EllipsisLoc = Expansion.EllipsisLoc;
00314       if (Expansion.NumExpansionsPlusOne > 0)
00315         Result.NumExpansions = Expansion.NumExpansionsPlusOne - 1;
00316     }
00317     return Result;
00318   }
00319     
00320   ObjCMethodDecl *getDictWithObjectsMethod() const
00321     { return DictWithObjectsMethod; }
00322 
00323   SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
00324   SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
00325   SourceRange getSourceRange() const LLVM_READONLY { return Range; }
00326   
00327   static bool classof(const Stmt *T) {
00328       return T->getStmtClass() == ObjCDictionaryLiteralClass;
00329   }
00330     
00331   // Iterators
00332   child_range children() { 
00333     // Note: we're taking advantage of the layout of the KeyValuePair struct
00334     // here. If that struct changes, this code will need to change as well.
00335     return child_range(reinterpret_cast<Stmt **>(this + 1),
00336                        reinterpret_cast<Stmt **>(this + 1) + NumElements * 2);
00337   }
00338     
00339   friend class ASTStmtReader;
00340   friend class ASTStmtWriter;
00341 };
00342 
00343 
00344 /// ObjCEncodeExpr, used for \@encode in Objective-C.  \@encode has the same
00345 /// type and behavior as StringLiteral except that the string initializer is
00346 /// obtained from ASTContext with the encoding type as an argument.
00347 class ObjCEncodeExpr : public Expr {
00348   TypeSourceInfo *EncodedType;
00349   SourceLocation AtLoc, RParenLoc;
00350 public:
00351   ObjCEncodeExpr(QualType T, TypeSourceInfo *EncodedType,
00352                  SourceLocation at, SourceLocation rp)
00353     : Expr(ObjCEncodeExprClass, T, VK_LValue, OK_Ordinary,
00354            EncodedType->getType()->isDependentType(),
00355            EncodedType->getType()->isDependentType(),
00356            EncodedType->getType()->isInstantiationDependentType(),
00357            EncodedType->getType()->containsUnexpandedParameterPack()), 
00358       EncodedType(EncodedType), AtLoc(at), RParenLoc(rp) {}
00359 
00360   explicit ObjCEncodeExpr(EmptyShell Empty) : Expr(ObjCEncodeExprClass, Empty){}
00361 
00362 
00363   SourceLocation getAtLoc() const { return AtLoc; }
00364   void setAtLoc(SourceLocation L) { AtLoc = L; }
00365   SourceLocation getRParenLoc() const { return RParenLoc; }
00366   void setRParenLoc(SourceLocation L) { RParenLoc = L; }
00367 
00368   QualType getEncodedType() const { return EncodedType->getType(); }
00369 
00370   TypeSourceInfo *getEncodedTypeSourceInfo() const { return EncodedType; }
00371   void setEncodedTypeSourceInfo(TypeSourceInfo *EncType) { 
00372     EncodedType = EncType; 
00373   }
00374 
00375   SourceLocation getLocStart() const LLVM_READONLY { return AtLoc; }
00376   SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
00377 
00378   static bool classof(const Stmt *T) {
00379     return T->getStmtClass() == ObjCEncodeExprClass;
00380   }
00381 
00382   // Iterators
00383   child_range children() { return child_range(); }
00384 };
00385 
00386 /// ObjCSelectorExpr used for \@selector in Objective-C.
00387 class ObjCSelectorExpr : public Expr {
00388   Selector SelName;
00389   SourceLocation AtLoc, RParenLoc;
00390 public:
00391   ObjCSelectorExpr(QualType T, Selector selInfo,
00392                    SourceLocation at, SourceLocation rp)
00393     : Expr(ObjCSelectorExprClass, T, VK_RValue, OK_Ordinary, false, false, 
00394            false, false),
00395     SelName(selInfo), AtLoc(at), RParenLoc(rp){}
00396   explicit ObjCSelectorExpr(EmptyShell Empty)
00397    : Expr(ObjCSelectorExprClass, Empty) {}
00398 
00399   Selector getSelector() const { return SelName; }
00400   void setSelector(Selector S) { SelName = S; }
00401 
00402   SourceLocation getAtLoc() const { return AtLoc; }
00403   SourceLocation getRParenLoc() const { return RParenLoc; }
00404   void setAtLoc(SourceLocation L) { AtLoc = L; }
00405   void setRParenLoc(SourceLocation L) { RParenLoc = L; }
00406 
00407   SourceLocation getLocStart() const LLVM_READONLY { return AtLoc; }
00408   SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
00409 
00410   /// getNumArgs - Return the number of actual arguments to this call.
00411   unsigned getNumArgs() const { return SelName.getNumArgs(); }
00412 
00413   static bool classof(const Stmt *T) {
00414     return T->getStmtClass() == ObjCSelectorExprClass;
00415   }
00416 
00417   // Iterators
00418   child_range children() { return child_range(); }
00419 };
00420 
00421 /// ObjCProtocolExpr used for protocol expression in Objective-C.
00422 ///
00423 /// This is used as: \@protocol(foo), as in:
00424 /// \code
00425 ///   [obj conformsToProtocol:@protocol(foo)]
00426 /// \endcode
00427 ///
00428 /// The return type is "Protocol*".
00429 class ObjCProtocolExpr : public Expr {
00430   ObjCProtocolDecl *TheProtocol;
00431   SourceLocation AtLoc, ProtoLoc, RParenLoc;
00432 public:
00433   ObjCProtocolExpr(QualType T, ObjCProtocolDecl *protocol,
00434                  SourceLocation at, SourceLocation protoLoc, SourceLocation rp)
00435     : Expr(ObjCProtocolExprClass, T, VK_RValue, OK_Ordinary, false, false,
00436            false, false),
00437       TheProtocol(protocol), AtLoc(at), ProtoLoc(protoLoc), RParenLoc(rp) {}
00438   explicit ObjCProtocolExpr(EmptyShell Empty)
00439     : Expr(ObjCProtocolExprClass, Empty) {}
00440 
00441   ObjCProtocolDecl *getProtocol() const { return TheProtocol; }
00442   void setProtocol(ObjCProtocolDecl *P) { TheProtocol = P; }
00443 
00444   SourceLocation getProtocolIdLoc() const { return ProtoLoc; }
00445   SourceLocation getAtLoc() const { return AtLoc; }
00446   SourceLocation getRParenLoc() const { return RParenLoc; }
00447   void setAtLoc(SourceLocation L) { AtLoc = L; }
00448   void setRParenLoc(SourceLocation L) { RParenLoc = L; }
00449 
00450   SourceLocation getLocStart() const LLVM_READONLY { return AtLoc; }
00451   SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
00452 
00453   static bool classof(const Stmt *T) {
00454     return T->getStmtClass() == ObjCProtocolExprClass;
00455   }
00456 
00457   // Iterators
00458   child_range children() { return child_range(); }
00459 
00460   friend class ASTStmtReader;
00461   friend class ASTStmtWriter;
00462 };
00463 
00464 /// ObjCIvarRefExpr - A reference to an ObjC instance variable.
00465 class ObjCIvarRefExpr : public Expr {
00466   ObjCIvarDecl *D;
00467   Stmt *Base;
00468   SourceLocation Loc;
00469   /// OpLoc - This is the location of '.' or '->'
00470   SourceLocation OpLoc;
00471   
00472   bool IsArrow:1;      // True if this is "X->F", false if this is "X.F".
00473   bool IsFreeIvar:1;   // True if ivar reference has no base (self assumed).
00474 
00475 public:
00476   ObjCIvarRefExpr(ObjCIvarDecl *d, QualType t,
00477                   SourceLocation l, SourceLocation oploc,
00478                   Expr *base,
00479                   bool arrow = false, bool freeIvar = false) :
00480     Expr(ObjCIvarRefExprClass, t, VK_LValue,
00481          d->isBitField() ? OK_BitField : OK_Ordinary,
00482          /*TypeDependent=*/false, base->isValueDependent(), 
00483          base->isInstantiationDependent(),
00484          base->containsUnexpandedParameterPack()), 
00485     D(d), Base(base), Loc(l), OpLoc(oploc),
00486     IsArrow(arrow), IsFreeIvar(freeIvar) {}
00487 
00488   explicit ObjCIvarRefExpr(EmptyShell Empty)
00489     : Expr(ObjCIvarRefExprClass, Empty) {}
00490 
00491   ObjCIvarDecl *getDecl() { return D; }
00492   const ObjCIvarDecl *getDecl() const { return D; }
00493   void setDecl(ObjCIvarDecl *d) { D = d; }
00494 
00495   const Expr *getBase() const { return cast<Expr>(Base); }
00496   Expr *getBase() { return cast<Expr>(Base); }
00497   void setBase(Expr * base) { Base = base; }
00498 
00499   bool isArrow() const { return IsArrow; }
00500   bool isFreeIvar() const { return IsFreeIvar; }
00501   void setIsArrow(bool A) { IsArrow = A; }
00502   void setIsFreeIvar(bool A) { IsFreeIvar = A; }
00503 
00504   SourceLocation getLocation() const { return Loc; }
00505   void setLocation(SourceLocation L) { Loc = L; }
00506 
00507   SourceLocation getLocStart() const LLVM_READONLY {
00508     return isFreeIvar() ? Loc : getBase()->getLocStart();
00509   }
00510   SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
00511   
00512   SourceLocation getOpLoc() const { return OpLoc; }
00513   void setOpLoc(SourceLocation L) { OpLoc = L; }
00514 
00515   static bool classof(const Stmt *T) {
00516     return T->getStmtClass() == ObjCIvarRefExprClass;
00517   }
00518 
00519   // Iterators
00520   child_range children() { return child_range(&Base, &Base+1); }
00521 };
00522 
00523 /// ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC
00524 /// property.
00525 class ObjCPropertyRefExpr : public Expr {
00526 private:
00527   /// If the bool is true, this is an implicit property reference; the
00528   /// pointer is an (optional) ObjCMethodDecl and Setter may be set.
00529   /// if the bool is false, this is an explicit property reference;
00530   /// the pointer is an ObjCPropertyDecl and Setter is always null.
00531   llvm::PointerIntPair<NamedDecl*, 1, bool> PropertyOrGetter;
00532 
00533   /// \brief Indicates whether the property reference will result in a message
00534   /// to the getter, the setter, or both.
00535   /// This applies to both implicit and explicit property references.
00536   enum MethodRefFlags {
00537     MethodRef_None = 0,
00538     MethodRef_Getter = 0x1,
00539     MethodRef_Setter = 0x2
00540   };
00541 
00542   /// \brief Contains the Setter method pointer and MethodRefFlags bit flags.
00543   llvm::PointerIntPair<ObjCMethodDecl *, 2, unsigned> SetterAndMethodRefFlags;
00544 
00545   // FIXME: Maybe we should store the property identifier here,
00546   // because it's not rederivable from the other data when there's an
00547   // implicit property with no getter (because the 'foo' -> 'setFoo:'
00548   // transformation is lossy on the first character).
00549 
00550   SourceLocation IdLoc;
00551   
00552   /// \brief When the receiver in property access is 'super', this is
00553   /// the location of the 'super' keyword.  When it's an interface,
00554   /// this is that interface.
00555   SourceLocation ReceiverLoc;
00556   llvm::PointerUnion3<Stmt*, const Type*, ObjCInterfaceDecl*> Receiver;
00557   
00558 public:
00559   ObjCPropertyRefExpr(ObjCPropertyDecl *PD, QualType t,
00560                       ExprValueKind VK, ExprObjectKind OK,
00561                       SourceLocation l, Expr *base)
00562     : Expr(ObjCPropertyRefExprClass, t, VK, OK,
00563            /*TypeDependent=*/false, base->isValueDependent(),
00564            base->isInstantiationDependent(),
00565            base->containsUnexpandedParameterPack()),
00566       PropertyOrGetter(PD, false), SetterAndMethodRefFlags(),
00567       IdLoc(l), ReceiverLoc(), Receiver(base) {
00568     assert(t->isSpecificPlaceholderType(BuiltinType::PseudoObject));
00569   }
00570   
00571   ObjCPropertyRefExpr(ObjCPropertyDecl *PD, QualType t,
00572                       ExprValueKind VK, ExprObjectKind OK,
00573                       SourceLocation l, SourceLocation sl, QualType st)
00574     : Expr(ObjCPropertyRefExprClass, t, VK, OK,
00575            /*TypeDependent=*/false, false, st->isInstantiationDependentType(),
00576            st->containsUnexpandedParameterPack()),
00577       PropertyOrGetter(PD, false), SetterAndMethodRefFlags(),
00578       IdLoc(l), ReceiverLoc(sl), Receiver(st.getTypePtr()) {
00579     assert(t->isSpecificPlaceholderType(BuiltinType::PseudoObject));
00580   }
00581 
00582   ObjCPropertyRefExpr(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter,
00583                       QualType T, ExprValueKind VK, ExprObjectKind OK,
00584                       SourceLocation IdLoc, Expr *Base)
00585     : Expr(ObjCPropertyRefExprClass, T, VK, OK, false,
00586            Base->isValueDependent(), Base->isInstantiationDependent(),
00587            Base->containsUnexpandedParameterPack()),
00588       PropertyOrGetter(Getter, true), SetterAndMethodRefFlags(Setter, 0),
00589       IdLoc(IdLoc), ReceiverLoc(), Receiver(Base) {
00590     assert(T->isSpecificPlaceholderType(BuiltinType::PseudoObject));
00591   }
00592 
00593   ObjCPropertyRefExpr(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter,
00594                       QualType T, ExprValueKind VK, ExprObjectKind OK,
00595                       SourceLocation IdLoc,
00596                       SourceLocation SuperLoc, QualType SuperTy)
00597     : Expr(ObjCPropertyRefExprClass, T, VK, OK, false, false, false, false),
00598       PropertyOrGetter(Getter, true), SetterAndMethodRefFlags(Setter, 0),
00599       IdLoc(IdLoc), ReceiverLoc(SuperLoc), Receiver(SuperTy.getTypePtr()) {
00600     assert(T->isSpecificPlaceholderType(BuiltinType::PseudoObject));
00601   }
00602 
00603   ObjCPropertyRefExpr(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter,
00604                       QualType T, ExprValueKind VK, ExprObjectKind OK,
00605                       SourceLocation IdLoc,
00606                       SourceLocation ReceiverLoc, ObjCInterfaceDecl *Receiver)
00607     : Expr(ObjCPropertyRefExprClass, T, VK, OK, false, false, false, false),
00608       PropertyOrGetter(Getter, true), SetterAndMethodRefFlags(Setter, 0),
00609       IdLoc(IdLoc), ReceiverLoc(ReceiverLoc), Receiver(Receiver) {
00610     assert(T->isSpecificPlaceholderType(BuiltinType::PseudoObject));
00611   }
00612 
00613   explicit ObjCPropertyRefExpr(EmptyShell Empty)
00614     : Expr(ObjCPropertyRefExprClass, Empty) {}
00615 
00616   bool isImplicitProperty() const { return PropertyOrGetter.getInt(); }
00617   bool isExplicitProperty() const { return !PropertyOrGetter.getInt(); }
00618 
00619   ObjCPropertyDecl *getExplicitProperty() const {
00620     assert(!isImplicitProperty());
00621     return cast<ObjCPropertyDecl>(PropertyOrGetter.getPointer());
00622   }
00623 
00624   ObjCMethodDecl *getImplicitPropertyGetter() const {
00625     assert(isImplicitProperty());
00626     return cast_or_null<ObjCMethodDecl>(PropertyOrGetter.getPointer());
00627   }
00628 
00629   ObjCMethodDecl *getImplicitPropertySetter() const {
00630     assert(isImplicitProperty());
00631     return SetterAndMethodRefFlags.getPointer();
00632   }
00633 
00634   Selector getGetterSelector() const {
00635     if (isImplicitProperty())
00636       return getImplicitPropertyGetter()->getSelector();
00637     return getExplicitProperty()->getGetterName();
00638   }
00639 
00640   Selector getSetterSelector() const {
00641     if (isImplicitProperty())
00642       return getImplicitPropertySetter()->getSelector();
00643     return getExplicitProperty()->getSetterName();
00644   }
00645 
00646   /// \brief True if the property reference will result in a message to the
00647   /// getter.
00648   /// This applies to both implicit and explicit property references.
00649   bool isMessagingGetter() const {
00650     return SetterAndMethodRefFlags.getInt() & MethodRef_Getter;
00651   }
00652 
00653   /// \brief True if the property reference will result in a message to the
00654   /// setter.
00655   /// This applies to both implicit and explicit property references.
00656   bool isMessagingSetter() const {
00657     return SetterAndMethodRefFlags.getInt() & MethodRef_Setter;
00658   }
00659 
00660   void setIsMessagingGetter(bool val = true) {
00661     setMethodRefFlag(MethodRef_Getter, val);
00662   }
00663 
00664   void setIsMessagingSetter(bool val = true) {
00665     setMethodRefFlag(MethodRef_Setter, val);
00666   }
00667 
00668   const Expr *getBase() const { 
00669     return cast<Expr>(Receiver.get<Stmt*>()); 
00670   }
00671   Expr *getBase() { 
00672     return cast<Expr>(Receiver.get<Stmt*>()); 
00673   }
00674 
00675   SourceLocation getLocation() const { return IdLoc; }
00676   
00677   SourceLocation getReceiverLocation() const { return ReceiverLoc; }
00678   QualType getSuperReceiverType() const { 
00679     return QualType(Receiver.get<const Type*>(), 0); 
00680   }
00681   QualType getGetterResultType() const {
00682     QualType ResultType;
00683     if (isExplicitProperty()) {
00684       const ObjCPropertyDecl *PDecl = getExplicitProperty();
00685       if (const ObjCMethodDecl *Getter = PDecl->getGetterMethodDecl())
00686         ResultType = Getter->getReturnType();
00687       else
00688         ResultType = PDecl->getType();
00689     } else {
00690       const ObjCMethodDecl *Getter = getImplicitPropertyGetter();
00691       if (Getter)
00692         ResultType = Getter->getReturnType(); // with reference!
00693     }
00694     return ResultType;
00695   }
00696 
00697   QualType getSetterArgType() const {
00698     QualType ArgType;
00699     if (isImplicitProperty()) {
00700       const ObjCMethodDecl *Setter = getImplicitPropertySetter();
00701       ObjCMethodDecl::param_const_iterator P = Setter->param_begin(); 
00702       ArgType = (*P)->getType();
00703     } else {
00704       if (ObjCPropertyDecl *PDecl = getExplicitProperty())
00705         if (const ObjCMethodDecl *Setter = PDecl->getSetterMethodDecl()) {
00706           ObjCMethodDecl::param_const_iterator P = Setter->param_begin(); 
00707           ArgType = (*P)->getType();
00708         }
00709       if (ArgType.isNull())
00710         ArgType = getType();
00711     }
00712     return ArgType;
00713   }
00714   
00715   ObjCInterfaceDecl *getClassReceiver() const {
00716     return Receiver.get<ObjCInterfaceDecl*>();
00717   }
00718   bool isObjectReceiver() const { return Receiver.is<Stmt*>(); }
00719   bool isSuperReceiver() const { return Receiver.is<const Type*>(); }
00720   bool isClassReceiver() const { return Receiver.is<ObjCInterfaceDecl*>(); }
00721 
00722   SourceLocation getLocStart() const LLVM_READONLY {
00723     return isObjectReceiver() ? getBase()->getLocStart() :getReceiverLocation();
00724   }
00725   SourceLocation getLocEnd() const LLVM_READONLY { return IdLoc; }
00726 
00727   static bool classof(const Stmt *T) {
00728     return T->getStmtClass() == ObjCPropertyRefExprClass;
00729   }
00730 
00731   // Iterators
00732   child_range children() {
00733     if (Receiver.is<Stmt*>()) {
00734       Stmt **begin = reinterpret_cast<Stmt**>(&Receiver); // hack!
00735       return child_range(begin, begin+1);
00736     }
00737     return child_range();
00738   }
00739 
00740 private:
00741   friend class ASTStmtReader;
00742   friend class ASTStmtWriter;
00743   void setExplicitProperty(ObjCPropertyDecl *D, unsigned methRefFlags) {
00744     PropertyOrGetter.setPointer(D);
00745     PropertyOrGetter.setInt(false);
00746     SetterAndMethodRefFlags.setPointer(nullptr);
00747     SetterAndMethodRefFlags.setInt(methRefFlags);
00748   }
00749   void setImplicitProperty(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter,
00750                            unsigned methRefFlags) {
00751     PropertyOrGetter.setPointer(Getter);
00752     PropertyOrGetter.setInt(true);
00753     SetterAndMethodRefFlags.setPointer(Setter);
00754     SetterAndMethodRefFlags.setInt(methRefFlags);
00755   }
00756   void setBase(Expr *Base) { Receiver = Base; }
00757   void setSuperReceiver(QualType T) { Receiver = T.getTypePtr(); }
00758   void setClassReceiver(ObjCInterfaceDecl *D) { Receiver = D; }
00759 
00760   void setLocation(SourceLocation L) { IdLoc = L; }
00761   void setReceiverLocation(SourceLocation Loc) { ReceiverLoc = Loc; }
00762 
00763   void setMethodRefFlag(MethodRefFlags flag, bool val) {
00764     unsigned f = SetterAndMethodRefFlags.getInt();
00765     if (val)
00766       f |= flag;
00767     else
00768       f &= ~flag;
00769     SetterAndMethodRefFlags.setInt(f);
00770   }
00771 };
00772   
00773 /// ObjCSubscriptRefExpr - used for array and dictionary subscripting.
00774 /// array[4] = array[3]; dictionary[key] = dictionary[alt_key];
00775 ///
00776 class ObjCSubscriptRefExpr : public Expr {
00777   // Location of ']' in an indexing expression.
00778   SourceLocation RBracket;
00779   // array/dictionary base expression.
00780   // for arrays, this is a numeric expression. For dictionaries, this is
00781   // an objective-c object pointer expression.
00782   enum { BASE, KEY, END_EXPR };
00783   Stmt* SubExprs[END_EXPR];
00784   
00785   ObjCMethodDecl *GetAtIndexMethodDecl;
00786   
00787   // For immutable objects this is null. When ObjCSubscriptRefExpr is to read
00788   // an indexed object this is null too.
00789   ObjCMethodDecl *SetAtIndexMethodDecl;
00790   
00791 public:
00792   
00793   ObjCSubscriptRefExpr(Expr *base, Expr *key, QualType T,
00794                        ExprValueKind VK, ExprObjectKind OK,
00795                        ObjCMethodDecl *getMethod,
00796                        ObjCMethodDecl *setMethod, SourceLocation RB)
00797     : Expr(ObjCSubscriptRefExprClass, T, VK, OK, 
00798            base->isTypeDependent() || key->isTypeDependent(), 
00799            base->isValueDependent() || key->isValueDependent(),
00800            base->isInstantiationDependent() || key->isInstantiationDependent(),
00801            (base->containsUnexpandedParameterPack() ||
00802             key->containsUnexpandedParameterPack())),
00803       RBracket(RB), 
00804   GetAtIndexMethodDecl(getMethod), 
00805   SetAtIndexMethodDecl(setMethod) 
00806     {SubExprs[BASE] = base; SubExprs[KEY] = key;}
00807 
00808   explicit ObjCSubscriptRefExpr(EmptyShell Empty)
00809     : Expr(ObjCSubscriptRefExprClass, Empty) {}
00810   
00811   static ObjCSubscriptRefExpr *Create(const ASTContext &C,
00812                                       Expr *base,
00813                                       Expr *key, QualType T, 
00814                                       ObjCMethodDecl *getMethod,
00815                                       ObjCMethodDecl *setMethod, 
00816                                       SourceLocation RB);
00817   
00818   SourceLocation getRBracket() const { return RBracket; }
00819   void setRBracket(SourceLocation RB) { RBracket = RB; }
00820 
00821   SourceLocation getLocStart() const LLVM_READONLY {
00822     return SubExprs[BASE]->getLocStart();
00823   }
00824   SourceLocation getLocEnd() const LLVM_READONLY { return RBracket; }
00825 
00826   static bool classof(const Stmt *T) {
00827     return T->getStmtClass() == ObjCSubscriptRefExprClass;
00828   }
00829   
00830   Expr *getBaseExpr() const { return cast<Expr>(SubExprs[BASE]); }
00831   void setBaseExpr(Stmt *S) { SubExprs[BASE] = S; }
00832   
00833   Expr *getKeyExpr() const { return cast<Expr>(SubExprs[KEY]); }
00834   void setKeyExpr(Stmt *S) { SubExprs[KEY] = S; }
00835   
00836   ObjCMethodDecl *getAtIndexMethodDecl() const {
00837     return GetAtIndexMethodDecl;
00838   }
00839  
00840   ObjCMethodDecl *setAtIndexMethodDecl() const {
00841     return SetAtIndexMethodDecl;
00842   }
00843   
00844   bool isArraySubscriptRefExpr() const {
00845     return getKeyExpr()->getType()->isIntegralOrEnumerationType();
00846   }
00847   
00848   child_range children() {
00849     return child_range(SubExprs, SubExprs+END_EXPR);
00850   }
00851 private:
00852   friend class ASTStmtReader;
00853 };
00854   
00855 
00856 /// \brief An expression that sends a message to the given Objective-C
00857 /// object or class.
00858 ///
00859 /// The following contains two message send expressions:
00860 ///
00861 /// \code
00862 ///   [[NSString alloc] initWithString:@"Hello"]
00863 /// \endcode
00864 ///
00865 /// The innermost message send invokes the "alloc" class method on the
00866 /// NSString class, while the outermost message send invokes the
00867 /// "initWithString" instance method on the object returned from
00868 /// NSString's "alloc". In all, an Objective-C message send can take
00869 /// on four different (although related) forms:
00870 ///
00871 ///   1. Send to an object instance.
00872 ///   2. Send to a class.
00873 ///   3. Send to the superclass instance of the current class.
00874 ///   4. Send to the superclass of the current class.
00875 ///
00876 /// All four kinds of message sends are modeled by the ObjCMessageExpr
00877 /// class, and can be distinguished via \c getReceiverKind(). Example:
00878 ///
00879 class ObjCMessageExpr : public Expr {
00880   /// \brief Stores either the selector that this message is sending
00881   /// to (when \c HasMethod is zero) or an \c ObjCMethodDecl pointer
00882   /// referring to the method that we type-checked against.
00883   uintptr_t SelectorOrMethod;
00884 
00885   enum { NumArgsBitWidth = 16 };
00886 
00887   /// \brief The number of arguments in the message send, not
00888   /// including the receiver.
00889   unsigned NumArgs : NumArgsBitWidth;
00890   
00891   void setNumArgs(unsigned Num) {
00892     assert((Num >> NumArgsBitWidth) == 0 && "Num of args is out of range!");
00893     NumArgs = Num;
00894   }
00895 
00896   /// \brief The kind of message send this is, which is one of the
00897   /// ReceiverKind values.
00898   ///
00899   /// We pad this out to a byte to avoid excessive masking and shifting.
00900   unsigned Kind : 8;
00901 
00902   /// \brief Whether we have an actual method prototype in \c
00903   /// SelectorOrMethod.
00904   ///
00905   /// When non-zero, we have a method declaration; otherwise, we just
00906   /// have a selector.
00907   unsigned HasMethod : 1;
00908 
00909   /// \brief Whether this message send is a "delegate init call",
00910   /// i.e. a call of an init method on self from within an init method.
00911   unsigned IsDelegateInitCall : 1;
00912 
00913   /// \brief Whether this message send was implicitly generated by
00914   /// the implementation rather than explicitly written by the user.
00915   unsigned IsImplicit : 1;
00916 
00917   /// \brief Whether the locations of the selector identifiers are in a
00918   /// "standard" position, a enum SelectorLocationsKind.
00919   unsigned SelLocsKind : 2;
00920 
00921   /// \brief When the message expression is a send to 'super', this is
00922   /// the location of the 'super' keyword.
00923   SourceLocation SuperLoc;
00924 
00925   /// \brief The source locations of the open and close square
00926   /// brackets ('[' and ']', respectively).
00927   SourceLocation LBracLoc, RBracLoc;
00928 
00929   ObjCMessageExpr(EmptyShell Empty, unsigned NumArgs)
00930     : Expr(ObjCMessageExprClass, Empty), SelectorOrMethod(0), Kind(0), 
00931       HasMethod(0), IsDelegateInitCall(0), IsImplicit(0), SelLocsKind(0) {
00932     setNumArgs(NumArgs);
00933   }
00934 
00935   ObjCMessageExpr(QualType T, ExprValueKind VK,
00936                   SourceLocation LBracLoc,
00937                   SourceLocation SuperLoc,
00938                   bool IsInstanceSuper,
00939                   QualType SuperType,
00940                   Selector Sel, 
00941                   ArrayRef<SourceLocation> SelLocs,
00942                   SelectorLocationsKind SelLocsK,
00943                   ObjCMethodDecl *Method,
00944                   ArrayRef<Expr *> Args,
00945                   SourceLocation RBracLoc,
00946                   bool isImplicit);
00947   ObjCMessageExpr(QualType T, ExprValueKind VK,
00948                   SourceLocation LBracLoc,
00949                   TypeSourceInfo *Receiver,
00950                   Selector Sel, 
00951                   ArrayRef<SourceLocation> SelLocs,
00952                   SelectorLocationsKind SelLocsK,
00953                   ObjCMethodDecl *Method,
00954                   ArrayRef<Expr *> Args,
00955                   SourceLocation RBracLoc,
00956                   bool isImplicit);
00957   ObjCMessageExpr(QualType T, ExprValueKind VK,
00958                   SourceLocation LBracLoc,
00959                   Expr *Receiver,
00960                   Selector Sel, 
00961                   ArrayRef<SourceLocation> SelLocs,
00962                   SelectorLocationsKind SelLocsK,
00963                   ObjCMethodDecl *Method,
00964                   ArrayRef<Expr *> Args,
00965                   SourceLocation RBracLoc,
00966                   bool isImplicit);
00967 
00968   void initArgsAndSelLocs(ArrayRef<Expr *> Args,
00969                           ArrayRef<SourceLocation> SelLocs,
00970                           SelectorLocationsKind SelLocsK);
00971 
00972   /// \brief Retrieve the pointer value of the message receiver.
00973   void *getReceiverPointer() const {
00974     return *const_cast<void **>(
00975                              reinterpret_cast<const void * const*>(this + 1));
00976   }
00977 
00978   /// \brief Set the pointer value of the message receiver.
00979   void setReceiverPointer(void *Value) {
00980     *reinterpret_cast<void **>(this + 1) = Value;
00981   }
00982 
00983   SelectorLocationsKind getSelLocsKind() const {
00984     return (SelectorLocationsKind)SelLocsKind;
00985   }
00986   bool hasStandardSelLocs() const {
00987     return getSelLocsKind() != SelLoc_NonStandard;
00988   }
00989 
00990   /// \brief Get a pointer to the stored selector identifiers locations array.
00991   /// No locations will be stored if HasStandardSelLocs is true.
00992   SourceLocation *getStoredSelLocs() {
00993     return reinterpret_cast<SourceLocation*>(getArgs() + getNumArgs());
00994   }
00995   const SourceLocation *getStoredSelLocs() const {
00996     return reinterpret_cast<const SourceLocation*>(getArgs() + getNumArgs());
00997   }
00998 
00999   /// \brief Get the number of stored selector identifiers locations.
01000   /// No locations will be stored if HasStandardSelLocs is true.
01001   unsigned getNumStoredSelLocs() const {
01002     if (hasStandardSelLocs())
01003       return 0;
01004     return getNumSelectorLocs();
01005   }
01006 
01007   static ObjCMessageExpr *alloc(const ASTContext &C,
01008                                 ArrayRef<Expr *> Args,
01009                                 SourceLocation RBraceLoc,
01010                                 ArrayRef<SourceLocation> SelLocs,
01011                                 Selector Sel,
01012                                 SelectorLocationsKind &SelLocsK);
01013   static ObjCMessageExpr *alloc(const ASTContext &C,
01014                                 unsigned NumArgs,
01015                                 unsigned NumStoredSelLocs);
01016 
01017 public:
01018   /// \brief The kind of receiver this message is sending to.
01019   enum ReceiverKind {
01020     /// \brief The receiver is a class.
01021     Class = 0,
01022     /// \brief The receiver is an object instance.
01023     Instance,
01024     /// \brief The receiver is a superclass.
01025     SuperClass,
01026     /// \brief The receiver is the instance of the superclass object.
01027     SuperInstance
01028   };
01029 
01030   /// \brief Create a message send to super.
01031   ///
01032   /// \param Context The ASTContext in which this expression will be created.
01033   ///
01034   /// \param T The result type of this message.
01035   ///
01036   /// \param VK The value kind of this message.  A message returning
01037   /// a l-value or r-value reference will be an l-value or x-value,
01038   /// respectively.
01039   ///
01040   /// \param LBracLoc The location of the open square bracket '['.
01041   ///
01042   /// \param SuperLoc The location of the "super" keyword.
01043   ///
01044   /// \param IsInstanceSuper Whether this is an instance "super"
01045   /// message (otherwise, it's a class "super" message).
01046   ///
01047   /// \param Sel The selector used to determine which method gets called.
01048   ///
01049   /// \param Method The Objective-C method against which this message
01050   /// send was type-checked. May be NULL.
01051   ///
01052   /// \param Args The message send arguments.
01053   ///
01054   /// \param RBracLoc The location of the closing square bracket ']'.
01055   static ObjCMessageExpr *Create(const ASTContext &Context, QualType T,
01056                                  ExprValueKind VK,
01057                                  SourceLocation LBracLoc,
01058                                  SourceLocation SuperLoc,
01059                                  bool IsInstanceSuper,
01060                                  QualType SuperType,
01061                                  Selector Sel, 
01062                                  ArrayRef<SourceLocation> SelLocs,
01063                                  ObjCMethodDecl *Method,
01064                                  ArrayRef<Expr *> Args,
01065                                  SourceLocation RBracLoc,
01066                                  bool isImplicit);
01067 
01068   /// \brief Create a class message send.
01069   ///
01070   /// \param Context The ASTContext in which this expression will be created.
01071   ///
01072   /// \param T The result type of this message.
01073   ///
01074   /// \param VK The value kind of this message.  A message returning
01075   /// a l-value or r-value reference will be an l-value or x-value,
01076   /// respectively.
01077   ///
01078   /// \param LBracLoc The location of the open square bracket '['.
01079   ///
01080   /// \param Receiver The type of the receiver, including
01081   /// source-location information.
01082   ///
01083   /// \param Sel The selector used to determine which method gets called.
01084   ///
01085   /// \param Method The Objective-C method against which this message
01086   /// send was type-checked. May be NULL.
01087   ///
01088   /// \param Args The message send arguments.
01089   ///
01090   /// \param RBracLoc The location of the closing square bracket ']'.
01091   static ObjCMessageExpr *Create(const ASTContext &Context, QualType T,
01092                                  ExprValueKind VK,
01093                                  SourceLocation LBracLoc,
01094                                  TypeSourceInfo *Receiver,
01095                                  Selector Sel, 
01096                                  ArrayRef<SourceLocation> SelLocs,
01097                                  ObjCMethodDecl *Method,
01098                                  ArrayRef<Expr *> Args,
01099                                  SourceLocation RBracLoc,
01100                                  bool isImplicit);
01101 
01102   /// \brief Create an instance message send.
01103   ///
01104   /// \param Context The ASTContext in which this expression will be created.
01105   ///
01106   /// \param T The result type of this message.
01107   ///
01108   /// \param VK The value kind of this message.  A message returning
01109   /// a l-value or r-value reference will be an l-value or x-value,
01110   /// respectively.
01111   ///
01112   /// \param LBracLoc The location of the open square bracket '['.
01113   ///
01114   /// \param Receiver The expression used to produce the object that
01115   /// will receive this message.
01116   ///
01117   /// \param Sel The selector used to determine which method gets called.
01118   ///
01119   /// \param Method The Objective-C method against which this message
01120   /// send was type-checked. May be NULL.
01121   ///
01122   /// \param Args The message send arguments.
01123   ///
01124   /// \param RBracLoc The location of the closing square bracket ']'.
01125   static ObjCMessageExpr *Create(const ASTContext &Context, QualType T,
01126                                  ExprValueKind VK,
01127                                  SourceLocation LBracLoc,
01128                                  Expr *Receiver,
01129                                  Selector Sel, 
01130                                  ArrayRef<SourceLocation> SeLocs,
01131                                  ObjCMethodDecl *Method,
01132                                  ArrayRef<Expr *> Args,
01133                                  SourceLocation RBracLoc,
01134                                  bool isImplicit);
01135 
01136   /// \brief Create an empty Objective-C message expression, to be
01137   /// filled in by subsequent calls.
01138   ///
01139   /// \param Context The context in which the message send will be created.
01140   ///
01141   /// \param NumArgs The number of message arguments, not including
01142   /// the receiver.
01143   static ObjCMessageExpr *CreateEmpty(const ASTContext &Context,
01144                                       unsigned NumArgs,
01145                                       unsigned NumStoredSelLocs);
01146 
01147   /// \brief Indicates whether the message send was implicitly
01148   /// generated by the implementation. If false, it was written explicitly
01149   /// in the source code.
01150   bool isImplicit() const { return IsImplicit; }
01151 
01152   /// \brief Determine the kind of receiver that this message is being
01153   /// sent to.
01154   ReceiverKind getReceiverKind() const { return (ReceiverKind)Kind; }
01155 
01156   /// \brief Source range of the receiver.
01157   SourceRange getReceiverRange() const;
01158 
01159   /// \brief Determine whether this is an instance message to either a
01160   /// computed object or to super.
01161   bool isInstanceMessage() const {
01162     return getReceiverKind() == Instance || getReceiverKind() == SuperInstance;
01163   }
01164 
01165   /// \brief Determine whether this is an class message to either a
01166   /// specified class or to super.
01167   bool isClassMessage() const {
01168     return getReceiverKind() == Class || getReceiverKind() == SuperClass;
01169   }
01170 
01171   /// \brief Returns the object expression (receiver) for an instance message,
01172   /// or null for a message that is not an instance message.
01173   Expr *getInstanceReceiver() {
01174     if (getReceiverKind() == Instance)
01175       return static_cast<Expr *>(getReceiverPointer());
01176 
01177     return nullptr;
01178   }
01179   const Expr *getInstanceReceiver() const {
01180     return const_cast<ObjCMessageExpr*>(this)->getInstanceReceiver();
01181   }
01182 
01183   /// \brief Turn this message send into an instance message that
01184   /// computes the receiver object with the given expression.
01185   void setInstanceReceiver(Expr *rec) { 
01186     Kind = Instance;
01187     setReceiverPointer(rec);
01188   }
01189   
01190   /// \brief Returns the type of a class message send, or NULL if the
01191   /// message is not a class message.
01192   QualType getClassReceiver() const { 
01193     if (TypeSourceInfo *TSInfo = getClassReceiverTypeInfo())
01194       return TSInfo->getType();
01195 
01196     return QualType();
01197   }
01198 
01199   /// \brief Returns a type-source information of a class message
01200   /// send, or NULL if the message is not a class message.
01201   TypeSourceInfo *getClassReceiverTypeInfo() const {
01202     if (getReceiverKind() == Class)
01203       return reinterpret_cast<TypeSourceInfo *>(getReceiverPointer());
01204     return nullptr;
01205   }
01206 
01207   void setClassReceiver(TypeSourceInfo *TSInfo) {
01208     Kind = Class;
01209     setReceiverPointer(TSInfo);
01210   }
01211 
01212   /// \brief Retrieve the location of the 'super' keyword for a class
01213   /// or instance message to 'super', otherwise an invalid source location.
01214   SourceLocation getSuperLoc() const { 
01215     if (getReceiverKind() == SuperInstance || getReceiverKind() == SuperClass)
01216       return SuperLoc;
01217 
01218     return SourceLocation();
01219   }
01220 
01221   /// \brief Retrieve the receiver type to which this message is being directed.
01222   ///
01223   /// This routine cross-cuts all of the different kinds of message
01224   /// sends to determine what the underlying (statically known) type
01225   /// of the receiver will be; use \c getReceiverKind() to determine
01226   /// whether the message is a class or an instance method, whether it
01227   /// is a send to super or not, etc.
01228   ///
01229   /// \returns The type of the receiver.
01230   QualType getReceiverType() const;
01231 
01232   /// \brief Retrieve the Objective-C interface to which this message
01233   /// is being directed, if known.
01234   ///
01235   /// This routine cross-cuts all of the different kinds of message
01236   /// sends to determine what the underlying (statically known) type
01237   /// of the receiver will be; use \c getReceiverKind() to determine
01238   /// whether the message is a class or an instance method, whether it
01239   /// is a send to super or not, etc.
01240   ///
01241   /// \returns The Objective-C interface if known, otherwise NULL.
01242   ObjCInterfaceDecl *getReceiverInterface() const;
01243 
01244   /// \brief Retrieve the type referred to by 'super'. 
01245   ///
01246   /// The returned type will either be an ObjCInterfaceType (for an
01247   /// class message to super) or an ObjCObjectPointerType that refers
01248   /// to a class (for an instance message to super);
01249   QualType getSuperType() const {
01250     if (getReceiverKind() == SuperInstance || getReceiverKind() == SuperClass)
01251       return QualType::getFromOpaquePtr(getReceiverPointer());
01252 
01253     return QualType();
01254   }
01255 
01256   void setSuper(SourceLocation Loc, QualType T, bool IsInstanceSuper) {
01257     Kind = IsInstanceSuper? SuperInstance : SuperClass;
01258     SuperLoc = Loc;
01259     setReceiverPointer(T.getAsOpaquePtr());
01260   }
01261 
01262   Selector getSelector() const;
01263 
01264   void setSelector(Selector S) { 
01265     HasMethod = false;
01266     SelectorOrMethod = reinterpret_cast<uintptr_t>(S.getAsOpaquePtr());
01267   }
01268 
01269   const ObjCMethodDecl *getMethodDecl() const { 
01270     if (HasMethod)
01271       return reinterpret_cast<const ObjCMethodDecl *>(SelectorOrMethod);
01272 
01273     return nullptr;
01274   }
01275 
01276   ObjCMethodDecl *getMethodDecl() { 
01277     if (HasMethod)
01278       return reinterpret_cast<ObjCMethodDecl *>(SelectorOrMethod);
01279 
01280     return nullptr;
01281   }
01282 
01283   void setMethodDecl(ObjCMethodDecl *MD) { 
01284     HasMethod = true;
01285     SelectorOrMethod = reinterpret_cast<uintptr_t>(MD);
01286   }
01287 
01288   ObjCMethodFamily getMethodFamily() const {
01289     if (HasMethod) return getMethodDecl()->getMethodFamily();
01290     return getSelector().getMethodFamily();
01291   }
01292 
01293   /// \brief Return the number of actual arguments in this message,
01294   /// not counting the receiver.
01295   unsigned getNumArgs() const { return NumArgs; }
01296 
01297   /// \brief Retrieve the arguments to this message, not including the
01298   /// receiver.
01299   Expr **getArgs() {
01300     return reinterpret_cast<Expr **>(this + 1) + 1;
01301   }
01302   const Expr * const *getArgs() const {
01303     return reinterpret_cast<const Expr * const *>(this + 1) + 1;
01304   }
01305 
01306   /// getArg - Return the specified argument.
01307   Expr *getArg(unsigned Arg) {
01308     assert(Arg < NumArgs && "Arg access out of range!");
01309     return cast<Expr>(getArgs()[Arg]);
01310   }
01311   const Expr *getArg(unsigned Arg) const {
01312     assert(Arg < NumArgs && "Arg access out of range!");
01313     return cast<Expr>(getArgs()[Arg]);
01314   }
01315   /// setArg - Set the specified argument.
01316   void setArg(unsigned Arg, Expr *ArgExpr) {
01317     assert(Arg < NumArgs && "Arg access out of range!");
01318     getArgs()[Arg] = ArgExpr;
01319   }
01320 
01321   /// isDelegateInitCall - Answers whether this message send has been
01322   /// tagged as a "delegate init call", i.e. a call to a method in the
01323   /// -init family on self from within an -init method implementation.
01324   bool isDelegateInitCall() const { return IsDelegateInitCall; }
01325   void setDelegateInitCall(bool isDelegate) { IsDelegateInitCall = isDelegate; }
01326 
01327   SourceLocation getLeftLoc() const { return LBracLoc; }
01328   SourceLocation getRightLoc() const { return RBracLoc; }
01329 
01330   SourceLocation getSelectorStartLoc() const {
01331     if (isImplicit())
01332       return getLocStart();
01333     return getSelectorLoc(0);
01334   }
01335   SourceLocation getSelectorLoc(unsigned Index) const {
01336     assert(Index < getNumSelectorLocs() && "Index out of range!");
01337     if (hasStandardSelLocs())
01338       return getStandardSelectorLoc(Index, getSelector(),
01339                                    getSelLocsKind() == SelLoc_StandardWithSpace,
01340                                llvm::makeArrayRef(const_cast<Expr**>(getArgs()),
01341                                                   getNumArgs()),
01342                                    RBracLoc);
01343     return getStoredSelLocs()[Index];
01344   }
01345 
01346   void getSelectorLocs(SmallVectorImpl<SourceLocation> &SelLocs) const;
01347 
01348   unsigned getNumSelectorLocs() const {
01349     if (isImplicit())
01350       return 0;
01351     Selector Sel = getSelector();
01352     if (Sel.isUnarySelector())
01353       return 1;
01354     return Sel.getNumArgs();
01355   }
01356 
01357   void setSourceRange(SourceRange R) {
01358     LBracLoc = R.getBegin();
01359     RBracLoc = R.getEnd();
01360   }
01361   SourceLocation getLocStart() const LLVM_READONLY { return LBracLoc; }
01362   SourceLocation getLocEnd() const LLVM_READONLY { return RBracLoc; }
01363 
01364   static bool classof(const Stmt *T) {
01365     return T->getStmtClass() == ObjCMessageExprClass;
01366   }
01367 
01368   // Iterators
01369   child_range children();
01370 
01371   typedef ExprIterator arg_iterator;
01372   typedef ConstExprIterator const_arg_iterator;
01373 
01374   arg_iterator arg_begin() { return reinterpret_cast<Stmt **>(getArgs()); }
01375   arg_iterator arg_end()   { 
01376     return reinterpret_cast<Stmt **>(getArgs() + NumArgs); 
01377   }
01378   const_arg_iterator arg_begin() const { 
01379     return reinterpret_cast<Stmt const * const*>(getArgs()); 
01380   }
01381   const_arg_iterator arg_end() const { 
01382     return reinterpret_cast<Stmt const * const*>(getArgs() + NumArgs); 
01383   }
01384 
01385   friend class ASTStmtReader;
01386   friend class ASTStmtWriter;
01387 };
01388 
01389 /// ObjCIsaExpr - Represent X->isa and X.isa when X is an ObjC 'id' type.
01390 /// (similar in spirit to MemberExpr).
01391 class ObjCIsaExpr : public Expr {
01392   /// Base - the expression for the base object pointer.
01393   Stmt *Base;
01394 
01395   /// IsaMemberLoc - This is the location of the 'isa'.
01396   SourceLocation IsaMemberLoc;
01397   
01398   /// OpLoc - This is the location of '.' or '->'
01399   SourceLocation OpLoc;
01400 
01401   /// IsArrow - True if this is "X->F", false if this is "X.F".
01402   bool IsArrow;
01403 public:
01404   ObjCIsaExpr(Expr *base, bool isarrow, SourceLocation l, SourceLocation oploc,
01405               QualType ty)
01406     : Expr(ObjCIsaExprClass, ty, VK_LValue, OK_Ordinary,
01407            /*TypeDependent=*/false, base->isValueDependent(),
01408            base->isInstantiationDependent(),
01409            /*ContainsUnexpandedParameterPack=*/false),
01410       Base(base), IsaMemberLoc(l), OpLoc(oploc), IsArrow(isarrow) {}
01411 
01412   /// \brief Build an empty expression.
01413   explicit ObjCIsaExpr(EmptyShell Empty) : Expr(ObjCIsaExprClass, Empty) { }
01414 
01415   void setBase(Expr *E) { Base = E; }
01416   Expr *getBase() const { return cast<Expr>(Base); }
01417 
01418   bool isArrow() const { return IsArrow; }
01419   void setArrow(bool A) { IsArrow = A; }
01420 
01421   /// getMemberLoc - Return the location of the "member", in X->F, it is the
01422   /// location of 'F'.
01423   SourceLocation getIsaMemberLoc() const { return IsaMemberLoc; }
01424   void setIsaMemberLoc(SourceLocation L) { IsaMemberLoc = L; }
01425   
01426   SourceLocation getOpLoc() const { return OpLoc; }
01427   void setOpLoc(SourceLocation L) { OpLoc = L; }
01428 
01429   SourceLocation getLocStart() const LLVM_READONLY {
01430     return getBase()->getLocStart();
01431   }
01432   
01433   SourceLocation getBaseLocEnd() const LLVM_READONLY {
01434     return getBase()->getLocEnd();
01435   }
01436   
01437   SourceLocation getLocEnd() const LLVM_READONLY { return IsaMemberLoc; }
01438 
01439   SourceLocation getExprLoc() const LLVM_READONLY { return IsaMemberLoc; }
01440 
01441   static bool classof(const Stmt *T) {
01442     return T->getStmtClass() == ObjCIsaExprClass;
01443   }
01444 
01445   // Iterators
01446   child_range children() { return child_range(&Base, &Base+1); }
01447 };
01448 
01449 
01450 /// ObjCIndirectCopyRestoreExpr - Represents the passing of a function
01451 /// argument by indirect copy-restore in ARC.  This is used to support
01452 /// passing indirect arguments with the wrong lifetime, e.g. when
01453 /// passing the address of a __strong local variable to an 'out'
01454 /// parameter.  This expression kind is only valid in an "argument"
01455 /// position to some sort of call expression.
01456 ///
01457 /// The parameter must have type 'pointer to T', and the argument must
01458 /// have type 'pointer to U', where T and U agree except possibly in
01459 /// qualification.  If the argument value is null, then a null pointer
01460 /// is passed;  otherwise it points to an object A, and:
01461 /// 1. A temporary object B of type T is initialized, either by
01462 ///    zero-initialization (used when initializing an 'out' parameter)
01463 ///    or copy-initialization (used when initializing an 'inout'
01464 ///    parameter).
01465 /// 2. The address of the temporary is passed to the function.
01466 /// 3. If the call completes normally, A is move-assigned from B.
01467 /// 4. Finally, A is destroyed immediately.
01468 ///
01469 /// Currently 'T' must be a retainable object lifetime and must be
01470 /// __autoreleasing;  this qualifier is ignored when initializing
01471 /// the value.
01472 class ObjCIndirectCopyRestoreExpr : public Expr {
01473   Stmt *Operand;
01474 
01475   // unsigned ObjCIndirectCopyRestoreBits.ShouldCopy : 1;
01476 
01477   friend class ASTReader;
01478   friend class ASTStmtReader;
01479 
01480   void setShouldCopy(bool shouldCopy) {
01481     ObjCIndirectCopyRestoreExprBits.ShouldCopy = shouldCopy;
01482   }
01483 
01484   explicit ObjCIndirectCopyRestoreExpr(EmptyShell Empty)
01485     : Expr(ObjCIndirectCopyRestoreExprClass, Empty) { }
01486 
01487 public:
01488   ObjCIndirectCopyRestoreExpr(Expr *operand, QualType type, bool shouldCopy)
01489     : Expr(ObjCIndirectCopyRestoreExprClass, type, VK_LValue, OK_Ordinary,
01490            operand->isTypeDependent(), operand->isValueDependent(),
01491            operand->isInstantiationDependent(),
01492            operand->containsUnexpandedParameterPack()),
01493       Operand(operand) {
01494     setShouldCopy(shouldCopy);
01495   }
01496 
01497   Expr *getSubExpr() { return cast<Expr>(Operand); }
01498   const Expr *getSubExpr() const { return cast<Expr>(Operand); }
01499 
01500   /// shouldCopy - True if we should do the 'copy' part of the
01501   /// copy-restore.  If false, the temporary will be zero-initialized.
01502   bool shouldCopy() const { return ObjCIndirectCopyRestoreExprBits.ShouldCopy; }
01503 
01504   child_range children() { return child_range(&Operand, &Operand+1); }  
01505 
01506   // Source locations are determined by the subexpression.
01507   SourceLocation getLocStart() const LLVM_READONLY {
01508     return Operand->getLocStart();
01509   }
01510   SourceLocation getLocEnd() const LLVM_READONLY { return Operand->getLocEnd();}
01511 
01512   SourceLocation getExprLoc() const LLVM_READONLY {
01513     return getSubExpr()->getExprLoc();
01514   }
01515 
01516   static bool classof(const Stmt *s) {
01517     return s->getStmtClass() == ObjCIndirectCopyRestoreExprClass;
01518   }
01519 };
01520 
01521 /// \brief An Objective-C "bridged" cast expression, which casts between
01522 /// Objective-C pointers and C pointers, transferring ownership in the process.
01523 ///
01524 /// \code
01525 /// NSString *str = (__bridge_transfer NSString *)CFCreateString();
01526 /// \endcode
01527 class ObjCBridgedCastExpr : public ExplicitCastExpr {
01528   SourceLocation LParenLoc;
01529   SourceLocation BridgeKeywordLoc;
01530   unsigned Kind : 2;
01531   
01532   friend class ASTStmtReader;
01533   friend class ASTStmtWriter;
01534   
01535 public:
01536   ObjCBridgedCastExpr(SourceLocation LParenLoc, ObjCBridgeCastKind Kind,
01537                       CastKind CK, SourceLocation BridgeKeywordLoc,
01538                       TypeSourceInfo *TSInfo, Expr *Operand)
01539     : ExplicitCastExpr(ObjCBridgedCastExprClass, TSInfo->getType(), VK_RValue,
01540                        CK, Operand, 0, TSInfo),
01541       LParenLoc(LParenLoc), BridgeKeywordLoc(BridgeKeywordLoc), Kind(Kind) { }
01542   
01543   /// \brief Construct an empty Objective-C bridged cast.
01544   explicit ObjCBridgedCastExpr(EmptyShell Shell)
01545     : ExplicitCastExpr(ObjCBridgedCastExprClass, Shell, 0) { }
01546 
01547   SourceLocation getLParenLoc() const { return LParenLoc; }
01548 
01549   /// \brief Determine which kind of bridge is being performed via this cast.
01550   ObjCBridgeCastKind getBridgeKind() const { 
01551     return static_cast<ObjCBridgeCastKind>(Kind); 
01552   }
01553   
01554   /// \brief Retrieve the kind of bridge being performed as a string.
01555   StringRef getBridgeKindName() const;
01556   
01557   /// \brief The location of the bridge keyword.
01558   SourceLocation getBridgeKeywordLoc() const { return BridgeKeywordLoc; }
01559   
01560   SourceLocation getLocStart() const LLVM_READONLY { return LParenLoc; }
01561   SourceLocation getLocEnd() const LLVM_READONLY {
01562     return getSubExpr()->getLocEnd();
01563   }
01564   
01565   static bool classof(const Stmt *T) {
01566     return T->getStmtClass() == ObjCBridgedCastExprClass;
01567   }
01568 };
01569   
01570 }  // end namespace clang
01571 
01572 #endif