DeclObjC.h revision 8cc488fefb2fb04bc8d5398da29f0182f97934cf
1980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff//===--- DeclObjC.h - Classes for representing declarations -----*- C++ -*-===//
2980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff//
3980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff//                     The LLVM Compiler Infrastructure
4980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff//
50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source
60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details.
7980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff//
8980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff//===----------------------------------------------------------------------===//
9980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff//
10980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff//  This file defines the DeclObjC interface and subclasses.
11980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff//
12980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff//===----------------------------------------------------------------------===//
13980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
14980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff#ifndef LLVM_CLANG_AST_DECLOBJC_H
15980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff#define LLVM_CLANG_AST_DECLOBJC_H
16980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
17980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff#include "clang/AST/Decl.h"
186ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson#include "llvm/ADT/STLExtras.h"
19980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
20980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffnamespace clang {
21980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffclass Expr;
22980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffclass Stmt;
23980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffclass FunctionDecl;
2460f8c868ffb346b78451a3eccaecd0461d2ae498Fariborz Jahanianclass RecordDecl;
25a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCIvarDecl;
26a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCMethodDecl;
27a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCProtocolDecl;
28a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCCategoryDecl;
29a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCPropertyDecl;
30f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanianclass ObjCPropertyImplDecl;
31cbb67480094b3bcb5b715acd827cbad55e2a204cSean Huntclass CXXCtorInitializer;
3268835718c4125f2f66740cd04de7088645ec695dChris Lattner
33793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnerclass ObjCListBase {
34793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  void operator=(const ObjCListBase &);     // DO NOT IMPLEMENT
35793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  ObjCListBase(const ObjCListBase&);        // DO NOT IMPLEMENT
36793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnerprotected:
37793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  /// List is an array of pointers to objects that are not owned by this object.
38793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  void **List;
393db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  unsigned NumElts;
40793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner
413db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattnerpublic:
42793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  ObjCListBase() : List(0), NumElts(0) {}
43793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  unsigned size() const { return NumElts; }
44793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  bool empty() const { return NumElts == 0; }
451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
46793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnerprotected:
4738af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  void set(void *const* InList, unsigned Elts, ASTContext &Ctx);
48793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner};
491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
51793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner/// ObjCList - This is a simple template class used to hold various lists of
52793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner/// decls etc, which is heavily used by the ObjC front-end.  This only use case
53793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner/// this supports is setting the list all at once and then reading elements out
54793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner/// of it.
55793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnertemplate <typename T>
56793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnerclass ObjCList : public ObjCListBase {
57793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnerpublic:
5838af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  void set(T* const* InList, unsigned Elts, ASTContext &Ctx) {
5938af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner    ObjCListBase::set(reinterpret_cast<void*const*>(InList), Elts, Ctx);
60793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  }
611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
62793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  typedef T* const * iterator;
63793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  iterator begin() const { return (iterator)List; }
64793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  iterator end() const { return (iterator)List+NumElts; }
651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
66793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  T* operator[](unsigned Idx) const {
67793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner    assert(Idx < NumElts && "Invalid access");
68793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner    return (T*)List[Idx];
693db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  }
703db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner};
713db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner
7218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor/// \brief A list of Objective-C protocols, along with the source
7318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor/// locations at which they were referenced.
7418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregorclass ObjCProtocolList : public ObjCList<ObjCProtocolDecl> {
7518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  SourceLocation *Locations;
7618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor
7718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  using ObjCList<ObjCProtocolDecl>::set;
7818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor
7918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregorpublic:
8018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  ObjCProtocolList() : ObjCList<ObjCProtocolDecl>(), Locations(0) { }
8118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor
8218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef const SourceLocation *loc_iterator;
8318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  loc_iterator loc_begin() const { return Locations; }
8418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  loc_iterator loc_end() const { return Locations + size(); }
8518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor
8618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  void set(ObjCProtocolDecl* const* InList, unsigned Elts,
8718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor           const SourceLocation *Locs, ASTContext &Ctx);
8818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor};
891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff
91a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCMethodDecl - Represents an instance or class method declaration.
9258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// ObjC methods can be declared within 4 contexts: class interfaces,
9358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// categories, protocols, and class implementations. While C++ member
941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// functions leverage C syntax, Objective-C method syntax is modeled after
951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Smalltalk (using colons to specify argument types/expressions).
9658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Here are some brief examples:
9758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff///
9858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Setter/getter instance methods:
9958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// - (void)setMenu:(NSMenu *)menu;
1001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// - (NSMenu *)menu;
1011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
10258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Instance method that takes 2 NSView arguments:
10358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// - (void)replaceSubview:(NSView *)oldView with:(NSView *)newView;
10458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff///
10558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Getter class method:
10658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// + (NSMenu *)defaultMenu;
10758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff///
10858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// A selector represents a unique name for a method. The selector names for
10958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// the above methods are setMenu:, menu, replaceSubview:with:, and defaultMenu.
11058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff///
1114afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCMethodDecl : public NamedDecl, public DeclContext {
11258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroffpublic:
11358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  enum ImplementationControl { None, Required, Optional };
11458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroffprivate:
11585f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  // The conventional meaning of this method; an ObjCMethodFamily.
11685f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  // This is not serialized; instead, it is computed on demand and
11785f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  // cached.
11885f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  mutable unsigned Family : ObjCMethodFamilyBitWidth;
11985f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall
12058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  /// instance (true) or class (false) method.
12185f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  unsigned IsInstance : 1;
12285f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  unsigned IsVariadic : 1;
1231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1244607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian  // Synthesized declaration method for a property setter/getter
12585f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  unsigned IsSynthesized : 1;
1263fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian
1273fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian  // Method has a definition.
12885f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  unsigned IsDefined : 1;
1291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
130ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  // NOTE: VC++ treats enums as signed, avoid using ImplementationControl enum
13158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  /// @required/@optional
132ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  unsigned DeclImplementation : 2;
1331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
134ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  // NOTE: VC++ treats enums as signed, avoid using the ObjCDeclQualifier enum
13558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  /// in, inout, etc.
136ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  unsigned objcDeclQualifier : 6;
1371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
138926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor  /// \brief Indicates whether this method has a related result type.
139926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor  unsigned RelatedResultType : 1;
140926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor
1417732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian  // Number of args separated by ':' in a method declaration.
1427732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian  unsigned NumSelectorArgs;
1437732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian
1444bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor  // Result type of this method.
14558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  QualType MethodDeclType;
1464bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor
1474bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor  // Type source information for the result type.
1484bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor  TypeSourceInfo *ResultTInfo;
1494bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor
1502073216a1075767b5d25c23d1462b7034686d94dChris Lattner  /// ParamInfo - List of pointers to VarDecls for the formal parameters of this
1512073216a1075767b5d25c23d1462b7034686d94dChris Lattner  /// Method.
1522073216a1075767b5d25c23d1462b7034686d94dChris Lattner  ObjCList<ParmVarDecl> ParamInfo;
1531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  /// List of attributes for this method declaration.
155a2e85ada1dfef36201a31f6646bc4ea3bd76a89aArgyrios Kyrtzidis  SourceLocation EndLoc; // the location of the ';' or '}'.
1561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  // The following are only used for method definitions, null otherwise.
15858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  // FIXME: space savings opportunity, consider a sub-class.
15958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  Stmt *Body;
160451318c08a6342c10b8986060386fd9274418437Daniel Dunbar
161451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// SelfDecl - Decl for the implicit self parameter. This is lazily
162451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// constructed by createImplicitParams.
1634111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  ImplicitParamDecl *SelfDecl;
164451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// CmdDecl - Decl for the implicit _cmd parameter. This is lazily
165451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// constructed by createImplicitParams.
1664111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  ImplicitParamDecl *CmdDecl;
1671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
168a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCMethodDecl(SourceLocation beginLoc, SourceLocation endLoc,
16958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff                 Selector SelInfo, QualType T,
1704bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor                 TypeSourceInfo *ResultTInfo,
1710701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff                 DeclContext *contextDecl,
172f6414927e67e27d9324d8d179c5f7ea620443924Daniel Dunbar                 bool isInstance = true,
17358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff                 bool isVariadic = false,
1744607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian                 bool isSynthesized = false,
1753fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian                 bool isDefined = false,
1767732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian                 ImplementationControl impControl = None,
177926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor                 bool HasRelatedResultType = false,
1787732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian                 unsigned numSelectorArgs = 0)
1794afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  : NamedDecl(ObjCMethod, contextDecl, beginLoc, SelInfo),
18085f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall    DeclContext(ObjCMethod), Family(InvalidObjCMethodFamily),
18158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff    IsInstance(isInstance), IsVariadic(isVariadic),
1824607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian    IsSynthesized(isSynthesized),
1833fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian    IsDefined(isDefined),
18458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff    DeclImplementation(impControl), objcDeclQualifier(OBJC_TQ_None),
185926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor    RelatedResultType(HasRelatedResultType), NumSelectorArgs(numSelectorArgs),
186926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor    MethodDeclType(T), ResultTInfo(ResultTInfo),
1874111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner    EndLoc(endLoc), Body(0), SelfDecl(0), CmdDecl(0) {}
1888a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek
18957ea6bee79cc60ba20c7886b453f40f380dce1b1Argyrios Kyrtzidis  /// \brief A definition will return its interface declaration.
19057ea6bee79cc60ba20c7886b453f40f380dce1b1Argyrios Kyrtzidis  /// An interface declaration will return its definition.
19157ea6bee79cc60ba20c7886b453f40f380dce1b1Argyrios Kyrtzidis  /// Otherwise it will return itself.
192da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor  virtual ObjCMethodDecl *getNextRedeclaration();
193da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor
1946c4ae5de0c356777446f823b573821fb95560d91Chris Lattnerpublic:
1950ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner  static ObjCMethodDecl *Create(ASTContext &C,
1961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                SourceLocation beginLoc,
1976c4ae5de0c356777446f823b573821fb95560d91Chris Lattner                                SourceLocation endLoc, Selector SelInfo,
1984bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor                                QualType T,
1994bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor                                TypeSourceInfo *ResultTInfo,
2004bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor                                DeclContext *contextDecl,
201f6414927e67e27d9324d8d179c5f7ea620443924Daniel Dunbar                                bool isInstance = true,
2026c4ae5de0c356777446f823b573821fb95560d91Chris Lattner                                bool isVariadic = false,
2034607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian                                bool isSynthesized = false,
2043fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian                                bool isDefined = false,
2057732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian                                ImplementationControl impControl = None,
206926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor                                bool HasRelatedResultType = false,
2077732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian                                unsigned numSelectorArgs = 0);
208e7f9d301a10b4b3223e91d9be4362b44cba0a212Argyrios Kyrtzidis
209da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor  virtual ObjCMethodDecl *getCanonicalDecl();
21013e635c55eb23f736d38abf9c954801bd6482db4Ted Kremenek  const ObjCMethodDecl *getCanonicalDecl() const {
21113e635c55eb23f736d38abf9c954801bd6482db4Ted Kremenek    return const_cast<ObjCMethodDecl*>(this)->getCanonicalDecl();
21213e635c55eb23f736d38abf9c954801bd6482db4Ted Kremenek  }
213e7f9d301a10b4b3223e91d9be4362b44cba0a212Argyrios Kyrtzidis
214ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  ObjCDeclQualifier getObjCDeclQualifier() const {
215ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek    return ObjCDeclQualifier(objcDeclQualifier);
216ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  }
217a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void setObjCDeclQualifier(ObjCDeclQualifier QV) { objcDeclQualifier = QV; }
2181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
219926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor  /// \brief Determine whether this method has a result type that is related
220926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor  /// to the message receiver's type.
221926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor  bool hasRelatedResultType() const { return RelatedResultType; }
222926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor
223926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor  /// \brief Note whether this method has a related result type.
224926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor  void SetRelatedResultType(bool RRT = true) { RelatedResultType = RRT; }
225926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor
2267732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian  unsigned getNumSelectorArgs() const { return NumSelectorArgs; }
2277732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian  void setNumSelectorArgs(unsigned numSelectorArgs) {
2287732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian    NumSelectorArgs = numSelectorArgs;
2297732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian  }
2307732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian
23158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  // Location information, modeled after the Stmt API.
23258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  SourceLocation getLocStart() const { return getLocation(); }
23358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  SourceLocation getLocEnd() const { return EndLoc; }
23453c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setEndLoc(SourceLocation Loc) { EndLoc = Loc; }
235da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor  virtual SourceRange getSourceRange() const {
2361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(getLocation(), EndLoc);
2379776ba0d844cf9f6888e871e3fd246ae782f76f4Daniel Dunbar  }
2381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2395619688510185081cbb4621d703daf7ee24cf39aChris Lattner  ObjCInterfaceDecl *getClassInterface();
2405619688510185081cbb4621d703daf7ee24cf39aChris Lattner  const ObjCInterfaceDecl *getClassInterface() const {
2415619688510185081cbb4621d703daf7ee24cf39aChris Lattner    return const_cast<ObjCMethodDecl*>(this)->getClassInterface();
242e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  }
2431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2442e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  Selector getSelector() const { return getDeclName().getObjCSelector(); }
2453a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson
24658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  QualType getResultType() const { return MethodDeclType; }
24753c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setResultType(QualType T) { MethodDeclType = T; }
2481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2495291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// \brief Determine the type of an expression that sends a message to this
2505291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// function.
2515291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  QualType getSendResultType() const {
2526398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor    return getResultType().getNonLValueExprType(getASTContext());
2535291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  }
2545291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor
2554bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor  TypeSourceInfo *getResultTypeSourceInfo() const { return ResultTInfo; }
2564bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor  void setResultTypeSourceInfo(TypeSourceInfo *TInfo) { ResultTInfo = TInfo; }
2574bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor
258d57f635d520e8cb5b93d3d770ff58db06c62de54Chris Lattner  // Iterator access to formal parameters.
2592073216a1075767b5d25c23d1462b7034686d94dChris Lattner  unsigned param_size() const { return ParamInfo.size(); }
2602073216a1075767b5d25c23d1462b7034686d94dChris Lattner  typedef ObjCList<ParmVarDecl>::iterator param_iterator;
2612073216a1075767b5d25c23d1462b7034686d94dChris Lattner  param_iterator param_begin() const { return ParamInfo.begin(); }
2622073216a1075767b5d25c23d1462b7034686d94dChris Lattner  param_iterator param_end() const { return ParamInfo.end(); }
2637732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian  // This method returns and of the parameters which are part of the selector
2647732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian  // name mangling requirements.
2657732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian  param_iterator sel_param_end() const {
2667732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian    return ParamInfo.begin() + NumSelectorArgs;
2677732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian  }
26889951a86b594513c2a013532ed45d197413b1087Chris Lattner
2694ecb25fa94897b2c03510292acace710e5262ba5Fariborz Jahanian  void setMethodParams(ASTContext &C, ParmVarDecl *const *List, unsigned Num,
2704ecb25fa94897b2c03510292acace710e5262ba5Fariborz Jahanian                       unsigned numSelectorArgs) {
27138af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner    ParamInfo.set(List, Num, C);
2724ecb25fa94897b2c03510292acace710e5262ba5Fariborz Jahanian    NumSelectorArgs = numSelectorArgs;
2732073216a1075767b5d25c23d1462b7034686d94dChris Lattner  }
2744111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner
2756ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson  // Iterator access to parameter types.
2766ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson  typedef std::const_mem_fun_t<QualType, ParmVarDecl> deref_fun;
2776ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson  typedef llvm::mapped_iterator<param_iterator, deref_fun> arg_type_iterator;
2786ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson
2796ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson  arg_type_iterator arg_type_begin() const {
2806ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson    return llvm::map_iterator(param_begin(), deref_fun(&ParmVarDecl::getType));
2816ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson  }
2826ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson  arg_type_iterator arg_type_end() const {
2836ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson    return llvm::map_iterator(param_end(), deref_fun(&ParmVarDecl::getType));
2846ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson  }
2851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
286451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// createImplicitParams - Used to lazily create the self and cmd
287451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// implict parameters. This must be called prior to using getSelfDecl()
288451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// or getCmdDecl(). The call is ignored if the implicit paramters
289451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// have already been created.
290fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian  void createImplicitParams(ASTContext &Context, const ObjCInterfaceDecl *ID);
291451318c08a6342c10b8986060386fd9274418437Daniel Dunbar
2924111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  ImplicitParamDecl * getSelfDecl() const { return SelfDecl; }
29353c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setSelfDecl(ImplicitParamDecl *SD) { SelfDecl = SD; }
2944111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  ImplicitParamDecl * getCmdDecl() const { return CmdDecl; }
29553c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setCmdDecl(ImplicitParamDecl *CD) { CmdDecl = CD; }
2961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
29785f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  /// Determines the family of this method.
29885f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  ObjCMethodFamily getMethodFamily() const;
29985f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall
300f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor  bool isInstanceMethod() const { return IsInstance; }
30153c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setInstanceMethod(bool isInst) { IsInstance = isInst; }
30258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  bool isVariadic() const { return IsVariadic; }
30353c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setVariadic(bool isVar) { IsVariadic = isVar; }
3041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
305f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor  bool isClassMethod() const { return !IsInstance; }
306f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor
3074607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian  bool isSynthesized() const { return IsSynthesized; }
30853c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setSynthesized(bool isSynth) { IsSynthesized = isSynth; }
3093fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian
3103fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian  bool isDefined() const { return IsDefined; }
3113fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian  void setDefined(bool isDefined) { IsDefined = isDefined; }
3121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  // Related to protocols declared in  @protocol
3141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setDeclImplementation(ImplementationControl ic) {
3151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    DeclImplementation = ic;
31658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  }
3171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ImplementationControl getImplementationControl() const {
3181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return ImplementationControl(DeclImplementation);
31958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  }
320792481eec23d8c1aa92173be589e2ae9d02514a5Ted Kremenek
321da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor  virtual Stmt *getBody() const {
3221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return (Stmt*) Body;
3237297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor  }
3246fb0aee4f9dc261bbec72e1283ad8dc0557a6d96Argyrios Kyrtzidis  CompoundStmt *getCompoundBody() { return (CompoundStmt*)Body; }
325d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl  void setBody(Stmt *B) { Body = B; }
32658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff
32766570b230941651245accbc5680b60e904eb993cArgyrios Kyrtzidis  /// \brief Returns whether this specific method is a definition.
32866570b230941651245accbc5680b60e904eb993cArgyrios Kyrtzidis  bool isThisDeclarationADefinition() const { return Body; }
32966570b230941651245accbc5680b60e904eb993cArgyrios Kyrtzidis
33058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  // Implement isa/cast/dyncast/etc.
33180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
332a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCMethodDecl *D) { return true; }
33380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCMethod; }
33442220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  static DeclContext *castToDeclContext(const ObjCMethodDecl *D) {
33542220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis    return static_cast<DeclContext *>(const_cast<ObjCMethodDecl*>(D));
33642220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  }
33742220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  static ObjCMethodDecl *castFromDeclContext(const DeclContext *DC) {
33842220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis    return static_cast<ObjCMethodDecl *>(const_cast<DeclContext*>(DC));
33942220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  }
34058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff};
341e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
342e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff/// ObjCContainerDecl - Represents a container for method declarations.
343aecae629269fae3bf484baf1d109e9a89d14eeadArgyrios Kyrtzidis/// Current sub-classes are ObjCInterfaceDecl, ObjCCategoryDecl,
3441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ObjCProtocolDecl, and ObjCImplDecl.
345e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff///
3464afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCContainerDecl : public NamedDecl, public DeclContext {
347782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  // These two locations in the range mark the end of the method container.
348782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  // The first points to the '@' token, and the second to the 'end' token.
349782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  SourceRange AtEnd;
350e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroffpublic:
351e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
3521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ObjCContainerDecl(Kind DK, DeclContext *DC, SourceLocation L,
353d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor                    IdentifierInfo *Id)
3544afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor    : NamedDecl(DK, DC, L, Id), DeclContext(DK) {}
355e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
35693983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff  // Iterator access to properties.
35793983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff  typedef specific_decl_iterator<ObjCPropertyDecl> prop_iterator;
3581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  prop_iterator prop_begin() const {
35917945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return prop_iterator(decls_begin());
36093983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff  }
3611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  prop_iterator prop_end() const {
36217945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return prop_iterator(decls_end());
36309c4719788a5cea09897525e528fa00420f1677bSteve Naroff  }
3641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3650701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  // Iterator access to instance/class methods.
366f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor  typedef specific_decl_iterator<ObjCMethodDecl> method_iterator;
3671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  method_iterator meth_begin() const {
36817945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return method_iterator(decls_begin());
3697ed4faca5162b3ab85be7f7e57aa40e6ec170971Ted Kremenek  }
3701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  method_iterator meth_end() const {
37117945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return method_iterator(decls_end());
3727ed4faca5162b3ab85be7f7e57aa40e6ec170971Ted Kremenek  }
3730701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
3741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  typedef filtered_decl_iterator<ObjCMethodDecl,
3751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                 &ObjCMethodDecl::isInstanceMethod>
376669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor    instmeth_iterator;
37717945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  instmeth_iterator instmeth_begin() const {
37817945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return instmeth_iterator(decls_begin());
379e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff  }
38017945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  instmeth_iterator instmeth_end() const {
38117945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return instmeth_iterator(decls_end());
382e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff  }
383e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
3841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  typedef filtered_decl_iterator<ObjCMethodDecl,
3851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                 &ObjCMethodDecl::isClassMethod>
386669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor    classmeth_iterator;
38717945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  classmeth_iterator classmeth_begin() const {
38817945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return classmeth_iterator(decls_begin());
389e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff  }
39017945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  classmeth_iterator classmeth_end() const {
39117945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return classmeth_iterator(decls_end());
3920701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  }
3930701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
3940701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  // Get the local instance/class method declared in this interface.
395467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis  ObjCMethodDecl *getMethod(Selector Sel, bool isInstance) const;
396467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis  ObjCMethodDecl *getInstanceMethod(Selector Sel) const {
397467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis    return getMethod(Sel, true/*isInstance*/);
39853df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner  }
399467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis  ObjCMethodDecl *getClassMethod(Selector Sel) const {
400467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis    return getMethod(Sel, false/*isInstance*/);
401467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis  }
402467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis  ObjCIvarDecl *getIvarDecl(IdentifierInfo *Id) const;
4031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
40417945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  ObjCPropertyDecl *FindPropertyDeclaration(IdentifierInfo *PropertyId) const;
40593983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff
406e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff  // Marks the end of the container.
407782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  SourceRange getAtEndRange() const {
408782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek    return AtEnd;
409782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  }
410782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  void setAtEndRange(SourceRange atEnd) {
411782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek    AtEnd = atEnd;
412782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  }
413ddfd4c9eda34765b08fae4cb31ad5a365face107Argyrios Kyrtzidis
414da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor  virtual SourceRange getSourceRange() const {
415782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek    return SourceRange(getLocation(), getAtEndRange().getEnd());
416ddfd4c9eda34765b08fae4cb31ad5a365face107Argyrios Kyrtzidis  }
4171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
41809c4719788a5cea09897525e528fa00420f1677bSteve Naroff  // Implement isa/cast/dyncast/etc.
41980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
42009c4719788a5cea09897525e528fa00420f1677bSteve Naroff  static bool classof(const ObjCContainerDecl *D) { return true; }
42180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) {
4229a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt    return K >= firstObjCContainer &&
4239a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt           K <= lastObjCContainer;
42480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  }
42509c4719788a5cea09897525e528fa00420f1677bSteve Naroff
42609c4719788a5cea09897525e528fa00420f1677bSteve Naroff  static DeclContext *castToDeclContext(const ObjCContainerDecl *D) {
42709c4719788a5cea09897525e528fa00420f1677bSteve Naroff    return static_cast<DeclContext *>(const_cast<ObjCContainerDecl*>(D));
42809c4719788a5cea09897525e528fa00420f1677bSteve Naroff  }
42909c4719788a5cea09897525e528fa00420f1677bSteve Naroff  static ObjCContainerDecl *castFromDeclContext(const DeclContext *DC) {
43009c4719788a5cea09897525e528fa00420f1677bSteve Naroff    return static_cast<ObjCContainerDecl *>(const_cast<DeclContext*>(DC));
43109c4719788a5cea09897525e528fa00420f1677bSteve Naroff  }
432e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff};
433e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
434a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCInterfaceDecl - Represents an ObjC class declaration. For example:
4350c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
4360c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   // MostPrimitive declares no super class (not particularly useful).
4371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///   @interface MostPrimitive
4380c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     // no instance variables or methods.
4390c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @end
4400c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
4411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///   // NSResponder inherits from NSObject & implements NSCoding (a protocol).
4420c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @interface NSResponder : NSObject <NSCoding>
443a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek///   { // instance variables are represented by ObjCIvarDecl.
4440c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     id nextResponder; // nextResponder instance variable.
4450c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   }
4460c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   - (NSResponder *)nextResponder; // return a pointer to NSResponder.
4470c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   - (void)mouseMoved:(NSEvent *)theEvent; // return void, takes a pointer
4480c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @end                                    // to an NSEvent.
4490c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
4500c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   Unlike C/C++, forward class declarations are accomplished with @class.
4510c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   Unlike C/C++, @class allows for a list of classes to be forward declared.
4520c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   Unlike C++, ObjC is a single-rooted class model. In Cocoa, classes
4530c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   typically inherit from NSObject (an exception is NSProxy).
4540c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
455deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregorclass ObjCInterfaceDecl : public ObjCContainerDecl {
4563110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff  /// TypeForDecl - This indicates the Type object that represents this
4573110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff  /// TypeDecl.  It is a cache maintained by ASTContext::getObjCInterfaceType
458f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  mutable const Type *TypeForDecl;
4593110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff  friend class ASTContext;
4601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
461980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  /// Class's super class.
462a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *SuperClass;
4631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
46453b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  /// Protocols referenced in the @interface  declaration
46518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  ObjCProtocolList ReferencedProtocols;
46653b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
46753b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  /// Protocols reference in both the @interface and class extensions.
46853b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  ObjCList<ObjCProtocolDecl> AllReferencedProtocols;
4691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4708c99d88a6cfa14fc2edab819d5e4325c973b2809Douglas Gregor  /// \brief List of categories and class extensions defined for this class.
4718c99d88a6cfa14fc2edab819d5e4325c973b2809Douglas Gregor  ///
4728c99d88a6cfa14fc2edab819d5e4325c973b2809Douglas Gregor  /// Categories are stored as a linked list in the AST, since the categories
4738c99d88a6cfa14fc2edab819d5e4325c973b2809Douglas Gregor  /// and class extensions come long after the initial interface declaration,
474fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner  /// and we avoid dynamically-resized arrays in the AST wherever possible.
475a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCCategoryDecl *CategoryList;
4762c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian
4772c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  /// IvarList - List of all ivars defined by this class; including class
4782c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  /// extensions and implementation. This list is built lazily.
4792c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  ObjCIvarDecl *IvarList;
4801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4813a3ca1b35a7121aea0bf465a192dce748465e10fFariborz Jahanian  bool ForwardDecl:1; // declared with @class.
4823a3ca1b35a7121aea0bf465a192dce748465e10fFariborz Jahanian  bool InternalInterface:1; // true - no @interface for @implementation
48326ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
48426ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  /// \brief Indicates that the contents of this Objective-C class will be
48526ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  /// completed by the external AST source when required.
48626ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  mutable bool ExternallyCompleted : 1;
48726ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
488d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff  SourceLocation ClassLoc; // location of the class identifier.
489d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff  SourceLocation SuperClassLoc; // location of the super class identifier.
490f908a87299d278164540f90b5b6e6cab7b14fb41Steve Naroff  SourceLocation EndLoc; // marks the '>', '}', or identifier.
4910e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner
492d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id,
493deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor                    SourceLocation CLoc, bool FD, bool isInternal);
4941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
49526ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  void LoadExternalDefinition() const;
4960e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattnerpublic:
497d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCInterfaceDecl *Create(ASTContext &C, DeclContext *DC,
4980ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner                                   SourceLocation atLoc,
4991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                   IdentifierInfo *Id,
500deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor                                   SourceLocation ClassLoc = SourceLocation(),
5010e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner                                   bool ForwardDecl = false,
5020e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner                                   bool isInternal = false);
50326ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
50426ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  /// \brief Indicate that this Objective-C class is complete, but that
50526ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  /// the external AST source will be responsible for filling in its contents
50626ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  /// when a complete class is required.
50726ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  void setExternallyCompleted();
50826ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
50918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  const ObjCProtocolList &getReferencedProtocols() const {
51026ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor    if (ExternallyCompleted)
51126ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
51226ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
5131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return ReferencedProtocols;
5147ed9e0f97f4645edc5d4670385b985ea4c617ce7Fariborz Jahanian  }
5158a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis
5168a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis  ObjCImplementationDecl *getImplementation() const;
5178a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis  void setImplementation(ObjCImplementationDecl *ImplD);
5188a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis
519559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  ObjCCategoryDecl *FindCategoryDeclaration(IdentifierInfo *CategoryId) const;
5201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5211cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis  // Get the local instance/class method declared in a category.
5221cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis  ObjCMethodDecl *getCategoryInstanceMethod(Selector Sel) const;
5231cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis  ObjCMethodDecl *getCategoryClassMethod(Selector Sel) const;
5241cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis  ObjCMethodDecl *getCategoryMethod(Selector Sel, bool isInstance) const {
5251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return isInstance ? getInstanceMethod(Sel)
5261cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis                      : getClassMethod(Sel);
5271cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis  }
5283db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner
52918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::iterator protocol_iterator;
53053b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
53153b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  protocol_iterator protocol_begin() const {
53226ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor    if (ExternallyCompleted)
53326ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
53426ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
53553b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek    return ReferencedProtocols.begin();
53653b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  }
53753b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  protocol_iterator protocol_end() const {
53826ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor    if (ExternallyCompleted)
53926ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
54026ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
54153b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek    return ReferencedProtocols.end();
54253b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  }
54353b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
54418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
54553b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
54618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  protocol_loc_iterator protocol_loc_begin() const {
54726ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor    if (ExternallyCompleted)
54826ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
54926ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
55018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    return ReferencedProtocols.loc_begin();
55118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
55253b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
55318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  protocol_loc_iterator protocol_loc_end() const {
55426ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor    if (ExternallyCompleted)
55526ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
55626ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
55718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    return ReferencedProtocols.loc_end();
55818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
55953b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
56053b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  typedef ObjCList<ObjCProtocolDecl>::iterator all_protocol_iterator;
56153b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
56253b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  all_protocol_iterator all_referenced_protocol_begin() const {
56326ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor    if (ExternallyCompleted)
56426ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
56526ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
56653b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek    return AllReferencedProtocols.empty() ? protocol_begin()
56753b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek      : AllReferencedProtocols.begin();
56853b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  }
56953b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  all_protocol_iterator all_referenced_protocol_end() const {
57026ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor    if (ExternallyCompleted)
57126ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
57226ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
57353b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek    return AllReferencedProtocols.empty() ? protocol_end()
57453b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek      : AllReferencedProtocols.end();
57553b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  }
576291be393aa33759e6e34b6429c5ffa206ba50115Douglas Gregor
57711062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian  typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
57853b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
57911062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian  ivar_iterator ivar_begin() const { return  ivar_iterator(decls_begin()); }
58011062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian  ivar_iterator ivar_end() const { return ivar_iterator(decls_end()); }
58153b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
58211062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian  unsigned ivar_size() const {
58311062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian    return std::distance(ivar_begin(), ivar_end());
58411062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian  }
58553b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
58611062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian  bool ivar_empty() const { return ivar_begin() == ivar_end(); }
5872c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian
5882c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  ObjCIvarDecl  *all_declared_ivar_begin();
5892c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  void setIvarList(ObjCIvarDecl *ivar) { IvarList = ivar; }
5902c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian
59138af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  /// setProtocolList - Set the list of protocols that this interface
592b752f289026ad8e5f44851b20e009a27ed61eefcChris Lattner  /// implements.
59338af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  void setProtocolList(ObjCProtocolDecl *const* List, unsigned Num,
59418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                       const SourceLocation *Locs, ASTContext &C) {
59518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    ReferencedProtocols.set(List, Num, Locs, C);
5963db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  }
5971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
598339798eae1eb61c50ca68766ed028c0a16d0a284Fariborz Jahanian  /// mergeClassExtensionProtocolList - Merge class extension's protocol list
599339798eae1eb61c50ca68766ed028c0a16d0a284Fariborz Jahanian  /// into the protocol list for this class.
60018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  void mergeClassExtensionProtocolList(ObjCProtocolDecl *const* List,
60118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                                       unsigned Num,
60218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                                       ASTContext &C);
603339798eae1eb61c50ca68766ed028c0a16d0a284Fariborz Jahanian
604768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff  bool isForwardDecl() const { return ForwardDecl; }
605768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff  void setForwardDecl(bool val) { ForwardDecl = val; }
6061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
60726ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  ObjCInterfaceDecl *getSuperClass() const {
60826ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor    if (ExternallyCompleted)
60926ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
61026ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
61126ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor    return SuperClass;
61226ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  }
61326ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
614a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void setSuperClass(ObjCInterfaceDecl * superCls) { SuperClass = superCls; }
6151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
61626ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  ObjCCategoryDecl* getCategoryList() const {
61726ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor    if (ExternallyCompleted)
61826ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
61926ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
62026ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor    return CategoryList;
62126ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  }
62226ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
6231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setCategoryList(ObjCCategoryDecl *category) {
62453efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    CategoryList = category;
625980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  }
62680aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian
62780aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  ObjCCategoryDecl* getFirstClassExtension() const;
62837cafb077ad5b170acae77e566638603011ef4c0Ted Kremenek
62937cafb077ad5b170acae77e566638603011ef4c0Ted Kremenek  ObjCPropertyDecl
63037cafb077ad5b170acae77e566638603011ef4c0Ted Kremenek    *FindPropertyVisibleInPrimaryClass(IdentifierInfo *PropertyId) const;
63137cafb077ad5b170acae77e566638603011ef4c0Ted Kremenek
63253efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner  /// isSuperClassOf - Return true if this class is the specified class or is a
63353efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner  /// super class of the specified interface class.
63453efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner  bool isSuperClassOf(const ObjCInterfaceDecl *I) const {
63553efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    // If RHS is derived from LHS it is OK; else it is not OK.
63653efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    while (I != NULL) {
63753efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner      if (this == I)
63853efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner        return true;
63953efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner      I = I->getSuperClass();
64053efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    }
64153efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    return false;
64253efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner  }
6431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6447263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian  /// isArcWeakrefUnavailable - Checks for a class or one of its super classes
6457263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian  /// to be incompatible with __weak references. Returns true if it is.
6467263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian  bool isArcWeakrefUnavailable() const {
6477263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian    const ObjCInterfaceDecl *Class = this;
6487263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian    while (Class) {
6497263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian      if (Class->hasAttr<ArcWeakrefUnavailableAttr>())
6507263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian        return true;
6517263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian      Class = Class->getSuperClass();
6527263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian   }
6537263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian   return false;
6547263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian  }
6557263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian
65617945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName,
65768a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner                                       ObjCInterfaceDecl *&ClassDeclared);
65817945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName) {
65968a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner    ObjCInterfaceDecl *ClassDeclared;
66017945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return lookupInstanceVariable(IVarName, ClassDeclared);
66168a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner  }
66268a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner
66394a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // Lookup a method. First, we search locally. If a method isn't
66494a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // found, we search referenced protocols and class categories.
665aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis  ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance) const;
666aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis  ObjCMethodDecl *lookupInstanceMethod(Selector Sel) const {
667aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis    return lookupMethod(Sel, true/*isInstance*/);
668aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis  }
669aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis  ObjCMethodDecl *lookupClassMethod(Selector Sel) const {
670aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis    return lookupMethod(Sel, false/*isInstance*/);
671aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis  }
672cd1876207f5564beba74e4b2524b664bdba0ba9fFariborz Jahanian  ObjCInterfaceDecl *lookupInheritedClass(const IdentifierInfo *ICName);
673d789d3d985e28c9404e62157af46dcb7331920e0Steve Naroff
674d789d3d985e28c9404e62157af46dcb7331920e0Steve Naroff  // Lookup a method in the classes implementation hierarchy.
67574b2756bc1f1f5f7c189996fe7e4cd3efef70263Fariborz Jahanian  ObjCMethodDecl *lookupPrivateMethod(const Selector &Sel, bool Instance=true);
67660fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff
677ddfd4c9eda34765b08fae4cb31ad5a365face107Argyrios Kyrtzidis  // Location information, modeled after the Stmt API.
67860fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff  SourceLocation getLocStart() const { return getLocation(); } // '@'interface
679f908a87299d278164540f90b5b6e6cab7b14fb41Steve Naroff  SourceLocation getLocEnd() const { return EndLoc; }
6807177dee8aee4b432911c91f1b788963bec0cac9fDaniel Dunbar  void setLocEnd(SourceLocation LE) { EndLoc = LE; }
6811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
68233feeb019a5742b286eededd5446ec0fe87c5a61Steve Naroff  void setClassLoc(SourceLocation Loc) { ClassLoc = Loc; }
683d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff  SourceLocation getClassLoc() const { return ClassLoc; }
684d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff  void setSuperClassLoc(SourceLocation Loc) { SuperClassLoc = Loc; }
685d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff  SourceLocation getSuperClassLoc() const { return SuperClassLoc; }
6861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
68728e71cf851b73a67604735a9a95aef800b144e2eSteve Naroff  /// isImplicitInterfaceDecl - check that this is an implicitly declared
688a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  /// ObjCInterfaceDecl node. This is for legacy objective-c @implementation
6894b6df3fa953267c5d755628c8afd818bb571e579Fariborz Jahanian  /// declaration without an @interface declaration.
69033feeb019a5742b286eededd5446ec0fe87c5a61Steve Naroff  bool isImplicitInterfaceDecl() const { return InternalInterface; }
69133feeb019a5742b286eededd5446ec0fe87c5a61Steve Naroff  void setImplicitInterfaceDecl(bool val) { InternalInterface = val; }
6921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6930fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian  /// ClassImplementsProtocol - Checks that 'lProto' protocol
6940fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian  /// has been implemented in IDecl class, its super class or categories (if
6950fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian  /// lookupCategory is true).
6960fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian  bool ClassImplementsProtocol(ObjCProtocolDecl *lProto,
6970fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian                               bool lookupCategory,
6980fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian                               bool RHSIsQualifiedID = false);
6991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
70033feeb019a5742b286eededd5446ec0fe87c5a61Steve Naroff  // Low-level accessor
701f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const Type *getTypeForDecl() const { return TypeForDecl; }
702f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  void setTypeForDecl(const Type *TD) const { TypeForDecl = TD; }
70333feeb019a5742b286eededd5446ec0fe87c5a61Steve Naroff
70480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
705a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCInterfaceDecl *D) { return true; }
70680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCInterface; }
70753b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
70853b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  friend class ASTDeclReader;
70953b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  friend class ASTDeclWriter;
710980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
711980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
712a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCIvarDecl - Represents an ObjC instance variable. In general, ObjC
7130c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// instance variables are identical to C. The only exception is Objective-C
7140c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// supports C++ style access control. For example:
7150c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
7160c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @interface IvarExample : NSObject
7170c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   {
718f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek///     id defaultToProtected;
7190c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @public:
7200c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     id canBePublic; // same as C++.
7210c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @protected:
7220c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     id canBeProtected; // same as C++.
7230c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @package:
7240c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     id canBePackage; // framework visibility (not available in C++).
7250c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   }
7260c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
727a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCIvarDecl : public FieldDecl {
7280e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattnerpublic:
729980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  enum AccessControl {
730980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff    None, Private, Protected, Public, Package
731980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  };
7321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
733b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenekprivate:
734ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara  ObjCIvarDecl(ObjCContainerDecl *DC, SourceLocation StartLoc,
735ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara               SourceLocation IdLoc, IdentifierInfo *Id,
736ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian               QualType T, TypeSourceInfo *TInfo, AccessControl ac, Expr *BW,
737ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian               bool synthesized)
738ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara    : FieldDecl(ObjCIvar, DC, StartLoc, IdLoc, Id, T, TInfo, BW,
7397a614d8380297fcd2bc23986241905d97222948cRichard Smith                /*Mutable=*/false, /*HasInit=*/false),
740ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara      NextIvar(0), DeclAccess(ac), Synthesized(synthesized) {}
7411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
742b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenekpublic:
743a06549226f45d5b72169a3d054415616dd1014a2Daniel Dunbar  static ObjCIvarDecl *Create(ASTContext &C, ObjCContainerDecl *DC,
744ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                              SourceLocation StartLoc, SourceLocation IdLoc,
745ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                              IdentifierInfo *Id, QualType T,
746a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall                              TypeSourceInfo *TInfo,
747ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian                              AccessControl ac, Expr *BW = NULL,
748ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian                              bool synthesized=false);
7491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
75027a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar  /// \brief Return the class interface that this ivar is logically contained
75127a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar  /// in; this is either the interface where the ivar was declared, or the
75227a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar  /// interface the ivar is conceptually a part of in the case of synthesized
75327a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar  /// ivars.
75427a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar  const ObjCInterfaceDecl *getContainingInterface() const;
7552c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian
7562c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  ObjCIvarDecl *getNextIvar() { return NextIvar; }
7572c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  void setNextIvar(ObjCIvarDecl *ivar) { NextIvar = ivar; }
75827a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar
759980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  void setAccessControl(AccessControl ac) { DeclAccess = ac; }
760f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek
761ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  AccessControl getAccessControl() const { return AccessControl(DeclAccess); }
762f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek
763f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek  AccessControl getCanonicalAccessControl() const {
764f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek    return DeclAccess == None ? Protected : AccessControl(DeclAccess);
765f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek  }
7661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
767ac0021ba802e193e0f9f8207768c7862c7603bc0Fariborz Jahanian  void setSynthesize(bool synth) { Synthesized = synth; }
768ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian  bool getSynthesize() const { return Synthesized; }
769ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian
770980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  // Implement isa/cast/dyncast/etc.
77180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
772a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCIvarDecl *D) { return true; }
77380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCIvar; }
774980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffprivate:
7752c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  /// NextIvar - Next Ivar in the list of ivars declared in class; class's
7762c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  /// extensions and class's implementation
7772c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  ObjCIvarDecl *NextIvar;
7782c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian
779ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  // NOTE: VC++ treats enums as signed, avoid using the AccessControl enum
780ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  unsigned DeclAccess : 3;
781ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian  unsigned Synthesized : 1;
782980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
783980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
7841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
78501e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek/// ObjCAtDefsFieldDecl - Represents a field declaration created by an
78601e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek///  @defs(...).
78701e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenekclass ObjCAtDefsFieldDecl : public FieldDecl {
78801e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenekprivate:
789ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara  ObjCAtDefsFieldDecl(DeclContext *DC, SourceLocation StartLoc,
790ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                      SourceLocation IdLoc, IdentifierInfo *Id,
79101e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek                      QualType T, Expr *BW)
792ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara    : FieldDecl(ObjCAtDefsField, DC, StartLoc, IdLoc, Id, T,
793a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall                /*TInfo=*/0, // FIXME: Do ObjCAtDefs have declarators ?
7947a614d8380297fcd2bc23986241905d97222948cRichard Smith                BW, /*Mutable=*/false, /*HasInit=*/false) {}
7951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
79601e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenekpublic:
79744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor  static ObjCAtDefsFieldDecl *Create(ASTContext &C, DeclContext *DC,
798ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                     SourceLocation StartLoc,
799ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                     SourceLocation IdLoc, IdentifierInfo *Id,
800ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                     QualType T, Expr *BW);
8011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
80201e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek  // Implement isa/cast/dyncast/etc.
80380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
80401e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek  static bool classof(const ObjCAtDefsFieldDecl *D) { return true; }
80580cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCAtDefsField; }
80601e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek};
807980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
808a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCProtocolDecl - Represents a protocol declaration. ObjC protocols
8091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// declare a pure abstract type (i.e no instance variables are permitted).
810fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner/// Protocols originally drew inspiration from C++ pure virtual functions (a C++
8110c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// feature with nice semantics and lousy syntax:-). Here is an example:
8120c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
813eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// @protocol NSDraggingInfo <refproto1, refproto2>
8140c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (NSWindow *)draggingDestinationWindow;
8150c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (NSImage *)draggedImage;
8160c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end
8170c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
818eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// This says that NSDraggingInfo requires two methods and requires everything
819eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// that the two "referenced protocols" 'refproto1' and 'refproto2' require as
820eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// well.
821eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner///
8220c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @interface ImplementsNSDraggingInfo : NSObject <NSDraggingInfo>
8230c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end
8240c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
825a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjC protocols inspired Java interfaces. Unlike Java, ObjC classes and
8260c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// protocols are in distinct namespaces. For example, Cocoa defines both
8271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// an NSObject protocol and class (which isn't allowed in Java). As a result,
8280c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// protocols are referenced using angle brackets as follows:
8290c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
8300c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// id <NSDraggingInfo> anyObjectThatImplementsNSDraggingInfo;
8310c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
832e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroffclass ObjCProtocolDecl : public ObjCContainerDecl {
833780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  /// Referenced protocols
83418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  ObjCProtocolList ReferencedProtocols;
8351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
836980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  bool isForwardProtoDecl; // declared with @protocol.
8371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
838423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff  SourceLocation EndLoc; // marks the '>' or identifier.
8391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
840d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  ObjCProtocolDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id)
8411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : ObjCContainerDecl(ObjCProtocol, DC, L, Id),
842c858105d41602a2dadb2efbc1af80a7b791ebac3Chris Lattner      isForwardProtoDecl(true) {
843cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattner  }
8441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
845cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattnerpublic:
8461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static ObjCProtocolDecl *Create(ASTContext &C, DeclContext *DC,
847d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor                                  SourceLocation L, IdentifierInfo *Id);
848cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattner
84918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  const ObjCProtocolList &getReferencedProtocols() const {
850780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner    return ReferencedProtocols;
851980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  }
85218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::iterator protocol_iterator;
853780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();}
854780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  protocol_iterator protocol_end() const { return ReferencedProtocols.end(); }
85518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
85618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  protocol_loc_iterator protocol_loc_begin() const {
85718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    return ReferencedProtocols.loc_begin();
85818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
85918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  protocol_loc_iterator protocol_loc_end() const {
86018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    return ReferencedProtocols.loc_end();
86118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
86230833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  unsigned protocol_size() const { return ReferencedProtocols.size(); }
8631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
86438af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  /// setProtocolList - Set the list of protocols that this interface
865780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  /// implements.
86638af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num,
86718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                       const SourceLocation *Locs, ASTContext &C) {
86818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    ReferencedProtocols.set(List, Num, Locs, C);
869aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian  }
8701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
87191b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff  ObjCProtocolDecl *lookupProtocolNamed(IdentifierInfo *PName);
8721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
87394a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // Lookup a method. First, we search locally. If a method isn't
87494a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // found, we search referenced protocols and class categories.
875094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis  ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance) const;
876094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis  ObjCMethodDecl *lookupInstanceMethod(Selector Sel) const {
877094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis    return lookupMethod(Sel, true/*isInstance*/);
878094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis  }
879094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis  ObjCMethodDecl *lookupClassMethod(Selector Sel) const {
880094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis    return lookupMethod(Sel, false/*isInstance*/);
881094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis  }
882d789d3d985e28c9404e62157af46dcb7331920e0Steve Naroff
883768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff  bool isForwardDecl() const { return isForwardProtoDecl; }
884768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff  void setForwardDecl(bool val) { isForwardProtoDecl = val; }
885980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
8861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // Location information, modeled after the Stmt API.
887423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff  SourceLocation getLocStart() const { return getLocation(); } // '@'protocol
888423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff  SourceLocation getLocEnd() const { return EndLoc; }
8897177dee8aee4b432911c91f1b788963bec0cac9fDaniel Dunbar  void setLocEnd(SourceLocation LE) { EndLoc = LE; }
8901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
89180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
892a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCProtocolDecl *D) { return true; }
89380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCProtocol; }
894980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
8951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
896a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCClassDecl - Specifies a list of forward class declarations. For example:
89706ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff///
89806ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff/// @class NSCursor, NSImage, NSPasteboard, NSWindow;
8990c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
9004afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCClassDecl : public Decl {
901321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenekpublic:
902321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek  class ObjCClassRef {
903321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek    ObjCInterfaceDecl *ID;
904321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek    SourceLocation L;
905321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek  public:
906321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek    ObjCClassRef(ObjCInterfaceDecl *d, SourceLocation l) : ID(d), L(l) {}
907321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek    SourceLocation getLocation() const { return L; }
908321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek    ObjCInterfaceDecl *getInterface() const { return ID; }
909321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek  };
910321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenekprivate:
911321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek  ObjCClassRef *ForwardDecls;
912321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek  unsigned NumDecls;
9131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ObjCClassDecl(DeclContext *DC, SourceLocation L,
915321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek                ObjCInterfaceDecl *const *Elts, const SourceLocation *Locs,
916321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek                unsigned nElts, ASTContext &C);
91761f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattnerpublic:
918d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCClassDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L,
9191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                               ObjCInterfaceDecl *const *Elts = 0,
920321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek                               const SourceLocation *Locs = 0,
92130833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff                               unsigned nElts = 0);
9222dbdd622d02d1bfbe1e5bcf421b07b74c7a748f1Ted Kremenek
923da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor  virtual SourceRange getSourceRange() const;
9241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
925321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek  typedef const ObjCClassRef* iterator;
926321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek  iterator begin() const { return ForwardDecls; }
927321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek  iterator end() const { return ForwardDecls + NumDecls; }
928321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek  unsigned size() const { return NumDecls; }
92930833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff
93030833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  /// setClassList - Set the list of forward classes.
931321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek  void setClassList(ASTContext &C, ObjCInterfaceDecl*const*List,
932321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek                    const SourceLocation *Locs, unsigned Num);
9331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
93480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
935a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCClassDecl *D) { return true; }
93680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCClass; }
93706ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff};
93806ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff
939a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCForwardProtocolDecl - Specifies a list of forward protocol declarations.
94006ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff/// For example:
9411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
9420c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @protocol NSTextInput, NSChangeSpelling, NSDraggingInfo;
9431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
9444afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCForwardProtocolDecl : public Decl {
94518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  ObjCProtocolList ReferencedProtocols;
9461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
947d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  ObjCForwardProtocolDecl(DeclContext *DC, SourceLocation L,
94838af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner                          ObjCProtocolDecl *const *Elts, unsigned nElts,
94918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                          const SourceLocation *Locs, ASTContext &C);
9501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
95161f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattnerpublic:
952d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCForwardProtocolDecl *Create(ASTContext &C, DeclContext *DC,
9531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                         SourceLocation L,
95418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                                         ObjCProtocolDecl *const *Elts,
95518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                                         unsigned Num,
95618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                                         const SourceLocation *Locs);
95718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor
95818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  static ObjCForwardProtocolDecl *Create(ASTContext &C, DeclContext *DC,
95918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                                         SourceLocation L) {
96018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    return Create(C, DC, L, 0, 0, 0);
96118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
96261f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner
96318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::iterator protocol_iterator;
96430833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();}
96530833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  protocol_iterator protocol_end() const { return ReferencedProtocols.end(); }
96618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
96718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  protocol_loc_iterator protocol_loc_begin() const {
96818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    return ReferencedProtocols.loc_begin();
96918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
97018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  protocol_loc_iterator protocol_loc_end() const {
97118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    return ReferencedProtocols.loc_end();
97218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
97318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor
97430833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  unsigned protocol_size() const { return ReferencedProtocols.size(); }
97530833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff
97630833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  /// setProtocolList - Set the list of forward protocols.
97730833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num,
97818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                       const SourceLocation *Locs, ASTContext &C) {
97918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    ReferencedProtocols.set(List, Num, Locs, C);
98030833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  }
98180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
982a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCForwardProtocolDecl *D) { return true; }
98380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCForwardProtocol; }
984980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
985980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
986a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCCategoryDecl - Represents a category declaration. A category allows
9870c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// you to add methods to an existing class (without subclassing or modifying
9881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// the original class interface or implementation:-). Categories don't allow
9890c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// you to add instance data. The following example adds "myMethod" to all
9900c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// NSView's within a process:
9910c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
9920c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @interface NSView (MyViewMethods)
9930c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - myMethod;
9940c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end
9950c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
99633ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor/// Categories also allow you to split the implementation of a class across
9970c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// several files (a feature more naturally supported in C++).
9980c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
9990c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// Categories were originally inspired by dynamic languages such as Common
10001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Lisp and Smalltalk.  More traditional class-based languages (C++, Java)
10010c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// don't support this level of dynamism, which is both powerful and dangerous.
10020c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
1003e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroffclass ObjCCategoryDecl : public ObjCContainerDecl {
1004980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  /// Interface belonging to this category
1005a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *ClassInterface;
10061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
100768c82cf61228102aba1194efef222fa1478af2a8Chris Lattner  /// referenced protocols in this category.
100818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  ObjCProtocolList ReferencedProtocols;
10091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1010a8ff9f455d94d9609766cfd5186b6e21dc2102f1Chris Lattner  /// Next category belonging to this class.
1011a8ff9f455d94d9609766cfd5186b6e21dc2102f1Chris Lattner  /// FIXME: this should not be a singly-linked list.  Move storage elsewhere.
1012a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCCategoryDecl *NextClassCategory;
10131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1014000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  /// true of class extension has at least one bitfield ivar.
1015000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  bool HasSynthBitfield : 1;
1016000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian
10173db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  /// \brief The location of the '@' in '@interface'
10183db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  SourceLocation AtLoc;
10193db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor
10203db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  /// \brief The location of the category name in this declaration.
10213db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  SourceLocation CategoryNameLoc;
10221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10233db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  ObjCCategoryDecl(DeclContext *DC, SourceLocation AtLoc,
10243db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor                   SourceLocation ClassNameLoc, SourceLocation CategoryNameLoc,
10253db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor                   IdentifierInfo *Id)
10263db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor    : ObjCContainerDecl(ObjCCategory, DC, ClassNameLoc, Id),
1027000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian      ClassInterface(0), NextClassCategory(0), HasSynthBitfield(false),
1028000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian      AtLoc(AtLoc), CategoryNameLoc(CategoryNameLoc) {
1029a906135721c350435319347d2672bbb3bf494f91Chris Lattner  }
103061f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattnerpublic:
10311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1032d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCCategoryDecl *Create(ASTContext &C, DeclContext *DC,
10333db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor                                  SourceLocation AtLoc,
10343db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor                                  SourceLocation ClassNameLoc,
10353db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor                                  SourceLocation CategoryNameLoc,
10363db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor                                  IdentifierInfo *Id);
10371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1038e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
1039e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; }
1040a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void setClassInterface(ObjCInterfaceDecl *IDecl) { ClassInterface = IDecl; }
10418a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis
10428a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis  ObjCCategoryImplDecl *getImplementation() const;
10438a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis  void setImplementation(ObjCCategoryImplDecl *ImplD);
10448a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis
104538af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  /// setProtocolList - Set the list of protocols that this interface
1046f7b2c98c16dfb2261ea57d40a1d5bc4738e73175Chris Lattner  /// implements.
104738af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num,
104818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                       const SourceLocation *Locs, ASTContext &C) {
104918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    ReferencedProtocols.set(List, Num, Locs, C);
1050780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  }
10511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
105218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  const ObjCProtocolList &getReferencedProtocols() const {
1053780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner    return ReferencedProtocols;
10548f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian  }
10551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
105618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::iterator protocol_iterator;
1057780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();}
1058780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  protocol_iterator protocol_end() const { return ReferencedProtocols.end(); }
105930833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  unsigned protocol_size() const { return ReferencedProtocols.size(); }
106018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
106118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  protocol_loc_iterator protocol_loc_begin() const {
106218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    return ReferencedProtocols.loc_begin();
106318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
106418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  protocol_loc_iterator protocol_loc_end() const {
106518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    return ReferencedProtocols.loc_end();
106618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
10671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1068a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCCategoryDecl *getNextClassCategory() const { return NextClassCategory; }
106930833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  void setNextClassCategory(ObjCCategoryDecl *Cat) {
107030833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff    NextClassCategory = Cat;
107130833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  }
1072980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  void insertNextClassCategory() {
10733d58138992b9bc7b34aaa680f3ddf3971292eb7dSteve Naroff    NextClassCategory = ClassInterface->getCategoryList();
10743d58138992b9bc7b34aaa680f3ddf3971292eb7dSteve Naroff    ClassInterface->setCategoryList(this);
10755e9888c2786bfffa6879a08ff40f5a11545eec23Douglas Gregor    ClassInterface->setChangedSinceDeserialization(true);
1076980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  }
10773db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor
107825760611365be23556b32332f8a66ae21ea93ecfFariborz Jahanian  bool IsClassExtension() const { return getIdentifier() == 0; }
107980aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  const ObjCCategoryDecl *getNextClassExtension() const;
108025760611365be23556b32332f8a66ae21ea93ecfFariborz Jahanian
1081000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  bool hasSynthBitfield() const { return HasSynthBitfield; }
1082000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  void setHasSynthBitfield (bool val) { HasSynthBitfield = val; }
1083000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian
10840e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
10850e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  ivar_iterator ivar_begin() const {
10860e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian    return ivar_iterator(decls_begin());
10870e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  }
10880e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  ivar_iterator ivar_end() const {
10890e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian    return ivar_iterator(decls_end());
10900e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  }
10910e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  unsigned ivar_size() const {
10920e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian    return std::distance(ivar_begin(), ivar_end());
10930e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  }
10940e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  bool ivar_empty() const {
10950e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian    return ivar_begin() == ivar_end();
10960e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  }
10970e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian
10983db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  SourceLocation getAtLoc() const { return AtLoc; }
10993db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  void setAtLoc(SourceLocation At) { AtLoc = At; }
11003db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor
11013db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  SourceLocation getCategoryNameLoc() const { return CategoryNameLoc; }
11023db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  void setCategoryNameLoc(SourceLocation Loc) { CategoryNameLoc = Loc; }
11033db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor
1104da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor  virtual SourceRange getSourceRange() const {
11053db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor    return SourceRange(AtLoc, getAtEndRange().getEnd());
11063db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  }
11071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
110880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1109a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCCategoryDecl *D) { return true; }
111080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCCategory; }
1111980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
11120c6b6243d3efd958c17943130e2a773653511edcSteve Naroff
1113aecae629269fae3bf484baf1d109e9a89d14eeadArgyrios Kyrtzidisclass ObjCImplDecl : public ObjCContainerDecl {
11140d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// Class interface for this class/category implementation
1115a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *ClassInterface;
11161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11173aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattnerprotected:
11183aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  ObjCImplDecl(Kind DK, DeclContext *DC, SourceLocation L,
11193aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner               ObjCInterfaceDecl *classInterface)
11201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : ObjCContainerDecl(DK, DC, L,
11211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                        classInterface? classInterface->getIdentifier() : 0),
1122aecae629269fae3bf484baf1d109e9a89d14eeadArgyrios Kyrtzidis      ClassInterface(classInterface) {}
11231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
112475c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattnerpublic:
1125e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; }
1126e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
11278a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis  void setClassInterface(ObjCInterfaceDecl *IFace);
11282c2d43c557beca1b4ba4bd743f33978aecb46a97Douglas Gregor
11291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void addInstanceMethod(ObjCMethodDecl *method) {
11302c2d43c557beca1b4ba4bd743f33978aecb46a97Douglas Gregor    // FIXME: Context should be set correctly before we get here.
1131653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor    method->setLexicalDeclContext(this);
11321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    addDecl(method);
1133e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff  }
11341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void addClassMethod(ObjCMethodDecl *method) {
11352c2d43c557beca1b4ba4bd743f33978aecb46a97Douglas Gregor    // FIXME: Context should be set correctly before we get here.
1136653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor    method->setLexicalDeclContext(this);
11371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    addDecl(method);
113853df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner  }
11391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
114017945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  void addPropertyImplementation(ObjCPropertyImplDecl *property);
11411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
114217945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  ObjCPropertyImplDecl *FindPropertyImplDecl(IdentifierInfo *propertyId) const;
114317945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  ObjCPropertyImplDecl *FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const;
1144653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor
1145653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor  // Iterator access to properties.
1146653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor  typedef specific_decl_iterator<ObjCPropertyImplDecl> propimpl_iterator;
11471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  propimpl_iterator propimpl_begin() const {
114817945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return propimpl_iterator(decls_begin());
1149559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  }
11501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  propimpl_iterator propimpl_end() const {
115117945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return propimpl_iterator(decls_end());
1152559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  }
1153653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor
115480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1155bfb498d0996ef049efe9476f2802976fd145cd60Argyrios Kyrtzidis  static bool classof(const ObjCImplDecl *D) { return true; }
115680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) {
11579a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt    return K >= firstObjCImpl && K <= lastObjCImpl;
115880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  }
11593aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner};
11601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ObjCCategoryImplDecl - An object of this class encapsulates a category
11621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// @implementation declaration. If a category class has declaration of a
11631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// property, its implementation must be specified in the category's
11643aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @implementation declaration. Example:
11653aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @interface I @end
11663aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @interface I(CATEGORY)
11673aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner///    @property int p1, d1;
11683aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @end
11693aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @implementation I(CATEGORY)
11703aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner///  @dynamic p1,d1;
11713aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @end
11723aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner///
11733aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// ObjCCategoryImplDecl
11743aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattnerclass ObjCCategoryImplDecl : public ObjCImplDecl {
11753aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  // Category name
11763aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  IdentifierInfo *Id;
11773aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner
11783aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  ObjCCategoryImplDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
11793aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner                       ObjCInterfaceDecl *classInterface)
11803aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner    : ObjCImplDecl(ObjCCategoryImpl, DC, L, classInterface), Id(Id) {}
11813aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattnerpublic:
11823aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  static ObjCCategoryImplDecl *Create(ASTContext &C, DeclContext *DC,
11833aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner                                      SourceLocation L, IdentifierInfo *Id,
11843aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner                                      ObjCInterfaceDecl *classInterface);
11851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11860d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// getIdentifier - Get the identifier that names the category
11873aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  /// interface associated with this implementation.
11880d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// FIXME: This is a bad API, we are overriding the NamedDecl::getIdentifier()
11890d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// to mean something different. For example:
11900d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// ((NamedDecl *)SomeCategoryImplDecl)->getIdentifier()
11910d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// returns the class interface name, whereas
11920d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// ((ObjCCategoryImplDecl *)SomeCategoryImplDecl)->getIdentifier()
11930d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// returns the category name.
11941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  IdentifierInfo *getIdentifier() const {
11951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return Id;
11963aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  }
119710b0e1fa3aabd8877dbbc0df1f2414e04afd5fddDouglas Gregor  void setIdentifier(IdentifierInfo *II) { Id = II; }
11981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11990d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  ObjCCategoryDecl *getCategoryDecl() const;
120010b0e1fa3aabd8877dbbc0df1f2414e04afd5fddDouglas Gregor
1201b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  /// getName - Get the name of identifier for the class interface associated
1202b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  /// with this implementation as a StringRef.
1203b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  //
1204b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  // FIXME: This is a bad API, we are overriding the NamedDecl::getName, to mean
1205b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  // something different.
1206686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getName() const {
1207b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar    return Id ? Id->getNameStart() : "";
1208b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  }
1209b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar
12103aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  /// getNameAsCString - Get the name of identifier for the class
12113aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  /// interface associated with this implementation as a C string
12123aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  /// (const char*).
12137fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar  //
1214b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  // FIXME: Deprecated, move clients to getName().
12153aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  const char *getNameAsCString() const {
12167fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar    return Id ? Id->getNameStart() : "";
12173aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  }
12181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12193aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  /// @brief Get the name of the class associated with this interface.
12207fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar  //
1221b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  // FIXME: Deprecated, move clients to getName().
12223aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  std::string getNameAsString() const {
1223b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar    return getName();
12243aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  }
12251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
122680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1227a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCCategoryImplDecl *D) { return true; }
122880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCCategoryImpl;}
12298f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian};
12308f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian
12318cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattnerraw_ostream &operator<<(raw_ostream &OS,
1232900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer                              const ObjCCategoryImplDecl *CID);
1233900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer
1234a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCImplementationDecl - Represents a class definition - this is where
12350c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// method definitions are specified. For example:
12360c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
123798abf4bd3526a00a0e5cf71a9462c181f97b1c81Fariborz Jahanian/// @code
12380c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @implementation MyClass
12390c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (void)myMethod { /* do something */ }
12400c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end
124198abf4bd3526a00a0e5cf71a9462c181f97b1c81Fariborz Jahanian/// @endcode
12420c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
12431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Typically, instance variables are specified in the class interface,
1244ec0d7a6f4b0699cc9960e6d9fee0f957c64d1cf9Douglas Gregor/// *not* in the implementation. Nevertheless (for legacy reasons), we
124553df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner/// allow instance variables to be specified in the implementation.  When
124653df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner/// specified, they need to be *identical* to the interface.
12470c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
12481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ObjCImplementationDecl : public ObjCImplDecl {
1249980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  /// Implementation Class's super class.
1250a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *SuperClass;
1251e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// Support for ivar initialization.
1252e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// IvarInitializers - The arguments used to initialize the ivars
1253cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt  CXXCtorInitializer **IvarInitializers;
1254e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  unsigned NumIvarInitializers;
1255f85e193739c953358c865005855253af4f68a497John McCall
1256f85e193739c953358c865005855253af4f68a497John McCall  /// true if class has a .cxx_[construct,destruct] method.
1257f85e193739c953358c865005855253af4f68a497John McCall  bool HasCXXStructors : 1;
1258e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian
1259000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  /// true of class extension has at least one bitfield ivar.
1260000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  bool HasSynthBitfield : 1;
1261000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian
12621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ObjCImplementationDecl(DeclContext *DC, SourceLocation L,
1263a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek                         ObjCInterfaceDecl *classInterface,
1264a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek                         ObjCInterfaceDecl *superDecl)
12651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : ObjCImplDecl(ObjCImplementation, DC, L, classInterface),
1266000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian       SuperClass(superDecl), IvarInitializers(0), NumIvarInitializers(0),
1267f85e193739c953358c865005855253af4f68a497John McCall       HasCXXStructors(false), HasSynthBitfield(false) {}
12681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
12691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static ObjCImplementationDecl *Create(ASTContext &C, DeclContext *DC,
12701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                        SourceLocation L,
127175c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner                                        ObjCInterfaceDecl *classInterface,
127275c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner                                        ObjCInterfaceDecl *superDecl);
1273e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian
1274e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// init_iterator - Iterates through the ivar initializer list.
1275cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt  typedef CXXCtorInitializer **init_iterator;
1276e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian
1277e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// init_const_iterator - Iterates through the ivar initializer list.
1278cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt  typedef CXXCtorInitializer * const * init_const_iterator;
1279e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian
1280e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// init_begin() - Retrieve an iterator to the first initializer.
1281e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  init_iterator       init_begin()       { return IvarInitializers; }
1282e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// begin() - Retrieve an iterator to the first initializer.
1283e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  init_const_iterator init_begin() const { return IvarInitializers; }
1284e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian
1285e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// init_end() - Retrieve an iterator past the last initializer.
1286e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  init_iterator       init_end()       {
1287e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian    return IvarInitializers + NumIvarInitializers;
1288e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  }
1289e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// end() - Retrieve an iterator past the last initializer.
1290e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  init_const_iterator init_end() const {
1291e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian    return IvarInitializers + NumIvarInitializers;
1292e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  }
1293e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// getNumArgs - Number of ivars which must be initialized.
1294e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  unsigned getNumIvarInitializers() const {
1295e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian    return NumIvarInitializers;
1296e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  }
1297e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian
1298e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  void setNumIvarInitializers(unsigned numNumIvarInitializers) {
1299e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian    NumIvarInitializers = numNumIvarInitializers;
1300e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  }
1301e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian
1302e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  void setIvarInitializers(ASTContext &C,
1303cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt                           CXXCtorInitializer ** initializers,
1304e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian                           unsigned numInitializers);
1305f85e193739c953358c865005855253af4f68a497John McCall
1306f85e193739c953358c865005855253af4f68a497John McCall  bool hasCXXStructors() const { return HasCXXStructors; }
1307f85e193739c953358c865005855253af4f68a497John McCall  void setHasCXXStructors(bool val) { HasCXXStructors = val; }
1308000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian
1309000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  bool hasSynthBitfield() const { return HasSynthBitfield; }
1310000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  void setHasSynthBitfield (bool val) { HasSynthBitfield = val; }
1311e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian
13124afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  /// getIdentifier - Get the identifier that names the class
13134afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  /// interface associated with this implementation.
13141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  IdentifierInfo *getIdentifier() const {
13151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return getClassInterface()->getIdentifier();
13164afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  }
13174afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor
1318d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  /// getName - Get the name of identifier for the class interface associated
1319d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  /// with this implementation as a StringRef.
1320d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  //
1321d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  // FIXME: This is a bad API, we are overriding the NamedDecl::getName, to mean
1322d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  // something different.
1323686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getName() const {
1324d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar    assert(getIdentifier() && "Name is not a simple identifier");
1325d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar    return getIdentifier()->getName();
1326d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  }
1327d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar
13284afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  /// getNameAsCString - Get the name of identifier for the class
13294afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  /// interface associated with this implementation as a C string
13304afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  /// (const char*).
13317fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar  //
13327fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar  // FIXME: Move to StringRef API.
13334afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  const char *getNameAsCString() const {
1334d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar    return getName().data();
13354afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  }
13364afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor
13374afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  /// @brief Get the name of the class associated with this interface.
13387fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar  //
13397fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar  // FIXME: Move to StringRef API.
13404afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  std::string getNameAsString() const {
1341d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar    return getName();
13424afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  }
13434afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor
1344e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  const ObjCInterfaceDecl *getSuperClass() const { return SuperClass; }
1345e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  ObjCInterfaceDecl *getSuperClass() { return SuperClass; }
13461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1347f3a7af901231535191d14cb524d58f22907ac4d2Chris Lattner  void setSuperClass(ObjCInterfaceDecl * superCls) { SuperClass = superCls; }
13481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13498f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor  typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
13501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ivar_iterator ivar_begin() const {
13511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return ivar_iterator(decls_begin());
13528f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor  }
13531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ivar_iterator ivar_end() const {
135417945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return ivar_iterator(decls_end());
13558f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor  }
13561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  unsigned ivar_size() const {
135717945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return std::distance(ivar_begin(), ivar_end());
13588f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor  }
13591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool ivar_empty() const {
136017945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return ivar_begin() == ivar_end();
13618f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor  }
13621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
136380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1364a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCImplementationDecl *D) { return true; }
136580cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCImplementation; }
13669d50c0635fb213b2a1857e3f8488580f0dab2f98Argyrios Kyrtzidis
1367d527cc06d78fe5afa5f20105b51697637eb02c56Sebastian Redl  friend class ASTDeclReader;
13683397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl  friend class ASTDeclWriter;
1369980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
1370243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian
13718cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattnerraw_ostream &operator<<(raw_ostream &OS,
1372900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer                              const ObjCImplementationDecl *ID);
1373900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer
13741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ObjCCompatibleAliasDecl - Represents alias of a class. This alias is
1375243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian/// declared as @compatibility_alias alias class.
13764afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCCompatibleAliasDecl : public NamedDecl {
1377243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian  /// Class that this is an alias of.
1378a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *AliasedClass;
13791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1380d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  ObjCCompatibleAliasDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
1381e8043c39176e7f253fbd92982b077eca6bf2fd59Steve Naroff                          ObjCInterfaceDecl* aliasedClass)
13824afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor    : NamedDecl(ObjCCompatibleAlias, DC, L, Id), AliasedClass(aliasedClass) {}
1383f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattnerpublic:
1384d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCCompatibleAliasDecl *Create(ASTContext &C, DeclContext *DC,
13850ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner                                         SourceLocation L, IdentifierInfo *Id,
1386f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner                                         ObjCInterfaceDecl* aliasedClass);
1387f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner
1388f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner  const ObjCInterfaceDecl *getClassInterface() const { return AliasedClass; }
1389f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner  ObjCInterfaceDecl *getClassInterface() { return AliasedClass; }
139030833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  void setClassInterface(ObjCInterfaceDecl *D) { AliasedClass = D; }
13911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
139280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1393a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCCompatibleAliasDecl *D) { return true; }
139480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCCompatibleAlias; }
13951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1396243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian};
13971de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian
13981de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian/// ObjCPropertyDecl - Represents one property declaration in an interface.
13991de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian/// For example:
14001de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian/// @property (assign, readwrite) int MyProperty;
14011de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian///
14024afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCPropertyDecl : public NamedDecl {
140382a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanianpublic:
1404a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner  enum PropertyAttributeKind {
14051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    OBJC_PR_noattr    = 0x00,
14061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    OBJC_PR_readonly  = 0x01,
1407a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_getter    = 0x02,
14081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    OBJC_PR_assign    = 0x04,
14091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    OBJC_PR_readwrite = 0x08,
1410a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_retain    = 0x10,
14111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    OBJC_PR_copy      = 0x20,
1412a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_nonatomic = 0x40,
141345937ae10a0f70f74508165aab4f2b63e18ea747Fariborz Jahanian    OBJC_PR_setter    = 0x80,
1414f85e193739c953358c865005855253af4f68a497John McCall    OBJC_PR_atomic    = 0x100,
1415f85e193739c953358c865005855253af4f68a497John McCall    OBJC_PR_weak      = 0x200,
1416f85e193739c953358c865005855253af4f68a497John McCall    OBJC_PR_strong    = 0x400,
14179f3480bab8fcb6547978f8ad9e2b8f468e3658eeArgyrios Kyrtzidis    OBJC_PR_unsafe_unretained = 0x800
14189f3480bab8fcb6547978f8ad9e2b8f468e3658eeArgyrios Kyrtzidis    // Adding a property should change NumPropertyAttrsBits
14199f3480bab8fcb6547978f8ad9e2b8f468e3658eeArgyrios Kyrtzidis  };
14200a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis
14219f3480bab8fcb6547978f8ad9e2b8f468e3658eeArgyrios Kyrtzidis  enum {
14220a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis    /// \brief Number of bits fitting all the property attributes.
14239f3480bab8fcb6547978f8ad9e2b8f468e3658eeArgyrios Kyrtzidis    NumPropertyAttrsBits = 12
1424a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner  };
1425af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
1426af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  enum SetterKind { Assign, Retain, Copy };
142746b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  enum PropertyControl { None, Required, Optional };
142882a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanianprivate:
1429d8265b838360578032020757d9a2a84c86457edcFariborz Jahanian  SourceLocation AtLoc;   // location of @property
143083a230c83a54190366138c1a4f4310ef838b88fcJohn McCall  TypeSourceInfo *DeclType;
14319f3480bab8fcb6547978f8ad9e2b8f468e3658eeArgyrios Kyrtzidis  unsigned PropertyAttributes : NumPropertyAttrsBits;
14329f3480bab8fcb6547978f8ad9e2b8f468e3658eeArgyrios Kyrtzidis  unsigned PropertyAttributesAsWritten : NumPropertyAttrsBits;
143346b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  // @required/@optional
143446b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  unsigned PropertyImplementation : 2;
14351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14365251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  Selector GetterName;    // getter name of NULL if no getter
14375251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  Selector SetterName;    // setter name of NULL if no setter
14381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
143933de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  ObjCMethodDecl *GetterMethodDecl; // Declaration of getter instance method
144033de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  ObjCMethodDecl *SetterMethodDecl; // Declaration of setter instance method
1441af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian  ObjCIvarDecl *PropertyIvarDecl;   // Synthesize ivar for this property
144233de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian
14431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ObjCPropertyDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
144483a230c83a54190366138c1a4f4310ef838b88fcJohn McCall                   SourceLocation AtLocation, TypeSourceInfo *T)
1445d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian    : NamedDecl(ObjCProperty, DC, L, Id), AtLoc(AtLocation), DeclType(T),
144680aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian      PropertyAttributes(OBJC_PR_noattr),
144780aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian      PropertyAttributesAsWritten(OBJC_PR_noattr),
144880aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian      PropertyImplementation(None),
14491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      GetterName(Selector()),
145033de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian      SetterName(Selector()),
1451af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian      GetterMethodDecl(0), SetterMethodDecl(0) , PropertyIvarDecl(0) {}
1452f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattnerpublic:
14531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static ObjCPropertyDecl *Create(ASTContext &C, DeclContext *DC,
14541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                  SourceLocation L,
1455d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian                                  IdentifierInfo *Id, SourceLocation AtLocation,
145683a230c83a54190366138c1a4f4310ef838b88fcJohn McCall                                  TypeSourceInfo *T,
145746b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian                                  PropertyControl propControl = None);
1458d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian  SourceLocation getAtLoc() const { return AtLoc; }
1459d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian  void setAtLoc(SourceLocation L) { AtLoc = L; }
1460d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian
146183a230c83a54190366138c1a4f4310ef838b88fcJohn McCall  TypeSourceInfo *getTypeSourceInfo() const { return DeclType; }
146283a230c83a54190366138c1a4f4310ef838b88fcJohn McCall  QualType getType() const { return DeclType->getType(); }
146383a230c83a54190366138c1a4f4310ef838b88fcJohn McCall  void setType(TypeSourceInfo *T) { DeclType = T; }
146470e5a14c6076d63833c62d1d6d628c26309897c1Douglas Gregor
1465a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner  PropertyAttributeKind getPropertyAttributes() const {
1466f4af5154571e0c5eadb19df10e65464766ef6683Chris Lattner    return PropertyAttributeKind(PropertyAttributes);
1467f4af5154571e0c5eadb19df10e65464766ef6683Chris Lattner  }
14681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setPropertyAttributes(PropertyAttributeKind PRVal) {
1469a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    PropertyAttributes |= PRVal;
147082a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian  }
1471394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar
147280aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  PropertyAttributeKind getPropertyAttributesAsWritten() const {
147380aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian    return PropertyAttributeKind(PropertyAttributesAsWritten);
147480aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  }
14750a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis
14760a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis  bool hasWrittenStorageAttribute() const {
14770a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis    return PropertyAttributesAsWritten & (OBJC_PR_assign | OBJC_PR_copy |
14780a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis        OBJC_PR_unsafe_unretained | OBJC_PR_retain | OBJC_PR_strong |
14790a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis        OBJC_PR_weak);
14800a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis  }
148180aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian
148280aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  void setPropertyAttributesAsWritten(PropertyAttributeKind PRVal) {
148380aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian    PropertyAttributesAsWritten = PRVal;
148480aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  }
148580aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian
14868cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian void makeitReadWriteAttribute(void) {
14878cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian    PropertyAttributes &= ~OBJC_PR_readonly;
14888cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian    PropertyAttributes |= OBJC_PR_readwrite;
14891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump }
14908cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian
1491af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  // Helper methods for accessing attributes.
1492af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
1493af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  /// isReadOnly - Return true iff the property has a setter.
1494394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar  bool isReadOnly() const {
1495394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar    return (PropertyAttributes & OBJC_PR_readonly);
1496394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar  }
1497af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
1498af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  /// getSetterKind - Return the method used for doing assignment in
1499af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  /// the property setter. This is only valid if the property has been
1500af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  /// defined to have a setter.
1501af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  SetterKind getSetterKind() const {
1502f85e193739c953358c865005855253af4f68a497John McCall    if (PropertyAttributes & (OBJC_PR_retain|OBJC_PR_strong))
1503af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar      return Retain;
1504af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar    if (PropertyAttributes & OBJC_PR_copy)
1505af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar      return Copy;
1506af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar    return Assign;
1507af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  }
1508af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
15095251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  Selector getGetterName() const { return GetterName; }
15105251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  void setGetterName(Selector Sel) { GetterName = Sel; }
15111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15125251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  Selector getSetterName() const { return SetterName; }
15135251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  void setSetterName(Selector Sel) { SetterName = Sel; }
15141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
151533de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  ObjCMethodDecl *getGetterMethodDecl() const { return GetterMethodDecl; }
151633de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  void setGetterMethodDecl(ObjCMethodDecl *gDecl) { GetterMethodDecl = gDecl; }
151733de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian
151833de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  ObjCMethodDecl *getSetterMethodDecl() const { return SetterMethodDecl; }
151933de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  void setSetterMethodDecl(ObjCMethodDecl *gDecl) { SetterMethodDecl = gDecl; }
15201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
152146b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  // Related to @optional/@required declared in @protocol
152246b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  void setPropertyImplementation(PropertyControl pc) {
152346b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian    PropertyImplementation = pc;
152446b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  }
152546b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  PropertyControl getPropertyImplementation() const {
152646b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian    return PropertyControl(PropertyImplementation);
15271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
15281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1529af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian  void setPropertyIvarDecl(ObjCIvarDecl *Ivar) {
1530af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian    PropertyIvarDecl = Ivar;
1531af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian  }
1532af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian  ObjCIvarDecl *getPropertyIvarDecl() const {
1533af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian    return PropertyIvarDecl;
1534af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian  }
15351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1536da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor  virtual SourceRange getSourceRange() const {
1537e3c60a7ce9e0f42c7ca2344b33203266aceca1dbDouglas Gregor    return SourceRange(AtLoc, getLocation());
1538e3c60a7ce9e0f42c7ca2344b33203266aceca1dbDouglas Gregor  }
1539e3c60a7ce9e0f42c7ca2344b33203266aceca1dbDouglas Gregor
15409f550ff05d496e6b9480e5619a21d9da0c9e27c1Ted Kremenek  /// Lookup a property by name in the specified DeclContext.
1541de09d0c9694f01a99870a8825266d44a29ebb325Ted Kremenek  static ObjCPropertyDecl *findPropertyDecl(const DeclContext *DC,
15429f550ff05d496e6b9480e5619a21d9da0c9e27c1Ted Kremenek                                            IdentifierInfo *propertyID);
15439f550ff05d496e6b9480e5619a21d9da0c9e27c1Ted Kremenek
154480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1545a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCPropertyDecl *D) { return true; }
154680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCProperty; }
154782a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian};
1548980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
15491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ObjCPropertyImplDecl - Represents implementation declaration of a property
155061d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian/// in a class or category implementation block. For example:
155161d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian/// @synthesize prop1 = ivar1;
155261d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian///
15534afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCPropertyImplDecl : public Decl {
155461d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanianpublic:
15559f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar  enum Kind {
15569f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar    Synthesize,
15579f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar    Dynamic
155861d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  };
155961d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanianprivate:
1560559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  SourceLocation AtLoc;   // location of @synthesize or @dynamic
1561a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor
1562a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  /// \brief For @synthesize, the location of the ivar, if it was written in
1563a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  /// the source code.
1564a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  ///
1565a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  /// \code
1566a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  /// @synthesize int a = b
1567a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  /// \endcode
1568a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  SourceLocation IvarLoc;
1569a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor
157061d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  /// Property declaration being implemented
157161d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  ObjCPropertyDecl *PropertyDecl;
1572be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek
157361d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  /// Null for @dynamic. Required for @synthesize.
157461d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  ObjCIvarDecl *PropertyIvarDecl;
157517cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian
157617cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  /// Null for @dynamic. Non-null if property must be copy-constructed in getter
157717cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  Expr *GetterCXXConstructor;
157817cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian
157917cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  /// Null for @dynamic. Non-null if property has assignment operator to call
158017cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  /// in Setter synthesis.
158117cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  Expr *SetterCXXAssignment;
1582be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek
1583d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  ObjCPropertyImplDecl(DeclContext *DC, SourceLocation atLoc, SourceLocation L,
15841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                       ObjCPropertyDecl *property,
15851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                       Kind PK,
1586a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor                       ObjCIvarDecl *ivarDecl,
1587a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor                       SourceLocation ivarLoc)
15881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : Decl(ObjCPropertyImpl, DC, L), AtLoc(atLoc),
1589a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor      IvarLoc(ivarLoc), PropertyDecl(property), PropertyIvarDecl(ivarDecl),
159017cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian      GetterCXXConstructor(0), SetterCXXAssignment(0) {
15919f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar    assert (PK == Dynamic || PropertyIvarDecl);
15929f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar  }
15931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15949f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbarpublic:
1595d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCPropertyImplDecl *Create(ASTContext &C, DeclContext *DC,
15961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                      SourceLocation atLoc, SourceLocation L,
15971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                      ObjCPropertyDecl *property,
15981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                      Kind PK,
1599a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor                                      ObjCIvarDecl *ivarDecl,
1600a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor                                      SourceLocation ivarLoc);
160161d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian
1602da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor  virtual SourceRange getSourceRange() const;
1603a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor
1604d40910b581b09c937a8c1fdcde9b8ec724398fb9Steve Naroff  SourceLocation getLocStart() const { return AtLoc; }
16058818c4fb69cb2a4eec94b217a90f94f9e075296eDouglas Gregor  void setAtLoc(SourceLocation Loc) { AtLoc = Loc; }
1606d40910b581b09c937a8c1fdcde9b8ec724398fb9Steve Naroff
1607be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek  ObjCPropertyDecl *getPropertyDecl() const {
1608be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek    return PropertyDecl;
1609be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek  }
16108818c4fb69cb2a4eec94b217a90f94f9e075296eDouglas Gregor  void setPropertyDecl(ObjCPropertyDecl *Prop) { PropertyDecl = Prop; }
16118818c4fb69cb2a4eec94b217a90f94f9e075296eDouglas Gregor
16129f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar  Kind getPropertyImplementation() const {
16139f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar    return PropertyIvarDecl ? Synthesize : Dynamic;
1614be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek  }
16151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1616af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  ObjCIvarDecl *getPropertyIvarDecl() const {
1617be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek    return PropertyIvarDecl;
1618be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek  }
1619a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  SourceLocation getPropertyIvarDeclLoc() const { return IvarLoc; }
1620a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor
1621a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  void setPropertyIvarDecl(ObjCIvarDecl *Ivar,
1622a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor                           SourceLocation IvarLoc) {
1623a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor    PropertyIvarDecl = Ivar;
1624a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor    this->IvarLoc = IvarLoc;
1625a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  }
162617cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian
162717cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  Expr *getGetterCXXConstructor() const {
162817cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian    return GetterCXXConstructor;
162917cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  }
163017cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  void setGetterCXXConstructor(Expr *getterCXXConstructor) {
163117cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian    GetterCXXConstructor = getterCXXConstructor;
163217cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  }
16338818c4fb69cb2a4eec94b217a90f94f9e075296eDouglas Gregor
163417cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  Expr *getSetterCXXAssignment() const {
163517cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian    return SetterCXXAssignment;
163617cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  }
163717cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  void setSetterCXXAssignment(Expr *setterCXXAssignment) {
163817cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian    SetterCXXAssignment = setterCXXAssignment;
163917cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  }
164017cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian
164180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
16421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const ObjCPropertyImplDecl *D) { return true; }
164380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Decl::Kind K) { return K == ObjCPropertyImpl; }
1644a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor
1645a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  friend class ASTDeclReader;
164661d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian};
164761d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian
1648980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff}  // end namespace clang
1649980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff#endif
1650