ExprObjC.h revision d4582b8e6d056f5d991f1b8372e89a6aae58feae
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//===--- ExprObjC.h - Classes for representing ObjC expressions -*- C++ -*-===// 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The LLVM Compiler Infrastructure 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This file is distributed under the University of Illinois Open Source 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// License. See LICENSE.TXT for details. 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//===----------------------------------------------------------------------===// 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This file defines the ExprObjC interface and subclasses. 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//===----------------------------------------------------------------------===// 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef LLVM_CLANG_AST_EXPROBJC_H 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define LLVM_CLANG_AST_EXPROBJC_H 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 17a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "clang/AST/DeclObjC.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "clang/AST/Expr.h" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "clang/AST/SelectorLocationsKind.h" 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "clang/Basic/IdentifierTable.h" 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "llvm/Support/Compiler.h" 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace clang { 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class IdentifierInfo; 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class ASTContext; 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// ObjCStringLiteral, used for Objective-C string literals 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// i.e. @"foo". 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ObjCStringLiteral : public Expr { 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Stmt *String; 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SourceLocation AtLoc; 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public: 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ObjCStringLiteral(StringLiteral *SL, QualType T, SourceLocation L) 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : Expr(ObjCStringLiteralClass, T, VK_RValue, OK_Ordinary, false, false, 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false, false), 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) String(SL), AtLoc(L) {} 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) explicit ObjCStringLiteral(EmptyShell Empty) 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : Expr(ObjCStringLiteralClass, Empty) {} 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) StringLiteral *getString() { return cast<StringLiteral>(String); } 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const StringLiteral *getString() const { return cast<StringLiteral>(String); } 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void setString(StringLiteral *S) { String = S; } 432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SourceLocation getAtLoc() const { return AtLoc; } 452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void setAtLoc(SourceLocation L) { AtLoc = L; } 465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SourceLocation getLocStart() const LLVM_READONLY { return AtLoc; } 482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SourceLocation getLocEnd() const LLVM_READONLY { return String->getLocEnd(); } 492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static bool classof(const Stmt *T) { 512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return T->getStmtClass() == ObjCStringLiteralClass; 522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Iterators 552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) child_range children() { return child_range(&String, &String+1); } 562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/// ObjCBoolLiteralExpr - Objective-C Boolean Literal. 592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/// 602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class ObjCBoolLiteralExpr : public Expr { 612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool Value; 622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SourceLocation Loc; 632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)public: 642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ObjCBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) : 652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Expr(ObjCBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false, 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) false, false), Value(val), Loc(l) {} 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) explicit ObjCBoolLiteralExpr(EmptyShell Empty) 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : Expr(ObjCBoolLiteralExprClass, Empty) { } 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool getValue() const { return Value; } 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void setValue(bool V) { Value = V; } 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SourceLocation getLocEnd() const LLVM_READONLY { return Loc; } 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SourceLocation getLocation() const { return Loc; } 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void setLocation(SourceLocation L) { Loc = L; } 79c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool classof(const Stmt *T) { 81c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch return T->getStmtClass() == ObjCBoolLiteralExprClass; 82c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch } 83c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Iterators 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) child_range children() { return child_range(); } 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// ObjCBoxedExpr - used for generalized expression boxing. 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// as in: @(strdup("hello world")) or @(random()) 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// Also used for boxing non-parenthesized numeric literals; 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// as in: @42 or \@true (c++/objc++) or \@__yes (c/objc). 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ObjCBoxedExpr : public Expr { 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Stmt *SubExpr; 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ObjCMethodDecl *BoxingMethod; 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SourceRange Range; 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public: 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ObjCBoxedExpr(Expr *E, QualType T, ObjCMethodDecl *method, 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SourceRange R) 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : Expr(ObjCBoxedExprClass, T, VK_RValue, OK_Ordinary, 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) E->isTypeDependent(), E->isValueDependent(), 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) E->isInstantiationDependent(), E->containsUnexpandedParameterPack()), 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SubExpr(E), BoxingMethod(method), Range(R) {} 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) explicit ObjCBoxedExpr(EmptyShell Empty) 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : Expr(ObjCBoxedExprClass, Empty) {} 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Expr *getSubExpr() { return cast<Expr>(SubExpr); } 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ObjCMethodDecl *getBoxingMethod() const { 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return BoxingMethod; 11190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 11290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 11390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) SourceLocation getAtLoc() const { return Range.getBegin(); } 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); } 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); } 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SourceRange getSourceRange() const LLVM_READONLY { 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return Range; 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool classof(const Stmt *T) { 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return T->getStmtClass() == ObjCBoxedExprClass; 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Iterators 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) child_range children() { return child_range(&SubExpr, &SubExpr+1); } 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class ASTStmtReader; 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// ObjCArrayLiteral - used for objective-c array containers; as in: 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// @[@"Hello", NSApp, [NSNumber numberWithInt:42]]; 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ObjCArrayLiteral : public Expr { 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) unsigned NumElements; 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SourceRange Range; 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ObjCMethodDecl *ArrayWithObjectsMethod; 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ObjCArrayLiteral(ArrayRef<Expr *> Elements, 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) QualType T, ObjCMethodDecl * Method, 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SourceRange SR); 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) explicit ObjCArrayLiteral(EmptyShell Empty, unsigned NumElements) 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : Expr(ObjCArrayLiteralClass, Empty), NumElements(NumElements) {} 144c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public: 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static ObjCArrayLiteral *Create(ASTContext &C, 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ArrayRef<Expr *> Elements, 148c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) QualType T, ObjCMethodDecl * Method, 149c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) SourceRange SR); 150c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 151c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) static ObjCArrayLiteral *CreateEmpty(ASTContext &C, unsigned NumElements); 152c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); } 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); } 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SourceRange getSourceRange() const LLVM_READONLY { return Range; } 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool classof(const Stmt *T) { 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return T->getStmtClass() == ObjCArrayLiteralClass; 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// \brief Retrieve elements of array of literals. 1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Expr **getElements() { return reinterpret_cast<Expr **>(this + 1); } 1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// \brief Retrieve elements of array of literals. 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Expr * const *getElements() const { 1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return reinterpret_cast<const Expr * const*>(this + 1); 1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// getNumElements - Return number of elements of objective-c array literal. 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) unsigned getNumElements() const { return NumElements; } 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// getExpr - Return the Expr at the specified index. 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Expr *getElement(unsigned Index) { 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) assert((Index < NumElements) && "Arg access out of range!"); 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return cast<Expr>(getElements()[Index]); 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Expr *getElement(unsigned Index) const { 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) assert((Index < NumElements) && "Arg access out of range!"); 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return cast<Expr>(getElements()[Index]); 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ObjCMethodDecl *getArrayWithObjectsMethod() const { 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return ArrayWithObjectsMethod; 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Iterators 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) child_range children() { 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return child_range((Stmt **)getElements(), 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) (Stmt **)getElements() + NumElements); 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class ASTStmtReader; 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// \brief An element in an Objective-C dictionary literal. 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct ObjCDictionaryElement { 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// \brief The key for the dictionary element. 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Expr *Key; 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// \brief The value of the dictionary element. 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Expr *Value; 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// \brief The location of the ellipsis, if this is a pack expansion. 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SourceLocation EllipsisLoc; 2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// \brief The number of elements this pack expansion will expand to, if 2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// this is a pack expansion and is known. 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Optional<unsigned> NumExpansions; 2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// \brief Determines whether this dictionary element is a pack expansion. 2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool isPackExpansion() const { return EllipsisLoc.isValid(); } 2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // end namespace clang 2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace llvm { 217c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)template <> struct isPodLike<clang::ObjCDictionaryElement> : llvm::true_type {}; 2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace clang { 2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// ObjCDictionaryLiteral - AST node to represent objective-c dictionary 2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// literals; as in: @{@"name" : NSUserName(), @"date" : [NSDate date] }; 2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ObjCDictionaryLiteral : public Expr { 2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// \brief Key/value pair used to store the key and value of a given element. 2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// 2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// Objects of this type are stored directly after the expression. 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) struct KeyValuePair { 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Expr *Key; 2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Expr *Value; 2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// \brief Data that describes an element that is a pack expansion, used if any 2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// of the elements in the dictionary literal are pack expansions. 2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) struct ExpansionData { 2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// \brief The location of the ellipsis, if this element is a pack 2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// expansion. 2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SourceLocation EllipsisLoc; 2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// \brief If non-zero, the number of elements that this pack 2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// expansion will expand to (+1). 2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) unsigned NumExpansionsPlusOne; 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// \brief The number of elements in this dictionary literal. 2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) unsigned NumElements : 31; 2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// \brief Determine whether this dictionary literal has any pack expansions. 2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// 2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// If the dictionary literal has pack expansions, then there will 2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// be an array of pack expansion data following the array of 2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// key/value pairs, which provide the locations of the ellipses (if 2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// any) and number of elements in the expansion (if known). If 2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// there are no pack expansions, we optimize away this storage. 2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) unsigned HasPackExpansions : 1; 2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SourceRange Range; 2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ObjCMethodDecl *DictWithObjectsMethod; 2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ObjCDictionaryLiteral(ArrayRef<ObjCDictionaryElement> VK, 2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool HasPackExpansions, 2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) QualType T, ObjCMethodDecl *method, 2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SourceRange SR); 2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) explicit ObjCDictionaryLiteral(EmptyShell Empty, unsigned NumElements, 2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool HasPackExpansions) 2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : Expr(ObjCDictionaryLiteralClass, Empty), NumElements(NumElements), 2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) HasPackExpansions(HasPackExpansions) {} 268a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 269a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) KeyValuePair *getKeyValues() { 2705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return reinterpret_cast<KeyValuePair *>(this + 1); 271a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 272a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const KeyValuePair *getKeyValues() const { 2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return reinterpret_cast<const KeyValuePair *>(this + 1); 2755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 2765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ExpansionData *getExpansionData() { 2785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!HasPackExpansions) 2795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return 0; 2805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return reinterpret_cast<ExpansionData *>(getKeyValues() + NumElements); 2822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 2832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const ExpansionData *getExpansionData() const { 2852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!HasPackExpansions) 2862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return 0; 2872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return reinterpret_cast<const ExpansionData *>(getKeyValues()+NumElements); 2892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public: 2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static ObjCDictionaryLiteral *Create(ASTContext &C, 2932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ArrayRef<ObjCDictionaryElement> VK, 2942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool HasPackExpansions, 2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) QualType T, ObjCMethodDecl *method, 2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SourceRange SR); 2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static ObjCDictionaryLiteral *CreateEmpty(ASTContext &C, 2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) unsigned NumElements, 300c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch bool HasPackExpansions); 301c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch 302c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch /// getNumElements - Return number of elements of objective-c dictionary 303c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch /// literal. 304c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch unsigned getNumElements() const { return NumElements; } 305c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch 3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ObjCDictionaryElement getKeyValueElement(unsigned Index) const { 307c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch assert((Index < NumElements) && "Arg access out of range!"); 308c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch const KeyValuePair &KV = getKeyValues()[Index]; 309c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch ObjCDictionaryElement Result = { KV.Key, KV.Value, SourceLocation(), None }; 3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (HasPackExpansions) { 3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ExpansionData &Expansion = getExpansionData()[Index]; 3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Result.EllipsisLoc = Expansion.EllipsisLoc; 3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (Expansion.NumExpansionsPlusOne > 0) 314 Result.NumExpansions = Expansion.NumExpansionsPlusOne - 1; 315 } 316 return Result; 317 } 318 319 ObjCMethodDecl *getDictWithObjectsMethod() const 320 { return DictWithObjectsMethod; } 321 322 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); } 323 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); } 324 SourceRange getSourceRange() const LLVM_READONLY { return Range; } 325 326 static bool classof(const Stmt *T) { 327 return T->getStmtClass() == ObjCDictionaryLiteralClass; 328 } 329 330 // Iterators 331 child_range children() { 332 // Note: we're taking advantage of the layout of the KeyValuePair struct 333 // here. If that struct changes, this code will need to change as well. 334 return child_range(reinterpret_cast<Stmt **>(this + 1), 335 reinterpret_cast<Stmt **>(this + 1) + NumElements * 2); 336 } 337 338 friend class ASTStmtReader; 339 friend class ASTStmtWriter; 340}; 341 342 343/// ObjCEncodeExpr, used for \@encode in Objective-C. \@encode has the same 344/// type and behavior as StringLiteral except that the string initializer is 345/// obtained from ASTContext with the encoding type as an argument. 346class ObjCEncodeExpr : public Expr { 347 TypeSourceInfo *EncodedType; 348 SourceLocation AtLoc, RParenLoc; 349public: 350 ObjCEncodeExpr(QualType T, TypeSourceInfo *EncodedType, 351 SourceLocation at, SourceLocation rp) 352 : Expr(ObjCEncodeExprClass, T, VK_LValue, OK_Ordinary, 353 EncodedType->getType()->isDependentType(), 354 EncodedType->getType()->isDependentType(), 355 EncodedType->getType()->isInstantiationDependentType(), 356 EncodedType->getType()->containsUnexpandedParameterPack()), 357 EncodedType(EncodedType), AtLoc(at), RParenLoc(rp) {} 358 359 explicit ObjCEncodeExpr(EmptyShell Empty) : Expr(ObjCEncodeExprClass, Empty){} 360 361 362 SourceLocation getAtLoc() const { return AtLoc; } 363 void setAtLoc(SourceLocation L) { AtLoc = L; } 364 SourceLocation getRParenLoc() const { return RParenLoc; } 365 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 366 367 QualType getEncodedType() const { return EncodedType->getType(); } 368 369 TypeSourceInfo *getEncodedTypeSourceInfo() const { return EncodedType; } 370 void setEncodedTypeSourceInfo(TypeSourceInfo *EncType) { 371 EncodedType = EncType; 372 } 373 374 SourceLocation getLocStart() const LLVM_READONLY { return AtLoc; } 375 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 376 377 static bool classof(const Stmt *T) { 378 return T->getStmtClass() == ObjCEncodeExprClass; 379 } 380 381 // Iterators 382 child_range children() { return child_range(); } 383}; 384 385/// ObjCSelectorExpr used for \@selector in Objective-C. 386class ObjCSelectorExpr : public Expr { 387 Selector SelName; 388 SourceLocation AtLoc, RParenLoc; 389public: 390 ObjCSelectorExpr(QualType T, Selector selInfo, 391 SourceLocation at, SourceLocation rp) 392 : Expr(ObjCSelectorExprClass, T, VK_RValue, OK_Ordinary, false, false, 393 false, false), 394 SelName(selInfo), AtLoc(at), RParenLoc(rp){} 395 explicit ObjCSelectorExpr(EmptyShell Empty) 396 : Expr(ObjCSelectorExprClass, Empty) {} 397 398 Selector getSelector() const { return SelName; } 399 void setSelector(Selector S) { SelName = S; } 400 401 SourceLocation getAtLoc() const { return AtLoc; } 402 SourceLocation getRParenLoc() const { return RParenLoc; } 403 void setAtLoc(SourceLocation L) { AtLoc = L; } 404 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 405 406 SourceLocation getLocStart() const LLVM_READONLY { return AtLoc; } 407 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 408 409 /// getNumArgs - Return the number of actual arguments to this call. 410 unsigned getNumArgs() const { return SelName.getNumArgs(); } 411 412 static bool classof(const Stmt *T) { 413 return T->getStmtClass() == ObjCSelectorExprClass; 414 } 415 416 // Iterators 417 child_range children() { return child_range(); } 418}; 419 420/// ObjCProtocolExpr used for protocol expression in Objective-C. 421/// 422/// This is used as: \@protocol(foo), as in: 423/// \code 424/// [obj conformsToProtocol:@protocol(foo)] 425/// \endcode 426/// 427/// The return type is "Protocol*". 428class ObjCProtocolExpr : public Expr { 429 ObjCProtocolDecl *TheProtocol; 430 SourceLocation AtLoc, ProtoLoc, RParenLoc; 431public: 432 ObjCProtocolExpr(QualType T, ObjCProtocolDecl *protocol, 433 SourceLocation at, SourceLocation protoLoc, SourceLocation rp) 434 : Expr(ObjCProtocolExprClass, T, VK_RValue, OK_Ordinary, false, false, 435 false, false), 436 TheProtocol(protocol), AtLoc(at), ProtoLoc(protoLoc), RParenLoc(rp) {} 437 explicit ObjCProtocolExpr(EmptyShell Empty) 438 : Expr(ObjCProtocolExprClass, Empty) {} 439 440 ObjCProtocolDecl *getProtocol() const { return TheProtocol; } 441 void setProtocol(ObjCProtocolDecl *P) { TheProtocol = P; } 442 443 SourceLocation getProtocolIdLoc() const { return ProtoLoc; } 444 SourceLocation getAtLoc() const { return AtLoc; } 445 SourceLocation getRParenLoc() const { return RParenLoc; } 446 void setAtLoc(SourceLocation L) { AtLoc = L; } 447 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 448 449 SourceLocation getLocStart() const LLVM_READONLY { return AtLoc; } 450 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 451 452 static bool classof(const Stmt *T) { 453 return T->getStmtClass() == ObjCProtocolExprClass; 454 } 455 456 // Iterators 457 child_range children() { return child_range(); } 458 459 friend class ASTStmtReader; 460 friend class ASTStmtWriter; 461}; 462 463/// ObjCIvarRefExpr - A reference to an ObjC instance variable. 464class ObjCIvarRefExpr : public Expr { 465 ObjCIvarDecl *D; 466 Stmt *Base; 467 SourceLocation Loc; 468 /// OpLoc - This is the location of '.' or '->' 469 SourceLocation OpLoc; 470 471 bool IsArrow:1; // True if this is "X->F", false if this is "X.F". 472 bool IsFreeIvar:1; // True if ivar reference has no base (self assumed). 473 474public: 475 ObjCIvarRefExpr(ObjCIvarDecl *d, QualType t, 476 SourceLocation l, SourceLocation oploc, 477 Expr *base, 478 bool arrow = false, bool freeIvar = false) : 479 Expr(ObjCIvarRefExprClass, t, VK_LValue, OK_Ordinary, 480 /*TypeDependent=*/false, base->isValueDependent(), 481 base->isInstantiationDependent(), 482 base->containsUnexpandedParameterPack()), 483 D(d), Base(base), Loc(l), OpLoc(oploc), 484 IsArrow(arrow), IsFreeIvar(freeIvar) {} 485 486 explicit ObjCIvarRefExpr(EmptyShell Empty) 487 : Expr(ObjCIvarRefExprClass, Empty) {} 488 489 ObjCIvarDecl *getDecl() { return D; } 490 const ObjCIvarDecl *getDecl() const { return D; } 491 void setDecl(ObjCIvarDecl *d) { D = d; } 492 493 const Expr *getBase() const { return cast<Expr>(Base); } 494 Expr *getBase() { return cast<Expr>(Base); } 495 void setBase(Expr * base) { Base = base; } 496 497 bool isArrow() const { return IsArrow; } 498 bool isFreeIvar() const { return IsFreeIvar; } 499 void setIsArrow(bool A) { IsArrow = A; } 500 void setIsFreeIvar(bool A) { IsFreeIvar = A; } 501 502 SourceLocation getLocation() const { return Loc; } 503 void setLocation(SourceLocation L) { Loc = L; } 504 505 SourceLocation getLocStart() const LLVM_READONLY { 506 return isFreeIvar() ? Loc : getBase()->getLocStart(); 507 } 508 SourceLocation getLocEnd() const LLVM_READONLY { return Loc; } 509 510 SourceLocation getOpLoc() const { return OpLoc; } 511 void setOpLoc(SourceLocation L) { OpLoc = L; } 512 513 static bool classof(const Stmt *T) { 514 return T->getStmtClass() == ObjCIvarRefExprClass; 515 } 516 517 // Iterators 518 child_range children() { return child_range(&Base, &Base+1); } 519}; 520 521/// ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC 522/// property. 523class ObjCPropertyRefExpr : public Expr { 524private: 525 /// If the bool is true, this is an implicit property reference; the 526 /// pointer is an (optional) ObjCMethodDecl and Setter may be set. 527 /// if the bool is false, this is an explicit property reference; 528 /// the pointer is an ObjCPropertyDecl and Setter is always null. 529 llvm::PointerIntPair<NamedDecl*, 1, bool> PropertyOrGetter; 530 531 /// \brief Indicates whether the property reference will result in a message 532 /// to the getter, the setter, or both. 533 /// This applies to both implicit and explicit property references. 534 enum MethodRefFlags { 535 MethodRef_None = 0, 536 MethodRef_Getter = 0x1, 537 MethodRef_Setter = 0x2 538 }; 539 540 /// \brief Contains the Setter method pointer and MethodRefFlags bit flags. 541 llvm::PointerIntPair<ObjCMethodDecl *, 2, unsigned> SetterAndMethodRefFlags; 542 543 // FIXME: Maybe we should store the property identifier here, 544 // because it's not rederivable from the other data when there's an 545 // implicit property with no getter (because the 'foo' -> 'setFoo:' 546 // transformation is lossy on the first character). 547 548 SourceLocation IdLoc; 549 550 /// \brief When the receiver in property access is 'super', this is 551 /// the location of the 'super' keyword. When it's an interface, 552 /// this is that interface. 553 SourceLocation ReceiverLoc; 554 llvm::PointerUnion3<Stmt*, const Type*, ObjCInterfaceDecl*> Receiver; 555 556public: 557 ObjCPropertyRefExpr(ObjCPropertyDecl *PD, QualType t, 558 ExprValueKind VK, ExprObjectKind OK, 559 SourceLocation l, Expr *base) 560 : Expr(ObjCPropertyRefExprClass, t, VK, OK, 561 /*TypeDependent=*/false, base->isValueDependent(), 562 base->isInstantiationDependent(), 563 base->containsUnexpandedParameterPack()), 564 PropertyOrGetter(PD, false), SetterAndMethodRefFlags(), 565 IdLoc(l), ReceiverLoc(), Receiver(base) { 566 assert(t->isSpecificPlaceholderType(BuiltinType::PseudoObject)); 567 } 568 569 ObjCPropertyRefExpr(ObjCPropertyDecl *PD, QualType t, 570 ExprValueKind VK, ExprObjectKind OK, 571 SourceLocation l, SourceLocation sl, QualType st) 572 : Expr(ObjCPropertyRefExprClass, t, VK, OK, 573 /*TypeDependent=*/false, false, st->isInstantiationDependentType(), 574 st->containsUnexpandedParameterPack()), 575 PropertyOrGetter(PD, false), SetterAndMethodRefFlags(), 576 IdLoc(l), ReceiverLoc(sl), Receiver(st.getTypePtr()) { 577 assert(t->isSpecificPlaceholderType(BuiltinType::PseudoObject)); 578 } 579 580 ObjCPropertyRefExpr(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter, 581 QualType T, ExprValueKind VK, ExprObjectKind OK, 582 SourceLocation IdLoc, Expr *Base) 583 : Expr(ObjCPropertyRefExprClass, T, VK, OK, false, 584 Base->isValueDependent(), Base->isInstantiationDependent(), 585 Base->containsUnexpandedParameterPack()), 586 PropertyOrGetter(Getter, true), SetterAndMethodRefFlags(Setter, 0), 587 IdLoc(IdLoc), ReceiverLoc(), Receiver(Base) { 588 assert(T->isSpecificPlaceholderType(BuiltinType::PseudoObject)); 589 } 590 591 ObjCPropertyRefExpr(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter, 592 QualType T, ExprValueKind VK, ExprObjectKind OK, 593 SourceLocation IdLoc, 594 SourceLocation SuperLoc, QualType SuperTy) 595 : Expr(ObjCPropertyRefExprClass, T, VK, OK, false, false, false, false), 596 PropertyOrGetter(Getter, true), SetterAndMethodRefFlags(Setter, 0), 597 IdLoc(IdLoc), ReceiverLoc(SuperLoc), Receiver(SuperTy.getTypePtr()) { 598 assert(T->isSpecificPlaceholderType(BuiltinType::PseudoObject)); 599 } 600 601 ObjCPropertyRefExpr(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter, 602 QualType T, ExprValueKind VK, ExprObjectKind OK, 603 SourceLocation IdLoc, 604 SourceLocation ReceiverLoc, ObjCInterfaceDecl *Receiver) 605 : Expr(ObjCPropertyRefExprClass, T, VK, OK, false, false, false, false), 606 PropertyOrGetter(Getter, true), SetterAndMethodRefFlags(Setter, 0), 607 IdLoc(IdLoc), ReceiverLoc(ReceiverLoc), Receiver(Receiver) { 608 assert(T->isSpecificPlaceholderType(BuiltinType::PseudoObject)); 609 } 610 611 explicit ObjCPropertyRefExpr(EmptyShell Empty) 612 : Expr(ObjCPropertyRefExprClass, Empty) {} 613 614 bool isImplicitProperty() const { return PropertyOrGetter.getInt(); } 615 bool isExplicitProperty() const { return !PropertyOrGetter.getInt(); } 616 617 ObjCPropertyDecl *getExplicitProperty() const { 618 assert(!isImplicitProperty()); 619 return cast<ObjCPropertyDecl>(PropertyOrGetter.getPointer()); 620 } 621 622 ObjCMethodDecl *getImplicitPropertyGetter() const { 623 assert(isImplicitProperty()); 624 return cast_or_null<ObjCMethodDecl>(PropertyOrGetter.getPointer()); 625 } 626 627 ObjCMethodDecl *getImplicitPropertySetter() const { 628 assert(isImplicitProperty()); 629 return SetterAndMethodRefFlags.getPointer(); 630 } 631 632 Selector getGetterSelector() const { 633 if (isImplicitProperty()) 634 return getImplicitPropertyGetter()->getSelector(); 635 return getExplicitProperty()->getGetterName(); 636 } 637 638 Selector getSetterSelector() const { 639 if (isImplicitProperty()) 640 return getImplicitPropertySetter()->getSelector(); 641 return getExplicitProperty()->getSetterName(); 642 } 643 644 /// \brief True if the property reference will result in a message to the 645 /// getter. 646 /// This applies to both implicit and explicit property references. 647 bool isMessagingGetter() const { 648 return SetterAndMethodRefFlags.getInt() & MethodRef_Getter; 649 } 650 651 /// \brief True if the property reference will result in a message to the 652 /// setter. 653 /// This applies to both implicit and explicit property references. 654 bool isMessagingSetter() const { 655 return SetterAndMethodRefFlags.getInt() & MethodRef_Setter; 656 } 657 658 void setIsMessagingGetter(bool val = true) { 659 setMethodRefFlag(MethodRef_Getter, val); 660 } 661 662 void setIsMessagingSetter(bool val = true) { 663 setMethodRefFlag(MethodRef_Setter, val); 664 } 665 666 const Expr *getBase() const { 667 return cast<Expr>(Receiver.get<Stmt*>()); 668 } 669 Expr *getBase() { 670 return cast<Expr>(Receiver.get<Stmt*>()); 671 } 672 673 SourceLocation getLocation() const { return IdLoc; } 674 675 SourceLocation getReceiverLocation() const { return ReceiverLoc; } 676 QualType getSuperReceiverType() const { 677 return QualType(Receiver.get<const Type*>(), 0); 678 } 679 QualType getGetterResultType() const { 680 QualType ResultType; 681 if (isExplicitProperty()) { 682 const ObjCPropertyDecl *PDecl = getExplicitProperty(); 683 if (const ObjCMethodDecl *Getter = PDecl->getGetterMethodDecl()) 684 ResultType = Getter->getResultType(); 685 else 686 ResultType = PDecl->getType(); 687 } else { 688 const ObjCMethodDecl *Getter = getImplicitPropertyGetter(); 689 if (Getter) 690 ResultType = Getter->getResultType(); // with reference! 691 } 692 return ResultType; 693 } 694 695 QualType getSetterArgType() const { 696 QualType ArgType; 697 if (isImplicitProperty()) { 698 const ObjCMethodDecl *Setter = getImplicitPropertySetter(); 699 ObjCMethodDecl::param_const_iterator P = Setter->param_begin(); 700 ArgType = (*P)->getType(); 701 } else { 702 if (ObjCPropertyDecl *PDecl = getExplicitProperty()) 703 if (const ObjCMethodDecl *Setter = PDecl->getSetterMethodDecl()) { 704 ObjCMethodDecl::param_const_iterator P = Setter->param_begin(); 705 ArgType = (*P)->getType(); 706 } 707 if (ArgType.isNull()) 708 ArgType = getType(); 709 } 710 return ArgType; 711 } 712 713 ObjCInterfaceDecl *getClassReceiver() const { 714 return Receiver.get<ObjCInterfaceDecl*>(); 715 } 716 bool isObjectReceiver() const { return Receiver.is<Stmt*>(); } 717 bool isSuperReceiver() const { return Receiver.is<const Type*>(); } 718 bool isClassReceiver() const { return Receiver.is<ObjCInterfaceDecl*>(); } 719 720 SourceLocation getLocStart() const LLVM_READONLY { 721 return isObjectReceiver() ? getBase()->getLocStart() :getReceiverLocation(); 722 } 723 SourceLocation getLocEnd() const LLVM_READONLY { return IdLoc; } 724 725 static bool classof(const Stmt *T) { 726 return T->getStmtClass() == ObjCPropertyRefExprClass; 727 } 728 729 // Iterators 730 child_range children() { 731 if (Receiver.is<Stmt*>()) { 732 Stmt **begin = reinterpret_cast<Stmt**>(&Receiver); // hack! 733 return child_range(begin, begin+1); 734 } 735 return child_range(); 736 } 737 738private: 739 friend class ASTStmtReader; 740 friend class ASTStmtWriter; 741 void setExplicitProperty(ObjCPropertyDecl *D, unsigned methRefFlags) { 742 PropertyOrGetter.setPointer(D); 743 PropertyOrGetter.setInt(false); 744 SetterAndMethodRefFlags.setPointer(0); 745 SetterAndMethodRefFlags.setInt(methRefFlags); 746 } 747 void setImplicitProperty(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter, 748 unsigned methRefFlags) { 749 PropertyOrGetter.setPointer(Getter); 750 PropertyOrGetter.setInt(true); 751 SetterAndMethodRefFlags.setPointer(Setter); 752 SetterAndMethodRefFlags.setInt(methRefFlags); 753 } 754 void setBase(Expr *Base) { Receiver = Base; } 755 void setSuperReceiver(QualType T) { Receiver = T.getTypePtr(); } 756 void setClassReceiver(ObjCInterfaceDecl *D) { Receiver = D; } 757 758 void setLocation(SourceLocation L) { IdLoc = L; } 759 void setReceiverLocation(SourceLocation Loc) { ReceiverLoc = Loc; } 760 761 void setMethodRefFlag(MethodRefFlags flag, bool val) { 762 unsigned f = SetterAndMethodRefFlags.getInt(); 763 if (val) 764 f |= flag; 765 else 766 f &= ~flag; 767 SetterAndMethodRefFlags.setInt(f); 768 } 769}; 770 771/// ObjCSubscriptRefExpr - used for array and dictionary subscripting. 772/// array[4] = array[3]; dictionary[key] = dictionary[alt_key]; 773/// 774class ObjCSubscriptRefExpr : public Expr { 775 // Location of ']' in an indexing expression. 776 SourceLocation RBracket; 777 // array/dictionary base expression. 778 // for arrays, this is a numeric expression. For dictionaries, this is 779 // an objective-c object pointer expression. 780 enum { BASE, KEY, END_EXPR }; 781 Stmt* SubExprs[END_EXPR]; 782 783 ObjCMethodDecl *GetAtIndexMethodDecl; 784 785 // For immutable objects this is null. When ObjCSubscriptRefExpr is to read 786 // an indexed object this is null too. 787 ObjCMethodDecl *SetAtIndexMethodDecl; 788 789public: 790 791 ObjCSubscriptRefExpr(Expr *base, Expr *key, QualType T, 792 ExprValueKind VK, ExprObjectKind OK, 793 ObjCMethodDecl *getMethod, 794 ObjCMethodDecl *setMethod, SourceLocation RB) 795 : Expr(ObjCSubscriptRefExprClass, T, VK, OK, 796 base->isTypeDependent() || key->isTypeDependent(), 797 base->isValueDependent() || key->isValueDependent(), 798 base->isInstantiationDependent() || key->isInstantiationDependent(), 799 (base->containsUnexpandedParameterPack() || 800 key->containsUnexpandedParameterPack())), 801 RBracket(RB), 802 GetAtIndexMethodDecl(getMethod), 803 SetAtIndexMethodDecl(setMethod) 804 {SubExprs[BASE] = base; SubExprs[KEY] = key;} 805 806 explicit ObjCSubscriptRefExpr(EmptyShell Empty) 807 : Expr(ObjCSubscriptRefExprClass, Empty) {} 808 809 static ObjCSubscriptRefExpr *Create(ASTContext &C, 810 Expr *base, 811 Expr *key, QualType T, 812 ObjCMethodDecl *getMethod, 813 ObjCMethodDecl *setMethod, 814 SourceLocation RB); 815 816 SourceLocation getRBracket() const { return RBracket; } 817 void setRBracket(SourceLocation RB) { RBracket = RB; } 818 819 SourceLocation getLocStart() const LLVM_READONLY { 820 return SubExprs[BASE]->getLocStart(); 821 } 822 SourceLocation getLocEnd() const LLVM_READONLY { return RBracket; } 823 824 static bool classof(const Stmt *T) { 825 return T->getStmtClass() == ObjCSubscriptRefExprClass; 826 } 827 828 Expr *getBaseExpr() const { return cast<Expr>(SubExprs[BASE]); } 829 void setBaseExpr(Stmt *S) { SubExprs[BASE] = S; } 830 831 Expr *getKeyExpr() const { return cast<Expr>(SubExprs[KEY]); } 832 void setKeyExpr(Stmt *S) { SubExprs[KEY] = S; } 833 834 ObjCMethodDecl *getAtIndexMethodDecl() const { 835 return GetAtIndexMethodDecl; 836 } 837 838 ObjCMethodDecl *setAtIndexMethodDecl() const { 839 return SetAtIndexMethodDecl; 840 } 841 842 bool isArraySubscriptRefExpr() const { 843 return getKeyExpr()->getType()->isIntegralOrEnumerationType(); 844 } 845 846 child_range children() { 847 return child_range(SubExprs, SubExprs+END_EXPR); 848 } 849private: 850 friend class ASTStmtReader; 851}; 852 853 854/// \brief An expression that sends a message to the given Objective-C 855/// object or class. 856/// 857/// The following contains two message send expressions: 858/// 859/// \code 860/// [[NSString alloc] initWithString:@"Hello"] 861/// \endcode 862/// 863/// The innermost message send invokes the "alloc" class method on the 864/// NSString class, while the outermost message send invokes the 865/// "initWithString" instance method on the object returned from 866/// NSString's "alloc". In all, an Objective-C message send can take 867/// on four different (although related) forms: 868/// 869/// 1. Send to an object instance. 870/// 2. Send to a class. 871/// 3. Send to the superclass instance of the current class. 872/// 4. Send to the superclass of the current class. 873/// 874/// All four kinds of message sends are modeled by the ObjCMessageExpr 875/// class, and can be distinguished via \c getReceiverKind(). Example: 876/// 877class ObjCMessageExpr : public Expr { 878 /// \brief Stores either the selector that this message is sending 879 /// to (when \c HasMethod is zero) or an \c ObjCMethodDecl pointer 880 /// referring to the method that we type-checked against. 881 uintptr_t SelectorOrMethod; 882 883 enum { NumArgsBitWidth = 16 }; 884 885 /// \brief The number of arguments in the message send, not 886 /// including the receiver. 887 unsigned NumArgs : NumArgsBitWidth; 888 889 void setNumArgs(unsigned Num) { 890 assert((Num >> NumArgsBitWidth) == 0 && "Num of args is out of range!"); 891 NumArgs = Num; 892 } 893 894 /// \brief The kind of message send this is, which is one of the 895 /// ReceiverKind values. 896 /// 897 /// We pad this out to a byte to avoid excessive masking and shifting. 898 unsigned Kind : 8; 899 900 /// \brief Whether we have an actual method prototype in \c 901 /// SelectorOrMethod. 902 /// 903 /// When non-zero, we have a method declaration; otherwise, we just 904 /// have a selector. 905 unsigned HasMethod : 1; 906 907 /// \brief Whether this message send is a "delegate init call", 908 /// i.e. a call of an init method on self from within an init method. 909 unsigned IsDelegateInitCall : 1; 910 911 /// \brief Whether this message send was implicitly generated by 912 /// the implementation rather than explicitly written by the user. 913 unsigned IsImplicit : 1; 914 915 /// \brief Whether the locations of the selector identifiers are in a 916 /// "standard" position, a enum SelectorLocationsKind. 917 unsigned SelLocsKind : 2; 918 919 /// \brief When the message expression is a send to 'super', this is 920 /// the location of the 'super' keyword. 921 SourceLocation SuperLoc; 922 923 /// \brief The source locations of the open and close square 924 /// brackets ('[' and ']', respectively). 925 SourceLocation LBracLoc, RBracLoc; 926 927 ObjCMessageExpr(EmptyShell Empty, unsigned NumArgs) 928 : Expr(ObjCMessageExprClass, Empty), SelectorOrMethod(0), Kind(0), 929 HasMethod(0), IsDelegateInitCall(0), IsImplicit(0), SelLocsKind(0) { 930 setNumArgs(NumArgs); 931 } 932 933 ObjCMessageExpr(QualType T, ExprValueKind VK, 934 SourceLocation LBracLoc, 935 SourceLocation SuperLoc, 936 bool IsInstanceSuper, 937 QualType SuperType, 938 Selector Sel, 939 ArrayRef<SourceLocation> SelLocs, 940 SelectorLocationsKind SelLocsK, 941 ObjCMethodDecl *Method, 942 ArrayRef<Expr *> Args, 943 SourceLocation RBracLoc, 944 bool isImplicit); 945 ObjCMessageExpr(QualType T, ExprValueKind VK, 946 SourceLocation LBracLoc, 947 TypeSourceInfo *Receiver, 948 Selector Sel, 949 ArrayRef<SourceLocation> SelLocs, 950 SelectorLocationsKind SelLocsK, 951 ObjCMethodDecl *Method, 952 ArrayRef<Expr *> Args, 953 SourceLocation RBracLoc, 954 bool isImplicit); 955 ObjCMessageExpr(QualType T, ExprValueKind VK, 956 SourceLocation LBracLoc, 957 Expr *Receiver, 958 Selector Sel, 959 ArrayRef<SourceLocation> SelLocs, 960 SelectorLocationsKind SelLocsK, 961 ObjCMethodDecl *Method, 962 ArrayRef<Expr *> Args, 963 SourceLocation RBracLoc, 964 bool isImplicit); 965 966 void initArgsAndSelLocs(ArrayRef<Expr *> Args, 967 ArrayRef<SourceLocation> SelLocs, 968 SelectorLocationsKind SelLocsK); 969 970 /// \brief Retrieve the pointer value of the message receiver. 971 void *getReceiverPointer() const { 972 return *const_cast<void **>( 973 reinterpret_cast<const void * const*>(this + 1)); 974 } 975 976 /// \brief Set the pointer value of the message receiver. 977 void setReceiverPointer(void *Value) { 978 *reinterpret_cast<void **>(this + 1) = Value; 979 } 980 981 SelectorLocationsKind getSelLocsKind() const { 982 return (SelectorLocationsKind)SelLocsKind; 983 } 984 bool hasStandardSelLocs() const { 985 return getSelLocsKind() != SelLoc_NonStandard; 986 } 987 988 /// \brief Get a pointer to the stored selector identifiers locations array. 989 /// No locations will be stored if HasStandardSelLocs is true. 990 SourceLocation *getStoredSelLocs() { 991 return reinterpret_cast<SourceLocation*>(getArgs() + getNumArgs()); 992 } 993 const SourceLocation *getStoredSelLocs() const { 994 return reinterpret_cast<const SourceLocation*>(getArgs() + getNumArgs()); 995 } 996 997 /// \brief Get the number of stored selector identifiers locations. 998 /// No locations will be stored if HasStandardSelLocs is true. 999 unsigned getNumStoredSelLocs() const { 1000 if (hasStandardSelLocs()) 1001 return 0; 1002 return getNumSelectorLocs(); 1003 } 1004 1005 static ObjCMessageExpr *alloc(ASTContext &C, 1006 ArrayRef<Expr *> Args, 1007 SourceLocation RBraceLoc, 1008 ArrayRef<SourceLocation> SelLocs, 1009 Selector Sel, 1010 SelectorLocationsKind &SelLocsK); 1011 static ObjCMessageExpr *alloc(ASTContext &C, 1012 unsigned NumArgs, 1013 unsigned NumStoredSelLocs); 1014 1015public: 1016 /// \brief The kind of receiver this message is sending to. 1017 enum ReceiverKind { 1018 /// \brief The receiver is a class. 1019 Class = 0, 1020 /// \brief The receiver is an object instance. 1021 Instance, 1022 /// \brief The receiver is a superclass. 1023 SuperClass, 1024 /// \brief The receiver is the instance of the superclass object. 1025 SuperInstance 1026 }; 1027 1028 /// \brief Create a message send to super. 1029 /// 1030 /// \param Context The ASTContext in which this expression will be created. 1031 /// 1032 /// \param T The result type of this message. 1033 /// 1034 /// \param VK The value kind of this message. A message returning 1035 /// a l-value or r-value reference will be an l-value or x-value, 1036 /// respectively. 1037 /// 1038 /// \param LBracLoc The location of the open square bracket '['. 1039 /// 1040 /// \param SuperLoc The location of the "super" keyword. 1041 /// 1042 /// \param IsInstanceSuper Whether this is an instance "super" 1043 /// message (otherwise, it's a class "super" message). 1044 /// 1045 /// \param Sel The selector used to determine which method gets called. 1046 /// 1047 /// \param Method The Objective-C method against which this message 1048 /// send was type-checked. May be NULL. 1049 /// 1050 /// \param Args The message send arguments. 1051 /// 1052 /// \param RBracLoc The location of the closing square bracket ']'. 1053 static ObjCMessageExpr *Create(ASTContext &Context, QualType T, 1054 ExprValueKind VK, 1055 SourceLocation LBracLoc, 1056 SourceLocation SuperLoc, 1057 bool IsInstanceSuper, 1058 QualType SuperType, 1059 Selector Sel, 1060 ArrayRef<SourceLocation> SelLocs, 1061 ObjCMethodDecl *Method, 1062 ArrayRef<Expr *> Args, 1063 SourceLocation RBracLoc, 1064 bool isImplicit); 1065 1066 /// \brief Create a class message send. 1067 /// 1068 /// \param Context The ASTContext in which this expression will be created. 1069 /// 1070 /// \param T The result type of this message. 1071 /// 1072 /// \param VK The value kind of this message. A message returning 1073 /// a l-value or r-value reference will be an l-value or x-value, 1074 /// respectively. 1075 /// 1076 /// \param LBracLoc The location of the open square bracket '['. 1077 /// 1078 /// \param Receiver The type of the receiver, including 1079 /// source-location information. 1080 /// 1081 /// \param Sel The selector used to determine which method gets called. 1082 /// 1083 /// \param Method The Objective-C method against which this message 1084 /// send was type-checked. May be NULL. 1085 /// 1086 /// \param Args The message send arguments. 1087 /// 1088 /// \param RBracLoc The location of the closing square bracket ']'. 1089 static ObjCMessageExpr *Create(ASTContext &Context, QualType T, 1090 ExprValueKind VK, 1091 SourceLocation LBracLoc, 1092 TypeSourceInfo *Receiver, 1093 Selector Sel, 1094 ArrayRef<SourceLocation> SelLocs, 1095 ObjCMethodDecl *Method, 1096 ArrayRef<Expr *> Args, 1097 SourceLocation RBracLoc, 1098 bool isImplicit); 1099 1100 /// \brief Create an instance message send. 1101 /// 1102 /// \param Context The ASTContext in which this expression will be created. 1103 /// 1104 /// \param T The result type of this message. 1105 /// 1106 /// \param VK The value kind of this message. A message returning 1107 /// a l-value or r-value reference will be an l-value or x-value, 1108 /// respectively. 1109 /// 1110 /// \param LBracLoc The location of the open square bracket '['. 1111 /// 1112 /// \param Receiver The expression used to produce the object that 1113 /// will receive this message. 1114 /// 1115 /// \param Sel The selector used to determine which method gets called. 1116 /// 1117 /// \param Method The Objective-C method against which this message 1118 /// send was type-checked. May be NULL. 1119 /// 1120 /// \param Args The message send arguments. 1121 /// 1122 /// \param RBracLoc The location of the closing square bracket ']'. 1123 static ObjCMessageExpr *Create(ASTContext &Context, QualType T, 1124 ExprValueKind VK, 1125 SourceLocation LBracLoc, 1126 Expr *Receiver, 1127 Selector Sel, 1128 ArrayRef<SourceLocation> SeLocs, 1129 ObjCMethodDecl *Method, 1130 ArrayRef<Expr *> Args, 1131 SourceLocation RBracLoc, 1132 bool isImplicit); 1133 1134 /// \brief Create an empty Objective-C message expression, to be 1135 /// filled in by subsequent calls. 1136 /// 1137 /// \param Context The context in which the message send will be created. 1138 /// 1139 /// \param NumArgs The number of message arguments, not including 1140 /// the receiver. 1141 static ObjCMessageExpr *CreateEmpty(ASTContext &Context, 1142 unsigned NumArgs, 1143 unsigned NumStoredSelLocs); 1144 1145 /// \brief Indicates whether the message send was implicitly 1146 /// generated by the implementation. If false, it was written explicitly 1147 /// in the source code. 1148 bool isImplicit() const { return IsImplicit; } 1149 1150 /// \brief Determine the kind of receiver that this message is being 1151 /// sent to. 1152 ReceiverKind getReceiverKind() const { return (ReceiverKind)Kind; } 1153 1154 /// \brief Source range of the receiver. 1155 SourceRange getReceiverRange() const; 1156 1157 /// \brief Determine whether this is an instance message to either a 1158 /// computed object or to super. 1159 bool isInstanceMessage() const { 1160 return getReceiverKind() == Instance || getReceiverKind() == SuperInstance; 1161 } 1162 1163 /// \brief Determine whether this is an class message to either a 1164 /// specified class or to super. 1165 bool isClassMessage() const { 1166 return getReceiverKind() == Class || getReceiverKind() == SuperClass; 1167 } 1168 1169 /// \brief Returns the object expression (receiver) for an instance message, 1170 /// or null for a message that is not an instance message. 1171 Expr *getInstanceReceiver() { 1172 if (getReceiverKind() == Instance) 1173 return static_cast<Expr *>(getReceiverPointer()); 1174 1175 return 0; 1176 } 1177 const Expr *getInstanceReceiver() const { 1178 return const_cast<ObjCMessageExpr*>(this)->getInstanceReceiver(); 1179 } 1180 1181 /// \brief Turn this message send into an instance message that 1182 /// computes the receiver object with the given expression. 1183 void setInstanceReceiver(Expr *rec) { 1184 Kind = Instance; 1185 setReceiverPointer(rec); 1186 } 1187 1188 /// \brief Returns the type of a class message send, or NULL if the 1189 /// message is not a class message. 1190 QualType getClassReceiver() const { 1191 if (TypeSourceInfo *TSInfo = getClassReceiverTypeInfo()) 1192 return TSInfo->getType(); 1193 1194 return QualType(); 1195 } 1196 1197 /// \brief Returns a type-source information of a class message 1198 /// send, or NULL if the message is not a class message. 1199 TypeSourceInfo *getClassReceiverTypeInfo() const { 1200 if (getReceiverKind() == Class) 1201 return reinterpret_cast<TypeSourceInfo *>(getReceiverPointer()); 1202 return 0; 1203 } 1204 1205 void setClassReceiver(TypeSourceInfo *TSInfo) { 1206 Kind = Class; 1207 setReceiverPointer(TSInfo); 1208 } 1209 1210 /// \brief Retrieve the location of the 'super' keyword for a class 1211 /// or instance message to 'super', otherwise an invalid source location. 1212 SourceLocation getSuperLoc() const { 1213 if (getReceiverKind() == SuperInstance || getReceiverKind() == SuperClass) 1214 return SuperLoc; 1215 1216 return SourceLocation(); 1217 } 1218 1219 /// \brief Retrieve the receiver type to which this message is being directed. 1220 /// 1221 /// This routine cross-cuts all of the different kinds of message 1222 /// sends to determine what the underlying (statically known) type 1223 /// of the receiver will be; use \c getReceiverKind() to determine 1224 /// whether the message is a class or an instance method, whether it 1225 /// is a send to super or not, etc. 1226 /// 1227 /// \returns The type of the receiver. 1228 QualType getReceiverType() const; 1229 1230 /// \brief Retrieve the Objective-C interface to which this message 1231 /// is being directed, if known. 1232 /// 1233 /// This routine cross-cuts all of the different kinds of message 1234 /// sends to determine what the underlying (statically known) type 1235 /// of the receiver will be; use \c getReceiverKind() to determine 1236 /// whether the message is a class or an instance method, whether it 1237 /// is a send to super or not, etc. 1238 /// 1239 /// \returns The Objective-C interface if known, otherwise NULL. 1240 ObjCInterfaceDecl *getReceiverInterface() const; 1241 1242 /// \brief Retrieve the type referred to by 'super'. 1243 /// 1244 /// The returned type will either be an ObjCInterfaceType (for an 1245 /// class message to super) or an ObjCObjectPointerType that refers 1246 /// to a class (for an instance message to super); 1247 QualType getSuperType() const { 1248 if (getReceiverKind() == SuperInstance || getReceiverKind() == SuperClass) 1249 return QualType::getFromOpaquePtr(getReceiverPointer()); 1250 1251 return QualType(); 1252 } 1253 1254 void setSuper(SourceLocation Loc, QualType T, bool IsInstanceSuper) { 1255 Kind = IsInstanceSuper? SuperInstance : SuperClass; 1256 SuperLoc = Loc; 1257 setReceiverPointer(T.getAsOpaquePtr()); 1258 } 1259 1260 Selector getSelector() const; 1261 1262 void setSelector(Selector S) { 1263 HasMethod = false; 1264 SelectorOrMethod = reinterpret_cast<uintptr_t>(S.getAsOpaquePtr()); 1265 } 1266 1267 const ObjCMethodDecl *getMethodDecl() const { 1268 if (HasMethod) 1269 return reinterpret_cast<const ObjCMethodDecl *>(SelectorOrMethod); 1270 1271 return 0; 1272 } 1273 1274 ObjCMethodDecl *getMethodDecl() { 1275 if (HasMethod) 1276 return reinterpret_cast<ObjCMethodDecl *>(SelectorOrMethod); 1277 1278 return 0; 1279 } 1280 1281 void setMethodDecl(ObjCMethodDecl *MD) { 1282 HasMethod = true; 1283 SelectorOrMethod = reinterpret_cast<uintptr_t>(MD); 1284 } 1285 1286 ObjCMethodFamily getMethodFamily() const { 1287 if (HasMethod) return getMethodDecl()->getMethodFamily(); 1288 return getSelector().getMethodFamily(); 1289 } 1290 1291 /// \brief Return the number of actual arguments in this message, 1292 /// not counting the receiver. 1293 unsigned getNumArgs() const { return NumArgs; } 1294 1295 /// \brief Retrieve the arguments to this message, not including the 1296 /// receiver. 1297 Expr **getArgs() { 1298 return reinterpret_cast<Expr **>(this + 1) + 1; 1299 } 1300 const Expr * const *getArgs() const { 1301 return reinterpret_cast<const Expr * const *>(this + 1) + 1; 1302 } 1303 1304 /// getArg - Return the specified argument. 1305 Expr *getArg(unsigned Arg) { 1306 assert(Arg < NumArgs && "Arg access out of range!"); 1307 return cast<Expr>(getArgs()[Arg]); 1308 } 1309 const Expr *getArg(unsigned Arg) const { 1310 assert(Arg < NumArgs && "Arg access out of range!"); 1311 return cast<Expr>(getArgs()[Arg]); 1312 } 1313 /// setArg - Set the specified argument. 1314 void setArg(unsigned Arg, Expr *ArgExpr) { 1315 assert(Arg < NumArgs && "Arg access out of range!"); 1316 getArgs()[Arg] = ArgExpr; 1317 } 1318 1319 /// isDelegateInitCall - Answers whether this message send has been 1320 /// tagged as a "delegate init call", i.e. a call to a method in the 1321 /// -init family on self from within an -init method implementation. 1322 bool isDelegateInitCall() const { return IsDelegateInitCall; } 1323 void setDelegateInitCall(bool isDelegate) { IsDelegateInitCall = isDelegate; } 1324 1325 SourceLocation getLeftLoc() const { return LBracLoc; } 1326 SourceLocation getRightLoc() const { return RBracLoc; } 1327 1328 SourceLocation getSelectorStartLoc() const { 1329 if (isImplicit()) 1330 return getLocStart(); 1331 return getSelectorLoc(0); 1332 } 1333 SourceLocation getSelectorLoc(unsigned Index) const { 1334 assert(Index < getNumSelectorLocs() && "Index out of range!"); 1335 if (hasStandardSelLocs()) 1336 return getStandardSelectorLoc(Index, getSelector(), 1337 getSelLocsKind() == SelLoc_StandardWithSpace, 1338 llvm::makeArrayRef(const_cast<Expr**>(getArgs()), 1339 getNumArgs()), 1340 RBracLoc); 1341 return getStoredSelLocs()[Index]; 1342 } 1343 1344 void getSelectorLocs(SmallVectorImpl<SourceLocation> &SelLocs) const; 1345 1346 unsigned getNumSelectorLocs() const { 1347 if (isImplicit()) 1348 return 0; 1349 Selector Sel = getSelector(); 1350 if (Sel.isUnarySelector()) 1351 return 1; 1352 return Sel.getNumArgs(); 1353 } 1354 1355 void setSourceRange(SourceRange R) { 1356 LBracLoc = R.getBegin(); 1357 RBracLoc = R.getEnd(); 1358 } 1359 SourceLocation getLocStart() const LLVM_READONLY { return LBracLoc; } 1360 SourceLocation getLocEnd() const LLVM_READONLY { return RBracLoc; } 1361 1362 static bool classof(const Stmt *T) { 1363 return T->getStmtClass() == ObjCMessageExprClass; 1364 } 1365 1366 // Iterators 1367 child_range children(); 1368 1369 typedef ExprIterator arg_iterator; 1370 typedef ConstExprIterator const_arg_iterator; 1371 1372 arg_iterator arg_begin() { return reinterpret_cast<Stmt **>(getArgs()); } 1373 arg_iterator arg_end() { 1374 return reinterpret_cast<Stmt **>(getArgs() + NumArgs); 1375 } 1376 const_arg_iterator arg_begin() const { 1377 return reinterpret_cast<Stmt const * const*>(getArgs()); 1378 } 1379 const_arg_iterator arg_end() const { 1380 return reinterpret_cast<Stmt const * const*>(getArgs() + NumArgs); 1381 } 1382 1383 friend class ASTStmtReader; 1384 friend class ASTStmtWriter; 1385}; 1386 1387/// ObjCIsaExpr - Represent X->isa and X.isa when X is an ObjC 'id' type. 1388/// (similar in spirit to MemberExpr). 1389class ObjCIsaExpr : public Expr { 1390 /// Base - the expression for the base object pointer. 1391 Stmt *Base; 1392 1393 /// IsaMemberLoc - This is the location of the 'isa'. 1394 SourceLocation IsaMemberLoc; 1395 1396 /// OpLoc - This is the location of '.' or '->' 1397 SourceLocation OpLoc; 1398 1399 /// IsArrow - True if this is "X->F", false if this is "X.F". 1400 bool IsArrow; 1401public: 1402 ObjCIsaExpr(Expr *base, bool isarrow, SourceLocation l, SourceLocation oploc, 1403 QualType ty) 1404 : Expr(ObjCIsaExprClass, ty, VK_LValue, OK_Ordinary, 1405 /*TypeDependent=*/false, base->isValueDependent(), 1406 base->isInstantiationDependent(), 1407 /*ContainsUnexpandedParameterPack=*/false), 1408 Base(base), IsaMemberLoc(l), OpLoc(oploc), IsArrow(isarrow) {} 1409 1410 /// \brief Build an empty expression. 1411 explicit ObjCIsaExpr(EmptyShell Empty) : Expr(ObjCIsaExprClass, Empty) { } 1412 1413 void setBase(Expr *E) { Base = E; } 1414 Expr *getBase() const { return cast<Expr>(Base); } 1415 1416 bool isArrow() const { return IsArrow; } 1417 void setArrow(bool A) { IsArrow = A; } 1418 1419 /// getMemberLoc - Return the location of the "member", in X->F, it is the 1420 /// location of 'F'. 1421 SourceLocation getIsaMemberLoc() const { return IsaMemberLoc; } 1422 void setIsaMemberLoc(SourceLocation L) { IsaMemberLoc = L; } 1423 1424 SourceLocation getOpLoc() const { return OpLoc; } 1425 void setOpLoc(SourceLocation L) { OpLoc = L; } 1426 1427 SourceLocation getLocStart() const LLVM_READONLY { 1428 return getBase()->getLocStart(); 1429 } 1430 1431 SourceLocation getBaseLocEnd() const LLVM_READONLY { 1432 return getBase()->getLocEnd(); 1433 } 1434 1435 SourceLocation getLocEnd() const LLVM_READONLY { return IsaMemberLoc; } 1436 1437 SourceLocation getExprLoc() const LLVM_READONLY { return IsaMemberLoc; } 1438 1439 static bool classof(const Stmt *T) { 1440 return T->getStmtClass() == ObjCIsaExprClass; 1441 } 1442 1443 // Iterators 1444 child_range children() { return child_range(&Base, &Base+1); } 1445}; 1446 1447 1448/// ObjCIndirectCopyRestoreExpr - Represents the passing of a function 1449/// argument by indirect copy-restore in ARC. This is used to support 1450/// passing indirect arguments with the wrong lifetime, e.g. when 1451/// passing the address of a __strong local variable to an 'out' 1452/// parameter. This expression kind is only valid in an "argument" 1453/// position to some sort of call expression. 1454/// 1455/// The parameter must have type 'pointer to T', and the argument must 1456/// have type 'pointer to U', where T and U agree except possibly in 1457/// qualification. If the argument value is null, then a null pointer 1458/// is passed; otherwise it points to an object A, and: 1459/// 1. A temporary object B of type T is initialized, either by 1460/// zero-initialization (used when initializing an 'out' parameter) 1461/// or copy-initialization (used when initializing an 'inout' 1462/// parameter). 1463/// 2. The address of the temporary is passed to the function. 1464/// 3. If the call completes normally, A is move-assigned from B. 1465/// 4. Finally, A is destroyed immediately. 1466/// 1467/// Currently 'T' must be a retainable object lifetime and must be 1468/// __autoreleasing; this qualifier is ignored when initializing 1469/// the value. 1470class ObjCIndirectCopyRestoreExpr : public Expr { 1471 Stmt *Operand; 1472 1473 // unsigned ObjCIndirectCopyRestoreBits.ShouldCopy : 1; 1474 1475 friend class ASTReader; 1476 friend class ASTStmtReader; 1477 1478 void setShouldCopy(bool shouldCopy) { 1479 ObjCIndirectCopyRestoreExprBits.ShouldCopy = shouldCopy; 1480 } 1481 1482 explicit ObjCIndirectCopyRestoreExpr(EmptyShell Empty) 1483 : Expr(ObjCIndirectCopyRestoreExprClass, Empty) { } 1484 1485public: 1486 ObjCIndirectCopyRestoreExpr(Expr *operand, QualType type, bool shouldCopy) 1487 : Expr(ObjCIndirectCopyRestoreExprClass, type, VK_LValue, OK_Ordinary, 1488 operand->isTypeDependent(), operand->isValueDependent(), 1489 operand->isInstantiationDependent(), 1490 operand->containsUnexpandedParameterPack()), 1491 Operand(operand) { 1492 setShouldCopy(shouldCopy); 1493 } 1494 1495 Expr *getSubExpr() { return cast<Expr>(Operand); } 1496 const Expr *getSubExpr() const { return cast<Expr>(Operand); } 1497 1498 /// shouldCopy - True if we should do the 'copy' part of the 1499 /// copy-restore. If false, the temporary will be zero-initialized. 1500 bool shouldCopy() const { return ObjCIndirectCopyRestoreExprBits.ShouldCopy; } 1501 1502 child_range children() { return child_range(&Operand, &Operand+1); } 1503 1504 // Source locations are determined by the subexpression. 1505 SourceLocation getLocStart() const LLVM_READONLY { 1506 return Operand->getLocStart(); 1507 } 1508 SourceLocation getLocEnd() const LLVM_READONLY { return Operand->getLocEnd();} 1509 1510 SourceLocation getExprLoc() const LLVM_READONLY { 1511 return getSubExpr()->getExprLoc(); 1512 } 1513 1514 static bool classof(const Stmt *s) { 1515 return s->getStmtClass() == ObjCIndirectCopyRestoreExprClass; 1516 } 1517}; 1518 1519/// \brief An Objective-C "bridged" cast expression, which casts between 1520/// Objective-C pointers and C pointers, transferring ownership in the process. 1521/// 1522/// \code 1523/// NSString *str = (__bridge_transfer NSString *)CFCreateString(); 1524/// \endcode 1525class ObjCBridgedCastExpr : public ExplicitCastExpr { 1526 SourceLocation LParenLoc; 1527 SourceLocation BridgeKeywordLoc; 1528 unsigned Kind : 2; 1529 1530 friend class ASTStmtReader; 1531 friend class ASTStmtWriter; 1532 1533public: 1534 ObjCBridgedCastExpr(SourceLocation LParenLoc, ObjCBridgeCastKind Kind, 1535 CastKind CK, SourceLocation BridgeKeywordLoc, 1536 TypeSourceInfo *TSInfo, Expr *Operand) 1537 : ExplicitCastExpr(ObjCBridgedCastExprClass, TSInfo->getType(), VK_RValue, 1538 CK, Operand, 0, TSInfo), 1539 LParenLoc(LParenLoc), BridgeKeywordLoc(BridgeKeywordLoc), Kind(Kind) { } 1540 1541 /// \brief Construct an empty Objective-C bridged cast. 1542 explicit ObjCBridgedCastExpr(EmptyShell Shell) 1543 : ExplicitCastExpr(ObjCBridgedCastExprClass, Shell, 0) { } 1544 1545 SourceLocation getLParenLoc() const { return LParenLoc; } 1546 1547 /// \brief Determine which kind of bridge is being performed via this cast. 1548 ObjCBridgeCastKind getBridgeKind() const { 1549 return static_cast<ObjCBridgeCastKind>(Kind); 1550 } 1551 1552 /// \brief Retrieve the kind of bridge being performed as a string. 1553 StringRef getBridgeKindName() const; 1554 1555 /// \brief The location of the bridge keyword. 1556 SourceLocation getBridgeKeywordLoc() const { return BridgeKeywordLoc; } 1557 1558 SourceLocation getLocStart() const LLVM_READONLY { return LParenLoc; } 1559 SourceLocation getLocEnd() const LLVM_READONLY { 1560 return getSubExpr()->getLocEnd(); 1561 } 1562 1563 static bool classof(const Stmt *T) { 1564 return T->getStmtClass() == ObjCBridgedCastExprClass; 1565 } 1566}; 1567 1568} // end namespace clang 1569 1570#endif 1571