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