ExprObjC.h revision b085d898bdfe35097eba45f4072b0f6865f561dc
1f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff//===--- ExprObjC.h - Classes for representing ObjC expressions -*- C++ -*-===// 2f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff// 3f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff// The LLVM Compiler Infrastructure 4f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff// 5f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff// This file is distributed under the University of Illinois Open Source 6f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff// License. See LICENSE.TXT for details. 7f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff// 8f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff//===----------------------------------------------------------------------===// 9f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff// 10f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff// This file defines the ExprObjC interface and subclasses. 11f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff// 12f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff//===----------------------------------------------------------------------===// 13f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff 14f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff#ifndef LLVM_CLANG_AST_EXPROBJC_H 15f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff#define LLVM_CLANG_AST_EXPROBJC_H 16f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff 1712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall#include "clang/AST/DeclObjC.h" 18f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff#include "clang/AST/Expr.h" 19207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis#include "clang/AST/SelectorLocationsKind.h" 20c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar#include "clang/Basic/IdentifierTable.h" 21aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar#include "llvm/Support/Compiler.h" 22f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff 23f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroffnamespace clang { 24f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff class IdentifierInfo; 25f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff class ASTContext; 261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff/// ObjCStringLiteral, used for Objective-C string literals 28f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff/// i.e. @"foo". 29f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroffclass ObjCStringLiteral : public Expr { 30c6c16af963eddc3e9b75b5d2614d069e1162fe27Chris Lattner Stmt *String; 31f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff SourceLocation AtLoc; 32f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroffpublic: 33f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff ObjCStringLiteral(StringLiteral *SL, QualType T, SourceLocation L) 34bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(ObjCStringLiteralClass, T, VK_RValue, OK_Ordinary, false, false, 35561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 36f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall String(SL), AtLoc(L) {} 373a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner explicit ObjCStringLiteral(EmptyShell Empty) 383a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner : Expr(ObjCStringLiteralClass, Empty) {} 393a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner 403a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner StringLiteral *getString() { return cast<StringLiteral>(String); } 413a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner const StringLiteral *getString() const { return cast<StringLiteral>(String); } 423a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner void setString(StringLiteral *S) { String = S; } 43f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff 44f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff SourceLocation getAtLoc() const { return AtLoc; } 453a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner void setAtLoc(SourceLocation L) { AtLoc = L; } 46f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff 47aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 48f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff return SourceRange(AtLoc, String->getLocEnd()); 49f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff } 501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ObjCStringLiteralClass; 53f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff } 541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const ObjCStringLiteral *) { return true; } 551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 56f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff // Iterators 5763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&String, &String+1); } 58f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff}; 591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 60ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// ObjCBoolLiteralExpr - Objective-C Boolean Literal. 61ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// 62ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenekclass ObjCBoolLiteralExpr : public Expr { 63ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool Value; 64ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceLocation Loc; 65ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenekpublic: 66ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) : 67ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr(ObjCBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false, 68ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek false, false), Value(val), Loc(l) {} 69ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 70ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek explicit ObjCBoolLiteralExpr(EmptyShell Empty) 71ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek : Expr(ObjCBoolLiteralExprClass, Empty) { } 72ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 73ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool getValue() const { return Value; } 74ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek void setValue(bool V) { Value = V; } 75ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 76aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); } 77ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 78ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceLocation getLocation() const { return Loc; } 79ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek void setLocation(SourceLocation L) { Loc = L; } 80ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 81ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek static bool classof(const Stmt *T) { 82ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return T->getStmtClass() == ObjCBoolLiteralExprClass; 83ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 84ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek static bool classof(const ObjCBoolLiteralExpr *) { return true; } 85ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 86ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Iterators 87ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek child_range children() { return child_range(); } 88ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek}; 89ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 90ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// ObjCNumericLiteral - used for objective-c numeric literals; 91ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// as in: @42 or @true (c++/objc++) or @__yes (c/objc) 92ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenekclass ObjCNumericLiteral : public Expr { 93ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// Number - expression AST node for the numeric literal 94ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Stmt *Number; 95ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *ObjCNumericLiteralMethod; 96ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceLocation AtLoc; 97ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenekpublic: 98ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCNumericLiteral(Stmt *NL, QualType T, ObjCMethodDecl *method, 99ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceLocation L) 100ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek : Expr(ObjCNumericLiteralClass, T, VK_RValue, OK_Ordinary, 101ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek false, false, false, false), Number(NL), 102ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCNumericLiteralMethod(method), AtLoc(L) {} 103ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek explicit ObjCNumericLiteral(EmptyShell Empty) 104ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek : Expr(ObjCNumericLiteralClass, Empty) {} 105ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 106ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr *getNumber() { return cast<Expr>(Number); } 107ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek const Expr *getNumber() const { return cast<Expr>(Number); } 108ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 109ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *getObjCNumericLiteralMethod() const { 110ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return ObjCNumericLiteralMethod; 111ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 112ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 113ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceLocation getAtLoc() const { return AtLoc; } 114ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 115aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 116ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return SourceRange(AtLoc, Number->getSourceRange().getEnd()); 117ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 118ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 119ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek static bool classof(const Stmt *T) { 120ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return T->getStmtClass() == ObjCNumericLiteralClass; 121ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 122ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek static bool classof(const ObjCNumericLiteral *) { return true; } 123ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 124ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Iterators 125ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek child_range children() { return child_range(&Number, &Number+1); } 126ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 127ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek friend class ASTStmtReader; 128ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek}; 129ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 130ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// ObjCArrayLiteral - used for objective-c array containers; as in: 131ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// @[@"Hello", NSApp, [NSNumber numberWithInt:42]]; 132ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenekclass ObjCArrayLiteral : public Expr { 133ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek unsigned NumElements; 134ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceRange Range; 135ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *ArrayWithObjectsMethod; 136ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 137ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCArrayLiteral(llvm::ArrayRef<Expr *> Elements, 138ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek QualType T, ObjCMethodDecl * Method, 139ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceRange SR); 140ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 141ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek explicit ObjCArrayLiteral(EmptyShell Empty, unsigned NumElements) 142ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek : Expr(ObjCArrayLiteralClass, Empty), NumElements(NumElements) {} 143ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 144ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenekpublic: 145ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek static ObjCArrayLiteral *Create(ASTContext &C, 146ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek llvm::ArrayRef<Expr *> Elements, 147ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek QualType T, ObjCMethodDecl * Method, 148ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceRange SR); 149ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 150ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek static ObjCArrayLiteral *CreateEmpty(ASTContext &C, unsigned NumElements); 151ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 152aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { return Range; } 153ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 154ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek static bool classof(const Stmt *T) { 155ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return T->getStmtClass() == ObjCArrayLiteralClass; 156ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 157ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek static bool classof(const ObjCArrayLiteral *) { return true; } 158ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 159ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief Retrieve elements of array of literals. 160ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr **getElements() { return reinterpret_cast<Expr **>(this + 1); } 161ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 162ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief Retrieve elements of array of literals. 163ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek const Expr * const *getElements() const { 164ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return reinterpret_cast<const Expr * const*>(this + 1); 165ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 166ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 167ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// getNumElements - Return number of elements of objective-c array literal. 168ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek unsigned getNumElements() const { return NumElements; } 169ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 170ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// getExpr - Return the Expr at the specified index. 171ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr *getElement(unsigned Index) { 172ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek assert((Index < NumElements) && "Arg access out of range!"); 173ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return cast<Expr>(getElements()[Index]); 174ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 175ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek const Expr *getElement(unsigned Index) const { 176ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek assert((Index < NumElements) && "Arg access out of range!"); 177ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return cast<Expr>(getElements()[Index]); 178ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 179ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 180ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *getArrayWithObjectsMethod() const { 181ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return ArrayWithObjectsMethod; 182ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 183ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 184ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Iterators 185ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek child_range children() { 186ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return child_range((Stmt **)getElements(), 187ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek (Stmt **)getElements() + NumElements); 188ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 189ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 190ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek friend class ASTStmtReader; 191ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek}; 192ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 193ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// \brief An element in an Objective-C dictionary literal. 194ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// 195ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenekstruct ObjCDictionaryElement { 196ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief The key for the dictionary element. 197ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr *Key; 198ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 199ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief The value of the dictionary element. 200ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr *Value; 201ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 202ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief The location of the ellipsis, if this is a pack expansion. 203ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceLocation EllipsisLoc; 204ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 205ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief The number of elements this pack expansion will expand to, if 206ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// this is a pack expansion and is known. 207ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek llvm::Optional<unsigned> NumExpansions; 208ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 209ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief Determines whether this dictionary element is a pack expansion. 210ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool isPackExpansion() const { return EllipsisLoc.isValid(); } 211ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek}; 212ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 213ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// ObjCDictionaryLiteral - AST node to represent objective-c dictionary 214ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// literals; as in: @{@"name" : NSUserName(), @"date" : [NSDate date] }; 215ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenekclass ObjCDictionaryLiteral : public Expr { 216ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief Key/value pair used to store the key and value of a given element. 217ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// 218ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// Objects of this type are stored directly after the expression. 219ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek struct KeyValuePair { 220ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr *Key; 221ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr *Value; 222ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek }; 223ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 224ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief Data that describes an element that is a pack expansion, used if any 225ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// of the elements in the dictionary literal are pack expansions. 226ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek struct ExpansionData { 227ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief The location of the ellipsis, if this element is a pack 228ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// expansion. 229ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceLocation EllipsisLoc; 230ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 231ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief If non-zero, the number of elements that this pack 232ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// expansion will expand to (+1). 233ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek unsigned NumExpansionsPlusOne; 234ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek }; 235ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 236ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief The number of elements in this dictionary literal. 237ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek unsigned NumElements : 31; 238ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 239ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief Determine whether this dictionary literal has any pack expansions. 240ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// 241ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// If the dictionary literal has pack expansions, then there will 242ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// be an array of pack expansion data following the array of 243ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// key/value pairs, which provide the locations of the ellipses (if 244ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// any) and number of elements in the expansion (if known). If 245ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// there are no pack expansions, we optimize away this storage. 246ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek unsigned HasPackExpansions : 1; 247ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 248ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceRange Range; 249ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *DictWithObjectsMethod; 250ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 251ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCDictionaryLiteral(ArrayRef<ObjCDictionaryElement> VK, 252ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool HasPackExpansions, 253ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek QualType T, ObjCMethodDecl *method, 254ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceRange SR); 255ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 256ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek explicit ObjCDictionaryLiteral(EmptyShell Empty, unsigned NumElements, 257ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool HasPackExpansions) 258ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek : Expr(ObjCDictionaryLiteralClass, Empty), NumElements(NumElements), 259ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek HasPackExpansions(HasPackExpansions) {} 260ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 261ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek KeyValuePair *getKeyValues() { 262ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return reinterpret_cast<KeyValuePair *>(this + 1); 263ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 264ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 265ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek const KeyValuePair *getKeyValues() const { 266ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return reinterpret_cast<const KeyValuePair *>(this + 1); 267ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 268ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 269ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExpansionData *getExpansionData() { 270ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (!HasPackExpansions) 271ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return 0; 272ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 273ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return reinterpret_cast<ExpansionData *>(getKeyValues() + NumElements); 274ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 275ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 276ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek const ExpansionData *getExpansionData() const { 277ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (!HasPackExpansions) 278ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return 0; 279ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 280ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return reinterpret_cast<const ExpansionData *>(getKeyValues()+NumElements); 281ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 282ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 283ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenekpublic: 284ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek static ObjCDictionaryLiteral *Create(ASTContext &C, 285ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ArrayRef<ObjCDictionaryElement> VK, 286ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool HasPackExpansions, 287ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek QualType T, ObjCMethodDecl *method, 288ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceRange SR); 289ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 290ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek static ObjCDictionaryLiteral *CreateEmpty(ASTContext &C, 291ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek unsigned NumElements, 292ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool HasPackExpansions); 293ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 294ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// getNumElements - Return number of elements of objective-c dictionary 295ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// literal. 296ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek unsigned getNumElements() const { return NumElements; } 297ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 298ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCDictionaryElement getKeyValueElement(unsigned Index) const { 299ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek assert((Index < NumElements) && "Arg access out of range!"); 300ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek const KeyValuePair &KV = getKeyValues()[Index]; 301ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCDictionaryElement Result = { KV.Key, KV.Value, SourceLocation(), 302ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek llvm::Optional<unsigned>() }; 303ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (HasPackExpansions) { 304ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek const ExpansionData &Expansion = getExpansionData()[Index]; 305ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Result.EllipsisLoc = Expansion.EllipsisLoc; 306ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Expansion.NumExpansionsPlusOne > 0) 307ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Result.NumExpansions = Expansion.NumExpansionsPlusOne - 1; 308ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 309ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return Result; 310ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 311ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 312ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *getDictWithObjectsMethod() const 313ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek { return DictWithObjectsMethod; } 314ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 315aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { return Range; } 316ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 317ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek static bool classof(const Stmt *T) { 318ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return T->getStmtClass() == ObjCDictionaryLiteralClass; 319ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 320ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek static bool classof(const ObjCDictionaryLiteral *) { return true; } 321ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 322ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Iterators 323ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek child_range children() { 324ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Note: we're taking advantage of the layout of the KeyValuePair struct 325ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // here. If that struct changes, this code will need to change as well. 326ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return child_range(reinterpret_cast<Stmt **>(this + 1), 327ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek reinterpret_cast<Stmt **>(this + 1) + NumElements * 2); 328ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 329ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 330ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek friend class ASTStmtReader; 331ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek friend class ASTStmtWriter; 332ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek}; 333ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 334ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 335eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner/// ObjCEncodeExpr, used for @encode in Objective-C. @encode has the same type 336eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner/// and behavior as StringLiteral except that the string initializer is obtained 337eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner/// from ASTContext with the encoding type as an argument. 338f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroffclass ObjCEncodeExpr : public Expr { 33981d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor TypeSourceInfo *EncodedType; 340f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff SourceLocation AtLoc, RParenLoc; 341f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroffpublic: 34281d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor ObjCEncodeExpr(QualType T, TypeSourceInfo *EncodedType, 343f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff SourceLocation at, SourceLocation rp) 344f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ObjCEncodeExprClass, T, VK_LValue, OK_Ordinary, 345f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall EncodedType->getType()->isDependentType(), 346bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor EncodedType->getType()->isDependentType(), 347561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor EncodedType->getType()->isInstantiationDependentType(), 348bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor EncodedType->getType()->containsUnexpandedParameterPack()), 34981d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor EncodedType(EncodedType), AtLoc(at), RParenLoc(rp) {} 3501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3514dcf151a555ff51e4d643e8e6eeb80f121d11d1bChris Lattner explicit ObjCEncodeExpr(EmptyShell Empty) : Expr(ObjCEncodeExprClass, Empty){} 3524dcf151a555ff51e4d643e8e6eeb80f121d11d1bChris Lattner 3531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 354f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff SourceLocation getAtLoc() const { return AtLoc; } 3554dcf151a555ff51e4d643e8e6eeb80f121d11d1bChris Lattner void setAtLoc(SourceLocation L) { AtLoc = L; } 356f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff SourceLocation getRParenLoc() const { return RParenLoc; } 3574dcf151a555ff51e4d643e8e6eeb80f121d11d1bChris Lattner void setRParenLoc(SourceLocation L) { RParenLoc = L; } 3581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 35981d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor QualType getEncodedType() const { return EncodedType->getType(); } 3604dcf151a555ff51e4d643e8e6eeb80f121d11d1bChris Lattner 36181d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor TypeSourceInfo *getEncodedTypeSourceInfo() const { return EncodedType; } 36281d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor void setEncodedTypeSourceInfo(TypeSourceInfo *EncType) { 36381d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor EncodedType = EncType; 36481d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor } 3651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 366aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 367f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff return SourceRange(AtLoc, RParenLoc); 368f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff } 3691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 370f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff static bool classof(const Stmt *T) { 371f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff return T->getStmtClass() == ObjCEncodeExprClass; 372f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff } 373f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff static bool classof(const ObjCEncodeExpr *) { return true; } 3741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 375f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff // Iterators 37663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 377f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff}; 378f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff 379f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff/// ObjCSelectorExpr used for @selector in Objective-C. 380f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroffclass ObjCSelectorExpr : public Expr { 381f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff Selector SelName; 382f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff SourceLocation AtLoc, RParenLoc; 383f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroffpublic: 384f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff ObjCSelectorExpr(QualType T, Selector selInfo, 385f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff SourceLocation at, SourceLocation rp) 386bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(ObjCSelectorExprClass, T, VK_RValue, OK_Ordinary, false, false, 387561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 388f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall SelName(selInfo), AtLoc(at), RParenLoc(rp){} 3893a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner explicit ObjCSelectorExpr(EmptyShell Empty) 3903a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner : Expr(ObjCSelectorExprClass, Empty) {} 3913a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner 392f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff Selector getSelector() const { return SelName; } 3933a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner void setSelector(Selector S) { SelName = S; } 3941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 395f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff SourceLocation getAtLoc() const { return AtLoc; } 396f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff SourceLocation getRParenLoc() const { return RParenLoc; } 3973a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner void setAtLoc(SourceLocation L) { AtLoc = L; } 3983a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner void setRParenLoc(SourceLocation L) { RParenLoc = L; } 399f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff 400aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 401f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff return SourceRange(AtLoc, RParenLoc); 402f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff } 4031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 404f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff /// getNumArgs - Return the number of actual arguments to this call. 405f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff unsigned getNumArgs() const { return SelName.getNumArgs(); } 4061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 407f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff static bool classof(const Stmt *T) { 408f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff return T->getStmtClass() == ObjCSelectorExprClass; 409f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff } 410f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff static bool classof(const ObjCSelectorExpr *) { return true; } 4111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 412f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff // Iterators 41363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 414f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff}; 4151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4163a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner/// ObjCProtocolExpr used for protocol expression in Objective-C. This is used 4173a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner/// as: @protocol(foo), as in: 4183a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner/// obj conformsToProtocol:@protocol(foo)] 4193a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner/// The return type is "Protocol*". 4201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ObjCProtocolExpr : public Expr { 4211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCProtocolDecl *TheProtocol; 422f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff SourceLocation AtLoc, RParenLoc; 423f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroffpublic: 424f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff ObjCProtocolExpr(QualType T, ObjCProtocolDecl *protocol, 425f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff SourceLocation at, SourceLocation rp) 426bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(ObjCProtocolExprClass, T, VK_RValue, OK_Ordinary, false, false, 427561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 428bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor TheProtocol(protocol), AtLoc(at), RParenLoc(rp) {} 4293a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner explicit ObjCProtocolExpr(EmptyShell Empty) 4303a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner : Expr(ObjCProtocolExprClass, Empty) {} 4313a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner 432262f9cf85294a1a0713420abc79d40f64aef7240Fariborz Jahanian ObjCProtocolDecl *getProtocol() const { return TheProtocol; } 433262f9cf85294a1a0713420abc79d40f64aef7240Fariborz Jahanian void setProtocol(ObjCProtocolDecl *P) { TheProtocol = P; } 4341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 435f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff SourceLocation getAtLoc() const { return AtLoc; } 436f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff SourceLocation getRParenLoc() const { return RParenLoc; } 4373a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner void setAtLoc(SourceLocation L) { AtLoc = L; } 4383a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner void setRParenLoc(SourceLocation L) { RParenLoc = L; } 439f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff 440aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 441f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff return SourceRange(AtLoc, RParenLoc); 442f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff } 4431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 444f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff static bool classof(const Stmt *T) { 445f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff return T->getStmtClass() == ObjCProtocolExprClass; 446f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff } 447f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff static bool classof(const ObjCProtocolExpr *) { return true; } 4481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 449f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff // Iterators 45063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 451f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff}; 452f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff 453f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff/// ObjCIvarRefExpr - A reference to an ObjC instance variable. 454f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroffclass ObjCIvarRefExpr : public Expr { 455d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer ObjCIvarDecl *D; 4565549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Base; 457d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer SourceLocation Loc; 458f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff bool IsArrow:1; // True if this is "X->F", false if this is "X.F". 459f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff bool IsFreeIvar:1; // True if ivar reference has no base (self assumed). 4601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 461f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroffpublic: 462f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ObjCIvarRefExpr(ObjCIvarDecl *d, QualType t, 463f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall SourceLocation l, Expr *base, 4641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool arrow = false, bool freeIvar = false) : 465f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(ObjCIvarRefExprClass, t, VK_LValue, OK_Ordinary, 466bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*TypeDependent=*/false, base->isValueDependent(), 467561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isInstantiationDependent(), 468bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->containsUnexpandedParameterPack()), 469d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer D(d), Base(base), Loc(l), IsArrow(arrow), IsFreeIvar(freeIvar) {} 4701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4710389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner explicit ObjCIvarRefExpr(EmptyShell Empty) 4720389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner : Expr(ObjCIvarRefExprClass, Empty) {} 4730389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner 474f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff ObjCIvarDecl *getDecl() { return D; } 475f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff const ObjCIvarDecl *getDecl() const { return D; } 4760389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner void setDecl(ObjCIvarDecl *d) { D = d; } 4771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4785549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getBase() const { return cast<Expr>(Base); } 4795549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getBase() { return cast<Expr>(Base); } 480f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff void setBase(Expr * base) { Base = base; } 4811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 482f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff bool isArrow() const { return IsArrow; } 483f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff bool isFreeIvar() const { return IsFreeIvar; } 4840389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner void setIsArrow(bool A) { IsArrow = A; } 4850389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner void setIsFreeIvar(bool A) { IsFreeIvar = A; } 4861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 487f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff SourceLocation getLocation() const { return Loc; } 4880389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner void setLocation(SourceLocation L) { Loc = L; } 4890389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner 490aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 4910389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner return isFreeIvar() ? SourceRange(Loc) 4921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : SourceRange(getBase()->getLocStart(), Loc); 4930389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner } 4941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 4961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ObjCIvarRefExprClass; 497f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff } 498f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff static bool classof(const ObjCIvarRefExpr *) { return true; } 4991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 500f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff // Iterators 50163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Base, &Base+1); } 502f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff}; 503f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff 504e66f4e3e3ae9d7d11b0c302211066fad69228abaDaniel Dunbar/// ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC 5055daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian/// property. 506ae7840776d6cd31b4d7a4a345b61bcbb3744df6cSteve Naroffclass ObjCPropertyRefExpr : public Expr { 507e66f4e3e3ae9d7d11b0c302211066fad69228abaDaniel Dunbarprivate: 50812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall /// If the bool is true, this is an implicit property reference; the 50912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall /// pointer is an (optional) ObjCMethodDecl and Setter may be set. 51012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall /// if the bool is false, this is an explicit property reference; 51112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall /// the pointer is an ObjCPropertyDecl and Setter is always null. 51212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall llvm::PointerIntPair<NamedDecl*, 1, bool> PropertyOrGetter; 513b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis 514b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis /// \brief Indicates whether the property reference will result in a message 515b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis /// to the getter, the setter, or both. 516b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis /// This applies to both implicit and explicit property references. 517b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis enum MethodRefFlags { 518b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis MethodRef_None = 0, 519b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis MethodRef_Getter = 0x1, 520b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis MethodRef_Setter = 0x2 521b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis }; 522b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis 523b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis /// \brief Contains the Setter method pointer and MethodRefFlags bit flags. 524b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis llvm::PointerIntPair<ObjCMethodDecl *, 2, unsigned> SetterAndMethodRefFlags; 52512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 5263c3b7f90a863af43fa63043d396553ecf205351cJohn McCall // FIXME: Maybe we should store the property identifier here, 5273c3b7f90a863af43fa63043d396553ecf205351cJohn McCall // because it's not rederivable from the other data when there's an 5283c3b7f90a863af43fa63043d396553ecf205351cJohn McCall // implicit property with no getter (because the 'foo' -> 'setFoo:' 5293c3b7f90a863af43fa63043d396553ecf205351cJohn McCall // transformation is lossy on the first character). 5303c3b7f90a863af43fa63043d396553ecf205351cJohn McCall 531c77a636688e188af7e7a9a05829e542adb48e880Steve Naroff SourceLocation IdLoc; 5328ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian 5338ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian /// \brief When the receiver in property access is 'super', this is 53412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall /// the location of the 'super' keyword. When it's an interface, 53512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall /// this is that interface. 53612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall SourceLocation ReceiverLoc; 537f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall llvm::PointerUnion3<Stmt*, const Type*, ObjCInterfaceDecl*> Receiver; 5388ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian 539ae7840776d6cd31b4d7a4a345b61bcbb3744df6cSteve Naroffpublic: 5401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCPropertyRefExpr(ObjCPropertyDecl *PD, QualType t, 541f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 542e66f4e3e3ae9d7d11b0c302211066fad69228abaDaniel Dunbar SourceLocation l, Expr *base) 543f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ObjCPropertyRefExprClass, t, VK, OK, 544bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*TypeDependent=*/false, base->isValueDependent(), 545561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isInstantiationDependent(), 546bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->containsUnexpandedParameterPack()), 547b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis PropertyOrGetter(PD, false), SetterAndMethodRefFlags(), 54812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall IdLoc(l), ReceiverLoc(), Receiver(base) { 5493c3b7f90a863af43fa63043d396553ecf205351cJohn McCall assert(t->isSpecificPlaceholderType(BuiltinType::PseudoObject)); 5508ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian } 5518ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian 5528ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian ObjCPropertyRefExpr(ObjCPropertyDecl *PD, QualType t, 553f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 5548ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian SourceLocation l, SourceLocation sl, QualType st) 55512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall : Expr(ObjCPropertyRefExprClass, t, VK, OK, 556561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*TypeDependent=*/false, false, st->isInstantiationDependentType(), 557bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor st->containsUnexpandedParameterPack()), 558b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis PropertyOrGetter(PD, false), SetterAndMethodRefFlags(), 55912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall IdLoc(l), ReceiverLoc(sl), Receiver(st.getTypePtr()) { 5603c3b7f90a863af43fa63043d396553ecf205351cJohn McCall assert(t->isSpecificPlaceholderType(BuiltinType::PseudoObject)); 56112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall } 56212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 56312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ObjCPropertyRefExpr(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter, 56412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall QualType T, ExprValueKind VK, ExprObjectKind OK, 56512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall SourceLocation IdLoc, Expr *Base) 56612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall : Expr(ObjCPropertyRefExprClass, T, VK, OK, false, 567561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Base->isValueDependent(), Base->isInstantiationDependent(), 568bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Base->containsUnexpandedParameterPack()), 569b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis PropertyOrGetter(Getter, true), SetterAndMethodRefFlags(Setter, 0), 57012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall IdLoc(IdLoc), ReceiverLoc(), Receiver(Base) { 5713c3b7f90a863af43fa63043d396553ecf205351cJohn McCall assert(T->isSpecificPlaceholderType(BuiltinType::PseudoObject)); 57212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall } 57312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 57412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ObjCPropertyRefExpr(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter, 57512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall QualType T, ExprValueKind VK, ExprObjectKind OK, 57612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall SourceLocation IdLoc, 57712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall SourceLocation SuperLoc, QualType SuperTy) 578561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(ObjCPropertyRefExprClass, T, VK, OK, false, false, false, false), 579b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis PropertyOrGetter(Getter, true), SetterAndMethodRefFlags(Setter, 0), 58012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall IdLoc(IdLoc), ReceiverLoc(SuperLoc), Receiver(SuperTy.getTypePtr()) { 5813c3b7f90a863af43fa63043d396553ecf205351cJohn McCall assert(T->isSpecificPlaceholderType(BuiltinType::PseudoObject)); 58212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall } 58312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 58412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ObjCPropertyRefExpr(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter, 58512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall QualType T, ExprValueKind VK, ExprObjectKind OK, 58612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall SourceLocation IdLoc, 58712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall SourceLocation ReceiverLoc, ObjCInterfaceDecl *Receiver) 588561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(ObjCPropertyRefExprClass, T, VK, OK, false, false, false, false), 589b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis PropertyOrGetter(Getter, true), SetterAndMethodRefFlags(Setter, 0), 59012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall IdLoc(IdLoc), ReceiverLoc(ReceiverLoc), Receiver(Receiver) { 5913c3b7f90a863af43fa63043d396553ecf205351cJohn McCall assert(T->isSpecificPlaceholderType(BuiltinType::PseudoObject)); 592e66f4e3e3ae9d7d11b0c302211066fad69228abaDaniel Dunbar } 5931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5940389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner explicit ObjCPropertyRefExpr(EmptyShell Empty) 5950389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner : Expr(ObjCPropertyRefExprClass, Empty) {} 5960389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner 59712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall bool isImplicitProperty() const { return PropertyOrGetter.getInt(); } 59812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall bool isExplicitProperty() const { return !PropertyOrGetter.getInt(); } 59912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 60012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ObjCPropertyDecl *getExplicitProperty() const { 60112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall assert(!isImplicitProperty()); 60212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return cast<ObjCPropertyDecl>(PropertyOrGetter.getPointer()); 60312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall } 60412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 60512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ObjCMethodDecl *getImplicitPropertyGetter() const { 60612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall assert(isImplicitProperty()); 60712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return cast_or_null<ObjCMethodDecl>(PropertyOrGetter.getPointer()); 60812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall } 60912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 61012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ObjCMethodDecl *getImplicitPropertySetter() const { 61112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall assert(isImplicitProperty()); 612b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis return SetterAndMethodRefFlags.getPointer(); 61312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall } 61412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 61512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall Selector getGetterSelector() const { 61612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall if (isImplicitProperty()) 61712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return getImplicitPropertyGetter()->getSelector(); 61812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return getExplicitProperty()->getGetterName(); 61912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall } 62012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 62112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall Selector getSetterSelector() const { 62212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall if (isImplicitProperty()) 62312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return getImplicitPropertySetter()->getSelector(); 62412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return getExplicitProperty()->getSetterName(); 62512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall } 6261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 627b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis /// \brief True if the property reference will result in a message to the 628b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis /// getter. 629b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis /// This applies to both implicit and explicit property references. 630b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis bool isMessagingGetter() const { 631b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis return SetterAndMethodRefFlags.getInt() & MethodRef_Getter; 632b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis } 633b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis 634b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis /// \brief True if the property reference will result in a message to the 635b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis /// setter. 636b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis /// This applies to both implicit and explicit property references. 637b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis bool isMessagingSetter() const { 638b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis return SetterAndMethodRefFlags.getInt() & MethodRef_Setter; 639b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis } 640b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis 641b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis void setIsMessagingGetter(bool val = true) { 642b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis setMethodRefFlag(MethodRef_Getter, val); 643b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis } 644b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis 645b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis void setIsMessagingSetter(bool val = true) { 646b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis setMethodRefFlag(MethodRef_Setter, val); 647b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis } 648b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis 6498ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian const Expr *getBase() const { 65012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return cast<Expr>(Receiver.get<Stmt*>()); 6518ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian } 6528ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian Expr *getBase() { 65312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return cast<Expr>(Receiver.get<Stmt*>()); 6548ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian } 6551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 656c77a636688e188af7e7a9a05829e542adb48e880Steve Naroff SourceLocation getLocation() const { return IdLoc; } 6578ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian 65812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall SourceLocation getReceiverLocation() const { return ReceiverLoc; } 65912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall QualType getSuperReceiverType() const { 660f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall return QualType(Receiver.get<const Type*>(), 0); 6618ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian } 66268af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian QualType getGetterResultType() const { 66368af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian QualType ResultType; 66468af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian if (isExplicitProperty()) { 66568af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian const ObjCPropertyDecl *PDecl = getExplicitProperty(); 66668af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian if (const ObjCMethodDecl *Getter = PDecl->getGetterMethodDecl()) 66768af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian ResultType = Getter->getResultType(); 66868af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian else 6693c3b7f90a863af43fa63043d396553ecf205351cJohn McCall ResultType = PDecl->getType(); 67068af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian } else { 67168af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian const ObjCMethodDecl *Getter = getImplicitPropertyGetter(); 6723c3b7f90a863af43fa63043d396553ecf205351cJohn McCall if (Getter) 6733c3b7f90a863af43fa63043d396553ecf205351cJohn McCall ResultType = Getter->getResultType(); // with reference! 67468af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian } 67568af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian return ResultType; 67668af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian } 6773c3b7f90a863af43fa63043d396553ecf205351cJohn McCall 67868af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian QualType getSetterArgType() const { 67968af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian QualType ArgType; 68068af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian if (isImplicitProperty()) { 68168af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian const ObjCMethodDecl *Setter = getImplicitPropertySetter(); 682491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis ObjCMethodDecl::param_const_iterator P = Setter->param_begin(); 68368af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian ArgType = (*P)->getType(); 68468af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian } else { 68568af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian if (ObjCPropertyDecl *PDecl = getExplicitProperty()) 68668af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian if (const ObjCMethodDecl *Setter = PDecl->getSetterMethodDecl()) { 687491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis ObjCMethodDecl::param_const_iterator P = Setter->param_begin(); 68868af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian ArgType = (*P)->getType(); 68968af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian } 69068af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian if (ArgType.isNull()) 69168af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian ArgType = getType(); 69268af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian } 69368af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian return ArgType; 69468af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian } 69568af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian 69612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ObjCInterfaceDecl *getClassReceiver() const { 69712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return Receiver.get<ObjCInterfaceDecl*>(); 69812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall } 69912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall bool isObjectReceiver() const { return Receiver.is<Stmt*>(); } 700f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall bool isSuperReceiver() const { return Receiver.is<const Type*>(); } 70112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall bool isClassReceiver() const { return Receiver.is<ObjCInterfaceDecl*>(); } 702ae7840776d6cd31b4d7a4a345b61bcbb3744df6cSteve Naroff 703aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 70412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return SourceRange((isObjectReceiver() ? getBase()->getLocStart() 70512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall : getReceiverLocation()), 70612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall IdLoc); 7070389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner } 7081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 7101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ObjCPropertyRefExprClass; 711ae7840776d6cd31b4d7a4a345b61bcbb3744df6cSteve Naroff } 712ae7840776d6cd31b4d7a4a345b61bcbb3744df6cSteve Naroff static bool classof(const ObjCPropertyRefExpr *) { return true; } 7131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 714ae7840776d6cd31b4d7a4a345b61bcbb3744df6cSteve Naroff // Iterators 71563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 71663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall if (Receiver.is<Stmt*>()) { 71763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin = reinterpret_cast<Stmt**>(&Receiver); // hack! 71863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, begin+1); 71963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 72063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(); 72163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 72263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 723f8730d7c313c421d5d7a2b9d97541fc89d5a52d4Ted Kremenekprivate: 724f8730d7c313c421d5d7a2b9d97541fc89d5a52d4Ted Kremenek friend class ASTStmtReader; 725b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis friend class ASTStmtWriter; 726b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis void setExplicitProperty(ObjCPropertyDecl *D, unsigned methRefFlags) { 72712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall PropertyOrGetter.setPointer(D); 72812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall PropertyOrGetter.setInt(false); 729b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis SetterAndMethodRefFlags.setPointer(0); 730b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis SetterAndMethodRefFlags.setInt(methRefFlags); 7318ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian } 732b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis void setImplicitProperty(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter, 733b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis unsigned methRefFlags) { 73412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall PropertyOrGetter.setPointer(Getter); 73512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall PropertyOrGetter.setInt(true); 736b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis SetterAndMethodRefFlags.setPointer(Setter); 737b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis SetterAndMethodRefFlags.setInt(methRefFlags); 7385daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian } 73912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall void setBase(Expr *Base) { Receiver = Base; } 74012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall void setSuperReceiver(QualType T) { Receiver = T.getTypePtr(); } 74112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall void setClassReceiver(ObjCInterfaceDecl *D) { Receiver = D; } 7421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 74312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall void setLocation(SourceLocation L) { IdLoc = L; } 74412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall void setReceiverLocation(SourceLocation Loc) { ReceiverLoc = Loc; } 745b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis 746b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis void setMethodRefFlag(MethodRefFlags flag, bool val) { 747b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis unsigned f = SetterAndMethodRefFlags.getInt(); 748b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis if (val) 749b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis f |= flag; 750b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis else 751b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis f &= ~flag; 752b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis SetterAndMethodRefFlags.setInt(f); 753b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis } 7545daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian}; 755ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 756ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// ObjCSubscriptRefExpr - used for array and dictionary subscripting. 757ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// array[4] = array[3]; dictionary[key] = dictionary[alt_key]; 758ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// 759ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenekclass ObjCSubscriptRefExpr : public Expr { 760ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Location of ']' in an indexing expression. 761ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceLocation RBracket; 762ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // array/dictionary base expression. 763ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // for arrays, this is a numeric expression. For dictionaries, this is 764ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // an objective-c object pointer expression. 765ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek enum { BASE, KEY, END_EXPR }; 766ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Stmt* SubExprs[END_EXPR]; 767ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 768ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *GetAtIndexMethodDecl; 769ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 770ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // For immutable objects this is null. When ObjCSubscriptRefExpr is to read 771ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // an indexed object this is null too. 772ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *SetAtIndexMethodDecl; 773ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 774ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenekpublic: 775ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 776ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCSubscriptRefExpr(Expr *base, Expr *key, QualType T, 777ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprValueKind VK, ExprObjectKind OK, 778ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *getMethod, 779ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *setMethod, SourceLocation RB) 780ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek : Expr(ObjCSubscriptRefExprClass, T, VK, OK, 781ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek base->isTypeDependent() || key->isTypeDependent(), 782ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek base->isValueDependent() || key->isValueDependent(), 783ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek base->isInstantiationDependent() || key->isInstantiationDependent(), 784ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek (base->containsUnexpandedParameterPack() || 785ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek key->containsUnexpandedParameterPack())), 786ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek RBracket(RB), 787ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek GetAtIndexMethodDecl(getMethod), 788ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SetAtIndexMethodDecl(setMethod) 789ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek {SubExprs[BASE] = base; SubExprs[KEY] = key;} 790ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 791ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek explicit ObjCSubscriptRefExpr(EmptyShell Empty) 792ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek : Expr(ObjCSubscriptRefExprClass, Empty) {} 793ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 794ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek static ObjCSubscriptRefExpr *Create(ASTContext &C, 795ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr *base, 796ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr *key, QualType T, 797ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *getMethod, 798ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *setMethod, 799ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceLocation RB); 800ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 801ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceLocation getRBracket() const { return RBracket; } 802ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek void setRBracket(SourceLocation RB) { RBracket = RB; } 803aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 804ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return SourceRange(SubExprs[BASE]->getLocStart(), RBracket); 805ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 806ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 807ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek static bool classof(const Stmt *T) { 808ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return T->getStmtClass() == ObjCSubscriptRefExprClass; 809ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 810ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek static bool classof(const ObjCSubscriptRefExpr *) { return true; } 811ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 812ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr *getBaseExpr() const { return cast<Expr>(SubExprs[BASE]); } 813ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek void setBaseExpr(Stmt *S) { SubExprs[BASE] = S; } 814ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 815ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr *getKeyExpr() const { return cast<Expr>(SubExprs[KEY]); } 816ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek void setKeyExpr(Stmt *S) { SubExprs[KEY] = S; } 817ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 818ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *getAtIndexMethodDecl() const { 819ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return GetAtIndexMethodDecl; 820ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 821ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 822ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *setAtIndexMethodDecl() const { 823ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return SetAtIndexMethodDecl; 824ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 825ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 826ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool isArraySubscriptRefExpr() const { 827ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return getKeyExpr()->getType()->isIntegralOrEnumerationType(); 828ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 829ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 830ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek child_range children() { 831ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return child_range(SubExprs, SubExprs+END_EXPR); 832ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 833ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenekprivate: 834ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek friend class ASTStmtReader; 835ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek}; 836ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8382725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \brief An expression that sends a message to the given Objective-C 8392725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// object or class. 8402725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 8412725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// The following contains two message send expressions: 8422725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 8432725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \code 8442725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// [[NSString alloc] initWithString:@"Hello"] 8452725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \endcode 8462725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 8472725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// The innermost message send invokes the "alloc" class method on the 8482725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// NSString class, while the outermost message send invokes the 8492725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// "initWithString" instance method on the object returned from 8502725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// NSString's "alloc". In all, an Objective-C message send can take 8512725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// on four different (although related) forms: 8522725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 8532725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 1. Send to an object instance. 8542725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 2. Send to a class. 8552725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 3. Send to the superclass instance of the current class. 8562725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 4. Send to the superclass of the current class. 8572725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 8582725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// All four kinds of message sends are modeled by the ObjCMessageExpr 8592725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// class, and can be distinguished via \c getReceiverKind(). Example: 8602725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 861f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroffclass ObjCMessageExpr : public Expr { 862b994e6c7d57b00e3e0f69d152065e2cf85d1de33Argyrios Kyrtzidis /// \brief Stores either the selector that this message is sending 863b994e6c7d57b00e3e0f69d152065e2cf85d1de33Argyrios Kyrtzidis /// to (when \c HasMethod is zero) or an \c ObjCMethodDecl pointer 864b994e6c7d57b00e3e0f69d152065e2cf85d1de33Argyrios Kyrtzidis /// referring to the method that we type-checked against. 865b994e6c7d57b00e3e0f69d152065e2cf85d1de33Argyrios Kyrtzidis uintptr_t SelectorOrMethod; 866b994e6c7d57b00e3e0f69d152065e2cf85d1de33Argyrios Kyrtzidis 86704fb8ef41ed2bd9533ba9392b4db1a7379752c16Argyrios Kyrtzidis enum { NumArgsBitWidth = 16 }; 86804fb8ef41ed2bd9533ba9392b4db1a7379752c16Argyrios Kyrtzidis 86904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief The number of arguments in the message send, not 87004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// including the receiver. 87104fb8ef41ed2bd9533ba9392b4db1a7379752c16Argyrios Kyrtzidis unsigned NumArgs : NumArgsBitWidth; 87204fb8ef41ed2bd9533ba9392b4db1a7379752c16Argyrios Kyrtzidis 87304fb8ef41ed2bd9533ba9392b4db1a7379752c16Argyrios Kyrtzidis void setNumArgs(unsigned Num) { 87404fb8ef41ed2bd9533ba9392b4db1a7379752c16Argyrios Kyrtzidis assert((Num >> NumArgsBitWidth) == 0 && "Num of args is out of range!"); 87504fb8ef41ed2bd9533ba9392b4db1a7379752c16Argyrios Kyrtzidis NumArgs = Num; 87604fb8ef41ed2bd9533ba9392b4db1a7379752c16Argyrios Kyrtzidis } 87704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 87804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief The kind of message send this is, which is one of the 87904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// ReceiverKind values. 88004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 88104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// We pad this out to a byte to avoid excessive masking and shifting. 88204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor unsigned Kind : 8; 88304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 88404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Whether we have an actual method prototype in \c 88504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// SelectorOrMethod. 88604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 88704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// When non-zero, we have a method declaration; otherwise, we just 88804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// have a selector. 889f85e193739c953358c865005855253af4f68a497John McCall unsigned HasMethod : 1; 890f85e193739c953358c865005855253af4f68a497John McCall 891f85e193739c953358c865005855253af4f68a497John McCall /// \brief Whether this message send is a "delegate init call", 892f85e193739c953358c865005855253af4f68a497John McCall /// i.e. a call of an init method on self from within an init method. 893f85e193739c953358c865005855253af4f68a497John McCall unsigned IsDelegateInitCall : 1; 894746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis 895746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis /// \brief Whether this message send was implicitly generated by 896746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis /// the implementation rather than explicitly written by the user. 897746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis unsigned IsImplicit : 1; 898746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis 899207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis /// \brief Whether the locations of the selector identifiers are in a 900207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis /// "standard" position, a enum SelectorLocationsKind. 901207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned SelLocsKind : 2; 90204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 90304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief When the message expression is a send to 'super', this is 90404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// the location of the 'super' keyword. 90504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation SuperLoc; 90604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 90704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief The source locations of the open and close square 90804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// brackets ('[' and ']', respectively). 90904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, RBracLoc; 91004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 91104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMessageExpr(EmptyShell Empty, unsigned NumArgs) 912b994e6c7d57b00e3e0f69d152065e2cf85d1de33Argyrios Kyrtzidis : Expr(ObjCMessageExprClass, Empty), SelectorOrMethod(0), Kind(0), 913746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis HasMethod(0), IsDelegateInitCall(0), IsImplicit(0), SelLocsKind(0) { 91404fb8ef41ed2bd9533ba9392b4db1a7379752c16Argyrios Kyrtzidis setNumArgs(NumArgs); 91504fb8ef41ed2bd9533ba9392b4db1a7379752c16Argyrios Kyrtzidis } 91604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 917f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ObjCMessageExpr(QualType T, ExprValueKind VK, 91804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 91904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation SuperLoc, 92004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor bool IsInstanceSuper, 92104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor QualType SuperType, 92204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Selector Sel, 923207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 924207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind SelLocsK, 92504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 9268d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 927746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 928746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit); 929f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ObjCMessageExpr(QualType T, ExprValueKind VK, 93004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 93104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor TypeSourceInfo *Receiver, 93204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Selector Sel, 933207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 934207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind SelLocsK, 93504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 9368d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 937746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 938746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit); 939f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ObjCMessageExpr(QualType T, ExprValueKind VK, 94004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 94104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr *Receiver, 94204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Selector Sel, 943207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 944207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind SelLocsK, 94504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 9468d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 947746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 948746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit); 94904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 950207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis void initArgsAndSelLocs(ArrayRef<Expr *> Args, 951207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 952207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind SelLocsK); 953207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 9542725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor /// \brief Retrieve the pointer value of the message receiver. 95504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor void *getReceiverPointer() const { 95604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return *const_cast<void **>( 95704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor reinterpret_cast<const void * const*>(this + 1)); 95804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 9591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 96004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Set the pointer value of the message receiver. 96104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor void setReceiverPointer(void *Value) { 96204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor *reinterpret_cast<void **>(this + 1) = Value; 96304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 9641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 965207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind getSelLocsKind() const { 966207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return (SelectorLocationsKind)SelLocsKind; 967207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis } 968207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis bool hasStandardSelLocs() const { 969207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return getSelLocsKind() != SelLoc_NonStandard; 970207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis } 971207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 972207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis /// \brief Get a pointer to the stored selector identifiers locations array. 973207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis /// No locations will be stored if HasStandardSelLocs is true. 974207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SourceLocation *getStoredSelLocs() { 975207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return reinterpret_cast<SourceLocation*>(getArgs() + getNumArgs()); 976207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis } 977207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis const SourceLocation *getStoredSelLocs() const { 978207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return reinterpret_cast<const SourceLocation*>(getArgs() + getNumArgs()); 979207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis } 980207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 981207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis /// \brief Get the number of stored selector identifiers locations. 982207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis /// No locations will be stored if HasStandardSelLocs is true. 983207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned getNumStoredSelLocs() const { 984207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis if (hasStandardSelLocs()) 985207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return 0; 986207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return getNumSelectorLocs(); 987207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis } 988207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 989207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis static ObjCMessageExpr *alloc(ASTContext &C, 990207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<Expr *> Args, 991207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SourceLocation RBraceLoc, 992207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 993207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis Selector Sel, 994207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind &SelLocsK); 995207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis static ObjCMessageExpr *alloc(ASTContext &C, 996207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned NumArgs, 997207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned NumStoredSelLocs); 998207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 99904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregorpublic: 100004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief The kind of receiver this message is sending to. 100104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor enum ReceiverKind { 100204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief The receiver is a class. 100304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Class = 0, 100404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief The receiver is an object instance. 100504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Instance, 100604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief The receiver is a superclass. 100704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SuperClass, 100804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief The receiver is the instance of the superclass object. 100904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SuperInstance 101004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor }; 1011c2350e553b853ad00914faf23fa731e5fc4a8a5cDouglas Gregor 101204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Create a message send to super. 101304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 101404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Context The ASTContext in which this expression will be created. 101504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 101604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param T The result type of this message. 101704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 1018f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// \param VK The value kind of this message. A message returning 1019f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// a l-value or r-value reference will be an l-value or x-value, 1020f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// respectively. 1021f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// 102204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param LBrac The location of the open square bracket '['. 102304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 102404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param SuperLoc The location of the "super" keyword. 102504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 102604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param IsInstanceSuper Whether this is an instance "super" 102704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// message (otherwise, it's a class "super" message). 102804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 102904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Sel The selector used to determine which method gets called. 103004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 103104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Method The Objective-C method against which this message 103204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// send was type-checked. May be NULL. 103304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 103404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Args The message send arguments. 103504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 103604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param NumArgs The number of arguments. 103704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 103804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param RBracLoc The location of the closing square bracket ']'. 1039f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall static ObjCMessageExpr *Create(ASTContext &Context, QualType T, 1040f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 104104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 104204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation SuperLoc, 104304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor bool IsInstanceSuper, 104404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor QualType SuperType, 104504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Selector Sel, 1046951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 104704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 10488d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 1049746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 1050746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit); 105104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 105204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Create a class message send. 105304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 105404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Context The ASTContext in which this expression will be created. 105504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 105604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param T The result type of this message. 105704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 1058f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// \param VK The value kind of this message. A message returning 1059f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// a l-value or r-value reference will be an l-value or x-value, 1060f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// respectively. 1061f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// 106204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param LBrac The location of the open square bracket '['. 106304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 106404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Receiver The type of the receiver, including 106504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// source-location information. 106604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 106704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Sel The selector used to determine which method gets called. 106804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 106904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Method The Objective-C method against which this message 107004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// send was type-checked. May be NULL. 107104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 107204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Args The message send arguments. 107304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 107404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param NumArgs The number of arguments. 107504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 107604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param RBracLoc The location of the closing square bracket ']'. 107704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor static ObjCMessageExpr *Create(ASTContext &Context, QualType T, 1078f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 107904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 108004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor TypeSourceInfo *Receiver, 108104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Selector Sel, 1082951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 108304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 10848d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 1085746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 1086746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit); 108704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 108804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Create an instance message send. 108904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 109004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Context The ASTContext in which this expression will be created. 109104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 109204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param T The result type of this message. 109304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 1094f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// \param VK The value kind of this message. A message returning 1095f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// a l-value or r-value reference will be an l-value or x-value, 1096f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// respectively. 1097f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// 109804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param LBrac The location of the open square bracket '['. 109904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 110004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Receiver The expression used to produce the object that 110104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// will receive this message. 110204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 110304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Sel The selector used to determine which method gets called. 110404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 110504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Method The Objective-C method against which this message 110604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// send was type-checked. May be NULL. 110704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 110804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Args The message send arguments. 110904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 111004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param NumArgs The number of arguments. 111104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 111204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param RBracLoc The location of the closing square bracket ']'. 111304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor static ObjCMessageExpr *Create(ASTContext &Context, QualType T, 1114f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 111504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 111604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr *Receiver, 111704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Selector Sel, 1118951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis ArrayRef<SourceLocation> SeLocs, 111904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 11208d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 1121746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 1122746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit); 112304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 112404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Create an empty Objective-C message expression, to be 112504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// filled in by subsequent calls. 112604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 112704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Context The context in which the message send will be created. 112804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 112904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param NumArgs The number of message arguments, not including 113004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// the receiver. 1131207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis static ObjCMessageExpr *CreateEmpty(ASTContext &Context, 1132207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned NumArgs, 1133207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned NumStoredSelLocs); 113404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 1135746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis /// \brief Indicates whether the message send was implicitly 1136746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis /// generated by the implementation. If false, it was written explicitly 1137746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis /// in the source code. 1138746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit() const { return IsImplicit; } 1139746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis 114004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Determine the kind of receiver that this message is being 114104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// sent to. 114204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ReceiverKind getReceiverKind() const { return (ReceiverKind)Kind; } 114304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 1144e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis /// \brief Source range of the receiver. 1145e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis SourceRange getReceiverRange() const; 1146e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis 114704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Determine whether this is an instance message to either a 114804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// computed object or to super. 114904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor bool isInstanceMessage() const { 115004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return getReceiverKind() == Instance || getReceiverKind() == SuperInstance; 115104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 11521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 115304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Determine whether this is an class message to either a 115404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// specified class or to super. 115504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor bool isClassMessage() const { 115604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return getReceiverKind() == Class || getReceiverKind() == SuperClass; 115704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 1158f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff 115904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Returns the receiver of an instance message. 116004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 116104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Returns the object expression for an instance message, or 116204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// NULL for a message that is not an instance message. 116304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr *getInstanceReceiver() { 116404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (getReceiverKind() == Instance) 116504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return static_cast<Expr *>(getReceiverPointer()); 1166be78424edfbc6095c4acb83c7ae7f53a42f0c870Ted Kremenek 116704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return 0; 116804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 116904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor const Expr *getInstanceReceiver() const { 117004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return const_cast<ObjCMessageExpr*>(this)->getInstanceReceiver(); 117104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 1172be78424edfbc6095c4acb83c7ae7f53a42f0c870Ted Kremenek 117304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Turn this message send into an instance message that 117404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// computes the receiver object with the given expression. 117504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor void setInstanceReceiver(Expr *rec) { 117604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Kind = Instance; 117704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor setReceiverPointer(rec); 117804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 117904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 118004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Returns the type of a class message send, or NULL if the 118104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// message is not a class message. 118204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor QualType getClassReceiver() const { 118304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (TypeSourceInfo *TSInfo = getClassReceiverTypeInfo()) 118404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return TSInfo->getType(); 118504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 118604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return QualType(); 118704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 11881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 118904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Returns a type-source information of a class message 119004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// send, or NULL if the message is not a class message. 119104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor TypeSourceInfo *getClassReceiverTypeInfo() const { 119204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (getReceiverKind() == Class) 119304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return reinterpret_cast<TypeSourceInfo *>(getReceiverPointer()); 119404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return 0; 119504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 11961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 119704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor void setClassReceiver(TypeSourceInfo *TSInfo) { 119804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Kind = Class; 119904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor setReceiverPointer(TSInfo); 120004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 120104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 120204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Retrieve the location of the 'super' keyword for a class 120304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// or instance message to 'super', otherwise an invalid source location. 120404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation getSuperLoc() const { 120504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (getReceiverKind() == SuperInstance || getReceiverKind() == SuperClass) 120604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return SuperLoc; 12071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 120804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return SourceLocation(); 120904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 1210c2350e553b853ad00914faf23fa731e5fc4a8a5cDouglas Gregor 121104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Retrieve the Objective-C interface to which this message 121204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// is being directed, if known. 121304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 121404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// This routine cross-cuts all of the different kinds of message 121504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// sends to determine what the underlying (statically known) type 121604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// of the receiver will be; use \c getReceiverKind() to determine 121704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// whether the message is a class or an instance method, whether it 121804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// is a send to super or not, etc. 121904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 122004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \returns The Objective-C interface if known, otherwise NULL. 122104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCInterfaceDecl *getReceiverInterface() const; 122204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 122304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Retrieve the type referred to by 'super'. 122404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 122504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// The returned type will either be an ObjCInterfaceType (for an 122604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// class message to super) or an ObjCObjectPointerType that refers 122704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// to a class (for an instance message to super); 122804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor QualType getSuperType() const { 122904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (getReceiverKind() == SuperInstance || getReceiverKind() == SuperClass) 123004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return QualType::getFromOpaquePtr(getReceiverPointer()); 123104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 123204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return QualType(); 123304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 1234c2350e553b853ad00914faf23fa731e5fc4a8a5cDouglas Gregor 123504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor void setSuper(SourceLocation Loc, QualType T, bool IsInstanceSuper) { 123604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Kind = IsInstanceSuper? SuperInstance : SuperClass; 123704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SuperLoc = Loc; 123804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor setReceiverPointer(T.getAsOpaquePtr()); 123904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 1240c2350e553b853ad00914faf23fa731e5fc4a8a5cDouglas Gregor 124104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Selector getSelector() const; 1242c2350e553b853ad00914faf23fa731e5fc4a8a5cDouglas Gregor 124304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor void setSelector(Selector S) { 124404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor HasMethod = false; 124504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SelectorOrMethod = reinterpret_cast<uintptr_t>(S.getAsOpaquePtr()); 124604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 12471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 124804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor const ObjCMethodDecl *getMethodDecl() const { 124904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (HasMethod) 125004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return reinterpret_cast<const ObjCMethodDecl *>(SelectorOrMethod); 12511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 125204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return 0; 1253f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff } 12541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 125504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *getMethodDecl() { 125604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (HasMethod) 125704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return reinterpret_cast<ObjCMethodDecl *>(SelectorOrMethod); 125804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 125904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return 0; 126004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 126104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 126204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor void setMethodDecl(ObjCMethodDecl *MD) { 126304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor HasMethod = true; 126404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SelectorOrMethod = reinterpret_cast<uintptr_t>(MD); 126504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 126604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 126785f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall ObjCMethodFamily getMethodFamily() const { 126885f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall if (HasMethod) return getMethodDecl()->getMethodFamily(); 126985f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall return getSelector().getMethodFamily(); 127085f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall } 127185f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall 127204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Return the number of actual arguments in this message, 127304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// not counting the receiver. 1274f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff unsigned getNumArgs() const { return NumArgs; } 127504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 127604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Retrieve the arguments to this message, not including the 127704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// receiver. 1278aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Expr **getArgs() { 1279aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return reinterpret_cast<Expr **>(this + 1) + 1; 128004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 1281aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor const Expr * const *getArgs() const { 1282aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return reinterpret_cast<const Expr * const *>(this + 1) + 1; 1283405bad07391494d2eb025f8222c256c66b56e5f8Douglas Gregor } 12841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1285f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff /// getArg - Return the specified argument. 1286f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff Expr *getArg(unsigned Arg) { 1287f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff assert(Arg < NumArgs && "Arg access out of range!"); 128804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return cast<Expr>(getArgs()[Arg]); 1289f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff } 1290f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff const Expr *getArg(unsigned Arg) const { 1291f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff assert(Arg < NumArgs && "Arg access out of range!"); 129204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return cast<Expr>(getArgs()[Arg]); 1293f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff } 1294f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff /// setArg - Set the specified argument. 1295f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff void setArg(unsigned Arg, Expr *ArgExpr) { 1296f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff assert(Arg < NumArgs && "Arg access out of range!"); 129704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor getArgs()[Arg] = ArgExpr; 1298f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff } 12991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1300f85e193739c953358c865005855253af4f68a497John McCall /// isDelegateInitCall - Answers whether this message send has been 1301f85e193739c953358c865005855253af4f68a497John McCall /// tagged as a "delegate init call", i.e. a call to a method in the 1302f85e193739c953358c865005855253af4f68a497John McCall /// -init family on self from within an -init method implementation. 1303f85e193739c953358c865005855253af4f68a497John McCall bool isDelegateInitCall() const { return IsDelegateInitCall; } 1304f85e193739c953358c865005855253af4f68a497John McCall void setDelegateInitCall(bool isDelegate) { IsDelegateInitCall = isDelegate; } 1305f85e193739c953358c865005855253af4f68a497John McCall 130604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation getLeftLoc() const { return LBracLoc; } 130704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation getRightLoc() const { return RBracLoc; } 1308207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 1309746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation getSelectorStartLoc() const { 1310746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis if (isImplicit()) 1311746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis return getLocStart(); 1312746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis return getSelectorLoc(0); 1313746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis } 1314207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SourceLocation getSelectorLoc(unsigned Index) const { 1315207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis assert(Index < getNumSelectorLocs() && "Index out of range!"); 1316207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis if (hasStandardSelLocs()) 1317207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return getStandardSelectorLoc(Index, getSelector(), 1318207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis getSelLocsKind() == SelLoc_StandardWithSpace, 1319207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis llvm::makeArrayRef(const_cast<Expr**>(getArgs()), 1320207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis getNumArgs()), 1321207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis RBracLoc); 1322207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return getStoredSelLocs()[Index]; 1323207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis } 1324207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 1325207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis void getSelectorLocs(SmallVectorImpl<SourceLocation> &SelLocs) const; 1326207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 1327207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned getNumSelectorLocs() const { 1328746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis if (isImplicit()) 1329746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis return 0; 1330207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis Selector Sel = getSelector(); 1331207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis if (Sel.isUnarySelector()) 1332207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return 1; 1333207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return Sel.getNumArgs(); 1334207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis } 13351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1336c4f0bbdb166fbc31ab2cf0f6ff573fde9fa307b3Steve Naroff void setSourceRange(SourceRange R) { 133704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor LBracLoc = R.getBegin(); 133804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor RBracLoc = R.getEnd(); 1339c4f0bbdb166fbc31ab2cf0f6ff573fde9fa307b3Steve Naroff } 1340aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 134104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return SourceRange(LBracLoc, RBracLoc); 1342f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff } 1343f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff 1344f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff static bool classof(const Stmt *T) { 1345f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff return T->getStmtClass() == ObjCMessageExprClass; 1346f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff } 1347f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff static bool classof(const ObjCMessageExpr *) { return true; } 13481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1349f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff // Iterators 135063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children(); 13511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13525549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ExprIterator arg_iterator; 13535549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ConstExprIterator const_arg_iterator; 13541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1355aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor arg_iterator arg_begin() { return reinterpret_cast<Stmt **>(getArgs()); } 1356aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor arg_iterator arg_end() { 1357aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return reinterpret_cast<Stmt **>(getArgs() + NumArgs); 1358aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor } 1359aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor const_arg_iterator arg_begin() const { 1360aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return reinterpret_cast<Stmt const * const*>(getArgs()); 1361aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor } 1362aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor const_arg_iterator arg_end() const { 1363aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return reinterpret_cast<Stmt const * const*>(getArgs() + NumArgs); 1364aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor } 1365f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis 1366f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis friend class ASTStmtReader; 1367f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis friend class ASTStmtWriter; 1368f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff}; 1369f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff 137099b10be143e3148b9499af4c0e9ebaf46757cfe6Steve Naroff/// ObjCIsaExpr - Represent X->isa and X.isa when X is an ObjC 'id' type. 1371fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner/// (similar in spirit to MemberExpr). 1372f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroffclass ObjCIsaExpr : public Expr { 1373f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff /// Base - the expression for the base object pointer. 1374f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff Stmt *Base; 13751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1376f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff /// IsaMemberLoc - This is the location of the 'isa'. 1377f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff SourceLocation IsaMemberLoc; 13781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1379f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff /// IsArrow - True if this is "X->F", false if this is "X.F". 1380f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff bool IsArrow; 1381f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroffpublic: 13821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCIsaExpr(Expr *base, bool isarrow, SourceLocation l, QualType ty) 1383f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ObjCIsaExprClass, ty, VK_LValue, OK_Ordinary, 1384bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*TypeDependent=*/false, base->isValueDependent(), 1385561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isInstantiationDependent(), 1386bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 1387f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff Base(base), IsaMemberLoc(l), IsArrow(isarrow) {} 13881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1389f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff /// \brief Build an empty expression. 1390f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff explicit ObjCIsaExpr(EmptyShell Empty) : Expr(ObjCIsaExprClass, Empty) { } 13911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1392f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff void setBase(Expr *E) { Base = E; } 1393f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff Expr *getBase() const { return cast<Expr>(Base); } 13941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1395f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff bool isArrow() const { return IsArrow; } 1396f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff void setArrow(bool A) { IsArrow = A; } 1397f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff 1398f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff /// getMemberLoc - Return the location of the "member", in X->F, it is the 1399f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff /// location of 'F'. 1400f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff SourceLocation getIsaMemberLoc() const { return IsaMemberLoc; } 1401f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff void setIsaMemberLoc(SourceLocation L) { IsaMemberLoc = L; } 1402f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff 1403aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 1404f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff return SourceRange(getBase()->getLocStart(), IsaMemberLoc); 1405f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff } 14061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14074f311183be3d923da9fbe8702c453688b4c426a9Daniel Dunbar SourceLocation getExprLoc() const LLVM_READONLY { return IsaMemberLoc; } 1408f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff 14091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 14101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ObjCIsaExprClass; 1411f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff } 1412f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff static bool classof(const ObjCIsaExpr *) { return true; } 14131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1414f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff // Iterators 141563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Base, &Base+1); } 1416f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff}; 1417f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff 1418f85e193739c953358c865005855253af4f68a497John McCall 1419f85e193739c953358c865005855253af4f68a497John McCall/// ObjCIndirectCopyRestoreExpr - Represents the passing of a function 1420f85e193739c953358c865005855253af4f68a497John McCall/// argument by indirect copy-restore in ARC. This is used to support 1421f85e193739c953358c865005855253af4f68a497John McCall/// passing indirect arguments with the wrong lifetime, e.g. when 1422f85e193739c953358c865005855253af4f68a497John McCall/// passing the address of a __strong local variable to an 'out' 1423f85e193739c953358c865005855253af4f68a497John McCall/// parameter. This expression kind is only valid in an "argument" 1424f85e193739c953358c865005855253af4f68a497John McCall/// position to some sort of call expression. 1425f85e193739c953358c865005855253af4f68a497John McCall/// 1426f85e193739c953358c865005855253af4f68a497John McCall/// The parameter must have type 'pointer to T', and the argument must 1427f85e193739c953358c865005855253af4f68a497John McCall/// have type 'pointer to U', where T and U agree except possibly in 1428f85e193739c953358c865005855253af4f68a497John McCall/// qualification. If the argument value is null, then a null pointer 1429f85e193739c953358c865005855253af4f68a497John McCall/// is passed; otherwise it points to an object A, and: 1430f85e193739c953358c865005855253af4f68a497John McCall/// 1. A temporary object B of type T is initialized, either by 1431f85e193739c953358c865005855253af4f68a497John McCall/// zero-initialization (used when initializing an 'out' parameter) 1432f85e193739c953358c865005855253af4f68a497John McCall/// or copy-initialization (used when initializing an 'inout' 1433f85e193739c953358c865005855253af4f68a497John McCall/// parameter). 1434f85e193739c953358c865005855253af4f68a497John McCall/// 2. The address of the temporary is passed to the function. 1435f85e193739c953358c865005855253af4f68a497John McCall/// 3. If the call completes normally, A is move-assigned from B. 1436f85e193739c953358c865005855253af4f68a497John McCall/// 4. Finally, A is destroyed immediately. 1437f85e193739c953358c865005855253af4f68a497John McCall/// 1438f85e193739c953358c865005855253af4f68a497John McCall/// Currently 'T' must be a retainable object lifetime and must be 1439f85e193739c953358c865005855253af4f68a497John McCall/// __autoreleasing; this qualifier is ignored when initializing 1440f85e193739c953358c865005855253af4f68a497John McCall/// the value. 1441f85e193739c953358c865005855253af4f68a497John McCallclass ObjCIndirectCopyRestoreExpr : public Expr { 1442f85e193739c953358c865005855253af4f68a497John McCall Stmt *Operand; 1443f85e193739c953358c865005855253af4f68a497John McCall 1444f85e193739c953358c865005855253af4f68a497John McCall // unsigned ObjCIndirectCopyRestoreBits.ShouldCopy : 1; 1445f85e193739c953358c865005855253af4f68a497John McCall 1446f85e193739c953358c865005855253af4f68a497John McCall friend class ASTReader; 1447f85e193739c953358c865005855253af4f68a497John McCall friend class ASTStmtReader; 1448f85e193739c953358c865005855253af4f68a497John McCall 1449f85e193739c953358c865005855253af4f68a497John McCall void setShouldCopy(bool shouldCopy) { 1450f85e193739c953358c865005855253af4f68a497John McCall ObjCIndirectCopyRestoreExprBits.ShouldCopy = shouldCopy; 1451f85e193739c953358c865005855253af4f68a497John McCall } 1452f85e193739c953358c865005855253af4f68a497John McCall 1453f85e193739c953358c865005855253af4f68a497John McCall explicit ObjCIndirectCopyRestoreExpr(EmptyShell Empty) 1454f85e193739c953358c865005855253af4f68a497John McCall : Expr(ObjCIndirectCopyRestoreExprClass, Empty) { } 1455f85e193739c953358c865005855253af4f68a497John McCall 1456f85e193739c953358c865005855253af4f68a497John McCallpublic: 1457f85e193739c953358c865005855253af4f68a497John McCall ObjCIndirectCopyRestoreExpr(Expr *operand, QualType type, bool shouldCopy) 1458f85e193739c953358c865005855253af4f68a497John McCall : Expr(ObjCIndirectCopyRestoreExprClass, type, VK_LValue, OK_Ordinary, 1459f85e193739c953358c865005855253af4f68a497John McCall operand->isTypeDependent(), operand->isValueDependent(), 1460561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor operand->isInstantiationDependent(), 1461f85e193739c953358c865005855253af4f68a497John McCall operand->containsUnexpandedParameterPack()), 1462f85e193739c953358c865005855253af4f68a497John McCall Operand(operand) { 1463f85e193739c953358c865005855253af4f68a497John McCall setShouldCopy(shouldCopy); 1464f85e193739c953358c865005855253af4f68a497John McCall } 1465f85e193739c953358c865005855253af4f68a497John McCall 1466f85e193739c953358c865005855253af4f68a497John McCall Expr *getSubExpr() { return cast<Expr>(Operand); } 1467f85e193739c953358c865005855253af4f68a497John McCall const Expr *getSubExpr() const { return cast<Expr>(Operand); } 1468f85e193739c953358c865005855253af4f68a497John McCall 1469f85e193739c953358c865005855253af4f68a497John McCall /// shouldCopy - True if we should do the 'copy' part of the 1470f85e193739c953358c865005855253af4f68a497John McCall /// copy-restore. If false, the temporary will be zero-initialized. 1471f85e193739c953358c865005855253af4f68a497John McCall bool shouldCopy() const { return ObjCIndirectCopyRestoreExprBits.ShouldCopy; } 1472f85e193739c953358c865005855253af4f68a497John McCall 1473f85e193739c953358c865005855253af4f68a497John McCall child_range children() { return child_range(&Operand, &Operand+1); } 1474f85e193739c953358c865005855253af4f68a497John McCall 1475f85e193739c953358c865005855253af4f68a497John McCall // Source locations are determined by the subexpression. 14764f311183be3d923da9fbe8702c453688b4c426a9Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 14774f311183be3d923da9fbe8702c453688b4c426a9Daniel Dunbar return Operand->getSourceRange(); 14784f311183be3d923da9fbe8702c453688b4c426a9Daniel Dunbar } 14794f311183be3d923da9fbe8702c453688b4c426a9Daniel Dunbar SourceLocation getExprLoc() const LLVM_READONLY { 14804f311183be3d923da9fbe8702c453688b4c426a9Daniel Dunbar return getSubExpr()->getExprLoc(); 14814f311183be3d923da9fbe8702c453688b4c426a9Daniel Dunbar } 1482f85e193739c953358c865005855253af4f68a497John McCall 1483f85e193739c953358c865005855253af4f68a497John McCall static bool classof(const Stmt *s) { 1484f85e193739c953358c865005855253af4f68a497John McCall return s->getStmtClass() == ObjCIndirectCopyRestoreExprClass; 1485f85e193739c953358c865005855253af4f68a497John McCall } 1486f85e193739c953358c865005855253af4f68a497John McCall static bool classof(const ObjCIndirectCopyRestoreExpr *) { return true; } 1487f85e193739c953358c865005855253af4f68a497John McCall}; 1488f85e193739c953358c865005855253af4f68a497John McCall 1489f85e193739c953358c865005855253af4f68a497John McCall/// \brief An Objective-C "bridged" cast expression, which casts between 1490f85e193739c953358c865005855253af4f68a497John McCall/// Objective-C pointers and C pointers, transferring ownership in the process. 1491f85e193739c953358c865005855253af4f68a497John McCall/// 1492f85e193739c953358c865005855253af4f68a497John McCall/// \code 1493f85e193739c953358c865005855253af4f68a497John McCall/// NSString *str = (__bridge_transfer NSString *)CFCreateString(); 1494f85e193739c953358c865005855253af4f68a497John McCall/// \endcode 1495f85e193739c953358c865005855253af4f68a497John McCallclass ObjCBridgedCastExpr : public ExplicitCastExpr { 1496f85e193739c953358c865005855253af4f68a497John McCall SourceLocation LParenLoc; 1497f85e193739c953358c865005855253af4f68a497John McCall SourceLocation BridgeKeywordLoc; 1498f85e193739c953358c865005855253af4f68a497John McCall unsigned Kind : 2; 1499f85e193739c953358c865005855253af4f68a497John McCall 1500f85e193739c953358c865005855253af4f68a497John McCall friend class ASTStmtReader; 1501f85e193739c953358c865005855253af4f68a497John McCall friend class ASTStmtWriter; 1502f85e193739c953358c865005855253af4f68a497John McCall 1503f85e193739c953358c865005855253af4f68a497John McCallpublic: 1504f85e193739c953358c865005855253af4f68a497John McCall ObjCBridgedCastExpr(SourceLocation LParenLoc, ObjCBridgeCastKind Kind, 15051d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall CastKind CK, SourceLocation BridgeKeywordLoc, 15061d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall TypeSourceInfo *TSInfo, Expr *Operand) 1507f85e193739c953358c865005855253af4f68a497John McCall : ExplicitCastExpr(ObjCBridgedCastExprClass, TSInfo->getType(), VK_RValue, 15081d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall CK, Operand, 0, TSInfo), 1509f85e193739c953358c865005855253af4f68a497John McCall LParenLoc(LParenLoc), BridgeKeywordLoc(BridgeKeywordLoc), Kind(Kind) { } 1510f85e193739c953358c865005855253af4f68a497John McCall 1511f85e193739c953358c865005855253af4f68a497John McCall /// \brief Construct an empty Objective-C bridged cast. 1512f85e193739c953358c865005855253af4f68a497John McCall explicit ObjCBridgedCastExpr(EmptyShell Shell) 1513f85e193739c953358c865005855253af4f68a497John McCall : ExplicitCastExpr(ObjCBridgedCastExprClass, Shell, 0) { } 1514f85e193739c953358c865005855253af4f68a497John McCall 1515f85e193739c953358c865005855253af4f68a497John McCall SourceLocation getLParenLoc() const { return LParenLoc; } 1516f85e193739c953358c865005855253af4f68a497John McCall 1517f85e193739c953358c865005855253af4f68a497John McCall /// \brief Determine which kind of bridge is being performed via this cast. 1518f85e193739c953358c865005855253af4f68a497John McCall ObjCBridgeCastKind getBridgeKind() const { 1519f85e193739c953358c865005855253af4f68a497John McCall return static_cast<ObjCBridgeCastKind>(Kind); 1520f85e193739c953358c865005855253af4f68a497John McCall } 1521f85e193739c953358c865005855253af4f68a497John McCall 1522f85e193739c953358c865005855253af4f68a497John McCall /// \brief Retrieve the kind of bridge being performed as a string. 1523686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef getBridgeKindName() const; 1524f85e193739c953358c865005855253af4f68a497John McCall 1525f85e193739c953358c865005855253af4f68a497John McCall /// \brief The location of the bridge keyword. 1526f85e193739c953358c865005855253af4f68a497John McCall SourceLocation getBridgeKeywordLoc() const { return BridgeKeywordLoc; } 1527f85e193739c953358c865005855253af4f68a497John McCall 1528aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 1529f85e193739c953358c865005855253af4f68a497John McCall return SourceRange(LParenLoc, getSubExpr()->getLocEnd()); 1530f85e193739c953358c865005855253af4f68a497John McCall } 1531f85e193739c953358c865005855253af4f68a497John McCall 1532f85e193739c953358c865005855253af4f68a497John McCall static bool classof(const Stmt *T) { 1533f85e193739c953358c865005855253af4f68a497John McCall return T->getStmtClass() == ObjCBridgedCastExprClass; 1534f85e193739c953358c865005855253af4f68a497John McCall } 1535f85e193739c953358c865005855253af4f68a497John McCall static bool classof(const ObjCBridgedCastExpr *) { return true; } 1536f85e193739c953358c865005855253af4f68a497John McCall 1537f85e193739c953358c865005855253af4f68a497John McCall}; 1538f85e193739c953358c865005855253af4f68a497John McCall 1539f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff} // end namespace clang 1540f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff 1541f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff#endif 1542