ExprObjC.h revision 74c8b794be93e73ffca42b1dcf70f26c92d9ccfd
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 4765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return AtLoc; } 4865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return String->getLocEnd(); } 491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ObjCStringLiteralClass; 52f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff } 531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 54f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff // Iterators 5563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&String, &String+1); } 56f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff}; 571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 58ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// ObjCBoolLiteralExpr - Objective-C Boolean Literal. 59ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// 60ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenekclass ObjCBoolLiteralExpr : public Expr { 61ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool Value; 62ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceLocation Loc; 63ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenekpublic: 64ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) : 65ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr(ObjCBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false, 66ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek false, false), Value(val), Loc(l) {} 67ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 68ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek explicit ObjCBoolLiteralExpr(EmptyShell Empty) 69ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek : Expr(ObjCBoolLiteralExprClass, Empty) { } 70ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 71ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool getValue() const { return Value; } 72ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek void setValue(bool V) { Value = V; } 73ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 7465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 7565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return Loc; } 7665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 77ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceLocation getLocation() const { return Loc; } 78ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek void setLocation(SourceLocation L) { Loc = L; } 79ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 80ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek static bool classof(const Stmt *T) { 81ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return T->getStmtClass() == ObjCBoolLiteralExprClass; 82ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 83ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 84ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Iterators 85ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek child_range children() { return child_range(); } 86ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek}; 87ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 88eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard/// ObjCBoxedExpr - used for generalized expression boxing. 89eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard/// as in: @(strdup("hello world")) or @(random()) 90eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard/// Also used for boxing non-parenthesized numeric literals; 910982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// as in: @42 or \@true (c++/objc++) or \@__yes (c/objc). 92eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beardclass ObjCBoxedExpr : public Expr { 93eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard Stmt *SubExpr; 94eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard ObjCMethodDecl *BoxingMethod; 95eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard SourceRange Range; 96ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenekpublic: 97eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard ObjCBoxedExpr(Expr *E, QualType T, ObjCMethodDecl *method, 98eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard SourceRange R) 99eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard : Expr(ObjCBoxedExprClass, T, VK_RValue, OK_Ordinary, 100eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard E->isTypeDependent(), E->isValueDependent(), 101eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard E->isInstantiationDependent(), E->containsUnexpandedParameterPack()), 102eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard SubExpr(E), BoxingMethod(method), Range(R) {} 103eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard explicit ObjCBoxedExpr(EmptyShell Empty) 104eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard : Expr(ObjCBoxedExprClass, Empty) {} 105ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 106eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard Expr *getSubExpr() { return cast<Expr>(SubExpr); } 107eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } 108ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 109eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard ObjCMethodDecl *getBoxingMethod() const { 110eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard return BoxingMethod; 111ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 112eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard 113eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard SourceLocation getAtLoc() const { return Range.getBegin(); } 114ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 11565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); } 11665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); } 117aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 118eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard return Range; 119ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 120eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard 121ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek static bool classof(const Stmt *T) { 122eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard return T->getStmtClass() == ObjCBoxedExprClass; 123ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 124ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 125ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Iterators 126eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard child_range children() { return child_range(&SubExpr, &SubExpr+1); } 127eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard 128ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek friend class ASTStmtReader; 129ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek}; 130ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 131ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// ObjCArrayLiteral - used for objective-c array containers; as in: 132ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// @[@"Hello", NSApp, [NSNumber numberWithInt:42]]; 133ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenekclass ObjCArrayLiteral : public Expr { 134ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek unsigned NumElements; 135ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceRange Range; 136ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *ArrayWithObjectsMethod; 137ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 138cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko ObjCArrayLiteral(ArrayRef<Expr *> Elements, 139ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek QualType T, ObjCMethodDecl * Method, 140ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceRange SR); 141ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 142ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek explicit ObjCArrayLiteral(EmptyShell Empty, unsigned NumElements) 143ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek : Expr(ObjCArrayLiteralClass, Empty), NumElements(NumElements) {} 144ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 145ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenekpublic: 146ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek static ObjCArrayLiteral *Create(ASTContext &C, 147cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko ArrayRef<Expr *> Elements, 148ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek QualType T, ObjCMethodDecl * Method, 149ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceRange SR); 150ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 151ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek static ObjCArrayLiteral *CreateEmpty(ASTContext &C, unsigned NumElements); 152ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 15365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); } 15465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); } 155aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { return Range; } 156ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 157ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek static bool classof(const Stmt *T) { 158ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return T->getStmtClass() == ObjCArrayLiteralClass; 159ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 160ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 161ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief Retrieve elements of array of literals. 162ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr **getElements() { return reinterpret_cast<Expr **>(this + 1); } 163ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 164ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief Retrieve elements of array of literals. 165ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek const Expr * const *getElements() const { 166ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return reinterpret_cast<const Expr * const*>(this + 1); 167ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 168ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 169ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// getNumElements - Return number of elements of objective-c array literal. 170ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek unsigned getNumElements() const { return NumElements; } 171ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 172ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// getExpr - Return the Expr at the specified index. 173ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr *getElement(unsigned Index) { 174ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek assert((Index < NumElements) && "Arg access out of range!"); 175ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return cast<Expr>(getElements()[Index]); 176ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 177ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek const Expr *getElement(unsigned Index) const { 178ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek assert((Index < NumElements) && "Arg access out of range!"); 179ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return cast<Expr>(getElements()[Index]); 180ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 181ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 182ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *getArrayWithObjectsMethod() const { 183ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return ArrayWithObjectsMethod; 184ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 185ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 186ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Iterators 187ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek child_range children() { 188ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return child_range((Stmt **)getElements(), 189ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek (Stmt **)getElements() + NumElements); 190ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 191ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 192ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek friend class ASTStmtReader; 193ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek}; 194ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 195ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// \brief An element in an Objective-C dictionary literal. 196ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// 197ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenekstruct ObjCDictionaryElement { 198ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief The key for the dictionary element. 199ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr *Key; 200ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 201ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief The value of the dictionary element. 202ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr *Value; 203ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 204ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief The location of the ellipsis, if this is a pack expansion. 205ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceLocation EllipsisLoc; 206ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 207ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief The number of elements this pack expansion will expand to, if 208ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// this is a pack expansion and is known. 209dc84cd5efdd3430efb22546b4ac656aa0540b210David Blaikie Optional<unsigned> NumExpansions; 210ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 211ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief Determines whether this dictionary element is a pack expansion. 212ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool isPackExpansion() const { return EllipsisLoc.isValid(); } 213ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek}; 21474c8b794be93e73ffca42b1dcf70f26c92d9ccfdBenjamin Kramer} // end namespace clang 215ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 21674c8b794be93e73ffca42b1dcf70f26c92d9ccfdBenjamin Kramernamespace llvm { 21774c8b794be93e73ffca42b1dcf70f26c92d9ccfdBenjamin Kramertemplate <> struct isPodLike<clang::ObjCDictionaryElement> : llvm::true_type {}; 21874c8b794be93e73ffca42b1dcf70f26c92d9ccfdBenjamin Kramer} 21974c8b794be93e73ffca42b1dcf70f26c92d9ccfdBenjamin Kramer 22074c8b794be93e73ffca42b1dcf70f26c92d9ccfdBenjamin Kramernamespace clang { 221ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// ObjCDictionaryLiteral - AST node to represent objective-c dictionary 222ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// literals; as in: @{@"name" : NSUserName(), @"date" : [NSDate date] }; 223ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenekclass ObjCDictionaryLiteral : public Expr { 224ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief Key/value pair used to store the key and value of a given element. 225ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// 226ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// Objects of this type are stored directly after the expression. 227ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek struct KeyValuePair { 228ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr *Key; 229ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr *Value; 230ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek }; 231ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 232ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief Data that describes an element that is a pack expansion, used if any 233ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// of the elements in the dictionary literal are pack expansions. 234ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek struct ExpansionData { 235ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief The location of the ellipsis, if this element is a pack 236ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// expansion. 237ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceLocation EllipsisLoc; 238ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 239ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief If non-zero, the number of elements that this pack 240ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// expansion will expand to (+1). 241ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek unsigned NumExpansionsPlusOne; 242ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek }; 243ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 244ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief The number of elements in this dictionary literal. 245ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek unsigned NumElements : 31; 246ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 247ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief Determine whether this dictionary literal has any pack expansions. 248ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// 249ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// If the dictionary literal has pack expansions, then there will 250ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// be an array of pack expansion data following the array of 251ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// key/value pairs, which provide the locations of the ellipses (if 252ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// any) and number of elements in the expansion (if known). If 253ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// there are no pack expansions, we optimize away this storage. 254ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek unsigned HasPackExpansions : 1; 255ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 256ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceRange Range; 257ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *DictWithObjectsMethod; 258ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 259ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCDictionaryLiteral(ArrayRef<ObjCDictionaryElement> VK, 260ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool HasPackExpansions, 261ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek QualType T, ObjCMethodDecl *method, 262ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceRange SR); 263ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 264ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek explicit ObjCDictionaryLiteral(EmptyShell Empty, unsigned NumElements, 265ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool HasPackExpansions) 266ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek : Expr(ObjCDictionaryLiteralClass, Empty), NumElements(NumElements), 267ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek HasPackExpansions(HasPackExpansions) {} 268ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 269ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek KeyValuePair *getKeyValues() { 270ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return reinterpret_cast<KeyValuePair *>(this + 1); 271ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 272ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 273ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek const KeyValuePair *getKeyValues() const { 274ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return reinterpret_cast<const KeyValuePair *>(this + 1); 275ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 276ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 277ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExpansionData *getExpansionData() { 278ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (!HasPackExpansions) 279ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return 0; 280ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 281ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return reinterpret_cast<ExpansionData *>(getKeyValues() + NumElements); 282ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 283ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 284ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek const ExpansionData *getExpansionData() const { 285ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (!HasPackExpansions) 286ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return 0; 287ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 288ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return reinterpret_cast<const ExpansionData *>(getKeyValues()+NumElements); 289ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 290ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 291ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenekpublic: 292ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek static ObjCDictionaryLiteral *Create(ASTContext &C, 293ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ArrayRef<ObjCDictionaryElement> VK, 294ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool HasPackExpansions, 295ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek QualType T, ObjCMethodDecl *method, 296ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceRange SR); 297ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 298ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek static ObjCDictionaryLiteral *CreateEmpty(ASTContext &C, 299ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek unsigned NumElements, 300ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool HasPackExpansions); 301ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 302ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// getNumElements - Return number of elements of objective-c dictionary 303ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// literal. 304ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek unsigned getNumElements() const { return NumElements; } 305ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 306ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCDictionaryElement getKeyValueElement(unsigned Index) const { 307ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek assert((Index < NumElements) && "Arg access out of range!"); 308ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek const KeyValuePair &KV = getKeyValues()[Index]; 30966874fb18afbffb8b2ca05576851a64534be3352David Blaikie ObjCDictionaryElement Result = { KV.Key, KV.Value, SourceLocation(), None }; 310ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (HasPackExpansions) { 311ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek const ExpansionData &Expansion = getExpansionData()[Index]; 312ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Result.EllipsisLoc = Expansion.EllipsisLoc; 313ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Expansion.NumExpansionsPlusOne > 0) 314ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Result.NumExpansions = Expansion.NumExpansionsPlusOne - 1; 315ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 316ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return Result; 317ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 318ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 319ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *getDictWithObjectsMethod() const 320ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek { return DictWithObjectsMethod; } 321ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 32265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); } 32365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); } 324aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { return Range; } 325ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 326ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek static bool classof(const Stmt *T) { 327ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return T->getStmtClass() == ObjCDictionaryLiteralClass; 328ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 329ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 330ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Iterators 331ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek child_range children() { 332ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Note: we're taking advantage of the layout of the KeyValuePair struct 333ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // here. If that struct changes, this code will need to change as well. 334ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return child_range(reinterpret_cast<Stmt **>(this + 1), 335ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek reinterpret_cast<Stmt **>(this + 1) + NumElements * 2); 336ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 337ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 338ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek friend class ASTStmtReader; 339ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek friend class ASTStmtWriter; 340ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek}; 341ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 342ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 3430982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// ObjCEncodeExpr, used for \@encode in Objective-C. \@encode has the same 3440982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// type and behavior as StringLiteral except that the string initializer is 3450982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// obtained from ASTContext with the encoding type as an argument. 346f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroffclass ObjCEncodeExpr : public Expr { 34781d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor TypeSourceInfo *EncodedType; 348f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff SourceLocation AtLoc, RParenLoc; 349f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroffpublic: 35081d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor ObjCEncodeExpr(QualType T, TypeSourceInfo *EncodedType, 351f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff SourceLocation at, SourceLocation rp) 352f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ObjCEncodeExprClass, T, VK_LValue, OK_Ordinary, 353f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall EncodedType->getType()->isDependentType(), 354bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor EncodedType->getType()->isDependentType(), 355561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor EncodedType->getType()->isInstantiationDependentType(), 356bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor EncodedType->getType()->containsUnexpandedParameterPack()), 35781d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor EncodedType(EncodedType), AtLoc(at), RParenLoc(rp) {} 3581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3594dcf151a555ff51e4d643e8e6eeb80f121d11d1bChris Lattner explicit ObjCEncodeExpr(EmptyShell Empty) : Expr(ObjCEncodeExprClass, Empty){} 3604dcf151a555ff51e4d643e8e6eeb80f121d11d1bChris Lattner 3611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 362f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff SourceLocation getAtLoc() const { return AtLoc; } 3634dcf151a555ff51e4d643e8e6eeb80f121d11d1bChris Lattner void setAtLoc(SourceLocation L) { AtLoc = L; } 364f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff SourceLocation getRParenLoc() const { return RParenLoc; } 3654dcf151a555ff51e4d643e8e6eeb80f121d11d1bChris Lattner void setRParenLoc(SourceLocation L) { RParenLoc = L; } 3661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36781d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor QualType getEncodedType() const { return EncodedType->getType(); } 3684dcf151a555ff51e4d643e8e6eeb80f121d11d1bChris Lattner 36981d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor TypeSourceInfo *getEncodedTypeSourceInfo() const { return EncodedType; } 37081d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor void setEncodedTypeSourceInfo(TypeSourceInfo *EncType) { 37181d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor EncodedType = EncType; 37281d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor } 3731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return AtLoc; } 37565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 3761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 377f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff static bool classof(const Stmt *T) { 378f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff return T->getStmtClass() == ObjCEncodeExprClass; 379f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff } 3801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 381f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff // Iterators 38263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 383f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff}; 384f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff 385809d1be9820039b4cf6efa48246a0d70ffa13394James Dennett/// ObjCSelectorExpr used for \@selector in Objective-C. 386f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroffclass ObjCSelectorExpr : public Expr { 387f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff Selector SelName; 388f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff SourceLocation AtLoc, RParenLoc; 389f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroffpublic: 390f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff ObjCSelectorExpr(QualType T, Selector selInfo, 391f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff SourceLocation at, SourceLocation rp) 392bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(ObjCSelectorExprClass, T, VK_RValue, OK_Ordinary, false, false, 393561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 394f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall SelName(selInfo), AtLoc(at), RParenLoc(rp){} 3953a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner explicit ObjCSelectorExpr(EmptyShell Empty) 3963a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner : Expr(ObjCSelectorExprClass, Empty) {} 3973a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner 398f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff Selector getSelector() const { return SelName; } 3993a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner void setSelector(Selector S) { SelName = S; } 4001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 401f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff SourceLocation getAtLoc() const { return AtLoc; } 402f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff SourceLocation getRParenLoc() const { return RParenLoc; } 4033a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner void setAtLoc(SourceLocation L) { AtLoc = L; } 4043a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner void setRParenLoc(SourceLocation L) { RParenLoc = L; } 405f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff 40665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return AtLoc; } 40765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 4081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 409f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff /// getNumArgs - Return the number of actual arguments to this call. 410f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff unsigned getNumArgs() const { return SelName.getNumArgs(); } 4111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 412f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff static bool classof(const Stmt *T) { 413f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff return T->getStmtClass() == ObjCSelectorExprClass; 414f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff } 4151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 416f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff // Iterators 41763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 418f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff}; 4191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4203a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner/// ObjCProtocolExpr used for protocol expression in Objective-C. This is used 4213a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner/// as: @protocol(foo), as in: 4223a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner/// obj conformsToProtocol:@protocol(foo)] 4233a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner/// The return type is "Protocol*". 4241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ObjCProtocolExpr : public Expr { 4251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCProtocolDecl *TheProtocol; 4267d24e289bea2accaaed79c6ca3e5cdd0c204ddc1Argyrios Kyrtzidis SourceLocation AtLoc, ProtoLoc, RParenLoc; 427f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroffpublic: 428f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff ObjCProtocolExpr(QualType T, ObjCProtocolDecl *protocol, 4297d24e289bea2accaaed79c6ca3e5cdd0c204ddc1Argyrios Kyrtzidis SourceLocation at, SourceLocation protoLoc, SourceLocation rp) 430bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(ObjCProtocolExprClass, T, VK_RValue, OK_Ordinary, false, false, 431561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 4327d24e289bea2accaaed79c6ca3e5cdd0c204ddc1Argyrios Kyrtzidis TheProtocol(protocol), AtLoc(at), ProtoLoc(protoLoc), RParenLoc(rp) {} 4333a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner explicit ObjCProtocolExpr(EmptyShell Empty) 4343a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner : Expr(ObjCProtocolExprClass, Empty) {} 4353a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner 436262f9cf85294a1a0713420abc79d40f64aef7240Fariborz Jahanian ObjCProtocolDecl *getProtocol() const { return TheProtocol; } 437262f9cf85294a1a0713420abc79d40f64aef7240Fariborz Jahanian void setProtocol(ObjCProtocolDecl *P) { TheProtocol = P; } 4381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4397d24e289bea2accaaed79c6ca3e5cdd0c204ddc1Argyrios Kyrtzidis SourceLocation getProtocolIdLoc() const { return ProtoLoc; } 440f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff SourceLocation getAtLoc() const { return AtLoc; } 441f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff SourceLocation getRParenLoc() const { return RParenLoc; } 4423a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner void setAtLoc(SourceLocation L) { AtLoc = L; } 4433a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner void setRParenLoc(SourceLocation L) { RParenLoc = L; } 444f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff 44565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return AtLoc; } 44665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 4471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 448f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff static bool classof(const Stmt *T) { 449f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff return T->getStmtClass() == ObjCProtocolExprClass; 450f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff } 4511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 452f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff // Iterators 45363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 4547d24e289bea2accaaed79c6ca3e5cdd0c204ddc1Argyrios Kyrtzidis 4557d24e289bea2accaaed79c6ca3e5cdd0c204ddc1Argyrios Kyrtzidis friend class ASTStmtReader; 4567d24e289bea2accaaed79c6ca3e5cdd0c204ddc1Argyrios Kyrtzidis friend class ASTStmtWriter; 457f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff}; 458f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff 459f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff/// ObjCIvarRefExpr - A reference to an ObjC instance variable. 460f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroffclass ObjCIvarRefExpr : public Expr { 461d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer ObjCIvarDecl *D; 4625549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Base; 463d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer SourceLocation Loc; 464f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff bool IsArrow:1; // True if this is "X->F", false if this is "X.F". 465f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff bool IsFreeIvar:1; // True if ivar reference has no base (self assumed). 4661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 467f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroffpublic: 468f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ObjCIvarRefExpr(ObjCIvarDecl *d, QualType t, 469f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall SourceLocation l, Expr *base, 4701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool arrow = false, bool freeIvar = false) : 471f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(ObjCIvarRefExprClass, t, VK_LValue, OK_Ordinary, 472bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*TypeDependent=*/false, base->isValueDependent(), 473561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isInstantiationDependent(), 474bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->containsUnexpandedParameterPack()), 475d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer D(d), Base(base), Loc(l), IsArrow(arrow), IsFreeIvar(freeIvar) {} 4761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4770389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner explicit ObjCIvarRefExpr(EmptyShell Empty) 4780389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner : Expr(ObjCIvarRefExprClass, Empty) {} 4790389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner 480f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff ObjCIvarDecl *getDecl() { return D; } 481f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff const ObjCIvarDecl *getDecl() const { return D; } 4820389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner void setDecl(ObjCIvarDecl *d) { D = d; } 4831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4845549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getBase() const { return cast<Expr>(Base); } 4855549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getBase() { return cast<Expr>(Base); } 486f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff void setBase(Expr * base) { Base = base; } 4871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 488f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff bool isArrow() const { return IsArrow; } 489f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff bool isFreeIvar() const { return IsFreeIvar; } 4900389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner void setIsArrow(bool A) { IsArrow = A; } 4910389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner void setIsFreeIvar(bool A) { IsFreeIvar = A; } 4921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 493f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff SourceLocation getLocation() const { return Loc; } 4940389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner void setLocation(SourceLocation L) { Loc = L; } 4950389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner 49665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { 49765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return isFreeIvar() ? Loc : getBase()->getLocStart(); 4980389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner } 49965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return Loc; } 5001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 5021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ObjCIvarRefExprClass; 503f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff } 5041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 505f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff // Iterators 50663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Base, &Base+1); } 507f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff}; 508f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff 509e66f4e3e3ae9d7d11b0c302211066fad69228abaDaniel Dunbar/// ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC 5105daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian/// property. 511ae7840776d6cd31b4d7a4a345b61bcbb3744df6cSteve Naroffclass ObjCPropertyRefExpr : public Expr { 512e66f4e3e3ae9d7d11b0c302211066fad69228abaDaniel Dunbarprivate: 51312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall /// If the bool is true, this is an implicit property reference; the 51412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall /// pointer is an (optional) ObjCMethodDecl and Setter may be set. 51512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall /// if the bool is false, this is an explicit property reference; 51612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall /// the pointer is an ObjCPropertyDecl and Setter is always null. 51712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall llvm::PointerIntPair<NamedDecl*, 1, bool> PropertyOrGetter; 518b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis 519b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis /// \brief Indicates whether the property reference will result in a message 520b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis /// to the getter, the setter, or both. 521b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis /// This applies to both implicit and explicit property references. 522b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis enum MethodRefFlags { 523b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis MethodRef_None = 0, 524b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis MethodRef_Getter = 0x1, 525b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis MethodRef_Setter = 0x2 526b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis }; 527b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis 528b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis /// \brief Contains the Setter method pointer and MethodRefFlags bit flags. 529b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis llvm::PointerIntPair<ObjCMethodDecl *, 2, unsigned> SetterAndMethodRefFlags; 53012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 5313c3b7f90a863af43fa63043d396553ecf205351cJohn McCall // FIXME: Maybe we should store the property identifier here, 5323c3b7f90a863af43fa63043d396553ecf205351cJohn McCall // because it's not rederivable from the other data when there's an 5333c3b7f90a863af43fa63043d396553ecf205351cJohn McCall // implicit property with no getter (because the 'foo' -> 'setFoo:' 5343c3b7f90a863af43fa63043d396553ecf205351cJohn McCall // transformation is lossy on the first character). 5353c3b7f90a863af43fa63043d396553ecf205351cJohn McCall 536c77a636688e188af7e7a9a05829e542adb48e880Steve Naroff SourceLocation IdLoc; 5378ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian 5388ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian /// \brief When the receiver in property access is 'super', this is 53912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall /// the location of the 'super' keyword. When it's an interface, 54012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall /// this is that interface. 54112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall SourceLocation ReceiverLoc; 542f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall llvm::PointerUnion3<Stmt*, const Type*, ObjCInterfaceDecl*> Receiver; 5438ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian 544ae7840776d6cd31b4d7a4a345b61bcbb3744df6cSteve Naroffpublic: 5451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCPropertyRefExpr(ObjCPropertyDecl *PD, QualType t, 546f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 547e66f4e3e3ae9d7d11b0c302211066fad69228abaDaniel Dunbar SourceLocation l, Expr *base) 548f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ObjCPropertyRefExprClass, t, VK, OK, 549bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*TypeDependent=*/false, base->isValueDependent(), 550561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isInstantiationDependent(), 551bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->containsUnexpandedParameterPack()), 552b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis PropertyOrGetter(PD, false), SetterAndMethodRefFlags(), 55312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall IdLoc(l), ReceiverLoc(), Receiver(base) { 5543c3b7f90a863af43fa63043d396553ecf205351cJohn McCall assert(t->isSpecificPlaceholderType(BuiltinType::PseudoObject)); 5558ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian } 5568ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian 5578ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian ObjCPropertyRefExpr(ObjCPropertyDecl *PD, QualType t, 558f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 5598ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian SourceLocation l, SourceLocation sl, QualType st) 56012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall : Expr(ObjCPropertyRefExprClass, t, VK, OK, 561561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*TypeDependent=*/false, false, st->isInstantiationDependentType(), 562bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor st->containsUnexpandedParameterPack()), 563b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis PropertyOrGetter(PD, false), SetterAndMethodRefFlags(), 56412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall IdLoc(l), ReceiverLoc(sl), Receiver(st.getTypePtr()) { 5653c3b7f90a863af43fa63043d396553ecf205351cJohn McCall assert(t->isSpecificPlaceholderType(BuiltinType::PseudoObject)); 56612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall } 56712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 56812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ObjCPropertyRefExpr(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter, 56912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall QualType T, ExprValueKind VK, ExprObjectKind OK, 57012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall SourceLocation IdLoc, Expr *Base) 57112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall : Expr(ObjCPropertyRefExprClass, T, VK, OK, false, 572561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Base->isValueDependent(), Base->isInstantiationDependent(), 573bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Base->containsUnexpandedParameterPack()), 574b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis PropertyOrGetter(Getter, true), SetterAndMethodRefFlags(Setter, 0), 57512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall IdLoc(IdLoc), ReceiverLoc(), Receiver(Base) { 5763c3b7f90a863af43fa63043d396553ecf205351cJohn McCall assert(T->isSpecificPlaceholderType(BuiltinType::PseudoObject)); 57712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall } 57812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 57912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ObjCPropertyRefExpr(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter, 58012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall QualType T, ExprValueKind VK, ExprObjectKind OK, 58112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall SourceLocation IdLoc, 58212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall SourceLocation SuperLoc, QualType SuperTy) 583561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(ObjCPropertyRefExprClass, T, VK, OK, false, false, false, false), 584b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis PropertyOrGetter(Getter, true), SetterAndMethodRefFlags(Setter, 0), 58512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall IdLoc(IdLoc), ReceiverLoc(SuperLoc), Receiver(SuperTy.getTypePtr()) { 5863c3b7f90a863af43fa63043d396553ecf205351cJohn McCall assert(T->isSpecificPlaceholderType(BuiltinType::PseudoObject)); 58712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall } 58812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 58912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ObjCPropertyRefExpr(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter, 59012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall QualType T, ExprValueKind VK, ExprObjectKind OK, 59112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall SourceLocation IdLoc, 59212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall SourceLocation ReceiverLoc, ObjCInterfaceDecl *Receiver) 593561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(ObjCPropertyRefExprClass, T, VK, OK, false, false, false, false), 594b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis PropertyOrGetter(Getter, true), SetterAndMethodRefFlags(Setter, 0), 59512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall IdLoc(IdLoc), ReceiverLoc(ReceiverLoc), Receiver(Receiver) { 5963c3b7f90a863af43fa63043d396553ecf205351cJohn McCall assert(T->isSpecificPlaceholderType(BuiltinType::PseudoObject)); 597e66f4e3e3ae9d7d11b0c302211066fad69228abaDaniel Dunbar } 5981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5990389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner explicit ObjCPropertyRefExpr(EmptyShell Empty) 6000389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner : Expr(ObjCPropertyRefExprClass, Empty) {} 6010389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner 60212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall bool isImplicitProperty() const { return PropertyOrGetter.getInt(); } 60312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall bool isExplicitProperty() const { return !PropertyOrGetter.getInt(); } 60412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 60512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ObjCPropertyDecl *getExplicitProperty() const { 60612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall assert(!isImplicitProperty()); 60712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return cast<ObjCPropertyDecl>(PropertyOrGetter.getPointer()); 60812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall } 60912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 61012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ObjCMethodDecl *getImplicitPropertyGetter() const { 61112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall assert(isImplicitProperty()); 61212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return cast_or_null<ObjCMethodDecl>(PropertyOrGetter.getPointer()); 61312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall } 61412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 61512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ObjCMethodDecl *getImplicitPropertySetter() const { 61612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall assert(isImplicitProperty()); 617b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis return SetterAndMethodRefFlags.getPointer(); 61812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall } 61912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 62012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall Selector getGetterSelector() const { 62112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall if (isImplicitProperty()) 62212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return getImplicitPropertyGetter()->getSelector(); 62312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return getExplicitProperty()->getGetterName(); 62412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall } 62512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 62612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall Selector getSetterSelector() const { 62712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall if (isImplicitProperty()) 62812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return getImplicitPropertySetter()->getSelector(); 62912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return getExplicitProperty()->getSetterName(); 63012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall } 6311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 632b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis /// \brief True if the property reference will result in a message to the 633b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis /// getter. 634b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis /// This applies to both implicit and explicit property references. 635b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis bool isMessagingGetter() const { 636b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis return SetterAndMethodRefFlags.getInt() & MethodRef_Getter; 637b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis } 638b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis 639b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis /// \brief True if the property reference will result in a message to the 640b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis /// setter. 641b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis /// This applies to both implicit and explicit property references. 642b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis bool isMessagingSetter() const { 643b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis return SetterAndMethodRefFlags.getInt() & MethodRef_Setter; 644b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis } 645b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis 646b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis void setIsMessagingGetter(bool val = true) { 647b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis setMethodRefFlag(MethodRef_Getter, val); 648b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis } 649b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis 650b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis void setIsMessagingSetter(bool val = true) { 651b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis setMethodRefFlag(MethodRef_Setter, val); 652b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis } 653b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis 6548ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian const Expr *getBase() const { 65512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return cast<Expr>(Receiver.get<Stmt*>()); 6568ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian } 6578ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian Expr *getBase() { 65812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return cast<Expr>(Receiver.get<Stmt*>()); 6598ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian } 6601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 661c77a636688e188af7e7a9a05829e542adb48e880Steve Naroff SourceLocation getLocation() const { return IdLoc; } 6628ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian 66312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall SourceLocation getReceiverLocation() const { return ReceiverLoc; } 66412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall QualType getSuperReceiverType() const { 665f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall return QualType(Receiver.get<const Type*>(), 0); 6668ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian } 66768af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian QualType getGetterResultType() const { 66868af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian QualType ResultType; 66968af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian if (isExplicitProperty()) { 67068af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian const ObjCPropertyDecl *PDecl = getExplicitProperty(); 67168af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian if (const ObjCMethodDecl *Getter = PDecl->getGetterMethodDecl()) 67268af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian ResultType = Getter->getResultType(); 67368af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian else 6743c3b7f90a863af43fa63043d396553ecf205351cJohn McCall ResultType = PDecl->getType(); 67568af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian } else { 67668af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian const ObjCMethodDecl *Getter = getImplicitPropertyGetter(); 6773c3b7f90a863af43fa63043d396553ecf205351cJohn McCall if (Getter) 6783c3b7f90a863af43fa63043d396553ecf205351cJohn McCall ResultType = Getter->getResultType(); // with reference! 67968af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian } 68068af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian return ResultType; 68168af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian } 6823c3b7f90a863af43fa63043d396553ecf205351cJohn McCall 68368af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian QualType getSetterArgType() const { 68468af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian QualType ArgType; 68568af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian if (isImplicitProperty()) { 68668af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian const ObjCMethodDecl *Setter = getImplicitPropertySetter(); 687491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis ObjCMethodDecl::param_const_iterator P = Setter->param_begin(); 68868af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian ArgType = (*P)->getType(); 68968af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian } else { 69068af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian if (ObjCPropertyDecl *PDecl = getExplicitProperty()) 69168af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian if (const ObjCMethodDecl *Setter = PDecl->getSetterMethodDecl()) { 692491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis ObjCMethodDecl::param_const_iterator P = Setter->param_begin(); 69368af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian ArgType = (*P)->getType(); 69468af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian } 69568af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian if (ArgType.isNull()) 69668af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian ArgType = getType(); 69768af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian } 69868af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian return ArgType; 69968af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian } 70068af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian 70112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ObjCInterfaceDecl *getClassReceiver() const { 70212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return Receiver.get<ObjCInterfaceDecl*>(); 70312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall } 70412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall bool isObjectReceiver() const { return Receiver.is<Stmt*>(); } 705f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall bool isSuperReceiver() const { return Receiver.is<const Type*>(); } 70612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall bool isClassReceiver() const { return Receiver.is<ObjCInterfaceDecl*>(); } 707ae7840776d6cd31b4d7a4a345b61bcbb3744df6cSteve Naroff 70865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { 70965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return isObjectReceiver() ? getBase()->getLocStart() :getReceiverLocation(); 7100389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner } 71165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return IdLoc; } 7121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 7141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ObjCPropertyRefExprClass; 715ae7840776d6cd31b4d7a4a345b61bcbb3744df6cSteve Naroff } 7161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 717ae7840776d6cd31b4d7a4a345b61bcbb3744df6cSteve Naroff // Iterators 71863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 71963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall if (Receiver.is<Stmt*>()) { 72063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin = reinterpret_cast<Stmt**>(&Receiver); // hack! 72163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, begin+1); 72263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 72363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(); 72463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 72563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 726f8730d7c313c421d5d7a2b9d97541fc89d5a52d4Ted Kremenekprivate: 727f8730d7c313c421d5d7a2b9d97541fc89d5a52d4Ted Kremenek friend class ASTStmtReader; 728b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis friend class ASTStmtWriter; 729b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis void setExplicitProperty(ObjCPropertyDecl *D, unsigned methRefFlags) { 73012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall PropertyOrGetter.setPointer(D); 73112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall PropertyOrGetter.setInt(false); 732b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis SetterAndMethodRefFlags.setPointer(0); 733b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis SetterAndMethodRefFlags.setInt(methRefFlags); 7348ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian } 735b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis void setImplicitProperty(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter, 736b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis unsigned methRefFlags) { 73712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall PropertyOrGetter.setPointer(Getter); 73812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall PropertyOrGetter.setInt(true); 739b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis SetterAndMethodRefFlags.setPointer(Setter); 740b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis SetterAndMethodRefFlags.setInt(methRefFlags); 7415daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian } 74212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall void setBase(Expr *Base) { Receiver = Base; } 74312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall void setSuperReceiver(QualType T) { Receiver = T.getTypePtr(); } 74412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall void setClassReceiver(ObjCInterfaceDecl *D) { Receiver = D; } 7451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 74612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall void setLocation(SourceLocation L) { IdLoc = L; } 74712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall void setReceiverLocation(SourceLocation Loc) { ReceiverLoc = Loc; } 748b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis 749b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis void setMethodRefFlag(MethodRefFlags flag, bool val) { 750b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis unsigned f = SetterAndMethodRefFlags.getInt(); 751b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis if (val) 752b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis f |= flag; 753b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis else 754b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis f &= ~flag; 755b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis SetterAndMethodRefFlags.setInt(f); 756b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis } 7575daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian}; 758ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 759ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// ObjCSubscriptRefExpr - used for array and dictionary subscripting. 760ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// array[4] = array[3]; dictionary[key] = dictionary[alt_key]; 761ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// 762ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenekclass ObjCSubscriptRefExpr : public Expr { 763ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Location of ']' in an indexing expression. 764ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceLocation RBracket; 765ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // array/dictionary base expression. 766ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // for arrays, this is a numeric expression. For dictionaries, this is 767ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // an objective-c object pointer expression. 768ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek enum { BASE, KEY, END_EXPR }; 769ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Stmt* SubExprs[END_EXPR]; 770ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 771ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *GetAtIndexMethodDecl; 772ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 773ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // For immutable objects this is null. When ObjCSubscriptRefExpr is to read 774ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // an indexed object this is null too. 775ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *SetAtIndexMethodDecl; 776ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 777ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenekpublic: 778ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 779ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCSubscriptRefExpr(Expr *base, Expr *key, QualType T, 780ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprValueKind VK, ExprObjectKind OK, 781ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *getMethod, 782ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *setMethod, SourceLocation RB) 783ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek : Expr(ObjCSubscriptRefExprClass, T, VK, OK, 784ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek base->isTypeDependent() || key->isTypeDependent(), 785ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek base->isValueDependent() || key->isValueDependent(), 786ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek base->isInstantiationDependent() || key->isInstantiationDependent(), 787ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek (base->containsUnexpandedParameterPack() || 788ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek key->containsUnexpandedParameterPack())), 789ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek RBracket(RB), 790ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek GetAtIndexMethodDecl(getMethod), 791ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SetAtIndexMethodDecl(setMethod) 792ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek {SubExprs[BASE] = base; SubExprs[KEY] = key;} 793ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 794ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek explicit ObjCSubscriptRefExpr(EmptyShell Empty) 795ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek : Expr(ObjCSubscriptRefExprClass, Empty) {} 796ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 797ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek static ObjCSubscriptRefExpr *Create(ASTContext &C, 798ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr *base, 799ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr *key, QualType T, 800ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *getMethod, 801ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *setMethod, 802ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceLocation RB); 803ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 804ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceLocation getRBracket() const { return RBracket; } 805ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek void setRBracket(SourceLocation RB) { RBracket = RB; } 80665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 80765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { 80865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return SubExprs[BASE]->getLocStart(); 809ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 81065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RBracket; } 81165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 812ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek static bool classof(const Stmt *T) { 813ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return T->getStmtClass() == ObjCSubscriptRefExprClass; 814ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 815ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 816ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr *getBaseExpr() const { return cast<Expr>(SubExprs[BASE]); } 817ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek void setBaseExpr(Stmt *S) { SubExprs[BASE] = S; } 818ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 819ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr *getKeyExpr() const { return cast<Expr>(SubExprs[KEY]); } 820ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek void setKeyExpr(Stmt *S) { SubExprs[KEY] = S; } 821ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 822ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *getAtIndexMethodDecl() const { 823ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return GetAtIndexMethodDecl; 824ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 825ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 826ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *setAtIndexMethodDecl() const { 827ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return SetAtIndexMethodDecl; 828ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 829ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 830ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool isArraySubscriptRefExpr() const { 831ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return getKeyExpr()->getType()->isIntegralOrEnumerationType(); 832ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 833ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 834ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek child_range children() { 835ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return child_range(SubExprs, SubExprs+END_EXPR); 836ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 837ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenekprivate: 838ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek friend class ASTStmtReader; 839ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek}; 840ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8422725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \brief An expression that sends a message to the given Objective-C 8432725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// object or class. 8442725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 8452725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// The following contains two message send expressions: 8462725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 8472725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \code 8482725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// [[NSString alloc] initWithString:@"Hello"] 8492725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \endcode 8502725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 8512725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// The innermost message send invokes the "alloc" class method on the 8522725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// NSString class, while the outermost message send invokes the 8532725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// "initWithString" instance method on the object returned from 8542725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// NSString's "alloc". In all, an Objective-C message send can take 8552725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// on four different (although related) forms: 8562725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 8572725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 1. Send to an object instance. 8582725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 2. Send to a class. 8592725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 3. Send to the superclass instance of the current class. 8602725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 4. Send to the superclass of the current class. 8612725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 8622725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// All four kinds of message sends are modeled by the ObjCMessageExpr 8632725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// class, and can be distinguished via \c getReceiverKind(). Example: 8642725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 865f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroffclass ObjCMessageExpr : public Expr { 866b994e6c7d57b00e3e0f69d152065e2cf85d1de33Argyrios Kyrtzidis /// \brief Stores either the selector that this message is sending 867b994e6c7d57b00e3e0f69d152065e2cf85d1de33Argyrios Kyrtzidis /// to (when \c HasMethod is zero) or an \c ObjCMethodDecl pointer 868b994e6c7d57b00e3e0f69d152065e2cf85d1de33Argyrios Kyrtzidis /// referring to the method that we type-checked against. 869b994e6c7d57b00e3e0f69d152065e2cf85d1de33Argyrios Kyrtzidis uintptr_t SelectorOrMethod; 870b994e6c7d57b00e3e0f69d152065e2cf85d1de33Argyrios Kyrtzidis 87104fb8ef41ed2bd9533ba9392b4db1a7379752c16Argyrios Kyrtzidis enum { NumArgsBitWidth = 16 }; 87204fb8ef41ed2bd9533ba9392b4db1a7379752c16Argyrios Kyrtzidis 87304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief The number of arguments in the message send, not 87404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// including the receiver. 87504fb8ef41ed2bd9533ba9392b4db1a7379752c16Argyrios Kyrtzidis unsigned NumArgs : NumArgsBitWidth; 87604fb8ef41ed2bd9533ba9392b4db1a7379752c16Argyrios Kyrtzidis 87704fb8ef41ed2bd9533ba9392b4db1a7379752c16Argyrios Kyrtzidis void setNumArgs(unsigned Num) { 87804fb8ef41ed2bd9533ba9392b4db1a7379752c16Argyrios Kyrtzidis assert((Num >> NumArgsBitWidth) == 0 && "Num of args is out of range!"); 87904fb8ef41ed2bd9533ba9392b4db1a7379752c16Argyrios Kyrtzidis NumArgs = Num; 88004fb8ef41ed2bd9533ba9392b4db1a7379752c16Argyrios Kyrtzidis } 88104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 88204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief The kind of message send this is, which is one of the 88304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// ReceiverKind values. 88404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 88504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// We pad this out to a byte to avoid excessive masking and shifting. 88604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor unsigned Kind : 8; 88704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 88804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Whether we have an actual method prototype in \c 88904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// SelectorOrMethod. 89004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 89104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// When non-zero, we have a method declaration; otherwise, we just 89204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// have a selector. 893f85e193739c953358c865005855253af4f68a497John McCall unsigned HasMethod : 1; 894f85e193739c953358c865005855253af4f68a497John McCall 895f85e193739c953358c865005855253af4f68a497John McCall /// \brief Whether this message send is a "delegate init call", 896f85e193739c953358c865005855253af4f68a497John McCall /// i.e. a call of an init method on self from within an init method. 897f85e193739c953358c865005855253af4f68a497John McCall unsigned IsDelegateInitCall : 1; 898746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis 899746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis /// \brief Whether this message send was implicitly generated by 900746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis /// the implementation rather than explicitly written by the user. 901746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis unsigned IsImplicit : 1; 902746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis 903207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis /// \brief Whether the locations of the selector identifiers are in a 904207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis /// "standard" position, a enum SelectorLocationsKind. 905207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned SelLocsKind : 2; 90604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 90704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief When the message expression is a send to 'super', this is 90804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// the location of the 'super' keyword. 90904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation SuperLoc; 91004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 91104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief The source locations of the open and close square 91204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// brackets ('[' and ']', respectively). 91304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, RBracLoc; 91404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 91504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMessageExpr(EmptyShell Empty, unsigned NumArgs) 916b994e6c7d57b00e3e0f69d152065e2cf85d1de33Argyrios Kyrtzidis : Expr(ObjCMessageExprClass, Empty), SelectorOrMethod(0), Kind(0), 917746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis HasMethod(0), IsDelegateInitCall(0), IsImplicit(0), SelLocsKind(0) { 91804fb8ef41ed2bd9533ba9392b4db1a7379752c16Argyrios Kyrtzidis setNumArgs(NumArgs); 91904fb8ef41ed2bd9533ba9392b4db1a7379752c16Argyrios Kyrtzidis } 92004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 921f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ObjCMessageExpr(QualType T, ExprValueKind VK, 92204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 92304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation SuperLoc, 92404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor bool IsInstanceSuper, 92504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor QualType SuperType, 92604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Selector Sel, 927207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 928207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind SelLocsK, 92904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 9308d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 931746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 932746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit); 933f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ObjCMessageExpr(QualType T, ExprValueKind VK, 93404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 93504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor TypeSourceInfo *Receiver, 93604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Selector Sel, 937207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 938207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind SelLocsK, 93904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 9408d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 941746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 942746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit); 943f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ObjCMessageExpr(QualType T, ExprValueKind VK, 94404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 94504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr *Receiver, 94604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Selector Sel, 947207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 948207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind SelLocsK, 94904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 9508d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 951746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 952746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit); 95304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 954207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis void initArgsAndSelLocs(ArrayRef<Expr *> Args, 955207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 956207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind SelLocsK); 957207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 9582725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor /// \brief Retrieve the pointer value of the message receiver. 95904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor void *getReceiverPointer() const { 96004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return *const_cast<void **>( 96104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor reinterpret_cast<const void * const*>(this + 1)); 96204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 9631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 96404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Set the pointer value of the message receiver. 96504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor void setReceiverPointer(void *Value) { 96604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor *reinterpret_cast<void **>(this + 1) = Value; 96704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 9681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 969207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind getSelLocsKind() const { 970207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return (SelectorLocationsKind)SelLocsKind; 971207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis } 972207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis bool hasStandardSelLocs() const { 973207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return getSelLocsKind() != SelLoc_NonStandard; 974207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis } 975207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 976207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis /// \brief Get a pointer to the stored selector identifiers locations array. 977207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis /// No locations will be stored if HasStandardSelLocs is true. 978207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SourceLocation *getStoredSelLocs() { 979207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return reinterpret_cast<SourceLocation*>(getArgs() + getNumArgs()); 980207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis } 981207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis const SourceLocation *getStoredSelLocs() const { 982207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return reinterpret_cast<const SourceLocation*>(getArgs() + getNumArgs()); 983207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis } 984207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 985207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis /// \brief Get the number of stored selector identifiers locations. 986207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis /// No locations will be stored if HasStandardSelLocs is true. 987207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned getNumStoredSelLocs() const { 988207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis if (hasStandardSelLocs()) 989207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return 0; 990207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return getNumSelectorLocs(); 991207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis } 992207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 993207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis static ObjCMessageExpr *alloc(ASTContext &C, 994207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<Expr *> Args, 995207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SourceLocation RBraceLoc, 996207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 997207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis Selector Sel, 998207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind &SelLocsK); 999207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis static ObjCMessageExpr *alloc(ASTContext &C, 1000207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned NumArgs, 1001207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned NumStoredSelLocs); 1002207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 100304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregorpublic: 100404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief The kind of receiver this message is sending to. 100504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor enum ReceiverKind { 100604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief The receiver is a class. 100704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Class = 0, 100804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief The receiver is an object instance. 100904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Instance, 101004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief The receiver is a superclass. 101104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SuperClass, 101204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief The receiver is the instance of the superclass object. 101304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SuperInstance 101404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor }; 1015c2350e553b853ad00914faf23fa731e5fc4a8a5cDouglas Gregor 101604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Create a message send to super. 101704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 101804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Context The ASTContext in which this expression will be created. 101904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 102004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param T The result type of this message. 102104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 1022f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// \param VK The value kind of this message. A message returning 1023f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// a l-value or r-value reference will be an l-value or x-value, 1024f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// respectively. 1025f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// 10260982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \param LBracLoc The location of the open square bracket '['. 102704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 102804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param SuperLoc The location of the "super" keyword. 102904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 103004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param IsInstanceSuper Whether this is an instance "super" 103104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// message (otherwise, it's a class "super" message). 103204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 103304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Sel The selector used to determine which method gets called. 103404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 103504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Method The Objective-C method against which this message 103604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// send was type-checked. May be NULL. 103704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 103804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Args The message send arguments. 103904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 104004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param RBracLoc The location of the closing square bracket ']'. 1041f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall static ObjCMessageExpr *Create(ASTContext &Context, QualType T, 1042f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 104304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 104404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation SuperLoc, 104504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor bool IsInstanceSuper, 104604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor QualType SuperType, 104704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Selector Sel, 1048951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 104904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 10508d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 1051746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 1052746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit); 105304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 105404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Create a class message send. 105504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 105604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Context The ASTContext in which this expression will be created. 105704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 105804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param T The result type of this message. 105904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 1060f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// \param VK The value kind of this message. A message returning 1061f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// a l-value or r-value reference will be an l-value or x-value, 1062f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// respectively. 1063f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// 10640982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \param LBracLoc The location of the open square bracket '['. 106504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 106604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Receiver The type of the receiver, including 106704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// source-location information. 106804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 106904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Sel The selector used to determine which method gets called. 107004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 107104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Method The Objective-C method against which this message 107204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// send was type-checked. May be NULL. 107304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 107404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Args The message send 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 /// 10980982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \param LBracLoc 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 RBracLoc The location of the closing square bracket ']'. 111104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor static ObjCMessageExpr *Create(ASTContext &Context, QualType T, 1112f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 111304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 111404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr *Receiver, 111504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Selector Sel, 1116951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis ArrayRef<SourceLocation> SeLocs, 111704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 11188d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 1119746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 1120746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit); 112104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 112204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Create an empty Objective-C message expression, to be 112304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// filled in by subsequent calls. 112404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 112504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Context The context in which the message send will be created. 112604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 112704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param NumArgs The number of message arguments, not including 112804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// the receiver. 1129207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis static ObjCMessageExpr *CreateEmpty(ASTContext &Context, 1130207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned NumArgs, 1131207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned NumStoredSelLocs); 113204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 1133746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis /// \brief Indicates whether the message send was implicitly 1134746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis /// generated by the implementation. If false, it was written explicitly 1135746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis /// in the source code. 1136746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit() const { return IsImplicit; } 1137746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis 113804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Determine the kind of receiver that this message is being 113904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// sent to. 114004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ReceiverKind getReceiverKind() const { return (ReceiverKind)Kind; } 114104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 1142e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis /// \brief Source range of the receiver. 1143e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis SourceRange getReceiverRange() const; 1144e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis 114504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Determine whether this is an instance message to either a 114604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// computed object or to super. 114704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor bool isInstanceMessage() const { 114804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return getReceiverKind() == Instance || getReceiverKind() == SuperInstance; 114904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 11501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 115104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Determine whether this is an class message to either a 115204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// specified class or to super. 115304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor bool isClassMessage() const { 115404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return getReceiverKind() == Class || getReceiverKind() == SuperClass; 115504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 1156f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff 1157ad0fe03b897f9486191e75c8d90c3ffa9b4fd6a5Ted Kremenek /// \brief Returns the object expression (receiver) for an instance message, 1158ad0fe03b897f9486191e75c8d90c3ffa9b4fd6a5Ted Kremenek /// or null for a message that is not an instance message. 115904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr *getInstanceReceiver() { 116004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (getReceiverKind() == Instance) 116104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return static_cast<Expr *>(getReceiverPointer()); 1162be78424edfbc6095c4acb83c7ae7f53a42f0c870Ted Kremenek 116304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return 0; 116404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 116504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor const Expr *getInstanceReceiver() const { 116604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return const_cast<ObjCMessageExpr*>(this)->getInstanceReceiver(); 116704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 1168be78424edfbc6095c4acb83c7ae7f53a42f0c870Ted Kremenek 116904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Turn this message send into an instance message that 117004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// computes the receiver object with the given expression. 117104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor void setInstanceReceiver(Expr *rec) { 117204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Kind = Instance; 117304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor setReceiverPointer(rec); 117404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 117504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 117604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Returns the type of a class message send, or NULL if the 117704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// message is not a class message. 117804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor QualType getClassReceiver() const { 117904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (TypeSourceInfo *TSInfo = getClassReceiverTypeInfo()) 118004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return TSInfo->getType(); 118104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 118204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return QualType(); 118304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 11841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 118504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Returns a type-source information of a class message 118604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// send, or NULL if the message is not a class message. 118704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor TypeSourceInfo *getClassReceiverTypeInfo() const { 118804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (getReceiverKind() == Class) 118904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return reinterpret_cast<TypeSourceInfo *>(getReceiverPointer()); 119004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return 0; 119104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 11921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 119304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor void setClassReceiver(TypeSourceInfo *TSInfo) { 119404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Kind = Class; 119504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor setReceiverPointer(TSInfo); 119604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 119704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 119804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Retrieve the location of the 'super' keyword for a class 119904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// or instance message to 'super', otherwise an invalid source location. 120004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation getSuperLoc() const { 120104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (getReceiverKind() == SuperInstance || getReceiverKind() == SuperClass) 120204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return SuperLoc; 12031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 120404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return SourceLocation(); 120504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 1206c2350e553b853ad00914faf23fa731e5fc4a8a5cDouglas Gregor 1207e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis /// \brief Retrieve the receiver type to which this message is being directed. 1208e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis /// 1209e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis /// This routine cross-cuts all of the different kinds of message 1210e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis /// sends to determine what the underlying (statically known) type 1211e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis /// of the receiver will be; use \c getReceiverKind() to determine 1212e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis /// whether the message is a class or an instance method, whether it 1213e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis /// is a send to super or not, etc. 1214e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis /// 1215e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis /// \returns The type of the receiver. 1216e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis QualType getReceiverType() const; 1217e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis 121804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Retrieve the Objective-C interface to which this message 121904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// is being directed, if known. 122004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 122104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// This routine cross-cuts all of the different kinds of message 122204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// sends to determine what the underlying (statically known) type 122304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// of the receiver will be; use \c getReceiverKind() to determine 122404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// whether the message is a class or an instance method, whether it 122504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// is a send to super or not, etc. 122604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 122704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \returns The Objective-C interface if known, otherwise NULL. 122804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCInterfaceDecl *getReceiverInterface() const; 122904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 123004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Retrieve the type referred to by 'super'. 123104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 123204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// The returned type will either be an ObjCInterfaceType (for an 123304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// class message to super) or an ObjCObjectPointerType that refers 123404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// to a class (for an instance message to super); 123504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor QualType getSuperType() const { 123604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (getReceiverKind() == SuperInstance || getReceiverKind() == SuperClass) 123704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return QualType::getFromOpaquePtr(getReceiverPointer()); 123804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 123904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return QualType(); 124004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 1241c2350e553b853ad00914faf23fa731e5fc4a8a5cDouglas Gregor 124204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor void setSuper(SourceLocation Loc, QualType T, bool IsInstanceSuper) { 124304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Kind = IsInstanceSuper? SuperInstance : SuperClass; 124404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SuperLoc = Loc; 124504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor setReceiverPointer(T.getAsOpaquePtr()); 124604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 1247c2350e553b853ad00914faf23fa731e5fc4a8a5cDouglas Gregor 124804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Selector getSelector() const; 1249c2350e553b853ad00914faf23fa731e5fc4a8a5cDouglas Gregor 125004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor void setSelector(Selector S) { 125104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor HasMethod = false; 125204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SelectorOrMethod = reinterpret_cast<uintptr_t>(S.getAsOpaquePtr()); 125304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 12541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 125504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor const ObjCMethodDecl *getMethodDecl() const { 125604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (HasMethod) 125704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return reinterpret_cast<const ObjCMethodDecl *>(SelectorOrMethod); 12581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 125904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return 0; 1260f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff } 12611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 126204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *getMethodDecl() { 126304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (HasMethod) 126404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return reinterpret_cast<ObjCMethodDecl *>(SelectorOrMethod); 126504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 126604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return 0; 126704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 126804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 126904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor void setMethodDecl(ObjCMethodDecl *MD) { 127004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor HasMethod = true; 127104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SelectorOrMethod = reinterpret_cast<uintptr_t>(MD); 127204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 127304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 127485f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall ObjCMethodFamily getMethodFamily() const { 127585f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall if (HasMethod) return getMethodDecl()->getMethodFamily(); 127685f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall return getSelector().getMethodFamily(); 127785f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall } 127885f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall 127904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Return the number of actual arguments in this message, 128004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// not counting the receiver. 1281f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff unsigned getNumArgs() const { return NumArgs; } 128204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 128304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Retrieve the arguments to this message, not including the 128404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// receiver. 1285aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Expr **getArgs() { 1286aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return reinterpret_cast<Expr **>(this + 1) + 1; 128704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 1288aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor const Expr * const *getArgs() const { 1289aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return reinterpret_cast<const Expr * const *>(this + 1) + 1; 1290405bad07391494d2eb025f8222c256c66b56e5f8Douglas Gregor } 12911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1292f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff /// getArg - Return the specified argument. 1293f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff Expr *getArg(unsigned Arg) { 1294f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff assert(Arg < NumArgs && "Arg access out of range!"); 129504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return cast<Expr>(getArgs()[Arg]); 1296f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff } 1297f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff const Expr *getArg(unsigned Arg) const { 1298f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff assert(Arg < NumArgs && "Arg access out of range!"); 129904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return cast<Expr>(getArgs()[Arg]); 1300f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff } 1301f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff /// setArg - Set the specified argument. 1302f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff void setArg(unsigned Arg, Expr *ArgExpr) { 1303f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff assert(Arg < NumArgs && "Arg access out of range!"); 130404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor getArgs()[Arg] = ArgExpr; 1305f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff } 13061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1307f85e193739c953358c865005855253af4f68a497John McCall /// isDelegateInitCall - Answers whether this message send has been 1308f85e193739c953358c865005855253af4f68a497John McCall /// tagged as a "delegate init call", i.e. a call to a method in the 1309f85e193739c953358c865005855253af4f68a497John McCall /// -init family on self from within an -init method implementation. 1310f85e193739c953358c865005855253af4f68a497John McCall bool isDelegateInitCall() const { return IsDelegateInitCall; } 1311f85e193739c953358c865005855253af4f68a497John McCall void setDelegateInitCall(bool isDelegate) { IsDelegateInitCall = isDelegate; } 1312f85e193739c953358c865005855253af4f68a497John McCall 131304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation getLeftLoc() const { return LBracLoc; } 131404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation getRightLoc() const { return RBracLoc; } 1315207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 1316746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation getSelectorStartLoc() const { 1317746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis if (isImplicit()) 1318746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis return getLocStart(); 1319746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis return getSelectorLoc(0); 1320746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis } 1321207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SourceLocation getSelectorLoc(unsigned Index) const { 1322207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis assert(Index < getNumSelectorLocs() && "Index out of range!"); 1323207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis if (hasStandardSelLocs()) 1324207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return getStandardSelectorLoc(Index, getSelector(), 1325207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis getSelLocsKind() == SelLoc_StandardWithSpace, 1326207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis llvm::makeArrayRef(const_cast<Expr**>(getArgs()), 1327207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis getNumArgs()), 1328207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis RBracLoc); 1329207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return getStoredSelLocs()[Index]; 1330207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis } 1331207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 1332207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis void getSelectorLocs(SmallVectorImpl<SourceLocation> &SelLocs) const; 1333207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 1334207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned getNumSelectorLocs() const { 1335746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis if (isImplicit()) 1336746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis return 0; 1337207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis Selector Sel = getSelector(); 1338207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis if (Sel.isUnarySelector()) 1339207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return 1; 1340207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return Sel.getNumArgs(); 1341207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis } 13421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1343c4f0bbdb166fbc31ab2cf0f6ff573fde9fa307b3Steve Naroff void setSourceRange(SourceRange R) { 134404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor LBracLoc = R.getBegin(); 134504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor RBracLoc = R.getEnd(); 1346c4f0bbdb166fbc31ab2cf0f6ff573fde9fa307b3Steve Naroff } 134765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return LBracLoc; } 134865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RBracLoc; } 1349f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff 1350f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff static bool classof(const Stmt *T) { 1351f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff return T->getStmtClass() == ObjCMessageExprClass; 1352f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff } 13531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1354f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff // Iterators 135563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children(); 13561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13575549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ExprIterator arg_iterator; 13585549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ConstExprIterator const_arg_iterator; 13591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1360aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor arg_iterator arg_begin() { return reinterpret_cast<Stmt **>(getArgs()); } 1361aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor arg_iterator arg_end() { 1362aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return reinterpret_cast<Stmt **>(getArgs() + NumArgs); 1363aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor } 1364aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor const_arg_iterator arg_begin() const { 1365aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return reinterpret_cast<Stmt const * const*>(getArgs()); 1366aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor } 1367aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor const_arg_iterator arg_end() const { 1368aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return reinterpret_cast<Stmt const * const*>(getArgs() + NumArgs); 1369aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor } 1370f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis 1371f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis friend class ASTStmtReader; 1372f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis friend class ASTStmtWriter; 1373f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff}; 1374f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff 137599b10be143e3148b9499af4c0e9ebaf46757cfe6Steve Naroff/// ObjCIsaExpr - Represent X->isa and X.isa when X is an ObjC 'id' type. 1376fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner/// (similar in spirit to MemberExpr). 1377f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroffclass ObjCIsaExpr : public Expr { 1378f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff /// Base - the expression for the base object pointer. 1379f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff Stmt *Base; 13801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1381f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff /// IsaMemberLoc - This is the location of the 'isa'. 1382f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff SourceLocation IsaMemberLoc; 13831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1384f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff /// IsArrow - True if this is "X->F", false if this is "X.F". 1385f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff bool IsArrow; 1386f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroffpublic: 13871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCIsaExpr(Expr *base, bool isarrow, SourceLocation l, QualType ty) 1388f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ObjCIsaExprClass, ty, VK_LValue, OK_Ordinary, 1389bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*TypeDependent=*/false, base->isValueDependent(), 1390561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isInstantiationDependent(), 1391bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 1392f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff Base(base), IsaMemberLoc(l), IsArrow(isarrow) {} 13931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1394f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff /// \brief Build an empty expression. 1395f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff explicit ObjCIsaExpr(EmptyShell Empty) : Expr(ObjCIsaExprClass, Empty) { } 13961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1397f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff void setBase(Expr *E) { Base = E; } 1398f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff Expr *getBase() const { return cast<Expr>(Base); } 13991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1400f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff bool isArrow() const { return IsArrow; } 1401f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff void setArrow(bool A) { IsArrow = A; } 1402f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff 1403f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff /// getMemberLoc - Return the location of the "member", in X->F, it is the 1404f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff /// location of 'F'. 1405f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff SourceLocation getIsaMemberLoc() const { return IsaMemberLoc; } 1406f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff void setIsaMemberLoc(SourceLocation L) { IsaMemberLoc = L; } 1407f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff 140865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { 140965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return getBase()->getLocStart(); 1410f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff } 141165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return IsaMemberLoc; } 14121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14134f311183be3d923da9fbe8702c453688b4c426a9Daniel Dunbar SourceLocation getExprLoc() const LLVM_READONLY { return IsaMemberLoc; } 1414f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff 14151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 14161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ObjCIsaExprClass; 1417f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff } 14181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1419f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff // Iterators 142063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Base, &Base+1); } 1421f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff}; 1422f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff 1423f85e193739c953358c865005855253af4f68a497John McCall 1424f85e193739c953358c865005855253af4f68a497John McCall/// ObjCIndirectCopyRestoreExpr - Represents the passing of a function 1425f85e193739c953358c865005855253af4f68a497John McCall/// argument by indirect copy-restore in ARC. This is used to support 1426f85e193739c953358c865005855253af4f68a497John McCall/// passing indirect arguments with the wrong lifetime, e.g. when 1427f85e193739c953358c865005855253af4f68a497John McCall/// passing the address of a __strong local variable to an 'out' 1428f85e193739c953358c865005855253af4f68a497John McCall/// parameter. This expression kind is only valid in an "argument" 1429f85e193739c953358c865005855253af4f68a497John McCall/// position to some sort of call expression. 1430f85e193739c953358c865005855253af4f68a497John McCall/// 1431f85e193739c953358c865005855253af4f68a497John McCall/// The parameter must have type 'pointer to T', and the argument must 1432f85e193739c953358c865005855253af4f68a497John McCall/// have type 'pointer to U', where T and U agree except possibly in 1433f85e193739c953358c865005855253af4f68a497John McCall/// qualification. If the argument value is null, then a null pointer 1434f85e193739c953358c865005855253af4f68a497John McCall/// is passed; otherwise it points to an object A, and: 1435f85e193739c953358c865005855253af4f68a497John McCall/// 1. A temporary object B of type T is initialized, either by 1436f85e193739c953358c865005855253af4f68a497John McCall/// zero-initialization (used when initializing an 'out' parameter) 1437f85e193739c953358c865005855253af4f68a497John McCall/// or copy-initialization (used when initializing an 'inout' 1438f85e193739c953358c865005855253af4f68a497John McCall/// parameter). 1439f85e193739c953358c865005855253af4f68a497John McCall/// 2. The address of the temporary is passed to the function. 1440f85e193739c953358c865005855253af4f68a497John McCall/// 3. If the call completes normally, A is move-assigned from B. 1441f85e193739c953358c865005855253af4f68a497John McCall/// 4. Finally, A is destroyed immediately. 1442f85e193739c953358c865005855253af4f68a497John McCall/// 1443f85e193739c953358c865005855253af4f68a497John McCall/// Currently 'T' must be a retainable object lifetime and must be 1444f85e193739c953358c865005855253af4f68a497John McCall/// __autoreleasing; this qualifier is ignored when initializing 1445f85e193739c953358c865005855253af4f68a497John McCall/// the value. 1446f85e193739c953358c865005855253af4f68a497John McCallclass ObjCIndirectCopyRestoreExpr : public Expr { 1447f85e193739c953358c865005855253af4f68a497John McCall Stmt *Operand; 1448f85e193739c953358c865005855253af4f68a497John McCall 1449f85e193739c953358c865005855253af4f68a497John McCall // unsigned ObjCIndirectCopyRestoreBits.ShouldCopy : 1; 1450f85e193739c953358c865005855253af4f68a497John McCall 1451f85e193739c953358c865005855253af4f68a497John McCall friend class ASTReader; 1452f85e193739c953358c865005855253af4f68a497John McCall friend class ASTStmtReader; 1453f85e193739c953358c865005855253af4f68a497John McCall 1454f85e193739c953358c865005855253af4f68a497John McCall void setShouldCopy(bool shouldCopy) { 1455f85e193739c953358c865005855253af4f68a497John McCall ObjCIndirectCopyRestoreExprBits.ShouldCopy = shouldCopy; 1456f85e193739c953358c865005855253af4f68a497John McCall } 1457f85e193739c953358c865005855253af4f68a497John McCall 1458f85e193739c953358c865005855253af4f68a497John McCall explicit ObjCIndirectCopyRestoreExpr(EmptyShell Empty) 1459f85e193739c953358c865005855253af4f68a497John McCall : Expr(ObjCIndirectCopyRestoreExprClass, Empty) { } 1460f85e193739c953358c865005855253af4f68a497John McCall 1461f85e193739c953358c865005855253af4f68a497John McCallpublic: 1462f85e193739c953358c865005855253af4f68a497John McCall ObjCIndirectCopyRestoreExpr(Expr *operand, QualType type, bool shouldCopy) 1463f85e193739c953358c865005855253af4f68a497John McCall : Expr(ObjCIndirectCopyRestoreExprClass, type, VK_LValue, OK_Ordinary, 1464f85e193739c953358c865005855253af4f68a497John McCall operand->isTypeDependent(), operand->isValueDependent(), 1465561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor operand->isInstantiationDependent(), 1466f85e193739c953358c865005855253af4f68a497John McCall operand->containsUnexpandedParameterPack()), 1467f85e193739c953358c865005855253af4f68a497John McCall Operand(operand) { 1468f85e193739c953358c865005855253af4f68a497John McCall setShouldCopy(shouldCopy); 1469f85e193739c953358c865005855253af4f68a497John McCall } 1470f85e193739c953358c865005855253af4f68a497John McCall 1471f85e193739c953358c865005855253af4f68a497John McCall Expr *getSubExpr() { return cast<Expr>(Operand); } 1472f85e193739c953358c865005855253af4f68a497John McCall const Expr *getSubExpr() const { return cast<Expr>(Operand); } 1473f85e193739c953358c865005855253af4f68a497John McCall 1474f85e193739c953358c865005855253af4f68a497John McCall /// shouldCopy - True if we should do the 'copy' part of the 1475f85e193739c953358c865005855253af4f68a497John McCall /// copy-restore. If false, the temporary will be zero-initialized. 1476f85e193739c953358c865005855253af4f68a497John McCall bool shouldCopy() const { return ObjCIndirectCopyRestoreExprBits.ShouldCopy; } 1477f85e193739c953358c865005855253af4f68a497John McCall 1478f85e193739c953358c865005855253af4f68a497John McCall child_range children() { return child_range(&Operand, &Operand+1); } 1479f85e193739c953358c865005855253af4f68a497John McCall 1480f85e193739c953358c865005855253af4f68a497John McCall // Source locations are determined by the subexpression. 148165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { 148265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return Operand->getLocStart(); 14834f311183be3d923da9fbe8702c453688b4c426a9Daniel Dunbar } 148465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return Operand->getLocEnd();} 148565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 14864f311183be3d923da9fbe8702c453688b4c426a9Daniel Dunbar SourceLocation getExprLoc() const LLVM_READONLY { 14874f311183be3d923da9fbe8702c453688b4c426a9Daniel Dunbar return getSubExpr()->getExprLoc(); 14884f311183be3d923da9fbe8702c453688b4c426a9Daniel Dunbar } 1489f85e193739c953358c865005855253af4f68a497John McCall 1490f85e193739c953358c865005855253af4f68a497John McCall static bool classof(const Stmt *s) { 1491f85e193739c953358c865005855253af4f68a497John McCall return s->getStmtClass() == ObjCIndirectCopyRestoreExprClass; 1492f85e193739c953358c865005855253af4f68a497John McCall } 1493f85e193739c953358c865005855253af4f68a497John McCall}; 1494f85e193739c953358c865005855253af4f68a497John McCall 1495f85e193739c953358c865005855253af4f68a497John McCall/// \brief An Objective-C "bridged" cast expression, which casts between 1496f85e193739c953358c865005855253af4f68a497John McCall/// Objective-C pointers and C pointers, transferring ownership in the process. 1497f85e193739c953358c865005855253af4f68a497John McCall/// 1498f85e193739c953358c865005855253af4f68a497John McCall/// \code 1499f85e193739c953358c865005855253af4f68a497John McCall/// NSString *str = (__bridge_transfer NSString *)CFCreateString(); 1500f85e193739c953358c865005855253af4f68a497John McCall/// \endcode 1501f85e193739c953358c865005855253af4f68a497John McCallclass ObjCBridgedCastExpr : public ExplicitCastExpr { 1502f85e193739c953358c865005855253af4f68a497John McCall SourceLocation LParenLoc; 1503f85e193739c953358c865005855253af4f68a497John McCall SourceLocation BridgeKeywordLoc; 1504f85e193739c953358c865005855253af4f68a497John McCall unsigned Kind : 2; 1505f85e193739c953358c865005855253af4f68a497John McCall 1506f85e193739c953358c865005855253af4f68a497John McCall friend class ASTStmtReader; 1507f85e193739c953358c865005855253af4f68a497John McCall friend class ASTStmtWriter; 1508f85e193739c953358c865005855253af4f68a497John McCall 1509f85e193739c953358c865005855253af4f68a497John McCallpublic: 1510f85e193739c953358c865005855253af4f68a497John McCall ObjCBridgedCastExpr(SourceLocation LParenLoc, ObjCBridgeCastKind Kind, 15111d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall CastKind CK, SourceLocation BridgeKeywordLoc, 15121d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall TypeSourceInfo *TSInfo, Expr *Operand) 1513f85e193739c953358c865005855253af4f68a497John McCall : ExplicitCastExpr(ObjCBridgedCastExprClass, TSInfo->getType(), VK_RValue, 15141d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall CK, Operand, 0, TSInfo), 1515f85e193739c953358c865005855253af4f68a497John McCall LParenLoc(LParenLoc), BridgeKeywordLoc(BridgeKeywordLoc), Kind(Kind) { } 1516f85e193739c953358c865005855253af4f68a497John McCall 1517f85e193739c953358c865005855253af4f68a497John McCall /// \brief Construct an empty Objective-C bridged cast. 1518f85e193739c953358c865005855253af4f68a497John McCall explicit ObjCBridgedCastExpr(EmptyShell Shell) 1519f85e193739c953358c865005855253af4f68a497John McCall : ExplicitCastExpr(ObjCBridgedCastExprClass, Shell, 0) { } 1520f85e193739c953358c865005855253af4f68a497John McCall 1521f85e193739c953358c865005855253af4f68a497John McCall SourceLocation getLParenLoc() const { return LParenLoc; } 1522f85e193739c953358c865005855253af4f68a497John McCall 1523f85e193739c953358c865005855253af4f68a497John McCall /// \brief Determine which kind of bridge is being performed via this cast. 1524f85e193739c953358c865005855253af4f68a497John McCall ObjCBridgeCastKind getBridgeKind() const { 1525f85e193739c953358c865005855253af4f68a497John McCall return static_cast<ObjCBridgeCastKind>(Kind); 1526f85e193739c953358c865005855253af4f68a497John McCall } 1527f85e193739c953358c865005855253af4f68a497John McCall 1528f85e193739c953358c865005855253af4f68a497John McCall /// \brief Retrieve the kind of bridge being performed as a string. 1529686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef getBridgeKindName() const; 1530f85e193739c953358c865005855253af4f68a497John McCall 1531f85e193739c953358c865005855253af4f68a497John McCall /// \brief The location of the bridge keyword. 1532f85e193739c953358c865005855253af4f68a497John McCall SourceLocation getBridgeKeywordLoc() const { return BridgeKeywordLoc; } 1533f85e193739c953358c865005855253af4f68a497John McCall 153465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return LParenLoc; } 153565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { 153665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return getSubExpr()->getLocEnd(); 1537f85e193739c953358c865005855253af4f68a497John McCall } 1538f85e193739c953358c865005855253af4f68a497John McCall 1539f85e193739c953358c865005855253af4f68a497John McCall static bool classof(const Stmt *T) { 1540f85e193739c953358c865005855253af4f68a497John McCall return T->getStmtClass() == ObjCBridgedCastExprClass; 1541f85e193739c953358c865005855253af4f68a497John McCall } 1542f85e193739c953358c865005855253af4f68a497John McCall}; 1543f85e193739c953358c865005855253af4f68a497John McCall 1544f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff} // end namespace clang 1545f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff 1546f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff#endif 1547