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: 1469db7a7eb4e23758e041752c9c0c0ec1663d5a0afCraig Topper static ObjCArrayLiteral *Create(const ASTContext &C, 147cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko ArrayRef<Expr *> Elements, 148ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek QualType T, ObjCMethodDecl * Method, 149ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceRange SR); 150ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 1519db7a7eb4e23758e041752c9c0c0ec1663d5a0afCraig Topper static ObjCArrayLiteral *CreateEmpty(const ASTContext &C, 1529db7a7eb4e23758e041752c9c0c0ec1663d5a0afCraig Topper unsigned NumElements); 153ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 15465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); } 15565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); } 156aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { return Range; } 157ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 158ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek static bool classof(const Stmt *T) { 159ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return T->getStmtClass() == ObjCArrayLiteralClass; 160ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 161ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 162ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief Retrieve elements of array of literals. 163ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr **getElements() { return reinterpret_cast<Expr **>(this + 1); } 164ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 165ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief Retrieve elements of array of literals. 166ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek const Expr * const *getElements() const { 167ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return reinterpret_cast<const Expr * const*>(this + 1); 168ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 169ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 170ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// getNumElements - Return number of elements of objective-c array literal. 171ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek unsigned getNumElements() const { return NumElements; } 172ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 173ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// getExpr - Return the Expr at the specified index. 174ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr *getElement(unsigned Index) { 175ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek assert((Index < NumElements) && "Arg access out of range!"); 176ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return cast<Expr>(getElements()[Index]); 177ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 178ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek const Expr *getElement(unsigned Index) const { 179ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek assert((Index < NumElements) && "Arg access out of range!"); 180ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return cast<Expr>(getElements()[Index]); 181ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 182ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 183ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *getArrayWithObjectsMethod() const { 184ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return ArrayWithObjectsMethod; 185ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 186ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 187ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Iterators 188ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek child_range children() { 189ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return child_range((Stmt **)getElements(), 190ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek (Stmt **)getElements() + NumElements); 191ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 192ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 193ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek friend class ASTStmtReader; 194ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek}; 195ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 196ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// \brief An element in an Objective-C dictionary literal. 197ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// 198ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenekstruct ObjCDictionaryElement { 199ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief The key for the dictionary element. 200ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr *Key; 201ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 202ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief The value of the dictionary element. 203ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr *Value; 204ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 205ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief The location of the ellipsis, if this is a pack expansion. 206ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceLocation EllipsisLoc; 207ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 208ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief The number of elements this pack expansion will expand to, if 209ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// this is a pack expansion and is known. 210dc84cd5efdd3430efb22546b4ac656aa0540b210David Blaikie Optional<unsigned> NumExpansions; 211ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 212ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief Determines whether this dictionary element is a pack expansion. 213ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool isPackExpansion() const { return EllipsisLoc.isValid(); } 214ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek}; 21574c8b794be93e73ffca42b1dcf70f26c92d9ccfdBenjamin Kramer} // end namespace clang 216ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 21774c8b794be93e73ffca42b1dcf70f26c92d9ccfdBenjamin Kramernamespace llvm { 218651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinestemplate <> struct isPodLike<clang::ObjCDictionaryElement> : std::true_type {}; 21974c8b794be93e73ffca42b1dcf70f26c92d9ccfdBenjamin Kramer} 22074c8b794be93e73ffca42b1dcf70f26c92d9ccfdBenjamin Kramer 22174c8b794be93e73ffca42b1dcf70f26c92d9ccfdBenjamin Kramernamespace clang { 222ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// ObjCDictionaryLiteral - AST node to represent objective-c dictionary 223ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// literals; as in: @{@"name" : NSUserName(), @"date" : [NSDate date] }; 224ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenekclass ObjCDictionaryLiteral : public Expr { 225ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief Key/value pair used to store the key and value of a given element. 226ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// 227ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// Objects of this type are stored directly after the expression. 228ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek struct KeyValuePair { 229ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr *Key; 230ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr *Value; 231ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek }; 232ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 233ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief Data that describes an element that is a pack expansion, used if any 234ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// of the elements in the dictionary literal are pack expansions. 235ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek struct ExpansionData { 236ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief The location of the ellipsis, if this element is a pack 237ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// expansion. 238ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceLocation EllipsisLoc; 239ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 240ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief If non-zero, the number of elements that this pack 241ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// expansion will expand to (+1). 242ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek unsigned NumExpansionsPlusOne; 243ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek }; 244ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 245ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief The number of elements in this dictionary literal. 246ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek unsigned NumElements : 31; 247ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 248ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief Determine whether this dictionary literal has any pack expansions. 249ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// 250ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// If the dictionary literal has pack expansions, then there will 251ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// be an array of pack expansion data following the array of 252ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// key/value pairs, which provide the locations of the ellipses (if 253ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// any) and number of elements in the expansion (if known). If 254ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// there are no pack expansions, we optimize away this storage. 255ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek unsigned HasPackExpansions : 1; 256ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 257ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceRange Range; 258ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *DictWithObjectsMethod; 259ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 260ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCDictionaryLiteral(ArrayRef<ObjCDictionaryElement> VK, 261ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool HasPackExpansions, 262ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek QualType T, ObjCMethodDecl *method, 263ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceRange SR); 264ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 265ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek explicit ObjCDictionaryLiteral(EmptyShell Empty, unsigned NumElements, 266ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool HasPackExpansions) 267ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek : Expr(ObjCDictionaryLiteralClass, Empty), NumElements(NumElements), 268ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek HasPackExpansions(HasPackExpansions) {} 269ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 270ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek KeyValuePair *getKeyValues() { 271ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return reinterpret_cast<KeyValuePair *>(this + 1); 272ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 273ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 274ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek const KeyValuePair *getKeyValues() const { 275ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return reinterpret_cast<const KeyValuePair *>(this + 1); 276ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 277ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 278ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExpansionData *getExpansionData() { 279ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (!HasPackExpansions) 2806bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return nullptr; 281ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 282ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return reinterpret_cast<ExpansionData *>(getKeyValues() + NumElements); 283ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 284ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 285ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek const ExpansionData *getExpansionData() const { 286ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (!HasPackExpansions) 2876bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return nullptr; 288ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 289ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return reinterpret_cast<const ExpansionData *>(getKeyValues()+NumElements); 290ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 291ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 292ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenekpublic: 2939db7a7eb4e23758e041752c9c0c0ec1663d5a0afCraig Topper static ObjCDictionaryLiteral *Create(const ASTContext &C, 294ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ArrayRef<ObjCDictionaryElement> VK, 295ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool HasPackExpansions, 296ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek QualType T, ObjCMethodDecl *method, 297ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceRange SR); 298ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 2999db7a7eb4e23758e041752c9c0c0ec1663d5a0afCraig Topper static ObjCDictionaryLiteral *CreateEmpty(const ASTContext &C, 300ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek unsigned NumElements, 301ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool HasPackExpansions); 302ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 303ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// getNumElements - Return number of elements of objective-c dictionary 304ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// literal. 305ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek unsigned getNumElements() const { return NumElements; } 306ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 307ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCDictionaryElement getKeyValueElement(unsigned Index) const { 308ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek assert((Index < NumElements) && "Arg access out of range!"); 309ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek const KeyValuePair &KV = getKeyValues()[Index]; 31066874fb18afbffb8b2ca05576851a64534be3352David Blaikie ObjCDictionaryElement Result = { KV.Key, KV.Value, SourceLocation(), None }; 311ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (HasPackExpansions) { 312ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek const ExpansionData &Expansion = getExpansionData()[Index]; 313ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Result.EllipsisLoc = Expansion.EllipsisLoc; 314ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Expansion.NumExpansionsPlusOne > 0) 315ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Result.NumExpansions = Expansion.NumExpansionsPlusOne - 1; 316ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 317ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return Result; 318ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 319ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 320ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *getDictWithObjectsMethod() const 321ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek { return DictWithObjectsMethod; } 322ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 32365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); } 32465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); } 325aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { return Range; } 326ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 327ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek static bool classof(const Stmt *T) { 328ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return T->getStmtClass() == ObjCDictionaryLiteralClass; 329ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 330ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 331ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Iterators 332ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek child_range children() { 333ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Note: we're taking advantage of the layout of the KeyValuePair struct 334ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // here. If that struct changes, this code will need to change as well. 335ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return child_range(reinterpret_cast<Stmt **>(this + 1), 336ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek reinterpret_cast<Stmt **>(this + 1) + NumElements * 2); 337ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 338ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 339ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek friend class ASTStmtReader; 340ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek friend class ASTStmtWriter; 341ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek}; 342ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 343ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 3440982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// ObjCEncodeExpr, used for \@encode in Objective-C. \@encode has the same 3450982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// type and behavior as StringLiteral except that the string initializer is 3460982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// obtained from ASTContext with the encoding type as an argument. 347f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroffclass ObjCEncodeExpr : public Expr { 34881d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor TypeSourceInfo *EncodedType; 349f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff SourceLocation AtLoc, RParenLoc; 350f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroffpublic: 35181d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor ObjCEncodeExpr(QualType T, TypeSourceInfo *EncodedType, 352f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff SourceLocation at, SourceLocation rp) 353f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ObjCEncodeExprClass, T, VK_LValue, OK_Ordinary, 354f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall EncodedType->getType()->isDependentType(), 355bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor EncodedType->getType()->isDependentType(), 356561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor EncodedType->getType()->isInstantiationDependentType(), 357bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor EncodedType->getType()->containsUnexpandedParameterPack()), 35881d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor EncodedType(EncodedType), AtLoc(at), RParenLoc(rp) {} 3591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3604dcf151a555ff51e4d643e8e6eeb80f121d11d1bChris Lattner explicit ObjCEncodeExpr(EmptyShell Empty) : Expr(ObjCEncodeExprClass, Empty){} 3614dcf151a555ff51e4d643e8e6eeb80f121d11d1bChris Lattner 3621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 363f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff SourceLocation getAtLoc() const { return AtLoc; } 3644dcf151a555ff51e4d643e8e6eeb80f121d11d1bChris Lattner void setAtLoc(SourceLocation L) { AtLoc = L; } 365f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff SourceLocation getRParenLoc() const { return RParenLoc; } 3664dcf151a555ff51e4d643e8e6eeb80f121d11d1bChris Lattner void setRParenLoc(SourceLocation L) { RParenLoc = L; } 3671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36881d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor QualType getEncodedType() const { return EncodedType->getType(); } 3694dcf151a555ff51e4d643e8e6eeb80f121d11d1bChris Lattner 37081d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor TypeSourceInfo *getEncodedTypeSourceInfo() const { return EncodedType; } 37181d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor void setEncodedTypeSourceInfo(TypeSourceInfo *EncType) { 37281d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor EncodedType = EncType; 37381d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor } 3741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return AtLoc; } 37665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 3771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 378f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff static bool classof(const Stmt *T) { 379f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff return T->getStmtClass() == ObjCEncodeExprClass; 380f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff } 3811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 382f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff // Iterators 38363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 384f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff}; 385f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff 386809d1be9820039b4cf6efa48246a0d70ffa13394James Dennett/// ObjCSelectorExpr used for \@selector in Objective-C. 387f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroffclass ObjCSelectorExpr : public Expr { 388f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff Selector SelName; 389f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff SourceLocation AtLoc, RParenLoc; 390f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroffpublic: 391f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff ObjCSelectorExpr(QualType T, Selector selInfo, 392f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff SourceLocation at, SourceLocation rp) 393bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(ObjCSelectorExprClass, T, VK_RValue, OK_Ordinary, false, false, 394561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 395f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall SelName(selInfo), AtLoc(at), RParenLoc(rp){} 3963a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner explicit ObjCSelectorExpr(EmptyShell Empty) 3973a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner : Expr(ObjCSelectorExprClass, Empty) {} 3983a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner 399f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff Selector getSelector() const { return SelName; } 4003a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner void setSelector(Selector S) { SelName = S; } 4011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 402f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff SourceLocation getAtLoc() const { return AtLoc; } 403f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff SourceLocation getRParenLoc() const { return RParenLoc; } 4043a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner void setAtLoc(SourceLocation L) { AtLoc = L; } 4053a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner void setRParenLoc(SourceLocation L) { RParenLoc = L; } 406f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff 40765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return AtLoc; } 40865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 4091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 410f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff /// getNumArgs - Return the number of actual arguments to this call. 411f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff unsigned getNumArgs() const { return SelName.getNumArgs(); } 4121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 413f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff static bool classof(const Stmt *T) { 414f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff return T->getStmtClass() == ObjCSelectorExprClass; 415f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff } 4161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 417f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff // Iterators 41863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 419f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff}; 4201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 421d4582b8e6d056f5d991f1b8372e89a6aae58feaeJordan Rose/// ObjCProtocolExpr used for protocol expression in Objective-C. 422d4582b8e6d056f5d991f1b8372e89a6aae58feaeJordan Rose/// 423d4582b8e6d056f5d991f1b8372e89a6aae58feaeJordan Rose/// This is used as: \@protocol(foo), as in: 424d4582b8e6d056f5d991f1b8372e89a6aae58feaeJordan Rose/// \code 425d4582b8e6d056f5d991f1b8372e89a6aae58feaeJordan Rose/// [obj conformsToProtocol:@protocol(foo)] 426d4582b8e6d056f5d991f1b8372e89a6aae58feaeJordan Rose/// \endcode 427d4582b8e6d056f5d991f1b8372e89a6aae58feaeJordan Rose/// 4283a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner/// The return type is "Protocol*". 4291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ObjCProtocolExpr : public Expr { 4301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCProtocolDecl *TheProtocol; 4317d24e289bea2accaaed79c6ca3e5cdd0c204ddc1Argyrios Kyrtzidis SourceLocation AtLoc, ProtoLoc, RParenLoc; 432f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroffpublic: 433f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff ObjCProtocolExpr(QualType T, ObjCProtocolDecl *protocol, 4347d24e289bea2accaaed79c6ca3e5cdd0c204ddc1Argyrios Kyrtzidis SourceLocation at, SourceLocation protoLoc, SourceLocation rp) 435bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(ObjCProtocolExprClass, T, VK_RValue, OK_Ordinary, false, false, 436561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 4377d24e289bea2accaaed79c6ca3e5cdd0c204ddc1Argyrios Kyrtzidis TheProtocol(protocol), AtLoc(at), ProtoLoc(protoLoc), RParenLoc(rp) {} 4383a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner explicit ObjCProtocolExpr(EmptyShell Empty) 4393a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner : Expr(ObjCProtocolExprClass, Empty) {} 4403a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner 441262f9cf85294a1a0713420abc79d40f64aef7240Fariborz Jahanian ObjCProtocolDecl *getProtocol() const { return TheProtocol; } 442262f9cf85294a1a0713420abc79d40f64aef7240Fariborz Jahanian void setProtocol(ObjCProtocolDecl *P) { TheProtocol = P; } 4431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4447d24e289bea2accaaed79c6ca3e5cdd0c204ddc1Argyrios Kyrtzidis SourceLocation getProtocolIdLoc() const { return ProtoLoc; } 445f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff SourceLocation getAtLoc() const { return AtLoc; } 446f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff SourceLocation getRParenLoc() const { return RParenLoc; } 4473a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner void setAtLoc(SourceLocation L) { AtLoc = L; } 4483a57a3765b6192a94ff4e5997ae0489a1471b308Chris Lattner void setRParenLoc(SourceLocation L) { RParenLoc = L; } 449f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff 45065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return AtLoc; } 45165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 4521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 453f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff static bool classof(const Stmt *T) { 454f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff return T->getStmtClass() == ObjCProtocolExprClass; 455f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff } 4561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 457f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff // Iterators 45863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 4597d24e289bea2accaaed79c6ca3e5cdd0c204ddc1Argyrios Kyrtzidis 4607d24e289bea2accaaed79c6ca3e5cdd0c204ddc1Argyrios Kyrtzidis friend class ASTStmtReader; 4617d24e289bea2accaaed79c6ca3e5cdd0c204ddc1Argyrios Kyrtzidis friend class ASTStmtWriter; 462f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff}; 463f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff 464f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff/// ObjCIvarRefExpr - A reference to an ObjC instance variable. 465f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroffclass ObjCIvarRefExpr : public Expr { 466d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer ObjCIvarDecl *D; 4675549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Base; 468d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer SourceLocation Loc; 4690c70181854a95fca0e0d56dfa1203eb2216052eaFariborz Jahanian /// OpLoc - This is the location of '.' or '->' 4700c70181854a95fca0e0d56dfa1203eb2216052eaFariborz Jahanian SourceLocation OpLoc; 4710c70181854a95fca0e0d56dfa1203eb2216052eaFariborz Jahanian 472f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff bool IsArrow:1; // True if this is "X->F", false if this is "X.F". 473f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff bool IsFreeIvar:1; // True if ivar reference has no base (self assumed). 4741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 475f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroffpublic: 476f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ObjCIvarRefExpr(ObjCIvarDecl *d, QualType t, 4770c70181854a95fca0e0d56dfa1203eb2216052eaFariborz Jahanian SourceLocation l, SourceLocation oploc, 4780c70181854a95fca0e0d56dfa1203eb2216052eaFariborz Jahanian Expr *base, 4791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool arrow = false, bool freeIvar = false) : 480993f43f24d7a45a5cd4678a3316b0852261fc5d4John McCall Expr(ObjCIvarRefExprClass, t, VK_LValue, 481993f43f24d7a45a5cd4678a3316b0852261fc5d4John McCall d->isBitField() ? OK_BitField : OK_Ordinary, 482bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*TypeDependent=*/false, base->isValueDependent(), 483561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isInstantiationDependent(), 484bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->containsUnexpandedParameterPack()), 4850c70181854a95fca0e0d56dfa1203eb2216052eaFariborz Jahanian D(d), Base(base), Loc(l), OpLoc(oploc), 4860c70181854a95fca0e0d56dfa1203eb2216052eaFariborz Jahanian IsArrow(arrow), IsFreeIvar(freeIvar) {} 4871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4880389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner explicit ObjCIvarRefExpr(EmptyShell Empty) 4890389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner : Expr(ObjCIvarRefExprClass, Empty) {} 4900389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner 491f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff ObjCIvarDecl *getDecl() { return D; } 492f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff const ObjCIvarDecl *getDecl() const { return D; } 4930389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner void setDecl(ObjCIvarDecl *d) { D = d; } 4941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4955549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getBase() const { return cast<Expr>(Base); } 4965549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getBase() { return cast<Expr>(Base); } 497f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff void setBase(Expr * base) { Base = base; } 4981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 499f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff bool isArrow() const { return IsArrow; } 500f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff bool isFreeIvar() const { return IsFreeIvar; } 5010389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner void setIsArrow(bool A) { IsArrow = A; } 5020389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner void setIsFreeIvar(bool A) { IsFreeIvar = A; } 5031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 504f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff SourceLocation getLocation() const { return Loc; } 5050389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner void setLocation(SourceLocation L) { Loc = L; } 5060389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner 50765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { 50865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return isFreeIvar() ? Loc : getBase()->getLocStart(); 5090389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner } 51065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return Loc; } 5110c70181854a95fca0e0d56dfa1203eb2216052eaFariborz Jahanian 5120c70181854a95fca0e0d56dfa1203eb2216052eaFariborz Jahanian SourceLocation getOpLoc() const { return OpLoc; } 5130c70181854a95fca0e0d56dfa1203eb2216052eaFariborz Jahanian void setOpLoc(SourceLocation L) { OpLoc = L; } 5141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 5161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ObjCIvarRefExprClass; 517f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff } 5181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 519f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff // Iterators 52063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Base, &Base+1); } 521f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff}; 522f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff 523e66f4e3e3ae9d7d11b0c302211066fad69228abaDaniel Dunbar/// ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC 5245daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian/// property. 525ae7840776d6cd31b4d7a4a345b61bcbb3744df6cSteve Naroffclass ObjCPropertyRefExpr : public Expr { 526e66f4e3e3ae9d7d11b0c302211066fad69228abaDaniel Dunbarprivate: 52712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall /// If the bool is true, this is an implicit property reference; the 52812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall /// pointer is an (optional) ObjCMethodDecl and Setter may be set. 52912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall /// if the bool is false, this is an explicit property reference; 53012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall /// the pointer is an ObjCPropertyDecl and Setter is always null. 53112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall llvm::PointerIntPair<NamedDecl*, 1, bool> PropertyOrGetter; 532b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis 533b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis /// \brief Indicates whether the property reference will result in a message 534b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis /// to the getter, the setter, or both. 535b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis /// This applies to both implicit and explicit property references. 536b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis enum MethodRefFlags { 537b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis MethodRef_None = 0, 538b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis MethodRef_Getter = 0x1, 539b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis MethodRef_Setter = 0x2 540b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis }; 541b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis 542b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis /// \brief Contains the Setter method pointer and MethodRefFlags bit flags. 543b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis llvm::PointerIntPair<ObjCMethodDecl *, 2, unsigned> SetterAndMethodRefFlags; 54412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 5453c3b7f90a863af43fa63043d396553ecf205351cJohn McCall // FIXME: Maybe we should store the property identifier here, 5463c3b7f90a863af43fa63043d396553ecf205351cJohn McCall // because it's not rederivable from the other data when there's an 5473c3b7f90a863af43fa63043d396553ecf205351cJohn McCall // implicit property with no getter (because the 'foo' -> 'setFoo:' 5483c3b7f90a863af43fa63043d396553ecf205351cJohn McCall // transformation is lossy on the first character). 5493c3b7f90a863af43fa63043d396553ecf205351cJohn McCall 550c77a636688e188af7e7a9a05829e542adb48e880Steve Naroff SourceLocation IdLoc; 5518ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian 5528ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian /// \brief When the receiver in property access is 'super', this is 55312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall /// the location of the 'super' keyword. When it's an interface, 55412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall /// this is that interface. 55512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall SourceLocation ReceiverLoc; 556f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall llvm::PointerUnion3<Stmt*, const Type*, ObjCInterfaceDecl*> Receiver; 5578ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian 558ae7840776d6cd31b4d7a4a345b61bcbb3744df6cSteve Naroffpublic: 5591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCPropertyRefExpr(ObjCPropertyDecl *PD, QualType t, 560f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 561e66f4e3e3ae9d7d11b0c302211066fad69228abaDaniel Dunbar SourceLocation l, Expr *base) 562f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ObjCPropertyRefExprClass, t, VK, OK, 563bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*TypeDependent=*/false, base->isValueDependent(), 564561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isInstantiationDependent(), 565bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->containsUnexpandedParameterPack()), 566b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis PropertyOrGetter(PD, false), SetterAndMethodRefFlags(), 56712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall IdLoc(l), ReceiverLoc(), Receiver(base) { 5683c3b7f90a863af43fa63043d396553ecf205351cJohn McCall assert(t->isSpecificPlaceholderType(BuiltinType::PseudoObject)); 5698ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian } 5708ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian 5718ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian ObjCPropertyRefExpr(ObjCPropertyDecl *PD, QualType t, 572f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 5738ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian SourceLocation l, SourceLocation sl, QualType st) 57412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall : Expr(ObjCPropertyRefExprClass, t, VK, OK, 575561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*TypeDependent=*/false, false, st->isInstantiationDependentType(), 576bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor st->containsUnexpandedParameterPack()), 577b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis PropertyOrGetter(PD, false), SetterAndMethodRefFlags(), 57812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall IdLoc(l), ReceiverLoc(sl), Receiver(st.getTypePtr()) { 5793c3b7f90a863af43fa63043d396553ecf205351cJohn McCall assert(t->isSpecificPlaceholderType(BuiltinType::PseudoObject)); 58012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall } 58112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 58212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ObjCPropertyRefExpr(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter, 58312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall QualType T, ExprValueKind VK, ExprObjectKind OK, 58412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall SourceLocation IdLoc, Expr *Base) 58512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall : Expr(ObjCPropertyRefExprClass, T, VK, OK, false, 586561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Base->isValueDependent(), Base->isInstantiationDependent(), 587bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Base->containsUnexpandedParameterPack()), 588b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis PropertyOrGetter(Getter, true), SetterAndMethodRefFlags(Setter, 0), 58912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall IdLoc(IdLoc), ReceiverLoc(), Receiver(Base) { 5903c3b7f90a863af43fa63043d396553ecf205351cJohn McCall assert(T->isSpecificPlaceholderType(BuiltinType::PseudoObject)); 59112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall } 59212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 59312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ObjCPropertyRefExpr(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter, 59412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall QualType T, ExprValueKind VK, ExprObjectKind OK, 59512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall SourceLocation IdLoc, 59612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall SourceLocation SuperLoc, QualType SuperTy) 597561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(ObjCPropertyRefExprClass, T, VK, OK, false, false, false, false), 598b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis PropertyOrGetter(Getter, true), SetterAndMethodRefFlags(Setter, 0), 59912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall IdLoc(IdLoc), ReceiverLoc(SuperLoc), Receiver(SuperTy.getTypePtr()) { 6003c3b7f90a863af43fa63043d396553ecf205351cJohn McCall assert(T->isSpecificPlaceholderType(BuiltinType::PseudoObject)); 60112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall } 60212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 60312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ObjCPropertyRefExpr(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter, 60412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall QualType T, ExprValueKind VK, ExprObjectKind OK, 60512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall SourceLocation IdLoc, 60612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall SourceLocation ReceiverLoc, ObjCInterfaceDecl *Receiver) 607561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(ObjCPropertyRefExprClass, T, VK, OK, false, false, false, false), 608b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis PropertyOrGetter(Getter, true), SetterAndMethodRefFlags(Setter, 0), 60912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall IdLoc(IdLoc), ReceiverLoc(ReceiverLoc), Receiver(Receiver) { 6103c3b7f90a863af43fa63043d396553ecf205351cJohn McCall assert(T->isSpecificPlaceholderType(BuiltinType::PseudoObject)); 611e66f4e3e3ae9d7d11b0c302211066fad69228abaDaniel Dunbar } 6121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6130389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner explicit ObjCPropertyRefExpr(EmptyShell Empty) 6140389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner : Expr(ObjCPropertyRefExprClass, Empty) {} 6150389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner 61612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall bool isImplicitProperty() const { return PropertyOrGetter.getInt(); } 61712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall bool isExplicitProperty() const { return !PropertyOrGetter.getInt(); } 61812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 61912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ObjCPropertyDecl *getExplicitProperty() const { 62012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall assert(!isImplicitProperty()); 62112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return cast<ObjCPropertyDecl>(PropertyOrGetter.getPointer()); 62212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall } 62312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 62412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ObjCMethodDecl *getImplicitPropertyGetter() const { 62512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall assert(isImplicitProperty()); 62612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return cast_or_null<ObjCMethodDecl>(PropertyOrGetter.getPointer()); 62712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall } 62812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 62912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ObjCMethodDecl *getImplicitPropertySetter() const { 63012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall assert(isImplicitProperty()); 631b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis return SetterAndMethodRefFlags.getPointer(); 63212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall } 63312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 63412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall Selector getGetterSelector() const { 63512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall if (isImplicitProperty()) 63612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return getImplicitPropertyGetter()->getSelector(); 63712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return getExplicitProperty()->getGetterName(); 63812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall } 63912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 64012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall Selector getSetterSelector() const { 64112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall if (isImplicitProperty()) 64212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return getImplicitPropertySetter()->getSelector(); 64312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return getExplicitProperty()->getSetterName(); 64412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall } 6451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 646b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis /// \brief True if the property reference will result in a message to the 647b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis /// getter. 648b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis /// This applies to both implicit and explicit property references. 649b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis bool isMessagingGetter() const { 650b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis return SetterAndMethodRefFlags.getInt() & MethodRef_Getter; 651b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis } 652b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis 653b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis /// \brief True if the property reference will result in a message to the 654b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis /// setter. 655b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis /// This applies to both implicit and explicit property references. 656b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis bool isMessagingSetter() const { 657b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis return SetterAndMethodRefFlags.getInt() & MethodRef_Setter; 658b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis } 659b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis 660b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis void setIsMessagingGetter(bool val = true) { 661b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis setMethodRefFlag(MethodRef_Getter, val); 662b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis } 663b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis 664b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis void setIsMessagingSetter(bool val = true) { 665b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis setMethodRefFlag(MethodRef_Setter, val); 666b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis } 667b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis 6688ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian const Expr *getBase() const { 66912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return cast<Expr>(Receiver.get<Stmt*>()); 6708ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian } 6718ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian Expr *getBase() { 67212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return cast<Expr>(Receiver.get<Stmt*>()); 6738ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian } 6741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 675c77a636688e188af7e7a9a05829e542adb48e880Steve Naroff SourceLocation getLocation() const { return IdLoc; } 6768ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian 67712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall SourceLocation getReceiverLocation() const { return ReceiverLoc; } 67812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall QualType getSuperReceiverType() const { 679f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall return QualType(Receiver.get<const Type*>(), 0); 6808ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian } 68168af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian QualType getGetterResultType() const { 68268af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian QualType ResultType; 68368af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian if (isExplicitProperty()) { 68468af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian const ObjCPropertyDecl *PDecl = getExplicitProperty(); 68568af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian if (const ObjCMethodDecl *Getter = PDecl->getGetterMethodDecl()) 686651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines ResultType = Getter->getReturnType(); 68768af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian else 6883c3b7f90a863af43fa63043d396553ecf205351cJohn McCall ResultType = PDecl->getType(); 68968af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian } else { 69068af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian const ObjCMethodDecl *Getter = getImplicitPropertyGetter(); 6913c3b7f90a863af43fa63043d396553ecf205351cJohn McCall if (Getter) 692651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines ResultType = Getter->getReturnType(); // with reference! 69368af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian } 69468af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian return ResultType; 69568af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian } 6963c3b7f90a863af43fa63043d396553ecf205351cJohn McCall 69768af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian QualType getSetterArgType() const { 69868af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian QualType ArgType; 69968af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian if (isImplicitProperty()) { 70068af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian const ObjCMethodDecl *Setter = getImplicitPropertySetter(); 701491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis ObjCMethodDecl::param_const_iterator P = Setter->param_begin(); 70268af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian ArgType = (*P)->getType(); 70368af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian } else { 70468af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian if (ObjCPropertyDecl *PDecl = getExplicitProperty()) 70568af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian if (const ObjCMethodDecl *Setter = PDecl->getSetterMethodDecl()) { 706491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis ObjCMethodDecl::param_const_iterator P = Setter->param_begin(); 70768af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian ArgType = (*P)->getType(); 70868af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian } 70968af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian if (ArgType.isNull()) 71068af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian ArgType = getType(); 71168af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian } 71268af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian return ArgType; 71368af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian } 71468af13f3ca39947e3f285f864fe3b76640fddf69Fariborz Jahanian 71512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ObjCInterfaceDecl *getClassReceiver() const { 71612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return Receiver.get<ObjCInterfaceDecl*>(); 71712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall } 71812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall bool isObjectReceiver() const { return Receiver.is<Stmt*>(); } 719f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall bool isSuperReceiver() const { return Receiver.is<const Type*>(); } 72012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall bool isClassReceiver() const { return Receiver.is<ObjCInterfaceDecl*>(); } 721ae7840776d6cd31b4d7a4a345b61bcbb3744df6cSteve Naroff 72265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { 72365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return isObjectReceiver() ? getBase()->getLocStart() :getReceiverLocation(); 7240389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner } 72565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return IdLoc; } 7261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 7281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ObjCPropertyRefExprClass; 729ae7840776d6cd31b4d7a4a345b61bcbb3744df6cSteve Naroff } 7301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 731ae7840776d6cd31b4d7a4a345b61bcbb3744df6cSteve Naroff // Iterators 73263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 73363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall if (Receiver.is<Stmt*>()) { 73463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin = reinterpret_cast<Stmt**>(&Receiver); // hack! 73563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, begin+1); 73663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 73763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(); 73863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 73963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 740f8730d7c313c421d5d7a2b9d97541fc89d5a52d4Ted Kremenekprivate: 741f8730d7c313c421d5d7a2b9d97541fc89d5a52d4Ted Kremenek friend class ASTStmtReader; 742b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis friend class ASTStmtWriter; 743b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis void setExplicitProperty(ObjCPropertyDecl *D, unsigned methRefFlags) { 74412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall PropertyOrGetter.setPointer(D); 74512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall PropertyOrGetter.setInt(false); 7466bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines SetterAndMethodRefFlags.setPointer(nullptr); 747b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis SetterAndMethodRefFlags.setInt(methRefFlags); 7488ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian } 749b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis void setImplicitProperty(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter, 750b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis unsigned methRefFlags) { 75112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall PropertyOrGetter.setPointer(Getter); 75212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall PropertyOrGetter.setInt(true); 753b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis SetterAndMethodRefFlags.setPointer(Setter); 754b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis SetterAndMethodRefFlags.setInt(methRefFlags); 7555daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian } 75612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall void setBase(Expr *Base) { Receiver = Base; } 75712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall void setSuperReceiver(QualType T) { Receiver = T.getTypePtr(); } 75812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall void setClassReceiver(ObjCInterfaceDecl *D) { Receiver = D; } 7591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 76012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall void setLocation(SourceLocation L) { IdLoc = L; } 76112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall void setReceiverLocation(SourceLocation Loc) { ReceiverLoc = Loc; } 762b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis 763b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis void setMethodRefFlag(MethodRefFlags flag, bool val) { 764b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis unsigned f = SetterAndMethodRefFlags.getInt(); 765b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis if (val) 766b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis f |= flag; 767b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis else 768b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis f &= ~flag; 769b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis SetterAndMethodRefFlags.setInt(f); 770b085d898bdfe35097eba45f4072b0f6865f561dcArgyrios Kyrtzidis } 7715daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian}; 772ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 773ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// ObjCSubscriptRefExpr - used for array and dictionary subscripting. 774ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// array[4] = array[3]; dictionary[key] = dictionary[alt_key]; 775ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek/// 776ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenekclass ObjCSubscriptRefExpr : public Expr { 777ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Location of ']' in an indexing expression. 778ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceLocation RBracket; 779ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // array/dictionary base expression. 780ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // for arrays, this is a numeric expression. For dictionaries, this is 781ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // an objective-c object pointer expression. 782ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek enum { BASE, KEY, END_EXPR }; 783ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Stmt* SubExprs[END_EXPR]; 784ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 785ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *GetAtIndexMethodDecl; 786ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 787ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // For immutable objects this is null. When ObjCSubscriptRefExpr is to read 788ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // an indexed object this is null too. 789ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *SetAtIndexMethodDecl; 790ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 791ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenekpublic: 792ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 793ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCSubscriptRefExpr(Expr *base, Expr *key, QualType T, 794ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprValueKind VK, ExprObjectKind OK, 795ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *getMethod, 796ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *setMethod, SourceLocation RB) 797ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek : Expr(ObjCSubscriptRefExprClass, T, VK, OK, 798ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek base->isTypeDependent() || key->isTypeDependent(), 799ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek base->isValueDependent() || key->isValueDependent(), 800ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek base->isInstantiationDependent() || key->isInstantiationDependent(), 801ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek (base->containsUnexpandedParameterPack() || 802ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek key->containsUnexpandedParameterPack())), 803ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek RBracket(RB), 804ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek GetAtIndexMethodDecl(getMethod), 805ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SetAtIndexMethodDecl(setMethod) 806ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek {SubExprs[BASE] = base; SubExprs[KEY] = key;} 807ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 808ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek explicit ObjCSubscriptRefExpr(EmptyShell Empty) 809ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek : Expr(ObjCSubscriptRefExprClass, Empty) {} 810ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8119db7a7eb4e23758e041752c9c0c0ec1663d5a0afCraig Topper static ObjCSubscriptRefExpr *Create(const ASTContext &C, 812ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr *base, 813ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr *key, QualType T, 814ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *getMethod, 815ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *setMethod, 816ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceLocation RB); 817ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 818ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceLocation getRBracket() const { return RBracket; } 819ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek void setRBracket(SourceLocation RB) { RBracket = RB; } 82065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 82165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { 82265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return SubExprs[BASE]->getLocStart(); 823ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 82465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RBracket; } 82565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 826ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek static bool classof(const Stmt *T) { 827ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return T->getStmtClass() == ObjCSubscriptRefExprClass; 828ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 829ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 830ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr *getBaseExpr() const { return cast<Expr>(SubExprs[BASE]); } 831ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek void setBaseExpr(Stmt *S) { SubExprs[BASE] = S; } 832ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 833ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr *getKeyExpr() const { return cast<Expr>(SubExprs[KEY]); } 834ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek void setKeyExpr(Stmt *S) { SubExprs[KEY] = S; } 835ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 836ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *getAtIndexMethodDecl() const { 837ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return GetAtIndexMethodDecl; 838ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 839ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 840ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *setAtIndexMethodDecl() const { 841ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return SetAtIndexMethodDecl; 842ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 843ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 844ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool isArraySubscriptRefExpr() const { 845ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return getKeyExpr()->getType()->isIntegralOrEnumerationType(); 846ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 847ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 848ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek child_range children() { 849ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return child_range(SubExprs, SubExprs+END_EXPR); 850ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 851ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenekprivate: 852ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek friend class ASTStmtReader; 853ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek}; 854ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8562725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \brief An expression that sends a message to the given Objective-C 8572725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// object or class. 8582725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 8592725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// The following contains two message send expressions: 8602725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 8612725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \code 8622725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// [[NSString alloc] initWithString:@"Hello"] 8632725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// \endcode 8642725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 8652725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// The innermost message send invokes the "alloc" class method on the 8662725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// NSString class, while the outermost message send invokes the 8672725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// "initWithString" instance method on the object returned from 8682725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// NSString's "alloc". In all, an Objective-C message send can take 8692725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// on four different (although related) forms: 8702725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 8712725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 1. Send to an object instance. 8722725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 2. Send to a class. 8732725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 3. Send to the superclass instance of the current class. 8742725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 4. Send to the superclass of the current class. 8752725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 8762725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// All four kinds of message sends are modeled by the ObjCMessageExpr 8772725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// class, and can be distinguished via \c getReceiverKind(). Example: 8782725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor/// 879f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroffclass ObjCMessageExpr : public Expr { 880b994e6c7d57b00e3e0f69d152065e2cf85d1de33Argyrios Kyrtzidis /// \brief Stores either the selector that this message is sending 881b994e6c7d57b00e3e0f69d152065e2cf85d1de33Argyrios Kyrtzidis /// to (when \c HasMethod is zero) or an \c ObjCMethodDecl pointer 882b994e6c7d57b00e3e0f69d152065e2cf85d1de33Argyrios Kyrtzidis /// referring to the method that we type-checked against. 883b994e6c7d57b00e3e0f69d152065e2cf85d1de33Argyrios Kyrtzidis uintptr_t SelectorOrMethod; 884b994e6c7d57b00e3e0f69d152065e2cf85d1de33Argyrios Kyrtzidis 88504fb8ef41ed2bd9533ba9392b4db1a7379752c16Argyrios Kyrtzidis enum { NumArgsBitWidth = 16 }; 88604fb8ef41ed2bd9533ba9392b4db1a7379752c16Argyrios Kyrtzidis 88704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief The number of arguments in the message send, not 88804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// including the receiver. 88904fb8ef41ed2bd9533ba9392b4db1a7379752c16Argyrios Kyrtzidis unsigned NumArgs : NumArgsBitWidth; 89004fb8ef41ed2bd9533ba9392b4db1a7379752c16Argyrios Kyrtzidis 89104fb8ef41ed2bd9533ba9392b4db1a7379752c16Argyrios Kyrtzidis void setNumArgs(unsigned Num) { 89204fb8ef41ed2bd9533ba9392b4db1a7379752c16Argyrios Kyrtzidis assert((Num >> NumArgsBitWidth) == 0 && "Num of args is out of range!"); 89304fb8ef41ed2bd9533ba9392b4db1a7379752c16Argyrios Kyrtzidis NumArgs = Num; 89404fb8ef41ed2bd9533ba9392b4db1a7379752c16Argyrios Kyrtzidis } 89504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 89604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief The kind of message send this is, which is one of the 89704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// ReceiverKind values. 89804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 89904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// We pad this out to a byte to avoid excessive masking and shifting. 90004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor unsigned Kind : 8; 90104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 90204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Whether we have an actual method prototype in \c 90304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// SelectorOrMethod. 90404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 90504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// When non-zero, we have a method declaration; otherwise, we just 90604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// have a selector. 907f85e193739c953358c865005855253af4f68a497John McCall unsigned HasMethod : 1; 908f85e193739c953358c865005855253af4f68a497John McCall 909f85e193739c953358c865005855253af4f68a497John McCall /// \brief Whether this message send is a "delegate init call", 910f85e193739c953358c865005855253af4f68a497John McCall /// i.e. a call of an init method on self from within an init method. 911f85e193739c953358c865005855253af4f68a497John McCall unsigned IsDelegateInitCall : 1; 912746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis 913746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis /// \brief Whether this message send was implicitly generated by 914746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis /// the implementation rather than explicitly written by the user. 915746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis unsigned IsImplicit : 1; 916746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis 917207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis /// \brief Whether the locations of the selector identifiers are in a 918207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis /// "standard" position, a enum SelectorLocationsKind. 919207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned SelLocsKind : 2; 92004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 92104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief When the message expression is a send to 'super', this is 92204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// the location of the 'super' keyword. 92304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation SuperLoc; 92404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 92504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief The source locations of the open and close square 92604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// brackets ('[' and ']', respectively). 92704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, RBracLoc; 92804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 92904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMessageExpr(EmptyShell Empty, unsigned NumArgs) 930b994e6c7d57b00e3e0f69d152065e2cf85d1de33Argyrios Kyrtzidis : Expr(ObjCMessageExprClass, Empty), SelectorOrMethod(0), Kind(0), 931746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis HasMethod(0), IsDelegateInitCall(0), IsImplicit(0), SelLocsKind(0) { 93204fb8ef41ed2bd9533ba9392b4db1a7379752c16Argyrios Kyrtzidis setNumArgs(NumArgs); 93304fb8ef41ed2bd9533ba9392b4db1a7379752c16Argyrios Kyrtzidis } 93404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 935f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ObjCMessageExpr(QualType T, ExprValueKind VK, 93604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 93704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation SuperLoc, 93804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor bool IsInstanceSuper, 93904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor QualType SuperType, 94004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Selector Sel, 941207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 942207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind SelLocsK, 94304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 9448d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 945746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 946746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit); 947f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ObjCMessageExpr(QualType T, ExprValueKind VK, 94804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 94904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor TypeSourceInfo *Receiver, 95004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Selector Sel, 951207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 952207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind SelLocsK, 95304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 9548d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 955746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 956746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit); 957f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ObjCMessageExpr(QualType T, ExprValueKind VK, 95804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 95904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr *Receiver, 96004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Selector Sel, 961207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 962207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind SelLocsK, 96304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 9648d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 965746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 966746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit); 96704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 968207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis void initArgsAndSelLocs(ArrayRef<Expr *> Args, 969207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 970207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind SelLocsK); 971207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 9722725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor /// \brief Retrieve the pointer value of the message receiver. 97304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor void *getReceiverPointer() const { 97404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return *const_cast<void **>( 97504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor reinterpret_cast<const void * const*>(this + 1)); 97604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 9771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 97804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Set the pointer value of the message receiver. 97904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor void setReceiverPointer(void *Value) { 98004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor *reinterpret_cast<void **>(this + 1) = Value; 98104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 9821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 983207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind getSelLocsKind() const { 984207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return (SelectorLocationsKind)SelLocsKind; 985207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis } 986207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis bool hasStandardSelLocs() const { 987207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return getSelLocsKind() != SelLoc_NonStandard; 988207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis } 989207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 990207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis /// \brief Get a pointer to the stored selector identifiers locations array. 991207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis /// No locations will be stored if HasStandardSelLocs is true. 992207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SourceLocation *getStoredSelLocs() { 993207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return reinterpret_cast<SourceLocation*>(getArgs() + getNumArgs()); 994207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis } 995207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis const SourceLocation *getStoredSelLocs() const { 996207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return reinterpret_cast<const SourceLocation*>(getArgs() + getNumArgs()); 997207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis } 998207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 999207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis /// \brief Get the number of stored selector identifiers locations. 1000207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis /// No locations will be stored if HasStandardSelLocs is true. 1001207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned getNumStoredSelLocs() const { 1002207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis if (hasStandardSelLocs()) 1003207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return 0; 1004207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return getNumSelectorLocs(); 1005207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis } 1006207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 10079db7a7eb4e23758e041752c9c0c0ec1663d5a0afCraig Topper static ObjCMessageExpr *alloc(const ASTContext &C, 1008207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<Expr *> Args, 1009207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SourceLocation RBraceLoc, 1010207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 1011207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis Selector Sel, 1012207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind &SelLocsK); 10139db7a7eb4e23758e041752c9c0c0ec1663d5a0afCraig Topper static ObjCMessageExpr *alloc(const ASTContext &C, 1014207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned NumArgs, 1015207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned NumStoredSelLocs); 1016207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 101704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregorpublic: 101804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief The kind of receiver this message is sending to. 101904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor enum ReceiverKind { 102004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief The receiver is a class. 102104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Class = 0, 102204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief The receiver is an object instance. 102304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Instance, 102404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief The receiver is a superclass. 102504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SuperClass, 102604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief The receiver is the instance of the superclass object. 102704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SuperInstance 102804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor }; 1029c2350e553b853ad00914faf23fa731e5fc4a8a5cDouglas Gregor 103004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Create a message send to super. 103104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 103204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Context The ASTContext in which this expression will be created. 103304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 103404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param T The result type of this message. 103504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 1036f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// \param VK The value kind of this message. A message returning 1037f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// a l-value or r-value reference will be an l-value or x-value, 1038f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// respectively. 1039f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// 10400982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \param LBracLoc The location of the open square bracket '['. 104104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 104204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param SuperLoc The location of the "super" keyword. 104304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 104404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param IsInstanceSuper Whether this is an instance "super" 104504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// message (otherwise, it's a class "super" message). 104604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 104704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Sel The selector used to determine which method gets called. 104804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 104904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Method The Objective-C method against which this message 105004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// send was type-checked. May be NULL. 105104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 105204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Args The message send arguments. 105304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 105404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param RBracLoc The location of the closing square bracket ']'. 10559db7a7eb4e23758e041752c9c0c0ec1663d5a0afCraig Topper static ObjCMessageExpr *Create(const ASTContext &Context, QualType T, 1056f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 105704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 105804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation SuperLoc, 105904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor bool IsInstanceSuper, 106004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor QualType SuperType, 106104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Selector Sel, 1062951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 106304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 10648d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 1065746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 1066746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit); 106704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 106804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Create a class message send. 106904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 107004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Context The ASTContext in which this expression will be created. 107104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 107204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param T The result type of this message. 107304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 1074f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// \param VK The value kind of this message. A message returning 1075f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// a l-value or r-value reference will be an l-value or x-value, 1076f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// respectively. 1077f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// 10780982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \param LBracLoc The location of the open square bracket '['. 107904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 108004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Receiver The type of the receiver, including 108104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// source-location information. 108204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 108304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Sel The selector used to determine which method gets called. 108404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 108504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Method The Objective-C method against which this message 108604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// send was type-checked. May be NULL. 108704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 108804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Args The message send arguments. 108904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 109004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param RBracLoc The location of the closing square bracket ']'. 10919db7a7eb4e23758e041752c9c0c0ec1663d5a0afCraig Topper static ObjCMessageExpr *Create(const ASTContext &Context, QualType T, 1092f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 109304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 109404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor TypeSourceInfo *Receiver, 109504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Selector Sel, 1096951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 109704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 10988d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 1099746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 1100746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit); 110104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 110204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Create an instance message send. 110304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 110404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Context The ASTContext in which this expression will be created. 110504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 110604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param T The result type of this message. 110704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 1108f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// \param VK The value kind of this message. A message returning 1109f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// a l-value or r-value reference will be an l-value or x-value, 1110f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// respectively. 1111f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// 11120982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \param LBracLoc The location of the open square bracket '['. 111304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 111404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Receiver The expression used to produce the object that 111504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// will receive this message. 111604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 111704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Sel The selector used to determine which method gets called. 111804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 111904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Method The Objective-C method against which this message 112004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// send was type-checked. May be NULL. 112104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 112204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Args The message send arguments. 112304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 112404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param RBracLoc The location of the closing square bracket ']'. 11259db7a7eb4e23758e041752c9c0c0ec1663d5a0afCraig Topper static ObjCMessageExpr *Create(const ASTContext &Context, QualType T, 1126f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 112704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 112804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr *Receiver, 112904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Selector Sel, 1130951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis ArrayRef<SourceLocation> SeLocs, 113104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 11328d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 1133746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation RBracLoc, 1134746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit); 113504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 113604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Create an empty Objective-C message expression, to be 113704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// filled in by subsequent calls. 113804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 113904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param Context The context in which the message send will be created. 114004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 114104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \param NumArgs The number of message arguments, not including 114204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// the receiver. 11439db7a7eb4e23758e041752c9c0c0ec1663d5a0afCraig Topper static ObjCMessageExpr *CreateEmpty(const ASTContext &Context, 1144207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned NumArgs, 1145207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned NumStoredSelLocs); 114604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 1147746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis /// \brief Indicates whether the message send was implicitly 1148746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis /// generated by the implementation. If false, it was written explicitly 1149746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis /// in the source code. 1150746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis bool isImplicit() const { return IsImplicit; } 1151746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis 115204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Determine the kind of receiver that this message is being 115304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// sent to. 115404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ReceiverKind getReceiverKind() const { return (ReceiverKind)Kind; } 115504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 1156e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis /// \brief Source range of the receiver. 1157e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis SourceRange getReceiverRange() const; 1158e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis 115904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Determine whether this is an instance message to either a 116004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// computed object or to super. 116104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor bool isInstanceMessage() const { 116204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return getReceiverKind() == Instance || getReceiverKind() == SuperInstance; 116304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 11641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 116504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Determine whether this is an class message to either a 116604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// specified class or to super. 116704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor bool isClassMessage() const { 116804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return getReceiverKind() == Class || getReceiverKind() == SuperClass; 116904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 1170f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff 1171ad0fe03b897f9486191e75c8d90c3ffa9b4fd6a5Ted Kremenek /// \brief Returns the object expression (receiver) for an instance message, 1172ad0fe03b897f9486191e75c8d90c3ffa9b4fd6a5Ted Kremenek /// or null for a message that is not an instance message. 117304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr *getInstanceReceiver() { 117404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (getReceiverKind() == Instance) 117504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return static_cast<Expr *>(getReceiverPointer()); 1176be78424edfbc6095c4acb83c7ae7f53a42f0c870Ted Kremenek 11776bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return nullptr; 117804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 117904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor const Expr *getInstanceReceiver() const { 118004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return const_cast<ObjCMessageExpr*>(this)->getInstanceReceiver(); 118104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 1182be78424edfbc6095c4acb83c7ae7f53a42f0c870Ted Kremenek 118304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Turn this message send into an instance message that 118404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// computes the receiver object with the given expression. 118504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor void setInstanceReceiver(Expr *rec) { 118604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Kind = Instance; 118704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor setReceiverPointer(rec); 118804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 118904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 119004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Returns the type of a class message send, or NULL if the 119104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// message is not a class message. 119204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor QualType getClassReceiver() const { 119304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (TypeSourceInfo *TSInfo = getClassReceiverTypeInfo()) 119404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return TSInfo->getType(); 119504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 119604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return QualType(); 119704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 11981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 119904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Returns a type-source information of a class message 120004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// send, or NULL if the message is not a class message. 120104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor TypeSourceInfo *getClassReceiverTypeInfo() const { 120204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (getReceiverKind() == Class) 120304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return reinterpret_cast<TypeSourceInfo *>(getReceiverPointer()); 12046bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return nullptr; 120504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 12061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 120704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor void setClassReceiver(TypeSourceInfo *TSInfo) { 120804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Kind = Class; 120904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor setReceiverPointer(TSInfo); 121004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 121104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 121204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Retrieve the location of the 'super' keyword for a class 121304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// or instance message to 'super', otherwise an invalid source location. 121404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation getSuperLoc() const { 121504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (getReceiverKind() == SuperInstance || getReceiverKind() == SuperClass) 121604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return SuperLoc; 12171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 121804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return SourceLocation(); 121904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 1220c2350e553b853ad00914faf23fa731e5fc4a8a5cDouglas Gregor 1221e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis /// \brief Retrieve the receiver type to which this message is being directed. 1222e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis /// 1223e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis /// This routine cross-cuts all of the different kinds of message 1224e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis /// sends to determine what the underlying (statically known) type 1225e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis /// of the receiver will be; use \c getReceiverKind() to determine 1226e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis /// whether the message is a class or an instance method, whether it 1227e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis /// is a send to super or not, etc. 1228e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis /// 1229e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis /// \returns The type of the receiver. 1230e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis QualType getReceiverType() const; 1231e4a990f34904eb572c8d6aa1deef19465214359cArgyrios Kyrtzidis 123204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Retrieve the Objective-C interface to which this message 123304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// is being directed, if known. 123404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 123504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// This routine cross-cuts all of the different kinds of message 123604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// sends to determine what the underlying (statically known) type 123704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// of the receiver will be; use \c getReceiverKind() to determine 123804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// whether the message is a class or an instance method, whether it 123904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// is a send to super or not, etc. 124004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 124104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \returns The Objective-C interface if known, otherwise NULL. 124204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCInterfaceDecl *getReceiverInterface() const; 124304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 124404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Retrieve the type referred to by 'super'. 124504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// 124604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// The returned type will either be an ObjCInterfaceType (for an 124704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// class message to super) or an ObjCObjectPointerType that refers 124804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// to a class (for an instance message to super); 124904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor QualType getSuperType() const { 125004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (getReceiverKind() == SuperInstance || getReceiverKind() == SuperClass) 125104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return QualType::getFromOpaquePtr(getReceiverPointer()); 125204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 125304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return QualType(); 125404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 1255c2350e553b853ad00914faf23fa731e5fc4a8a5cDouglas Gregor 125604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor void setSuper(SourceLocation Loc, QualType T, bool IsInstanceSuper) { 125704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Kind = IsInstanceSuper? SuperInstance : SuperClass; 125804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SuperLoc = Loc; 125904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor setReceiverPointer(T.getAsOpaquePtr()); 126004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 1261c2350e553b853ad00914faf23fa731e5fc4a8a5cDouglas Gregor 126204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Selector getSelector() const; 1263c2350e553b853ad00914faf23fa731e5fc4a8a5cDouglas Gregor 126404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor void setSelector(Selector S) { 126504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor HasMethod = false; 126604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SelectorOrMethod = reinterpret_cast<uintptr_t>(S.getAsOpaquePtr()); 126704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 12681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 126904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor const ObjCMethodDecl *getMethodDecl() const { 127004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (HasMethod) 127104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return reinterpret_cast<const ObjCMethodDecl *>(SelectorOrMethod); 12721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12736bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return nullptr; 1274f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff } 12751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 127604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *getMethodDecl() { 127704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (HasMethod) 127804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return reinterpret_cast<ObjCMethodDecl *>(SelectorOrMethod); 127904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 12806bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return nullptr; 128104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 128204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 128304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor void setMethodDecl(ObjCMethodDecl *MD) { 128404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor HasMethod = true; 128504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SelectorOrMethod = reinterpret_cast<uintptr_t>(MD); 128604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 128704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 128885f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall ObjCMethodFamily getMethodFamily() const { 128985f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall if (HasMethod) return getMethodDecl()->getMethodFamily(); 129085f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall return getSelector().getMethodFamily(); 129185f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall } 129285f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall 129304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Return the number of actual arguments in this message, 129404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// not counting the receiver. 1295f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff unsigned getNumArgs() const { return NumArgs; } 129604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 129704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// \brief Retrieve the arguments to this message, not including the 129804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor /// receiver. 1299aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Expr **getArgs() { 1300aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return reinterpret_cast<Expr **>(this + 1) + 1; 130104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 1302aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor const Expr * const *getArgs() const { 1303aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return reinterpret_cast<const Expr * const *>(this + 1) + 1; 1304405bad07391494d2eb025f8222c256c66b56e5f8Douglas Gregor } 13051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1306f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff /// getArg - Return the specified argument. 1307f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff Expr *getArg(unsigned Arg) { 1308f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff assert(Arg < NumArgs && "Arg access out of range!"); 130904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return cast<Expr>(getArgs()[Arg]); 1310f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff } 1311f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff const Expr *getArg(unsigned Arg) const { 1312f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff assert(Arg < NumArgs && "Arg access out of range!"); 131304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return cast<Expr>(getArgs()[Arg]); 1314f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff } 1315f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff /// setArg - Set the specified argument. 1316f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff void setArg(unsigned Arg, Expr *ArgExpr) { 1317f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff assert(Arg < NumArgs && "Arg access out of range!"); 131804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor getArgs()[Arg] = ArgExpr; 1319f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff } 13201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1321f85e193739c953358c865005855253af4f68a497John McCall /// isDelegateInitCall - Answers whether this message send has been 1322f85e193739c953358c865005855253af4f68a497John McCall /// tagged as a "delegate init call", i.e. a call to a method in the 1323f85e193739c953358c865005855253af4f68a497John McCall /// -init family on self from within an -init method implementation. 1324f85e193739c953358c865005855253af4f68a497John McCall bool isDelegateInitCall() const { return IsDelegateInitCall; } 1325f85e193739c953358c865005855253af4f68a497John McCall void setDelegateInitCall(bool isDelegate) { IsDelegateInitCall = isDelegate; } 1326f85e193739c953358c865005855253af4f68a497John McCall 132704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation getLeftLoc() const { return LBracLoc; } 132804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation getRightLoc() const { return RBracLoc; } 1329207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 1330746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis SourceLocation getSelectorStartLoc() const { 1331746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis if (isImplicit()) 1332746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis return getLocStart(); 1333746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis return getSelectorLoc(0); 1334746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis } 1335207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SourceLocation getSelectorLoc(unsigned Index) const { 1336207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis assert(Index < getNumSelectorLocs() && "Index out of range!"); 1337207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis if (hasStandardSelLocs()) 1338207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return getStandardSelectorLoc(Index, getSelector(), 1339207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis getSelLocsKind() == SelLoc_StandardWithSpace, 1340207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis llvm::makeArrayRef(const_cast<Expr**>(getArgs()), 1341207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis getNumArgs()), 1342207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis RBracLoc); 1343207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return getStoredSelLocs()[Index]; 1344207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis } 1345207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 1346207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis void getSelectorLocs(SmallVectorImpl<SourceLocation> &SelLocs) const; 1347207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 1348207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned getNumSelectorLocs() const { 1349746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis if (isImplicit()) 1350746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis return 0; 1351207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis Selector Sel = getSelector(); 1352207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis if (Sel.isUnarySelector()) 1353207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return 1; 1354207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return Sel.getNumArgs(); 1355207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis } 13561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1357c4f0bbdb166fbc31ab2cf0f6ff573fde9fa307b3Steve Naroff void setSourceRange(SourceRange R) { 135804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor LBracLoc = R.getBegin(); 135904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor RBracLoc = R.getEnd(); 1360c4f0bbdb166fbc31ab2cf0f6ff573fde9fa307b3Steve Naroff } 136165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return LBracLoc; } 136265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RBracLoc; } 1363f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff 1364f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff static bool classof(const Stmt *T) { 1365f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff return T->getStmtClass() == ObjCMessageExprClass; 1366f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff } 13671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1368f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff // Iterators 136963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children(); 13701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13715549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ExprIterator arg_iterator; 13725549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ConstExprIterator const_arg_iterator; 13731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1374aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor arg_iterator arg_begin() { return reinterpret_cast<Stmt **>(getArgs()); } 1375aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor arg_iterator arg_end() { 1376aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return reinterpret_cast<Stmt **>(getArgs() + NumArgs); 1377aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor } 1378aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor const_arg_iterator arg_begin() const { 1379aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return reinterpret_cast<Stmt const * const*>(getArgs()); 1380aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor } 1381aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor const_arg_iterator arg_end() const { 1382aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return reinterpret_cast<Stmt const * const*>(getArgs() + NumArgs); 1383aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor } 1384f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis 1385f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis friend class ASTStmtReader; 1386f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis friend class ASTStmtWriter; 1387f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff}; 1388f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff 138999b10be143e3148b9499af4c0e9ebaf46757cfe6Steve Naroff/// ObjCIsaExpr - Represent X->isa and X.isa when X is an ObjC 'id' type. 1390fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner/// (similar in spirit to MemberExpr). 1391f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroffclass ObjCIsaExpr : public Expr { 1392f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff /// Base - the expression for the base object pointer. 1393f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff Stmt *Base; 13941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1395f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff /// IsaMemberLoc - This is the location of the 'isa'. 1396f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff SourceLocation IsaMemberLoc; 1397ec8deba768e7ba93ad9974763dc3902896924a3cFariborz Jahanian 1398ec8deba768e7ba93ad9974763dc3902896924a3cFariborz Jahanian /// OpLoc - This is the location of '.' or '->' 1399ec8deba768e7ba93ad9974763dc3902896924a3cFariborz Jahanian SourceLocation OpLoc; 14001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1401f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff /// IsArrow - True if this is "X->F", false if this is "X.F". 1402f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff bool IsArrow; 1403f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroffpublic: 1404ec8deba768e7ba93ad9974763dc3902896924a3cFariborz Jahanian ObjCIsaExpr(Expr *base, bool isarrow, SourceLocation l, SourceLocation oploc, 1405ec8deba768e7ba93ad9974763dc3902896924a3cFariborz Jahanian QualType ty) 1406f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ObjCIsaExprClass, ty, VK_LValue, OK_Ordinary, 1407bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*TypeDependent=*/false, base->isValueDependent(), 1408561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isInstantiationDependent(), 1409bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 1410ec8deba768e7ba93ad9974763dc3902896924a3cFariborz Jahanian Base(base), IsaMemberLoc(l), OpLoc(oploc), IsArrow(isarrow) {} 14111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1412f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff /// \brief Build an empty expression. 1413f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff explicit ObjCIsaExpr(EmptyShell Empty) : Expr(ObjCIsaExprClass, Empty) { } 14141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1415f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff void setBase(Expr *E) { Base = E; } 1416f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff Expr *getBase() const { return cast<Expr>(Base); } 14171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1418f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff bool isArrow() const { return IsArrow; } 1419f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff void setArrow(bool A) { IsArrow = A; } 1420f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff 1421f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff /// getMemberLoc - Return the location of the "member", in X->F, it is the 1422f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff /// location of 'F'. 1423f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff SourceLocation getIsaMemberLoc() const { return IsaMemberLoc; } 1424f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff void setIsaMemberLoc(SourceLocation L) { IsaMemberLoc = L; } 1425ec8deba768e7ba93ad9974763dc3902896924a3cFariborz Jahanian 1426ec8deba768e7ba93ad9974763dc3902896924a3cFariborz Jahanian SourceLocation getOpLoc() const { return OpLoc; } 1427ec8deba768e7ba93ad9974763dc3902896924a3cFariborz Jahanian void setOpLoc(SourceLocation L) { OpLoc = L; } 1428f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff 142965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { 143065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return getBase()->getLocStart(); 1431f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff } 1432ec8deba768e7ba93ad9974763dc3902896924a3cFariborz Jahanian 1433ec8deba768e7ba93ad9974763dc3902896924a3cFariborz Jahanian SourceLocation getBaseLocEnd() const LLVM_READONLY { 1434ec8deba768e7ba93ad9974763dc3902896924a3cFariborz Jahanian return getBase()->getLocEnd(); 1435ec8deba768e7ba93ad9974763dc3902896924a3cFariborz Jahanian } 1436ec8deba768e7ba93ad9974763dc3902896924a3cFariborz Jahanian 143765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return IsaMemberLoc; } 14381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14394f311183be3d923da9fbe8702c453688b4c426a9Daniel Dunbar SourceLocation getExprLoc() const LLVM_READONLY { return IsaMemberLoc; } 1440f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff 14411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 14421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ObjCIsaExprClass; 1443f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff } 14441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1445f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff // Iterators 144663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Base, &Base+1); } 1447f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff}; 1448f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff 1449f85e193739c953358c865005855253af4f68a497John McCall 1450f85e193739c953358c865005855253af4f68a497John McCall/// ObjCIndirectCopyRestoreExpr - Represents the passing of a function 1451f85e193739c953358c865005855253af4f68a497John McCall/// argument by indirect copy-restore in ARC. This is used to support 1452f85e193739c953358c865005855253af4f68a497John McCall/// passing indirect arguments with the wrong lifetime, e.g. when 1453f85e193739c953358c865005855253af4f68a497John McCall/// passing the address of a __strong local variable to an 'out' 1454f85e193739c953358c865005855253af4f68a497John McCall/// parameter. This expression kind is only valid in an "argument" 1455f85e193739c953358c865005855253af4f68a497John McCall/// position to some sort of call expression. 1456f85e193739c953358c865005855253af4f68a497John McCall/// 1457f85e193739c953358c865005855253af4f68a497John McCall/// The parameter must have type 'pointer to T', and the argument must 1458f85e193739c953358c865005855253af4f68a497John McCall/// have type 'pointer to U', where T and U agree except possibly in 1459f85e193739c953358c865005855253af4f68a497John McCall/// qualification. If the argument value is null, then a null pointer 1460f85e193739c953358c865005855253af4f68a497John McCall/// is passed; otherwise it points to an object A, and: 1461f85e193739c953358c865005855253af4f68a497John McCall/// 1. A temporary object B of type T is initialized, either by 1462f85e193739c953358c865005855253af4f68a497John McCall/// zero-initialization (used when initializing an 'out' parameter) 1463f85e193739c953358c865005855253af4f68a497John McCall/// or copy-initialization (used when initializing an 'inout' 1464f85e193739c953358c865005855253af4f68a497John McCall/// parameter). 1465f85e193739c953358c865005855253af4f68a497John McCall/// 2. The address of the temporary is passed to the function. 1466f85e193739c953358c865005855253af4f68a497John McCall/// 3. If the call completes normally, A is move-assigned from B. 1467f85e193739c953358c865005855253af4f68a497John McCall/// 4. Finally, A is destroyed immediately. 1468f85e193739c953358c865005855253af4f68a497John McCall/// 1469f85e193739c953358c865005855253af4f68a497John McCall/// Currently 'T' must be a retainable object lifetime and must be 1470f85e193739c953358c865005855253af4f68a497John McCall/// __autoreleasing; this qualifier is ignored when initializing 1471f85e193739c953358c865005855253af4f68a497John McCall/// the value. 1472f85e193739c953358c865005855253af4f68a497John McCallclass ObjCIndirectCopyRestoreExpr : public Expr { 1473f85e193739c953358c865005855253af4f68a497John McCall Stmt *Operand; 1474f85e193739c953358c865005855253af4f68a497John McCall 1475f85e193739c953358c865005855253af4f68a497John McCall // unsigned ObjCIndirectCopyRestoreBits.ShouldCopy : 1; 1476f85e193739c953358c865005855253af4f68a497John McCall 1477f85e193739c953358c865005855253af4f68a497John McCall friend class ASTReader; 1478f85e193739c953358c865005855253af4f68a497John McCall friend class ASTStmtReader; 1479f85e193739c953358c865005855253af4f68a497John McCall 1480f85e193739c953358c865005855253af4f68a497John McCall void setShouldCopy(bool shouldCopy) { 1481f85e193739c953358c865005855253af4f68a497John McCall ObjCIndirectCopyRestoreExprBits.ShouldCopy = shouldCopy; 1482f85e193739c953358c865005855253af4f68a497John McCall } 1483f85e193739c953358c865005855253af4f68a497John McCall 1484f85e193739c953358c865005855253af4f68a497John McCall explicit ObjCIndirectCopyRestoreExpr(EmptyShell Empty) 1485f85e193739c953358c865005855253af4f68a497John McCall : Expr(ObjCIndirectCopyRestoreExprClass, Empty) { } 1486f85e193739c953358c865005855253af4f68a497John McCall 1487f85e193739c953358c865005855253af4f68a497John McCallpublic: 1488f85e193739c953358c865005855253af4f68a497John McCall ObjCIndirectCopyRestoreExpr(Expr *operand, QualType type, bool shouldCopy) 1489f85e193739c953358c865005855253af4f68a497John McCall : Expr(ObjCIndirectCopyRestoreExprClass, type, VK_LValue, OK_Ordinary, 1490f85e193739c953358c865005855253af4f68a497John McCall operand->isTypeDependent(), operand->isValueDependent(), 1491561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor operand->isInstantiationDependent(), 1492f85e193739c953358c865005855253af4f68a497John McCall operand->containsUnexpandedParameterPack()), 1493f85e193739c953358c865005855253af4f68a497John McCall Operand(operand) { 1494f85e193739c953358c865005855253af4f68a497John McCall setShouldCopy(shouldCopy); 1495f85e193739c953358c865005855253af4f68a497John McCall } 1496f85e193739c953358c865005855253af4f68a497John McCall 1497f85e193739c953358c865005855253af4f68a497John McCall Expr *getSubExpr() { return cast<Expr>(Operand); } 1498f85e193739c953358c865005855253af4f68a497John McCall const Expr *getSubExpr() const { return cast<Expr>(Operand); } 1499f85e193739c953358c865005855253af4f68a497John McCall 1500f85e193739c953358c865005855253af4f68a497John McCall /// shouldCopy - True if we should do the 'copy' part of the 1501f85e193739c953358c865005855253af4f68a497John McCall /// copy-restore. If false, the temporary will be zero-initialized. 1502f85e193739c953358c865005855253af4f68a497John McCall bool shouldCopy() const { return ObjCIndirectCopyRestoreExprBits.ShouldCopy; } 1503f85e193739c953358c865005855253af4f68a497John McCall 1504f85e193739c953358c865005855253af4f68a497John McCall child_range children() { return child_range(&Operand, &Operand+1); } 1505f85e193739c953358c865005855253af4f68a497John McCall 1506f85e193739c953358c865005855253af4f68a497John McCall // Source locations are determined by the subexpression. 150765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { 150865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return Operand->getLocStart(); 15094f311183be3d923da9fbe8702c453688b4c426a9Daniel Dunbar } 151065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return Operand->getLocEnd();} 151165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 15124f311183be3d923da9fbe8702c453688b4c426a9Daniel Dunbar SourceLocation getExprLoc() const LLVM_READONLY { 15134f311183be3d923da9fbe8702c453688b4c426a9Daniel Dunbar return getSubExpr()->getExprLoc(); 15144f311183be3d923da9fbe8702c453688b4c426a9Daniel Dunbar } 1515f85e193739c953358c865005855253af4f68a497John McCall 1516f85e193739c953358c865005855253af4f68a497John McCall static bool classof(const Stmt *s) { 1517f85e193739c953358c865005855253af4f68a497John McCall return s->getStmtClass() == ObjCIndirectCopyRestoreExprClass; 1518f85e193739c953358c865005855253af4f68a497John McCall } 1519f85e193739c953358c865005855253af4f68a497John McCall}; 1520f85e193739c953358c865005855253af4f68a497John McCall 1521f85e193739c953358c865005855253af4f68a497John McCall/// \brief An Objective-C "bridged" cast expression, which casts between 1522f85e193739c953358c865005855253af4f68a497John McCall/// Objective-C pointers and C pointers, transferring ownership in the process. 1523f85e193739c953358c865005855253af4f68a497John McCall/// 1524f85e193739c953358c865005855253af4f68a497John McCall/// \code 1525f85e193739c953358c865005855253af4f68a497John McCall/// NSString *str = (__bridge_transfer NSString *)CFCreateString(); 1526f85e193739c953358c865005855253af4f68a497John McCall/// \endcode 1527f85e193739c953358c865005855253af4f68a497John McCallclass ObjCBridgedCastExpr : public ExplicitCastExpr { 1528f85e193739c953358c865005855253af4f68a497John McCall SourceLocation LParenLoc; 1529f85e193739c953358c865005855253af4f68a497John McCall SourceLocation BridgeKeywordLoc; 1530f85e193739c953358c865005855253af4f68a497John McCall unsigned Kind : 2; 1531f85e193739c953358c865005855253af4f68a497John McCall 1532f85e193739c953358c865005855253af4f68a497John McCall friend class ASTStmtReader; 1533f85e193739c953358c865005855253af4f68a497John McCall friend class ASTStmtWriter; 1534f85e193739c953358c865005855253af4f68a497John McCall 1535f85e193739c953358c865005855253af4f68a497John McCallpublic: 1536f85e193739c953358c865005855253af4f68a497John McCall ObjCBridgedCastExpr(SourceLocation LParenLoc, ObjCBridgeCastKind Kind, 15371d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall CastKind CK, SourceLocation BridgeKeywordLoc, 15381d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall TypeSourceInfo *TSInfo, Expr *Operand) 1539f85e193739c953358c865005855253af4f68a497John McCall : ExplicitCastExpr(ObjCBridgedCastExprClass, TSInfo->getType(), VK_RValue, 15401d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall CK, Operand, 0, TSInfo), 1541f85e193739c953358c865005855253af4f68a497John McCall LParenLoc(LParenLoc), BridgeKeywordLoc(BridgeKeywordLoc), Kind(Kind) { } 1542f85e193739c953358c865005855253af4f68a497John McCall 1543f85e193739c953358c865005855253af4f68a497John McCall /// \brief Construct an empty Objective-C bridged cast. 1544f85e193739c953358c865005855253af4f68a497John McCall explicit ObjCBridgedCastExpr(EmptyShell Shell) 1545f85e193739c953358c865005855253af4f68a497John McCall : ExplicitCastExpr(ObjCBridgedCastExprClass, Shell, 0) { } 1546f85e193739c953358c865005855253af4f68a497John McCall 1547f85e193739c953358c865005855253af4f68a497John McCall SourceLocation getLParenLoc() const { return LParenLoc; } 1548f85e193739c953358c865005855253af4f68a497John McCall 1549f85e193739c953358c865005855253af4f68a497John McCall /// \brief Determine which kind of bridge is being performed via this cast. 1550f85e193739c953358c865005855253af4f68a497John McCall ObjCBridgeCastKind getBridgeKind() const { 1551f85e193739c953358c865005855253af4f68a497John McCall return static_cast<ObjCBridgeCastKind>(Kind); 1552f85e193739c953358c865005855253af4f68a497John McCall } 1553f85e193739c953358c865005855253af4f68a497John McCall 1554f85e193739c953358c865005855253af4f68a497John McCall /// \brief Retrieve the kind of bridge being performed as a string. 1555686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef getBridgeKindName() const; 1556f85e193739c953358c865005855253af4f68a497John McCall 1557f85e193739c953358c865005855253af4f68a497John McCall /// \brief The location of the bridge keyword. 1558f85e193739c953358c865005855253af4f68a497John McCall SourceLocation getBridgeKeywordLoc() const { return BridgeKeywordLoc; } 1559f85e193739c953358c865005855253af4f68a497John McCall 156065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return LParenLoc; } 156165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { 156265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return getSubExpr()->getLocEnd(); 1563f85e193739c953358c865005855253af4f68a497John McCall } 1564f85e193739c953358c865005855253af4f68a497John McCall 1565f85e193739c953358c865005855253af4f68a497John McCall static bool classof(const Stmt *T) { 1566f85e193739c953358c865005855253af4f68a497John McCall return T->getStmtClass() == ObjCBridgedCastExprClass; 1567f85e193739c953358c865005855253af4f68a497John McCall } 1568f85e193739c953358c865005855253af4f68a497John McCall}; 1569f85e193739c953358c865005855253af4f68a497John McCall 1570f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff} // end namespace clang 1571f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff 1572f494b579b22f9950f5af021f0bf9879a91bb8b41Steve Naroff#endif 1573