DeclObjC.h revision 634c5634817b9ad384a706fe87ab302985566bba
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"
18491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis#include "clang/AST/SelectorLocationsKind.h"
196ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson#include "llvm/ADT/STLExtras.h"
20aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar#include "llvm/Support/Compiler.h"
21980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
22980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffnamespace clang {
23980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffclass Expr;
24980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffclass Stmt;
25980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffclass FunctionDecl;
2660f8c868ffb346b78451a3eccaecd0461d2ae498Fariborz Jahanianclass RecordDecl;
27a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCIvarDecl;
28a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCMethodDecl;
29a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCProtocolDecl;
30a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCCategoryDecl;
31a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCPropertyDecl;
32f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanianclass ObjCPropertyImplDecl;
33cbb67480094b3bcb5b715acd827cbad55e2a204cSean Huntclass CXXCtorInitializer;
3468835718c4125f2f66740cd04de7088645ec695dChris Lattner
35793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnerclass ObjCListBase {
36f56faa01936b9cf909623d7f06e3c2569ca4a78eDmitri Gribenko  ObjCListBase(const ObjCListBase &) LLVM_DELETED_FUNCTION;
37f56faa01936b9cf909623d7f06e3c2569ca4a78eDmitri Gribenko  void operator=(const ObjCListBase &) LLVM_DELETED_FUNCTION;
38793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnerprotected:
39793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  /// List is an array of pointers to objects that are not owned by this object.
40793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  void **List;
413db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  unsigned NumElts;
42793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner
433db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattnerpublic:
44793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  ObjCListBase() : List(0), NumElts(0) {}
45793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  unsigned size() const { return NumElts; }
46793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  bool empty() const { return NumElts == 0; }
471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
48793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnerprotected:
4938af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  void set(void *const* InList, unsigned Elts, ASTContext &Ctx);
50793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner};
511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
53793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner/// ObjCList - This is a simple template class used to hold various lists of
54793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner/// decls etc, which is heavily used by the ObjC front-end.  This only use case
55793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner/// this supports is setting the list all at once and then reading elements out
56793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner/// of it.
57793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnertemplate <typename T>
58793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnerclass ObjCList : public ObjCListBase {
59793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnerpublic:
6038af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  void set(T* const* InList, unsigned Elts, ASTContext &Ctx) {
6138af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner    ObjCListBase::set(reinterpret_cast<void*const*>(InList), Elts, Ctx);
62793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  }
631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
64793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  typedef T* const * iterator;
65793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  iterator begin() const { return (iterator)List; }
66793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  iterator end() const { return (iterator)List+NumElts; }
671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
68793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  T* operator[](unsigned Idx) const {
69793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner    assert(Idx < NumElts && "Invalid access");
70793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner    return (T*)List[Idx];
713db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  }
723db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner};
733db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner
7418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor/// \brief A list of Objective-C protocols, along with the source
7518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor/// locations at which they were referenced.
7618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregorclass ObjCProtocolList : public ObjCList<ObjCProtocolDecl> {
7718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  SourceLocation *Locations;
7818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor
7918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  using ObjCList<ObjCProtocolDecl>::set;
8018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor
8118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregorpublic:
8218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  ObjCProtocolList() : ObjCList<ObjCProtocolDecl>(), Locations(0) { }
8318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor
8418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef const SourceLocation *loc_iterator;
8518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  loc_iterator loc_begin() const { return Locations; }
8618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  loc_iterator loc_end() const { return Locations + size(); }
8718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor
88ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  void set(ObjCProtocolDecl* const* InList, unsigned Elts,
8918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor           const SourceLocation *Locs, ASTContext &Ctx);
9018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor};
911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff
93a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCMethodDecl - Represents an instance or class method declaration.
9458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// ObjC methods can be declared within 4 contexts: class interfaces,
9558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// categories, protocols, and class implementations. While C++ member
961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// functions leverage C syntax, Objective-C method syntax is modeled after
971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Smalltalk (using colons to specify argument types/expressions).
9858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Here are some brief examples:
9958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff///
10058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Setter/getter instance methods:
10158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// - (void)setMenu:(NSMenu *)menu;
1021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// - (NSMenu *)menu;
1031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
10458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Instance method that takes 2 NSView arguments:
10558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// - (void)replaceSubview:(NSView *)oldView with:(NSView *)newView;
10658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff///
10758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Getter class method:
10858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// + (NSMenu *)defaultMenu;
10958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff///
11058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// A selector represents a unique name for a method. The selector names for
11158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// the above methods are setMenu:, menu, replaceSubview:with:, and defaultMenu.
11258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff///
1134afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCMethodDecl : public NamedDecl, public DeclContext {
11458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroffpublic:
11558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  enum ImplementationControl { None, Required, Optional };
11658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroffprivate:
11785f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  // The conventional meaning of this method; an ObjCMethodFamily.
11885f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  // This is not serialized; instead, it is computed on demand and
11985f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  // cached.
12085f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  mutable unsigned Family : ObjCMethodFamilyBitWidth;
12185f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall
12258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  /// instance (true) or class (false) method.
12385f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  unsigned IsInstance : 1;
12485f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  unsigned IsVariadic : 1;
1251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1261e4691b9d8e1bdcc8ef62b323969d702c51b3c08Jordan Rose  /// True if this method is the getter or setter for an explicit property.
1271e4691b9d8e1bdcc8ef62b323969d702c51b3c08Jordan Rose  unsigned IsPropertyAccessor : 1;
128ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1293fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian  // Method has a definition.
13085f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  unsigned IsDefined : 1;
1311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13272b2625aa67c8213acaf4bf6209b67859d60e2cfArgyrios Kyrtzidis  /// \brief Method redeclaration in the same interface.
1333a919e7110407ae7609bb6edc57aac16a5990661Argyrios Kyrtzidis  unsigned IsRedeclaration : 1;
1343a919e7110407ae7609bb6edc57aac16a5990661Argyrios Kyrtzidis
13572b2625aa67c8213acaf4bf6209b67859d60e2cfArgyrios Kyrtzidis  /// \brief Is redeclared in the same interface.
13672b2625aa67c8213acaf4bf6209b67859d60e2cfArgyrios Kyrtzidis  mutable unsigned HasRedeclaration : 1;
13772b2625aa67c8213acaf4bf6209b67859d60e2cfArgyrios Kyrtzidis
138ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  // NOTE: VC++ treats enums as signed, avoid using ImplementationControl enum
13941c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  /// \@required/\@optional
140ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  unsigned DeclImplementation : 2;
1411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
142ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  // NOTE: VC++ treats enums as signed, avoid using the ObjCDeclQualifier enum
14358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  /// in, inout, etc.
144ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  unsigned objcDeclQualifier : 6;
1451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
146926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor  /// \brief Indicates whether this method has a related result type.
147926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor  unsigned RelatedResultType : 1;
148ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
149491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// \brief Whether the locations of the selector identifiers are in a
150491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// "standard" position, a enum SelectorLocationsKind.
151491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  unsigned SelLocsKind : 2;
1527732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian
153e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis  /// \brief Whether this method overrides any other in the class hierarchy.
154e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis  ///
155e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis  /// A method is said to override any method in the class's
156e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis  /// base classes, its protocols, or its categories' protocols, that has
157e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis  /// the same selector and is of the same kind (class or instance).
158e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis  /// A method in an implementation is not considered as overriding the same
159e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis  /// method in the interface or its categories.
160e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis  unsigned IsOverriding : 1;
161e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis
16235f3f36cb9451f347b83a6e7f01e3c702df4732dArgyrios Kyrtzidis  /// \brief Indicates if the method was a definition but its body was skipped.
16335f3f36cb9451f347b83a6e7f01e3c702df4732dArgyrios Kyrtzidis  unsigned HasSkippedBody : 1;
16435f3f36cb9451f347b83a6e7f01e3c702df4732dArgyrios Kyrtzidis
1654bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor  // Result type of this method.
16658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  QualType MethodDeclType;
167ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1684bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor  // Type source information for the result type.
1694bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor  TypeSourceInfo *ResultTInfo;
1704bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor
171491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// \brief Array of ParmVarDecls for the formal parameters of this method
172491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// and optionally followed by selector locations.
173491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  void *ParamsAndSelLocs;
174491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  unsigned NumParams;
1751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  /// List of attributes for this method declaration.
177a0cff720d40f239fee0e5ecc8378122b456c1991Argyrios Kyrtzidis  SourceLocation DeclEndLoc; // the location of the ';' or '{'.
1781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  // The following are only used for method definitions, null otherwise.
1805456b0fe40714a78cd0ba7c1a5b7dc34eda385afDouglas Gregor  LazyDeclStmtPtr Body;
181451318c08a6342c10b8986060386fd9274418437Daniel Dunbar
182451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// SelfDecl - Decl for the implicit self parameter. This is lazily
183451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// constructed by createImplicitParams.
1844111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  ImplicitParamDecl *SelfDecl;
185451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// CmdDecl - Decl for the implicit _cmd parameter. This is lazily
186451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// constructed by createImplicitParams.
1874111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  ImplicitParamDecl *CmdDecl;
1881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
189491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  SelectorLocationsKind getSelLocsKind() const {
190491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    return (SelectorLocationsKind)SelLocsKind;
191491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  }
192491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  bool hasStandardSelLocs() const {
193491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    return getSelLocsKind() != SelLoc_NonStandard;
194491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  }
195491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis
196491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// \brief Get a pointer to the stored selector identifiers locations array.
197491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// No locations will be stored if HasStandardSelLocs is true.
198491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  SourceLocation *getStoredSelLocs() {
199491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    return reinterpret_cast<SourceLocation*>(getParams() + NumParams);
200491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  }
201491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  const SourceLocation *getStoredSelLocs() const {
202491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    return reinterpret_cast<const SourceLocation*>(getParams() + NumParams);
203491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  }
204491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis
205491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// \brief Get a pointer to the stored selector identifiers locations array.
206491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// No locations will be stored if HasStandardSelLocs is true.
207491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  ParmVarDecl **getParams() {
208491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    return reinterpret_cast<ParmVarDecl **>(ParamsAndSelLocs);
209491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  }
210491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  const ParmVarDecl *const *getParams() const {
211491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    return reinterpret_cast<const ParmVarDecl *const *>(ParamsAndSelLocs);
212491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  }
213491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis
214491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// \brief Get the number of stored selector identifiers locations.
215491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// No locations will be stored if HasStandardSelLocs is true.
216491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  unsigned getNumStoredSelLocs() const {
217491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    if (hasStandardSelLocs())
218491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis      return 0;
219491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    return getNumSelectorLocs();
220491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  }
221491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis
222491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  void setParamsAndSelLocs(ASTContext &C,
223491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis                           ArrayRef<ParmVarDecl*> Params,
224491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis                           ArrayRef<SourceLocation> SelLocs);
225491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis
226a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCMethodDecl(SourceLocation beginLoc, SourceLocation endLoc,
22758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff                 Selector SelInfo, QualType T,
2284bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor                 TypeSourceInfo *ResultTInfo,
2290701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff                 DeclContext *contextDecl,
230f6414927e67e27d9324d8d179c5f7ea620443924Daniel Dunbar                 bool isInstance = true,
23158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff                 bool isVariadic = false,
2321e4691b9d8e1bdcc8ef62b323969d702c51b3c08Jordan Rose                 bool isPropertyAccessor = false,
23375cf3e86d33ce810c12084126385371b335c30baArgyrios Kyrtzidis                 bool isImplicitlyDeclared = false,
2343fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian                 bool isDefined = false,
2357732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian                 ImplementationControl impControl = None,
236da92a7f91cf88f49e02050919676f7fb8e3bdff8Argyrios Kyrtzidis                 bool HasRelatedResultType = false)
2374afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  : NamedDecl(ObjCMethod, contextDecl, beginLoc, SelInfo),
23885f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall    DeclContext(ObjCMethod), Family(InvalidObjCMethodFamily),
23958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff    IsInstance(isInstance), IsVariadic(isVariadic),
2401e4691b9d8e1bdcc8ef62b323969d702c51b3c08Jordan Rose    IsPropertyAccessor(isPropertyAccessor),
24172b2625aa67c8213acaf4bf6209b67859d60e2cfArgyrios Kyrtzidis    IsDefined(isDefined), IsRedeclaration(0), HasRedeclaration(0),
24258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff    DeclImplementation(impControl), objcDeclQualifier(OBJC_TQ_None),
243da92a7f91cf88f49e02050919676f7fb8e3bdff8Argyrios Kyrtzidis    RelatedResultType(HasRelatedResultType),
244fb4f3a2591782f8643f06724703d2e5b03af36d2Argyrios Kyrtzidis    SelLocsKind(SelLoc_StandardNoSpace), IsOverriding(0), HasSkippedBody(0),
245926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor    MethodDeclType(T), ResultTInfo(ResultTInfo),
246491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    ParamsAndSelLocs(0), NumParams(0),
2475456b0fe40714a78cd0ba7c1a5b7dc34eda385afDouglas Gregor    DeclEndLoc(endLoc), Body(), SelfDecl(0), CmdDecl(0) {
24875cf3e86d33ce810c12084126385371b335c30baArgyrios Kyrtzidis    setImplicit(isImplicitlyDeclared);
24975cf3e86d33ce810c12084126385371b335c30baArgyrios Kyrtzidis  }
2508a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek
25157ea6bee79cc60ba20c7886b453f40f380dce1b1Argyrios Kyrtzidis  /// \brief A definition will return its interface declaration.
25257ea6bee79cc60ba20c7886b453f40f380dce1b1Argyrios Kyrtzidis  /// An interface declaration will return its definition.
25357ea6bee79cc60ba20c7886b453f40f380dce1b1Argyrios Kyrtzidis  /// Otherwise it will return itself.
254da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor  virtual ObjCMethodDecl *getNextRedeclaration();
255da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor
2566c4ae5de0c356777446f823b573821fb95560d91Chris Lattnerpublic:
2570ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner  static ObjCMethodDecl *Create(ASTContext &C,
2581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                SourceLocation beginLoc,
25911d77169555480ee0a04c6e5bc390d8fde41175dArgyrios Kyrtzidis                                SourceLocation endLoc,
26011d77169555480ee0a04c6e5bc390d8fde41175dArgyrios Kyrtzidis                                Selector SelInfo,
261ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                QualType T,
2624bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor                                TypeSourceInfo *ResultTInfo,
2634bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor                                DeclContext *contextDecl,
264f6414927e67e27d9324d8d179c5f7ea620443924Daniel Dunbar                                bool isInstance = true,
2656c4ae5de0c356777446f823b573821fb95560d91Chris Lattner                                bool isVariadic = false,
2661e4691b9d8e1bdcc8ef62b323969d702c51b3c08Jordan Rose                                bool isPropertyAccessor = false,
26775cf3e86d33ce810c12084126385371b335c30baArgyrios Kyrtzidis                                bool isImplicitlyDeclared = false,
2683fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian                                bool isDefined = false,
2697732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian                                ImplementationControl impControl = None,
270da92a7f91cf88f49e02050919676f7fb8e3bdff8Argyrios Kyrtzidis                                bool HasRelatedResultType = false);
271e7f9d301a10b4b3223e91d9be4362b44cba0a212Argyrios Kyrtzidis
2721e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor  static ObjCMethodDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2731e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor
274da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor  virtual ObjCMethodDecl *getCanonicalDecl();
27513e635c55eb23f736d38abf9c954801bd6482db4Ted Kremenek  const ObjCMethodDecl *getCanonicalDecl() const {
27613e635c55eb23f736d38abf9c954801bd6482db4Ted Kremenek    return const_cast<ObjCMethodDecl*>(this)->getCanonicalDecl();
27713e635c55eb23f736d38abf9c954801bd6482db4Ted Kremenek  }
278e7f9d301a10b4b3223e91d9be4362b44cba0a212Argyrios Kyrtzidis
279ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  ObjCDeclQualifier getObjCDeclQualifier() const {
280ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek    return ObjCDeclQualifier(objcDeclQualifier);
281ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  }
282a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void setObjCDeclQualifier(ObjCDeclQualifier QV) { objcDeclQualifier = QV; }
2831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
284926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor  /// \brief Determine whether this method has a result type that is related
285926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor  /// to the message receiver's type.
286926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor  bool hasRelatedResultType() const { return RelatedResultType; }
287ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
288926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor  /// \brief Note whether this method has a related result type.
289926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor  void SetRelatedResultType(bool RRT = true) { RelatedResultType = RRT; }
2903a919e7110407ae7609bb6edc57aac16a5990661Argyrios Kyrtzidis
2913a919e7110407ae7609bb6edc57aac16a5990661Argyrios Kyrtzidis  /// \brief True if this is a method redeclaration in the same interface.
2923a919e7110407ae7609bb6edc57aac16a5990661Argyrios Kyrtzidis  bool isRedeclaration() const { return IsRedeclaration; }
2933a919e7110407ae7609bb6edc57aac16a5990661Argyrios Kyrtzidis  void setAsRedeclaration(const ObjCMethodDecl *PrevMethod);
294ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
295a0cff720d40f239fee0e5ecc8378122b456c1991Argyrios Kyrtzidis  /// \brief Returns the location where the declarator ends. It will be
296a0cff720d40f239fee0e5ecc8378122b456c1991Argyrios Kyrtzidis  /// the location of ';' for a method declaration and the location of '{'
297a0cff720d40f239fee0e5ecc8378122b456c1991Argyrios Kyrtzidis  /// for a method definition.
298a0cff720d40f239fee0e5ecc8378122b456c1991Argyrios Kyrtzidis  SourceLocation getDeclaratorEndLoc() const { return DeclEndLoc; }
299a0cff720d40f239fee0e5ecc8378122b456c1991Argyrios Kyrtzidis
30058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  // Location information, modeled after the Stmt API.
301aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceLocation getLocStart() const LLVM_READONLY { return getLocation(); }
302a0cff720d40f239fee0e5ecc8378122b456c1991Argyrios Kyrtzidis  SourceLocation getLocEnd() const LLVM_READONLY;
303aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  virtual SourceRange getSourceRange() const LLVM_READONLY {
304a0cff720d40f239fee0e5ecc8378122b456c1991Argyrios Kyrtzidis    return SourceRange(getLocation(), getLocEnd());
3059776ba0d844cf9f6888e871e3fd246ae782f76f4Daniel Dunbar  }
3061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
307746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis  SourceLocation getSelectorStartLoc() const {
308746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis    if (isImplicit())
309746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis      return getLocStart();
310746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis    return getSelectorLoc(0);
311746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis  }
312491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  SourceLocation getSelectorLoc(unsigned Index) const {
313491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    assert(Index < getNumSelectorLocs() && "Index out of range!");
314491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    if (hasStandardSelLocs())
315491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis      return getStandardSelectorLoc(Index, getSelector(),
316491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis                                   getSelLocsKind() == SelLoc_StandardWithSpace,
317491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis                      llvm::makeArrayRef(const_cast<ParmVarDecl**>(getParams()),
318491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis                                         NumParams),
319a0cff720d40f239fee0e5ecc8378122b456c1991Argyrios Kyrtzidis                                   DeclEndLoc);
320491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    return getStoredSelLocs()[Index];
321491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  }
322491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis
323491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  void getSelectorLocs(SmallVectorImpl<SourceLocation> &SelLocs) const;
324491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis
325491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  unsigned getNumSelectorLocs() const {
326491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    if (isImplicit())
327491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis      return 0;
328491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    Selector Sel = getSelector();
329491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    if (Sel.isUnarySelector())
330491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis      return 1;
331491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    return Sel.getNumArgs();
332491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  }
333491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis
3345619688510185081cbb4621d703daf7ee24cf39aChris Lattner  ObjCInterfaceDecl *getClassInterface();
3355619688510185081cbb4621d703daf7ee24cf39aChris Lattner  const ObjCInterfaceDecl *getClassInterface() const {
3365619688510185081cbb4621d703daf7ee24cf39aChris Lattner    return const_cast<ObjCMethodDecl*>(this)->getClassInterface();
337e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  }
3381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3392e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  Selector getSelector() const { return getDeclName().getObjCSelector(); }
3403a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson
34158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  QualType getResultType() const { return MethodDeclType; }
34253c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setResultType(QualType T) { MethodDeclType = T; }
3431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
344ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Determine the type of an expression that sends a message to this
3455291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// function.
3465291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  QualType getSendResultType() const {
3476398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor    return getResultType().getNonLValueExprType(getASTContext());
3485291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  }
349ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3504bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor  TypeSourceInfo *getResultTypeSourceInfo() const { return ResultTInfo; }
3514bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor  void setResultTypeSourceInfo(TypeSourceInfo *TInfo) { ResultTInfo = TInfo; }
3524bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor
353d57f635d520e8cb5b93d3d770ff58db06c62de54Chris Lattner  // Iterator access to formal parameters.
354491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  unsigned param_size() const { return NumParams; }
355491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  typedef const ParmVarDecl *const *param_const_iterator;
356491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  typedef ParmVarDecl *const *param_iterator;
357491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  param_const_iterator param_begin() const { return getParams(); }
358491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  param_const_iterator param_end() const { return getParams() + NumParams; }
359491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  param_iterator param_begin() { return getParams(); }
360491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  param_iterator param_end() { return getParams() + NumParams; }
3617732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian  // This method returns and of the parameters which are part of the selector
3627732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian  // name mangling requirements.
363ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  param_const_iterator sel_param_end() const {
364ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return param_begin() + getSelector().getNumArgs();
3657732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian  }
36689951a86b594513c2a013532ed45d197413b1087Chris Lattner
3679dd0065e61ea4b48b19eee550704ce964e64e946Argyrios Kyrtzidis  /// \brief Sets the method's parameters and selector source locations.
3681824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko  /// If the method is implicit (not coming from source) \p SelLocs is
3699dd0065e61ea4b48b19eee550704ce964e64e946Argyrios Kyrtzidis  /// ignored.
370491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  void setMethodParams(ASTContext &C,
371491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis                       ArrayRef<ParmVarDecl*> Params,
3729dd0065e61ea4b48b19eee550704ce964e64e946Argyrios Kyrtzidis                       ArrayRef<SourceLocation> SelLocs =
3739dd0065e61ea4b48b19eee550704ce964e64e946Argyrios Kyrtzidis                           ArrayRef<SourceLocation>());
3744111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner
3756ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson  // Iterator access to parameter types.
3766ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson  typedef std::const_mem_fun_t<QualType, ParmVarDecl> deref_fun;
377491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  typedef llvm::mapped_iterator<param_const_iterator, deref_fun>
378491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis      arg_type_iterator;
3796ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson
3806ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson  arg_type_iterator arg_type_begin() const {
3816ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson    return llvm::map_iterator(param_begin(), deref_fun(&ParmVarDecl::getType));
3826ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson  }
3836ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson  arg_type_iterator arg_type_end() const {
3846ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson    return llvm::map_iterator(param_end(), deref_fun(&ParmVarDecl::getType));
3856ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson  }
3861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
387451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// createImplicitParams - Used to lazily create the self and cmd
388451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// implict parameters. This must be called prior to using getSelfDecl()
389451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// or getCmdDecl(). The call is ignored if the implicit paramters
390451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// have already been created.
391fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian  void createImplicitParams(ASTContext &Context, const ObjCInterfaceDecl *ID);
392451318c08a6342c10b8986060386fd9274418437Daniel Dunbar
3934111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  ImplicitParamDecl * getSelfDecl() const { return SelfDecl; }
39453c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setSelfDecl(ImplicitParamDecl *SD) { SelfDecl = SD; }
3954111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  ImplicitParamDecl * getCmdDecl() const { return CmdDecl; }
39653c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setCmdDecl(ImplicitParamDecl *CD) { CmdDecl = CD; }
3971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
39885f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  /// Determines the family of this method.
39985f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  ObjCMethodFamily getMethodFamily() const;
40085f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall
401f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor  bool isInstanceMethod() const { return IsInstance; }
40253c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setInstanceMethod(bool isInst) { IsInstance = isInst; }
40358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  bool isVariadic() const { return IsVariadic; }
40453c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setVariadic(bool isVar) { IsVariadic = isVar; }
4051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
406f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor  bool isClassMethod() const { return !IsInstance; }
407f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor
4081e4691b9d8e1bdcc8ef62b323969d702c51b3c08Jordan Rose  bool isPropertyAccessor() const { return IsPropertyAccessor; }
4091e4691b9d8e1bdcc8ef62b323969d702c51b3c08Jordan Rose  void setPropertyAccessor(bool isAccessor) { IsPropertyAccessor = isAccessor; }
410ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
4113fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian  bool isDefined() const { return IsDefined; }
4123fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian  void setDefined(bool isDefined) { IsDefined = isDefined; }
4131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
414e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis  /// \brief Whether this method overrides any other in the class hierarchy.
415e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis  ///
416e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis  /// A method is said to override any method in the class's
417e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis  /// base classes, its protocols, or its categories' protocols, that has
418e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis  /// the same selector and is of the same kind (class or instance).
419e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis  /// A method in an implementation is not considered as overriding the same
420e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis  /// method in the interface or its categories.
421e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis  bool isOverriding() const { return IsOverriding; }
422e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis  void setOverriding(bool isOverriding) { IsOverriding = isOverriding; }
423740ae67dbf8dac44dbc8d6593a60f4f37a0a2aa5Argyrios Kyrtzidis
424740ae67dbf8dac44dbc8d6593a60f4f37a0a2aa5Argyrios Kyrtzidis  /// \brief Return overridden methods for the given \p Method.
425740ae67dbf8dac44dbc8d6593a60f4f37a0a2aa5Argyrios Kyrtzidis  ///
426740ae67dbf8dac44dbc8d6593a60f4f37a0a2aa5Argyrios Kyrtzidis  /// An ObjC method is considered to override any method in the class's
427bf967be66ea8c51b66c61659c23240f762a56dbeFariborz Jahanian  /// base classes (and base's categories), its protocols, or its categories'
428bf967be66ea8c51b66c61659c23240f762a56dbeFariborz Jahanian  /// protocols, that has
429740ae67dbf8dac44dbc8d6593a60f4f37a0a2aa5Argyrios Kyrtzidis  /// the same selector and is of the same kind (class or instance).
430740ae67dbf8dac44dbc8d6593a60f4f37a0a2aa5Argyrios Kyrtzidis  /// A method in an implementation is not considered as overriding the same
431740ae67dbf8dac44dbc8d6593a60f4f37a0a2aa5Argyrios Kyrtzidis  /// method in the interface or its categories.
432740ae67dbf8dac44dbc8d6593a60f4f37a0a2aa5Argyrios Kyrtzidis  void getOverriddenMethods(
433740ae67dbf8dac44dbc8d6593a60f4f37a0a2aa5Argyrios Kyrtzidis                     SmallVectorImpl<const ObjCMethodDecl *> &Overridden) const;
43404bec39d61f2b392d798882c9141fecf3ca653c5Jordan Rose
43535f3f36cb9451f347b83a6e7f01e3c702df4732dArgyrios Kyrtzidis  /// \brief True if the method was a definition but its body was skipped.
43635f3f36cb9451f347b83a6e7f01e3c702df4732dArgyrios Kyrtzidis  bool hasSkippedBody() const { return HasSkippedBody; }
43735f3f36cb9451f347b83a6e7f01e3c702df4732dArgyrios Kyrtzidis  void setHasSkippedBody(bool Skipped = true) { HasSkippedBody = Skipped; }
43835f3f36cb9451f347b83a6e7f01e3c702df4732dArgyrios Kyrtzidis
43904bec39d61f2b392d798882c9141fecf3ca653c5Jordan Rose  /// \brief Returns the property associated with this method's selector.
44004bec39d61f2b392d798882c9141fecf3ca653c5Jordan Rose  ///
44104bec39d61f2b392d798882c9141fecf3ca653c5Jordan Rose  /// Note that even if this particular method is not marked as a property
44204bec39d61f2b392d798882c9141fecf3ca653c5Jordan Rose  /// accessor, it is still possible for it to match a property declared in a
44304bec39d61f2b392d798882c9141fecf3ca653c5Jordan Rose  /// superclass. Pass \c false if you only want to check the current class.
44404bec39d61f2b392d798882c9141fecf3ca653c5Jordan Rose  const ObjCPropertyDecl *findPropertyDecl(bool CheckOverrides = true) const;
44504bec39d61f2b392d798882c9141fecf3ca653c5Jordan Rose
44641c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  // Related to protocols declared in  \@protocol
4471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setDeclImplementation(ImplementationControl ic) {
4481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    DeclImplementation = ic;
44958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  }
4501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ImplementationControl getImplementationControl() const {
4511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return ImplementationControl(DeclImplementation);
45258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  }
453792481eec23d8c1aa92173be589e2ae9d02514a5Ted Kremenek
4545456b0fe40714a78cd0ba7c1a5b7dc34eda385afDouglas Gregor  /// \brief Determine whether this method has a body.
4555456b0fe40714a78cd0ba7c1a5b7dc34eda385afDouglas Gregor  virtual bool hasBody() const { return Body; }
4565456b0fe40714a78cd0ba7c1a5b7dc34eda385afDouglas Gregor
4575456b0fe40714a78cd0ba7c1a5b7dc34eda385afDouglas Gregor  /// \brief Retrieve the body of this method, if it has one.
4585456b0fe40714a78cd0ba7c1a5b7dc34eda385afDouglas Gregor  virtual Stmt *getBody() const;
4595456b0fe40714a78cd0ba7c1a5b7dc34eda385afDouglas Gregor
4605456b0fe40714a78cd0ba7c1a5b7dc34eda385afDouglas Gregor  void setLazyBody(uint64_t Offset) { Body = Offset; }
4615456b0fe40714a78cd0ba7c1a5b7dc34eda385afDouglas Gregor
4625456b0fe40714a78cd0ba7c1a5b7dc34eda385afDouglas Gregor  CompoundStmt *getCompoundBody() { return (CompoundStmt*)getBody(); }
463d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl  void setBody(Stmt *B) { Body = B; }
46458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff
46566570b230941651245accbc5680b60e904eb993cArgyrios Kyrtzidis  /// \brief Returns whether this specific method is a definition.
46666570b230941651245accbc5680b60e904eb993cArgyrios Kyrtzidis  bool isThisDeclarationADefinition() const { return Body; }
46766570b230941651245accbc5680b60e904eb993cArgyrios Kyrtzidis
46858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  // Implement isa/cast/dyncast/etc.
46980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
47080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCMethod; }
47142220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  static DeclContext *castToDeclContext(const ObjCMethodDecl *D) {
47242220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis    return static_cast<DeclContext *>(const_cast<ObjCMethodDecl*>(D));
47342220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  }
47442220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  static ObjCMethodDecl *castFromDeclContext(const DeclContext *DC) {
47542220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis    return static_cast<ObjCMethodDecl *>(const_cast<DeclContext*>(DC));
47642220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  }
477491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis
478491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  friend class ASTDeclReader;
479491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  friend class ASTDeclWriter;
48058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff};
481e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
482e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff/// ObjCContainerDecl - Represents a container for method declarations.
483aecae629269fae3bf484baf1d109e9a89d14eeadArgyrios Kyrtzidis/// Current sub-classes are ObjCInterfaceDecl, ObjCCategoryDecl,
4841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ObjCProtocolDecl, and ObjCImplDecl.
485e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff///
4864afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCContainerDecl : public NamedDecl, public DeclContext {
48799ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
48899ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie
4891711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis  SourceLocation AtStart;
4901711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis
491782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  // These two locations in the range mark the end of the method container.
492782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  // The first points to the '@' token, and the second to the 'end' token.
493782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  SourceRange AtEnd;
494e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroffpublic:
495e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
4961711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis  ObjCContainerDecl(Kind DK, DeclContext *DC,
4971711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                    IdentifierInfo *Id, SourceLocation nameLoc,
4981711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                    SourceLocation atStartLoc)
4991711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis    : NamedDecl(DK, DC, nameLoc, Id), DeclContext(DK), AtStart(atStartLoc) {}
500e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
50193983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff  // Iterator access to properties.
50293983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff  typedef specific_decl_iterator<ObjCPropertyDecl> prop_iterator;
5031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  prop_iterator prop_begin() const {
50417945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return prop_iterator(decls_begin());
50593983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff  }
5061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  prop_iterator prop_end() const {
50717945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return prop_iterator(decls_end());
50809c4719788a5cea09897525e528fa00420f1677bSteve Naroff  }
5091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5100701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  // Iterator access to instance/class methods.
511f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor  typedef specific_decl_iterator<ObjCMethodDecl> method_iterator;
5121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  method_iterator meth_begin() const {
51317945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return method_iterator(decls_begin());
5147ed4faca5162b3ab85be7f7e57aa40e6ec170971Ted Kremenek  }
5151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  method_iterator meth_end() const {
51617945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return method_iterator(decls_end());
5177ed4faca5162b3ab85be7f7e57aa40e6ec170971Ted Kremenek  }
5180701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
5191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  typedef filtered_decl_iterator<ObjCMethodDecl,
5201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                 &ObjCMethodDecl::isInstanceMethod>
521669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor    instmeth_iterator;
52217945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  instmeth_iterator instmeth_begin() const {
52317945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return instmeth_iterator(decls_begin());
524e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff  }
52517945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  instmeth_iterator instmeth_end() const {
52617945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return instmeth_iterator(decls_end());
527e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff  }
528e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
5291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  typedef filtered_decl_iterator<ObjCMethodDecl,
5301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                 &ObjCMethodDecl::isClassMethod>
531669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor    classmeth_iterator;
53217945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  classmeth_iterator classmeth_begin() const {
53317945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return classmeth_iterator(decls_begin());
534e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff  }
53517945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  classmeth_iterator classmeth_end() const {
53617945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return classmeth_iterator(decls_end());
5370701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  }
5380701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
5390701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  // Get the local instance/class method declared in this interface.
54004593d0f9d84f6adf942bd66f1587e05c6a47c42Argyrios Kyrtzidis  ObjCMethodDecl *getMethod(Selector Sel, bool isInstance,
54104593d0f9d84f6adf942bd66f1587e05c6a47c42Argyrios Kyrtzidis                            bool AllowHidden = false) const;
54204593d0f9d84f6adf942bd66f1587e05c6a47c42Argyrios Kyrtzidis  ObjCMethodDecl *getInstanceMethod(Selector Sel,
54304593d0f9d84f6adf942bd66f1587e05c6a47c42Argyrios Kyrtzidis                                    bool AllowHidden = false) const {
54404593d0f9d84f6adf942bd66f1587e05c6a47c42Argyrios Kyrtzidis    return getMethod(Sel, true/*isInstance*/, AllowHidden);
54504593d0f9d84f6adf942bd66f1587e05c6a47c42Argyrios Kyrtzidis  }
54604593d0f9d84f6adf942bd66f1587e05c6a47c42Argyrios Kyrtzidis  ObjCMethodDecl *getClassMethod(Selector Sel, bool AllowHidden = false) const {
54704593d0f9d84f6adf942bd66f1587e05c6a47c42Argyrios Kyrtzidis    return getMethod(Sel, false/*isInstance*/, AllowHidden);
548467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis  }
5495bdaef55d486f20346fe16f3d41324694d3ff0d5Fariborz Jahanian  bool HasUserDeclaredSetterMethod(const ObjCPropertyDecl *P) const;
550467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis  ObjCIvarDecl *getIvarDecl(IdentifierInfo *Id) const;
5511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
55217945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  ObjCPropertyDecl *FindPropertyDeclaration(IdentifierInfo *PropertyId) const;
55393983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff
554e63aedd0cb064fc106636ad856cc0e645e6374ceAnna Zaks  typedef llvm::DenseMap<IdentifierInfo*, ObjCPropertyDecl*> PropertyMap;
555cfaed8d399a34e79fbab9f70eb4ea1bbeb81a02bFariborz Jahanian
556cfaed8d399a34e79fbab9f70eb4ea1bbeb81a02bFariborz Jahanian  typedef llvm::SmallVector<ObjCPropertyDecl*, 8> PropertyDeclOrder;
557cfaed8d399a34e79fbab9f70eb4ea1bbeb81a02bFariborz Jahanian
558b36ea375e20f71df19c101fa2399b7ea3a607e04Anna Zaks  /// This routine collects list of properties to be implemented in the class.
559b36ea375e20f71df19c101fa2399b7ea3a607e04Anna Zaks  /// This includes, class's and its conforming protocols' properties.
560e63aedd0cb064fc106636ad856cc0e645e6374ceAnna Zaks  /// Note, the superclass's properties are not included in the list.
561cfaed8d399a34e79fbab9f70eb4ea1bbeb81a02bFariborz Jahanian  virtual void collectPropertiesToImplement(PropertyMap &PM,
562cfaed8d399a34e79fbab9f70eb4ea1bbeb81a02bFariborz Jahanian                                            PropertyDeclOrder &PO) const {}
563b36ea375e20f71df19c101fa2399b7ea3a607e04Anna Zaks
5641711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis  SourceLocation getAtStartLoc() const { return AtStart; }
5651711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis  void setAtStartLoc(SourceLocation Loc) { AtStart = Loc; }
5661711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis
567e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff  // Marks the end of the container.
568782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  SourceRange getAtEndRange() const {
569782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek    return AtEnd;
570782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  }
571782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  void setAtEndRange(SourceRange atEnd) {
572782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek    AtEnd = atEnd;
573782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  }
574ddfd4c9eda34765b08fae4cb31ad5a365face107Argyrios Kyrtzidis
575aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  virtual SourceRange getSourceRange() const LLVM_READONLY {
5761711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis    return SourceRange(AtStart, getAtEndRange().getEnd());
577ddfd4c9eda34765b08fae4cb31ad5a365face107Argyrios Kyrtzidis  }
5781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
57909c4719788a5cea09897525e528fa00420f1677bSteve Naroff  // Implement isa/cast/dyncast/etc.
58080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
58180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) {
5829a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt    return K >= firstObjCContainer &&
5839a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt           K <= lastObjCContainer;
58480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  }
58509c4719788a5cea09897525e528fa00420f1677bSteve Naroff
58609c4719788a5cea09897525e528fa00420f1677bSteve Naroff  static DeclContext *castToDeclContext(const ObjCContainerDecl *D) {
58709c4719788a5cea09897525e528fa00420f1677bSteve Naroff    return static_cast<DeclContext *>(const_cast<ObjCContainerDecl*>(D));
58809c4719788a5cea09897525e528fa00420f1677bSteve Naroff  }
58909c4719788a5cea09897525e528fa00420f1677bSteve Naroff  static ObjCContainerDecl *castFromDeclContext(const DeclContext *DC) {
59009c4719788a5cea09897525e528fa00420f1677bSteve Naroff    return static_cast<ObjCContainerDecl *>(const_cast<DeclContext*>(DC));
59109c4719788a5cea09897525e528fa00420f1677bSteve Naroff  }
592e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff};
593e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
5940982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief Represents an ObjC class declaration.
5950c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
5960982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// For example:
5970982205bade2fb4fc984c27b2ab401e683963b10James Dennett///
5980982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \code
5990c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   // MostPrimitive declares no super class (not particularly useful).
60041c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth///   \@interface MostPrimitive
6010c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     // no instance variables or methods.
60241c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth///   \@end
6030c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
6041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///   // NSResponder inherits from NSObject & implements NSCoding (a protocol).
6050982205bade2fb4fc984c27b2ab401e683963b10James Dennett///   \@interface NSResponder : NSObject \<NSCoding>
606a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek///   { // instance variables are represented by ObjCIvarDecl.
6070c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     id nextResponder; // nextResponder instance variable.
6080c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   }
6090c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   - (NSResponder *)nextResponder; // return a pointer to NSResponder.
6100c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   - (void)mouseMoved:(NSEvent *)theEvent; // return void, takes a pointer
61141c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth///   \@end                                    // to an NSEvent.
6120982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \endcode
6130c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
61441c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth///   Unlike C/C++, forward class declarations are accomplished with \@class.
61541c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth///   Unlike C/C++, \@class allows for a list of classes to be forward declared.
6160c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   Unlike C++, ObjC is a single-rooted class model. In Cocoa, classes
6170c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   typically inherit from NSObject (an exception is NSProxy).
6180c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
61953df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregorclass ObjCInterfaceDecl : public ObjCContainerDecl
62053df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor                        , public Redeclarable<ObjCInterfaceDecl> {
62199ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
62299ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie
6233110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff  /// TypeForDecl - This indicates the Type object that represents this
6243110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff  /// TypeDecl.  It is a cache maintained by ASTContext::getObjCInterfaceType
625f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  mutable const Type *TypeForDecl;
6263110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff  friend class ASTContext;
6272e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
6282e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  struct DefinitionData {
62926fec63b14565e9e2d8c9935b276b99be950444aDouglas Gregor    /// \brief The definition of this class, for quick access from any
63026fec63b14565e9e2d8c9935b276b99be950444aDouglas Gregor    /// declaration.
63126fec63b14565e9e2d8c9935b276b99be950444aDouglas Gregor    ObjCInterfaceDecl *Definition;
63226fec63b14565e9e2d8c9935b276b99be950444aDouglas Gregor
6332e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    /// Class's super class.
6342e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    ObjCInterfaceDecl *SuperClass;
6351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
63641c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth    /// Protocols referenced in the \@interface  declaration
6372e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    ObjCProtocolList ReferencedProtocols;
6381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
63941c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth    /// Protocols reference in both the \@interface and class extensions.
6402e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    ObjCList<ObjCProtocolDecl> AllReferencedProtocols;
641ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
6422e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    /// \brief List of categories and class extensions defined for this class.
6432e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    ///
6442e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    /// Categories are stored as a linked list in the AST, since the categories
6452e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    /// and class extensions come long after the initial interface declaration,
6462e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    /// and we avoid dynamically-resized arrays in the AST wherever possible.
6472e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    ObjCCategoryDecl *CategoryList;
6481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6492e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    /// IvarList - List of all ivars defined by this class; including class
6502e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    /// extensions and implementation. This list is built lazily.
6512e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    ObjCIvarDecl *IvarList;
652ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
6532e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    /// \brief Indicates that the contents of this Objective-C class will be
6542e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    /// completed by the external AST source when required.
6552e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    mutable bool ExternallyCompleted : 1;
6562e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
6574919de6a53a007487c6d6b173921b5e7152a2004Adrian Prantl    /// \brief Indicates that the ivar cache does not yet include ivars
6584919de6a53a007487c6d6b173921b5e7152a2004Adrian Prantl    /// declared in the implementation.
6594919de6a53a007487c6d6b173921b5e7152a2004Adrian Prantl    mutable bool IvarListMissingImplementation : 1;
6604919de6a53a007487c6d6b173921b5e7152a2004Adrian Prantl
66105c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor    /// \brief The location of the superclass, if any.
66205c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor    SourceLocation SuperClassLoc;
663161794732195881c33305f701f6e58721998541fDouglas Gregor
66405c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor    /// \brief The location of the last location in this declaration, before
66505c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor    /// the properties/methods. For example, this will be the '>', '}', or
66605c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor    /// identifier,
66705c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor    SourceLocation EndLoc;
66805c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor
66926fec63b14565e9e2d8c9935b276b99be950444aDouglas Gregor    DefinitionData() : Definition(), SuperClass(), CategoryList(), IvarList(),
6704919de6a53a007487c6d6b173921b5e7152a2004Adrian Prantl                       ExternallyCompleted(),
6714919de6a53a007487c6d6b173921b5e7152a2004Adrian Prantl                       IvarListMissingImplementation(true) { }
6722e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  };
6732e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
6742e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id,
67537f953f021c67e3b97f1ef38e1ef3cb08bd9d146Douglas Gregor                    SourceLocation CLoc, ObjCInterfaceDecl *PrevDecl,
67637f953f021c67e3b97f1ef38e1ef3cb08bd9d146Douglas Gregor                    bool isInternal);
6772e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
6782e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  void LoadExternalDefinition() const;
6792e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
6802e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  /// \brief Contains a pointer to the data associated with this class,
6812e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  /// which will be NULL if this class has not yet been defined.
6826bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor  ///
6836bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor  /// The bit indicates when we don't need to check for out-of-date
6846bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor  /// declarations. It will be set unless modules are enabled.
6856bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor  llvm::PointerIntPair<DefinitionData *, 1, bool> Data;
6862e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
6872e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  DefinitionData &data() const {
6886bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor    assert(Data.getPointer() && "Declaration has no definition!");
6896bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor    return *Data.getPointer();
6902e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  }
6911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6922e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  /// \brief Allocate the definition data for this class.
6932e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  void allocateDefinitionData();
6942e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
69553df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor  typedef Redeclarable<ObjCInterfaceDecl> redeclarable_base;
69653df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor  virtual ObjCInterfaceDecl *getNextRedeclaration() {
6976bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor    return RedeclLink.getNext();
69853df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor  }
699ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor  virtual ObjCInterfaceDecl *getPreviousDeclImpl() {
700ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor    return getPreviousDecl();
701ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor  }
702ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor  virtual ObjCInterfaceDecl *getMostRecentDeclImpl() {
703ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor    return getMostRecentDecl();
704ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor  }
70553df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor
7060e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattnerpublic:
707a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor  static ObjCInterfaceDecl *Create(const ASTContext &C, DeclContext *DC,
7080ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner                                   SourceLocation atLoc,
7091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                   IdentifierInfo *Id,
7100af550115df1f57f17a4f125ff0e8b34820c65d1Douglas Gregor                                   ObjCInterfaceDecl *PrevDecl,
711deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor                                   SourceLocation ClassLoc = SourceLocation(),
7120e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner                                   bool isInternal = false);
713d1cf3ff6c7e34fce764293cd2900fce99a60ed69Argyrios Kyrtzidis
7141e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor  static ObjCInterfaceDecl *CreateDeserialized(ASTContext &C, unsigned ID);
7150af550115df1f57f17a4f125ff0e8b34820c65d1Douglas Gregor
716aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  virtual SourceRange getSourceRange() const LLVM_READONLY {
7177723fec9b45b7258c0eddf4cbfd0d335348f5edcDouglas Gregor    if (isThisDeclarationADefinition())
7187723fec9b45b7258c0eddf4cbfd0d335348f5edcDouglas Gregor      return ObjCContainerDecl::getSourceRange();
7197723fec9b45b7258c0eddf4cbfd0d335348f5edcDouglas Gregor
7207723fec9b45b7258c0eddf4cbfd0d335348f5edcDouglas Gregor    return SourceRange(getAtStartLoc(), getLocation());
721d1cf3ff6c7e34fce764293cd2900fce99a60ed69Argyrios Kyrtzidis  }
722ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
72326ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  /// \brief Indicate that this Objective-C class is complete, but that
72426ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  /// the external AST source will be responsible for filling in its contents
72526ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  /// when a complete class is required.
72626ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  void setExternallyCompleted();
727ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
72818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  const ObjCProtocolList &getReferencedProtocols() const {
729a5f4441de7890953460d95f4e88b9fa432b48dc2Argyrios Kyrtzidis    assert(hasDefinition() && "Caller did not check for forward reference!");
7302e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (data().ExternallyCompleted)
73126ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
732ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
7332e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    return data().ReferencedProtocols;
7347ed9e0f97f4645edc5d4670385b985ea4c617ce7Fariborz Jahanian  }
7358a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis
7368a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis  ObjCImplementationDecl *getImplementation() const;
7378a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis  void setImplementation(ObjCImplementationDecl *ImplD);
7388a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis
739559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  ObjCCategoryDecl *FindCategoryDeclaration(IdentifierInfo *CategoryId) const;
7401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7411cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis  // Get the local instance/class method declared in a category.
7421cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis  ObjCMethodDecl *getCategoryInstanceMethod(Selector Sel) const;
7431cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis  ObjCMethodDecl *getCategoryClassMethod(Selector Sel) const;
7441cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis  ObjCMethodDecl *getCategoryMethod(Selector Sel, bool isInstance) const {
7451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return isInstance ? getInstanceMethod(Sel)
7461cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis                      : getClassMethod(Sel);
7471cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis  }
7483db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner
74918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::iterator protocol_iterator;
750ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
75153b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  protocol_iterator protocol_begin() const {
7522e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    // FIXME: Should make sure no callers ever do this.
7532e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (!hasDefinition())
7542e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor      return protocol_iterator();
7552e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
7562e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (data().ExternallyCompleted)
75726ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
75826ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
7592e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    return data().ReferencedProtocols.begin();
76053b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  }
76153b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  protocol_iterator protocol_end() const {
7622e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    // FIXME: Should make sure no callers ever do this.
7632e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (!hasDefinition())
7642e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor      return protocol_iterator();
7652e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
7662e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (data().ExternallyCompleted)
76726ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
76826ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
7692e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    return data().ReferencedProtocols.end();
77053b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  }
77153b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
77218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
77353b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
774ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  protocol_loc_iterator protocol_loc_begin() const {
7752e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    // FIXME: Should make sure no callers ever do this.
7762e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (!hasDefinition())
7772e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor      return protocol_loc_iterator();
7782e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
7792e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (data().ExternallyCompleted)
78026ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
78126ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
7822e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    return data().ReferencedProtocols.loc_begin();
78318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
78453b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
785ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  protocol_loc_iterator protocol_loc_end() const {
7862e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    // FIXME: Should make sure no callers ever do this.
7872e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (!hasDefinition())
7882e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor      return protocol_loc_iterator();
7892e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
7902e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (data().ExternallyCompleted)
79126ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
79226ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
7932e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    return data().ReferencedProtocols.loc_end();
79418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
795ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
79653b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  typedef ObjCList<ObjCProtocolDecl>::iterator all_protocol_iterator;
797ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
79853b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  all_protocol_iterator all_referenced_protocol_begin() const {
7992e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    // FIXME: Should make sure no callers ever do this.
8002e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (!hasDefinition())
8012e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor      return all_protocol_iterator();
8022e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
8032e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (data().ExternallyCompleted)
80426ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
80526ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
8062e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    return data().AllReferencedProtocols.empty()
8072e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor             ? protocol_begin()
8082e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor             : data().AllReferencedProtocols.begin();
80953b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  }
81053b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  all_protocol_iterator all_referenced_protocol_end() const {
8112e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    // FIXME: Should make sure no callers ever do this.
8122e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (!hasDefinition())
8132e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor      return all_protocol_iterator();
8142e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
8152e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (data().ExternallyCompleted)
81626ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
81726ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
8182e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    return data().AllReferencedProtocols.empty()
8192e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor             ? protocol_end()
8202e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor             : data().AllReferencedProtocols.end();
82153b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  }
822291be393aa33759e6e34b6429c5ffa206ba50115Douglas Gregor
82311062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian  typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
82453b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
8252e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  ivar_iterator ivar_begin() const {
8262e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (const ObjCInterfaceDecl *Def = getDefinition())
8272e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor      return ivar_iterator(Def->decls_begin());
8282e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
8292e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    // FIXME: Should make sure no callers ever do this.
8302e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    return ivar_iterator();
8312e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  }
8322e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  ivar_iterator ivar_end() const {
8332e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (const ObjCInterfaceDecl *Def = getDefinition())
8342e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor      return ivar_iterator(Def->decls_end());
8352e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
8362e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    // FIXME: Should make sure no callers ever do this.
8372e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    return ivar_iterator();
8382e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  }
83953b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
84011062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian  unsigned ivar_size() const {
84111062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian    return std::distance(ivar_begin(), ivar_end());
84211062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian  }
843ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
84411062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian  bool ivar_empty() const { return ivar_begin() == ivar_end(); }
845ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
846db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose  ObjCIvarDecl *all_declared_ivar_begin();
847db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose  const ObjCIvarDecl *all_declared_ivar_begin() const {
848db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose    // Even though this modifies IvarList, it's conceptually const:
849db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose    // the ivar chain is essentially a cached property of ObjCInterfaceDecl.
850db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose    return const_cast<ObjCInterfaceDecl *>(this)->all_declared_ivar_begin();
851db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose  }
8522e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  void setIvarList(ObjCIvarDecl *ivar) { data().IvarList = ivar; }
853ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
85438af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  /// setProtocolList - Set the list of protocols that this interface
855b752f289026ad8e5f44851b20e009a27ed61eefcChris Lattner  /// implements.
85638af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  void setProtocolList(ObjCProtocolDecl *const* List, unsigned Num,
85718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                       const SourceLocation *Locs, ASTContext &C) {
8582e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    data().ReferencedProtocols.set(List, Num, Locs, C);
8593db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  }
8601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
861339798eae1eb61c50ca68766ed028c0a16d0a284Fariborz Jahanian  /// mergeClassExtensionProtocolList - Merge class extension's protocol list
862339798eae1eb61c50ca68766ed028c0a16d0a284Fariborz Jahanian  /// into the protocol list for this class.
863ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  void mergeClassExtensionProtocolList(ObjCProtocolDecl *const* List,
86418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                                       unsigned Num,
86518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                                       ASTContext &C);
866339798eae1eb61c50ca68766ed028c0a16d0a284Fariborz Jahanian
86753df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor  /// \brief Determine whether this particular declaration of this class is
86853df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor  /// actually also a definition.
86926fec63b14565e9e2d8c9935b276b99be950444aDouglas Gregor  bool isThisDeclarationADefinition() const {
8706bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor    return getDefinition() == this;
87126fec63b14565e9e2d8c9935b276b99be950444aDouglas Gregor  }
87253df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor
8732e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  /// \brief Determine whether this class has been defined.
8746bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor  bool hasDefinition() const {
8756bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor    // If the name of this class is out-of-date, bring it up-to-date, which
8766bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor    // might bring in a definition.
8776bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor    // Note: a null value indicates that we don't have a definition and that
8786bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor    // modules are enabled.
8796bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor    if (!Data.getOpaqueValue()) {
8806bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor      if (IdentifierInfo *II = getIdentifier()) {
8816bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor        if (II->isOutOfDate()) {
8826bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor          updateOutOfDate(*II);
8836bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor        }
8846bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor      }
8856bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor    }
8866bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor
8876bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor    return Data.getPointer();
8886bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor  }
88953df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor
8902e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  /// \brief Retrieve the definition of this class, or NULL if this class
89141c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  /// has been forward-declared (with \@class) but not yet defined (with
89241c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  /// \@interface).
8932e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  ObjCInterfaceDecl *getDefinition() {
8946bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor    return hasDefinition()? Data.getPointer()->Definition : 0;
8952e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  }
896ad834d534e9a5db3d3baa09593775f83ceaff1f2Argyrios Kyrtzidis
8972e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  /// \brief Retrieve the definition of this class, or NULL if this class
89841c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  /// has been forward-declared (with \@class) but not yet defined (with
89941c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  /// \@interface).
9002e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  const ObjCInterfaceDecl *getDefinition() const {
9016bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor    return hasDefinition()? Data.getPointer()->Definition : 0;
9022e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  }
9031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9042e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  /// \brief Starts the definition of this Objective-C class, taking it from
90541c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  /// a forward declaration (\@class) to a definition (\@interface).
9062e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  void startDefinition();
9072e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
908ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  ObjCInterfaceDecl *getSuperClass() const {
9092e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    // FIXME: Should make sure no callers ever do this.
9102e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (!hasDefinition())
9112e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor      return 0;
9122e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
9132e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (data().ExternallyCompleted)
91426ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
91526ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
9162e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    return data().SuperClass;
91726ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  }
918ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
9192e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  void setSuperClass(ObjCInterfaceDecl * superCls) {
920712ef874534ee1bef41d1aa4664ae36148ec8b12Fariborz Jahanian    data().SuperClass =
921712ef874534ee1bef41d1aa4664ae36148ec8b12Fariborz Jahanian      (superCls && superCls->hasDefinition()) ? superCls->getDefinition()
922712ef874534ee1bef41d1aa4664ae36148ec8b12Fariborz Jahanian                                              : superCls;
9232e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  }
9241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
925d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// \brief Iterator that walks over the list of categories, filtering out
926d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// those that do not meet specific criteria.
927d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  ///
928d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// This class template is used for the various permutations of category
929d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// and extension iterators.
930d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  template<bool (*Filter)(ObjCCategoryDecl *)>
931d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  class filtered_category_iterator {
932d329724745b49f894b768d47275b7c2713106e89Douglas Gregor    ObjCCategoryDecl *Current;
933d329724745b49f894b768d47275b7c2713106e89Douglas Gregor
934d329724745b49f894b768d47275b7c2713106e89Douglas Gregor    void findAcceptableCategory();
935d329724745b49f894b768d47275b7c2713106e89Douglas Gregor
936d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  public:
937d329724745b49f894b768d47275b7c2713106e89Douglas Gregor    typedef ObjCCategoryDecl *      value_type;
938d329724745b49f894b768d47275b7c2713106e89Douglas Gregor    typedef value_type              reference;
939d329724745b49f894b768d47275b7c2713106e89Douglas Gregor    typedef value_type              pointer;
940d329724745b49f894b768d47275b7c2713106e89Douglas Gregor    typedef std::ptrdiff_t          difference_type;
941d329724745b49f894b768d47275b7c2713106e89Douglas Gregor    typedef std::input_iterator_tag iterator_category;
942d329724745b49f894b768d47275b7c2713106e89Douglas Gregor
943d329724745b49f894b768d47275b7c2713106e89Douglas Gregor    filtered_category_iterator() : Current(0) { }
944d329724745b49f894b768d47275b7c2713106e89Douglas Gregor    explicit filtered_category_iterator(ObjCCategoryDecl *Current)
945d329724745b49f894b768d47275b7c2713106e89Douglas Gregor      : Current(Current)
946d329724745b49f894b768d47275b7c2713106e89Douglas Gregor    {
947d329724745b49f894b768d47275b7c2713106e89Douglas Gregor      findAcceptableCategory();
948d329724745b49f894b768d47275b7c2713106e89Douglas Gregor    }
949d329724745b49f894b768d47275b7c2713106e89Douglas Gregor
950d329724745b49f894b768d47275b7c2713106e89Douglas Gregor    reference operator*() const { return Current; }
951d329724745b49f894b768d47275b7c2713106e89Douglas Gregor    pointer operator->() const { return Current; }
952d329724745b49f894b768d47275b7c2713106e89Douglas Gregor
953d329724745b49f894b768d47275b7c2713106e89Douglas Gregor    filtered_category_iterator &operator++();
954d329724745b49f894b768d47275b7c2713106e89Douglas Gregor
955d329724745b49f894b768d47275b7c2713106e89Douglas Gregor    filtered_category_iterator operator++(int) {
956d329724745b49f894b768d47275b7c2713106e89Douglas Gregor      filtered_category_iterator Tmp = *this;
957d329724745b49f894b768d47275b7c2713106e89Douglas Gregor      ++(*this);
958d329724745b49f894b768d47275b7c2713106e89Douglas Gregor      return Tmp;
959d329724745b49f894b768d47275b7c2713106e89Douglas Gregor    }
960d329724745b49f894b768d47275b7c2713106e89Douglas Gregor
961d329724745b49f894b768d47275b7c2713106e89Douglas Gregor    friend bool operator==(filtered_category_iterator X,
962d329724745b49f894b768d47275b7c2713106e89Douglas Gregor                           filtered_category_iterator Y) {
9631c2397539d1b105eacee2a69ece4775d0af45618Matt Beaumont-Gay      return X.Current == Y.Current;
964d329724745b49f894b768d47275b7c2713106e89Douglas Gregor    }
965d329724745b49f894b768d47275b7c2713106e89Douglas Gregor
966d329724745b49f894b768d47275b7c2713106e89Douglas Gregor    friend bool operator!=(filtered_category_iterator X,
967d329724745b49f894b768d47275b7c2713106e89Douglas Gregor                           filtered_category_iterator Y) {
968d329724745b49f894b768d47275b7c2713106e89Douglas Gregor      return X.Current != Y.Current;
969d329724745b49f894b768d47275b7c2713106e89Douglas Gregor    }
970d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  };
971d329724745b49f894b768d47275b7c2713106e89Douglas Gregor
972d329724745b49f894b768d47275b7c2713106e89Douglas Gregorprivate:
973d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// \brief Test whether the given category is visible.
974d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  ///
975d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// Used in the \c visible_categories_iterator.
976d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  static bool isVisibleCategory(ObjCCategoryDecl *Cat);
977d329724745b49f894b768d47275b7c2713106e89Douglas Gregor
978d329724745b49f894b768d47275b7c2713106e89Douglas Gregorpublic:
979d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// \brief Iterator that walks over the list of categories and extensions
980d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// that are visible, i.e., not hidden in a non-imported submodule.
981d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  typedef filtered_category_iterator<isVisibleCategory>
982d329724745b49f894b768d47275b7c2713106e89Douglas Gregor    visible_categories_iterator;
983d329724745b49f894b768d47275b7c2713106e89Douglas Gregor
984d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// \brief Retrieve an iterator to the beginning of the visible-categories
985d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// list.
986d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  visible_categories_iterator visible_categories_begin() const {
987d329724745b49f894b768d47275b7c2713106e89Douglas Gregor    return visible_categories_iterator(getCategoryListRaw());
988d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  }
989d329724745b49f894b768d47275b7c2713106e89Douglas Gregor
990d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// \brief Retrieve an iterator to the end of the visible-categories list.
991d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  visible_categories_iterator visible_categories_end() const {
992d329724745b49f894b768d47275b7c2713106e89Douglas Gregor    return visible_categories_iterator();
993d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  }
994d329724745b49f894b768d47275b7c2713106e89Douglas Gregor
995d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// \brief Determine whether the visible-categories list is empty.
996d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  bool visible_categories_empty() const {
997d329724745b49f894b768d47275b7c2713106e89Douglas Gregor    return visible_categories_begin() == visible_categories_end();
998d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  }
999d329724745b49f894b768d47275b7c2713106e89Douglas Gregor
1000d329724745b49f894b768d47275b7c2713106e89Douglas Gregorprivate:
1001d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// \brief Test whether the given category... is a category.
1002d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  ///
1003d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// Used in the \c known_categories_iterator.
1004d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  static bool isKnownCategory(ObjCCategoryDecl *) { return true; }
1005d329724745b49f894b768d47275b7c2713106e89Douglas Gregor
1006d329724745b49f894b768d47275b7c2713106e89Douglas Gregorpublic:
1007d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// \brief Iterator that walks over all of the known categories and
1008d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// extensions, including those that are hidden.
1009d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  typedef filtered_category_iterator<isKnownCategory> known_categories_iterator;
1010d329724745b49f894b768d47275b7c2713106e89Douglas Gregor
1011d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// \brief Retrieve an iterator to the beginning of the known-categories
1012d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// list.
1013d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  known_categories_iterator known_categories_begin() const {
1014d329724745b49f894b768d47275b7c2713106e89Douglas Gregor    return known_categories_iterator(getCategoryListRaw());
1015d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  }
1016d329724745b49f894b768d47275b7c2713106e89Douglas Gregor
1017d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// \brief Retrieve an iterator to the end of the known-categories list.
1018d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  known_categories_iterator known_categories_end() const {
1019d329724745b49f894b768d47275b7c2713106e89Douglas Gregor    return known_categories_iterator();
1020d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  }
1021d329724745b49f894b768d47275b7c2713106e89Douglas Gregor
1022d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// \brief Determine whether the known-categories list is empty.
1023d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  bool known_categories_empty() const {
1024d329724745b49f894b768d47275b7c2713106e89Douglas Gregor    return known_categories_begin() == known_categories_end();
1025d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  }
1026d329724745b49f894b768d47275b7c2713106e89Douglas Gregor
1027d329724745b49f894b768d47275b7c2713106e89Douglas Gregorprivate:
1028d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// \brief Test whether the given category is a visible extension.
1029d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  ///
1030d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// Used in the \c visible_extensions_iterator.
1031d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  static bool isVisibleExtension(ObjCCategoryDecl *Cat);
1032d329724745b49f894b768d47275b7c2713106e89Douglas Gregor
1033d329724745b49f894b768d47275b7c2713106e89Douglas Gregorpublic:
1034d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// \brief Iterator that walks over all of the visible extensions, skipping
1035d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// any that are known but hidden.
1036d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  typedef filtered_category_iterator<isVisibleExtension>
1037d329724745b49f894b768d47275b7c2713106e89Douglas Gregor    visible_extensions_iterator;
1038d329724745b49f894b768d47275b7c2713106e89Douglas Gregor
1039d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// \brief Retrieve an iterator to the beginning of the visible-extensions
1040d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// list.
1041d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  visible_extensions_iterator visible_extensions_begin() const {
1042d329724745b49f894b768d47275b7c2713106e89Douglas Gregor    return visible_extensions_iterator(getCategoryListRaw());
1043d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  }
1044d329724745b49f894b768d47275b7c2713106e89Douglas Gregor
1045d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// \brief Retrieve an iterator to the end of the visible-extensions list.
1046d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  visible_extensions_iterator visible_extensions_end() const {
1047d329724745b49f894b768d47275b7c2713106e89Douglas Gregor    return visible_extensions_iterator();
1048d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  }
1049d329724745b49f894b768d47275b7c2713106e89Douglas Gregor
1050d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// \brief Determine whether the visible-extensions list is empty.
1051d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  bool visible_extensions_empty() const {
1052d329724745b49f894b768d47275b7c2713106e89Douglas Gregor    return visible_extensions_begin() == visible_extensions_end();
1053d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  }
1054d329724745b49f894b768d47275b7c2713106e89Douglas Gregor
1055d329724745b49f894b768d47275b7c2713106e89Douglas Gregorprivate:
1056d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// \brief Test whether the given category is an extension.
1057d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  ///
1058d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// Used in the \c known_extensions_iterator.
1059d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  static bool isKnownExtension(ObjCCategoryDecl *Cat);
1060d329724745b49f894b768d47275b7c2713106e89Douglas Gregor
1061d329724745b49f894b768d47275b7c2713106e89Douglas Gregorpublic:
1062d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// \brief Iterator that walks over all of the known extensions.
1063d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  typedef filtered_category_iterator<isKnownExtension>
1064d329724745b49f894b768d47275b7c2713106e89Douglas Gregor    known_extensions_iterator;
1065d329724745b49f894b768d47275b7c2713106e89Douglas Gregor
1066d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// \brief Retrieve an iterator to the beginning of the known-extensions
1067d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// list.
1068d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  known_extensions_iterator known_extensions_begin() const {
1069d329724745b49f894b768d47275b7c2713106e89Douglas Gregor    return known_extensions_iterator(getCategoryListRaw());
1070d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  }
1071d329724745b49f894b768d47275b7c2713106e89Douglas Gregor
1072d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// \brief Retrieve an iterator to the end of the known-extensions list.
1073d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  known_extensions_iterator known_extensions_end() const {
1074d329724745b49f894b768d47275b7c2713106e89Douglas Gregor    return known_extensions_iterator();
1075d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  }
1076d329724745b49f894b768d47275b7c2713106e89Douglas Gregor
1077d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// \brief Determine whether the known-extensions list is empty.
1078d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  bool known_extensions_empty() const {
1079d329724745b49f894b768d47275b7c2713106e89Douglas Gregor    return known_extensions_begin() == known_extensions_end();
1080d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  }
1081d329724745b49f894b768d47275b7c2713106e89Douglas Gregor
1082d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// \brief Retrieve the raw pointer to the start of the category/extension
1083d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// list.
1084d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  ObjCCategoryDecl* getCategoryListRaw() const {
10852e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    // FIXME: Should make sure no callers ever do this.
10862e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (!hasDefinition())
10872e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor      return 0;
10882e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
10892e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (data().ExternallyCompleted)
109026ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
109126ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
10922e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    return data().CategoryList;
109326ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  }
1094ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1095d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// \brief Set the raw pointer to the start of the category/extension
1096d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// list.
1097d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  void setCategoryListRaw(ObjCCategoryDecl *category) {
10982e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    data().CategoryList = category;
1099980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  }
1100ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
110137cafb077ad5b170acae77e566638603011ef4c0Ted Kremenek  ObjCPropertyDecl
110237cafb077ad5b170acae77e566638603011ef4c0Ted Kremenek    *FindPropertyVisibleInPrimaryClass(IdentifierInfo *PropertyId) const;
110337cafb077ad5b170acae77e566638603011ef4c0Ted Kremenek
1104cfaed8d399a34e79fbab9f70eb4ea1bbeb81a02bFariborz Jahanian  virtual void collectPropertiesToImplement(PropertyMap &PM,
1105cfaed8d399a34e79fbab9f70eb4ea1bbeb81a02bFariborz Jahanian                                            PropertyDeclOrder &PO) const;
1106b36ea375e20f71df19c101fa2399b7ea3a607e04Anna Zaks
110753efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner  /// isSuperClassOf - Return true if this class is the specified class or is a
110853efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner  /// super class of the specified interface class.
110953efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner  bool isSuperClassOf(const ObjCInterfaceDecl *I) const {
111053efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    // If RHS is derived from LHS it is OK; else it is not OK.
111153efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    while (I != NULL) {
111260ef308e51c71b760d7f598c1b763ceb7b768148Douglas Gregor      if (declaresSameEntity(this, I))
111353efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner        return true;
11142e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
111553efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner      I = I->getSuperClass();
111653efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    }
111753efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    return false;
111853efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner  }
11191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11207263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian  /// isArcWeakrefUnavailable - Checks for a class or one of its super classes
11217263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian  /// to be incompatible with __weak references. Returns true if it is.
11222fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer  bool isArcWeakrefUnavailable() const;
11237263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian
112471207fc0470e1eee40a2951cd5cc3ff47725b755Ted Kremenek  /// isObjCRequiresPropertyDefs - Checks that a class or one of its super
112541c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  /// classes must not be auto-synthesized. Returns class decl. if it must not
112641c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  /// be; 0, otherwise.
11272fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer  const ObjCInterfaceDecl *isObjCRequiresPropertyDefs() const;
1128e23dcf3524fe01208cc79e707412f0a5dd8eed7bFariborz Jahanian
112917945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName,
113068a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner                                       ObjCInterfaceDecl *&ClassDeclared);
113117945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName) {
113268a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner    ObjCInterfaceDecl *ClassDeclared;
113317945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return lookupInstanceVariable(IVarName, ClassDeclared);
113468a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner  }
113568a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner
113694a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // Lookup a method. First, we search locally. If a method isn't
113794a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // found, we search referenced protocols and class categories.
1138bb3d14e55d267bf5228699c7bf0c8ccdb71c8f46Fariborz Jahanian  ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance,
1139c775b1a0702621e297d00452a897381c8bf10f3fFariborz Jahanian                               bool shallowCategoryLookup= false,
1140f3f0f357f8d6b4511b6d605cc8a39ae3787fef6dFariborz Jahanian                               const ObjCCategoryDecl *C= 0) const;
1141bb3d14e55d267bf5228699c7bf0c8ccdb71c8f46Fariborz Jahanian  ObjCMethodDecl *lookupInstanceMethod(Selector Sel,
1142bf393be8a0b8b573ceb23ed19ac953832a2a69e4Fariborz Jahanian                            bool shallowCategoryLookup = false) const {
1143bf393be8a0b8b573ceb23ed19ac953832a2a69e4Fariborz Jahanian    return lookupMethod(Sel, true/*isInstance*/, shallowCategoryLookup);
1144bb3d14e55d267bf5228699c7bf0c8ccdb71c8f46Fariborz Jahanian  }
1145bb3d14e55d267bf5228699c7bf0c8ccdb71c8f46Fariborz Jahanian  ObjCMethodDecl *lookupClassMethod(Selector Sel,
1146bf393be8a0b8b573ceb23ed19ac953832a2a69e4Fariborz Jahanian                     bool shallowCategoryLookup = false) const {
1147bf393be8a0b8b573ceb23ed19ac953832a2a69e4Fariborz Jahanian    return lookupMethod(Sel, false/*isInstance*/, shallowCategoryLookup);
1148aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis  }
1149cd1876207f5564beba74e4b2524b664bdba0ba9fFariborz Jahanian  ObjCInterfaceDecl *lookupInheritedClass(const IdentifierInfo *ICName);
1150ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1151e61354b274ec5aa6acf3d15271896ce7596bb123Anna Zaks  /// \brief Lookup a method in the classes implementation hierarchy.
1152ca93ee707d9570b74d24c7d55defe18dac38bcc0Anna Zaks  ObjCMethodDecl *lookupPrivateMethod(const Selector &Sel,
1153ca93ee707d9570b74d24c7d55defe18dac38bcc0Anna Zaks                                      bool Instance=true) const;
115460fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff
1155e61354b274ec5aa6acf3d15271896ce7596bb123Anna Zaks  ObjCMethodDecl *lookupPrivateClassMethod(const Selector &Sel) {
1156e61354b274ec5aa6acf3d15271896ce7596bb123Anna Zaks    return lookupPrivateMethod(Sel, false);
1157e61354b274ec5aa6acf3d15271896ce7596bb123Anna Zaks  }
1158e61354b274ec5aa6acf3d15271896ce7596bb123Anna Zaks
1159f3f0f357f8d6b4511b6d605cc8a39ae3787fef6dFariborz Jahanian  /// \brief Lookup a setter or getter in the class hierarchy,
1160f3f0f357f8d6b4511b6d605cc8a39ae3787fef6dFariborz Jahanian  /// including in all categories except for category passed
1161f3f0f357f8d6b4511b6d605cc8a39ae3787fef6dFariborz Jahanian  /// as argument.
1162f3f0f357f8d6b4511b6d605cc8a39ae3787fef6dFariborz Jahanian  ObjCMethodDecl *lookupPropertyAccessor(const Selector Sel,
1163f3f0f357f8d6b4511b6d605cc8a39ae3787fef6dFariborz Jahanian                                         const ObjCCategoryDecl *Cat) const {
1164f3f0f357f8d6b4511b6d605cc8a39ae3787fef6dFariborz Jahanian    return lookupMethod(Sel, true/*isInstance*/,
1165f3f0f357f8d6b4511b6d605cc8a39ae3787fef6dFariborz Jahanian                        false/*shallowCategoryLookup*/, Cat);
1166c775b1a0702621e297d00452a897381c8bf10f3fFariborz Jahanian  }
1167f3f0f357f8d6b4511b6d605cc8a39ae3787fef6dFariborz Jahanian
116805c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor  SourceLocation getEndOfDefinitionLoc() const {
116905c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor    if (!hasDefinition())
117005c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor      return getLocation();
117105c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor
117205c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor    return data().EndLoc;
117305c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor  }
117405c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor
117505c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor  void setEndOfDefinitionLoc(SourceLocation LE) { data().EndLoc = LE; }
11761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11772e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  void setSuperClassLoc(SourceLocation Loc) { data().SuperClassLoc = Loc; }
11782e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  SourceLocation getSuperClassLoc() const { return data().SuperClassLoc; }
11791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
118028e71cf851b73a67604735a9a95aef800b144e2eSteve Naroff  /// isImplicitInterfaceDecl - check that this is an implicitly declared
118141c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  /// ObjCInterfaceDecl node. This is for legacy objective-c \@implementation
118241c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  /// declaration without an \@interface declaration.
118397bbab2df74cbfe221fb20454738d607a41f3ca4Fariborz Jahanian  bool isImplicitInterfaceDecl() const {
11846bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor    return hasDefinition() ? data().Definition->isImplicit() : isImplicit();
118597bbab2df74cbfe221fb20454738d607a41f3ca4Fariborz Jahanian  }
11861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11870fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian  /// ClassImplementsProtocol - Checks that 'lProto' protocol
11880fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian  /// has been implemented in IDecl class, its super class or categories (if
11890fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian  /// lookupCategory is true).
11900fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian  bool ClassImplementsProtocol(ObjCProtocolDecl *lProto,
11910fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian                               bool lookupCategory,
11920fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian                               bool RHSIsQualifiedID = false);
11931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1194a54fbf2499c7cc999e22abb9be484ce976ed9689Douglas Gregor  typedef redeclarable_base::redecl_iterator redecl_iterator;
1195ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor  using redeclarable_base::redecls_begin;
1196ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor  using redeclarable_base::redecls_end;
1197ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor  using redeclarable_base::getPreviousDecl;
1198ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor  using redeclarable_base::getMostRecentDecl;
1199f785a7d611404cf4747287a2bbc59b4d0e6a5a8cDouglas Gregor
120053df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor  /// Retrieves the canonical declaration of this Objective-C class.
120153df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor  ObjCInterfaceDecl *getCanonicalDecl() {
120253df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor    return getFirstDeclaration();
120353df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor  }
120453df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor  const ObjCInterfaceDecl *getCanonicalDecl() const {
120553df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor    return getFirstDeclaration();
120653df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor  }
120753df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor
120833feeb019a5742b286eededd5446ec0fe87c5a61Steve Naroff  // Low-level accessor
1209f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const Type *getTypeForDecl() const { return TypeForDecl; }
1210f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  void setTypeForDecl(const Type *TD) const { TypeForDecl = TD; }
121133feeb019a5742b286eededd5446ec0fe87c5a61Steve Naroff
121280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
121380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCInterface; }
121453b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
1215fc529f7fcafe7da0b8a32621e13685891e8ce52aDouglas Gregor  friend class ASTReader;
121653b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  friend class ASTDeclReader;
121753b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  friend class ASTDeclWriter;
1218980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
1219980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
1220a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCIvarDecl - Represents an ObjC instance variable. In general, ObjC
12210c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// instance variables are identical to C. The only exception is Objective-C
12220c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// supports C++ style access control. For example:
12230c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
122441c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth///   \@interface IvarExample : NSObject
12250c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   {
1226f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek///     id defaultToProtected;
122741c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth///   \@public:
12280c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     id canBePublic; // same as C++.
122941c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth///   \@protected:
12300c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     id canBeProtected; // same as C++.
123141c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth///   \@package:
12320c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     id canBePackage; // framework visibility (not available in C++).
12330c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   }
12340c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
1235a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCIvarDecl : public FieldDecl {
123699ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
123799ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie
12380e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattnerpublic:
1239980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  enum AccessControl {
1240980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff    None, Private, Protected, Public, Package
1241980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  };
12421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1243b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenekprivate:
1244ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara  ObjCIvarDecl(ObjCContainerDecl *DC, SourceLocation StartLoc,
1245ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara               SourceLocation IdLoc, IdentifierInfo *Id,
1246ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian               QualType T, TypeSourceInfo *TInfo, AccessControl ac, Expr *BW,
1247ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian               bool synthesized)
1248ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara    : FieldDecl(ObjCIvar, DC, StartLoc, IdLoc, Id, T, TInfo, BW,
1249ca5233044ef679840d1ad1c46a36b16e2ee8a6e1Richard Smith                /*Mutable=*/false, /*HasInit=*/ICIS_NoInit),
1250ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara      NextIvar(0), DeclAccess(ac), Synthesized(synthesized) {}
12511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1252b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenekpublic:
1253a06549226f45d5b72169a3d054415616dd1014a2Daniel Dunbar  static ObjCIvarDecl *Create(ASTContext &C, ObjCContainerDecl *DC,
1254ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                              SourceLocation StartLoc, SourceLocation IdLoc,
1255ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                              IdentifierInfo *Id, QualType T,
1256a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall                              TypeSourceInfo *TInfo,
1257ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian                              AccessControl ac, Expr *BW = NULL,
1258ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian                              bool synthesized=false);
12591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12601e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor  static ObjCIvarDecl *CreateDeserialized(ASTContext &C, unsigned ID);
12611e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor
126227a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar  /// \brief Return the class interface that this ivar is logically contained
126327a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar  /// in; this is either the interface where the ivar was declared, or the
126427a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar  /// interface the ivar is conceptually a part of in the case of synthesized
126527a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar  /// ivars.
126627a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar  const ObjCInterfaceDecl *getContainingInterface() const;
1267ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
12682c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  ObjCIvarDecl *getNextIvar() { return NextIvar; }
1269db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose  const ObjCIvarDecl *getNextIvar() const { return NextIvar; }
12702c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  void setNextIvar(ObjCIvarDecl *ivar) { NextIvar = ivar; }
127127a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar
1272980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  void setAccessControl(AccessControl ac) { DeclAccess = ac; }
1273f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek
1274ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  AccessControl getAccessControl() const { return AccessControl(DeclAccess); }
1275f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek
1276f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek  AccessControl getCanonicalAccessControl() const {
1277f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek    return DeclAccess == None ? Protected : AccessControl(DeclAccess);
1278f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek  }
12791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1280ac0021ba802e193e0f9f8207768c7862c7603bc0Fariborz Jahanian  void setSynthesize(bool synth) { Synthesized = synth; }
1281ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian  bool getSynthesize() const { return Synthesized; }
1282ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1283980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  // Implement isa/cast/dyncast/etc.
128480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
128580cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCIvar; }
1286980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffprivate:
1287ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// NextIvar - Next Ivar in the list of ivars declared in class; class's
12882c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  /// extensions and class's implementation
12892c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  ObjCIvarDecl *NextIvar;
1290ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1291ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  // NOTE: VC++ treats enums as signed, avoid using the AccessControl enum
1292ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  unsigned DeclAccess : 3;
1293ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian  unsigned Synthesized : 1;
1294980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
1295980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
12961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12970982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief Represents a field declaration created by an \@defs(...).
129801e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenekclass ObjCAtDefsFieldDecl : public FieldDecl {
129999ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
1300ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara  ObjCAtDefsFieldDecl(DeclContext *DC, SourceLocation StartLoc,
1301ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                      SourceLocation IdLoc, IdentifierInfo *Id,
130201e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek                      QualType T, Expr *BW)
1303ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara    : FieldDecl(ObjCAtDefsField, DC, StartLoc, IdLoc, Id, T,
1304a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall                /*TInfo=*/0, // FIXME: Do ObjCAtDefs have declarators ?
1305ca5233044ef679840d1ad1c46a36b16e2ee8a6e1Richard Smith                BW, /*Mutable=*/false, /*HasInit=*/ICIS_NoInit) {}
13061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
130701e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenekpublic:
130844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor  static ObjCAtDefsFieldDecl *Create(ASTContext &C, DeclContext *DC,
1309ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                     SourceLocation StartLoc,
1310ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                     SourceLocation IdLoc, IdentifierInfo *Id,
1311ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                     QualType T, Expr *BW);
13121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13131e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor  static ObjCAtDefsFieldDecl *CreateDeserialized(ASTContext &C, unsigned ID);
13141e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor
131501e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek  // Implement isa/cast/dyncast/etc.
131680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
131780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCAtDefsField; }
131801e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek};
1319980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
13200982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief Represents an Objective-C protocol declaration.
13210982205bade2fb4fc984c27b2ab401e683963b10James Dennett///
13220982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// Objective-C protocols declare a pure abstract type (i.e., no instance
13230982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// variables are permitted).  Protocols originally drew inspiration from
13240982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// C++ pure virtual functions (a C++ feature with nice semantics and lousy
13250982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// syntax:-). Here is an example:
13260c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
13270982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \code
132841c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth/// \@protocol NSDraggingInfo <refproto1, refproto2>
13290c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (NSWindow *)draggingDestinationWindow;
13300c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (NSImage *)draggedImage;
133141c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth/// \@end
13320982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \endcode
13330c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
1334eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// This says that NSDraggingInfo requires two methods and requires everything
1335eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// that the two "referenced protocols" 'refproto1' and 'refproto2' require as
1336eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// well.
1337eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner///
13380982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \code
13390982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \@interface ImplementsNSDraggingInfo : NSObject \<NSDraggingInfo>
134041c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth/// \@end
13410982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \endcode
13420c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
1343a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjC protocols inspired Java interfaces. Unlike Java, ObjC classes and
13440c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// protocols are in distinct namespaces. For example, Cocoa defines both
13451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// an NSObject protocol and class (which isn't allowed in Java). As a result,
13460c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// protocols are referenced using angle brackets as follows:
13470c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
13480982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// id \<NSDraggingInfo> anyObjectThatImplementsNSDraggingInfo;
13490c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
13501d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregorclass ObjCProtocolDecl : public ObjCContainerDecl,
13511d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor                         public Redeclarable<ObjCProtocolDecl> {
135299ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
135399ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie
13545e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  struct DefinitionData {
13551d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor    // \brief The declaration that defines this protocol.
13561d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor    ObjCProtocolDecl *Definition;
13571d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor
1358ec1a58b201b3276966aaade8ac3ac4705aba96c2Douglas Gregor    /// \brief Referenced protocols
13595e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    ObjCProtocolList ReferencedProtocols;
13605e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  };
13616bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor
13626bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor  /// \brief Contains a pointer to the data associated with this class,
13636bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor  /// which will be NULL if this class has not yet been defined.
13646bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor  ///
13656bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor  /// The bit indicates when we don't need to check for out-of-date
13666bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor  /// declarations. It will be set unless modules are enabled.
13676bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor  llvm::PointerIntPair<DefinitionData *, 1, bool> Data;
13681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13695e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  DefinitionData &data() const {
13706bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor    assert(Data.getPointer() && "Objective-C protocol has no definition!");
13716bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor    return *Data.getPointer();
13725e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  }
13735e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor
13741711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis  ObjCProtocolDecl(DeclContext *DC, IdentifierInfo *Id,
1375b05d7b20171bbd2feb14b059f39332cbe1bf1014Argyrios Kyrtzidis                   SourceLocation nameLoc, SourceLocation atStartLoc,
1376c9d3c7edb513e9b8a6ab65b04133653e71d7a72bDouglas Gregor                   ObjCProtocolDecl *PrevDecl);
13771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13785e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  void allocateDefinitionData();
13791d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor
13801d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor  typedef Redeclarable<ObjCProtocolDecl> redeclarable_base;
13811d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor  virtual ObjCProtocolDecl *getNextRedeclaration() {
13821d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor    return RedeclLink.getNext();
13831d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor  }
1384ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor  virtual ObjCProtocolDecl *getPreviousDeclImpl() {
1385ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor    return getPreviousDecl();
1386ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor  }
1387ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor  virtual ObjCProtocolDecl *getMostRecentDeclImpl() {
1388ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor    return getMostRecentDecl();
1389ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor  }
13906bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor
1391cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattnerpublic:
13921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static ObjCProtocolDecl *Create(ASTContext &C, DeclContext *DC,
13931711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                                  IdentifierInfo *Id,
13941711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                                  SourceLocation nameLoc,
1395b05d7b20171bbd2feb14b059f39332cbe1bf1014Argyrios Kyrtzidis                                  SourceLocation atStartLoc,
1396c9d3c7edb513e9b8a6ab65b04133653e71d7a72bDouglas Gregor                                  ObjCProtocolDecl *PrevDecl);
1397cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattner
13981e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor  static ObjCProtocolDecl *CreateDeserialized(ASTContext &C, unsigned ID);
13991e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor
140018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  const ObjCProtocolList &getReferencedProtocols() const {
14015e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    assert(hasDefinition() && "No definition available!");
14025e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    return data().ReferencedProtocols;
1403980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  }
140418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::iterator protocol_iterator;
14055e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  protocol_iterator protocol_begin() const {
14065e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    if (!hasDefinition())
14075e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor      return protocol_iterator();
14085e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor
14095e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    return data().ReferencedProtocols.begin();
14105e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  }
14115e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  protocol_iterator protocol_end() const {
14125e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    if (!hasDefinition())
14135e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor      return protocol_iterator();
14145e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor
14155e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    return data().ReferencedProtocols.end();
14165e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  }
141718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
1418ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  protocol_loc_iterator protocol_loc_begin() const {
14195e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    if (!hasDefinition())
14205e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor      return protocol_loc_iterator();
14215e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor
14225e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    return data().ReferencedProtocols.loc_begin();
142318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
1424ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  protocol_loc_iterator protocol_loc_end() const {
14255e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    if (!hasDefinition())
14265e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor      return protocol_loc_iterator();
14275e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor
14285e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    return data().ReferencedProtocols.loc_end();
14295e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  }
14305e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  unsigned protocol_size() const {
14315e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    if (!hasDefinition())
14325e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor      return 0;
14335e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor
14345e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    return data().ReferencedProtocols.size();
143518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
14361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
143738af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  /// setProtocolList - Set the list of protocols that this interface
1438780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  /// implements.
143938af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num,
144018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                       const SourceLocation *Locs, ASTContext &C) {
14416bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor    assert(hasDefinition() && "Protocol is not defined");
14425e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    data().ReferencedProtocols.set(List, Num, Locs, C);
1443aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian  }
14441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
144591b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff  ObjCProtocolDecl *lookupProtocolNamed(IdentifierInfo *PName);
14461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
144794a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // Lookup a method. First, we search locally. If a method isn't
144894a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // found, we search referenced protocols and class categories.
1449094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis  ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance) const;
1450094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis  ObjCMethodDecl *lookupInstanceMethod(Selector Sel) const {
1451094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis    return lookupMethod(Sel, true/*isInstance*/);
1452094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis  }
1453094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis  ObjCMethodDecl *lookupClassMethod(Selector Sel) const {
1454094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis    return lookupMethod(Sel, false/*isInstance*/);
1455094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis  }
1456b05d7b20171bbd2feb14b059f39332cbe1bf1014Argyrios Kyrtzidis
14575e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  /// \brief Determine whether this protocol has a definition.
14586bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor  bool hasDefinition() const {
14596bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor    // If the name of this protocol is out-of-date, bring it up-to-date, which
14606bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor    // might bring in a definition.
14616bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor    // Note: a null value indicates that we don't have a definition and that
14626bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor    // modules are enabled.
14636bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor    if (!Data.getOpaqueValue()) {
14646bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor      if (IdentifierInfo *II = getIdentifier()) {
14656bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor        if (II->isOutOfDate()) {
14666bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor          updateOutOfDate(*II);
14676bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor        }
14686bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor      }
14696bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor    }
14706bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor
14716bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor    return Data.getPointer();
14726bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor  }
14735e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor
14745e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  /// \brief Retrieve the definition of this protocol, if any.
14755e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  ObjCProtocolDecl *getDefinition() {
14766bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor    return hasDefinition()? Data.getPointer()->Definition : 0;
14775e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  }
14785e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor
14795e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  /// \brief Retrieve the definition of this protocol, if any.
14805e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  const ObjCProtocolDecl *getDefinition() const {
14816bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor    return hasDefinition()? Data.getPointer()->Definition : 0;
14825e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  }
14835e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor
14845e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  /// \brief Determine whether this particular declaration is also the
14855e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  /// definition.
14865e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  bool isThisDeclarationADefinition() const {
14875e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    return getDefinition() == this;
14885e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  }
14895e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor
14905e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  /// \brief Starts the definition of this Objective-C protocol.
14915e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  void startDefinition();
14925e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor
1493aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  virtual SourceRange getSourceRange() const LLVM_READONLY {
1494ec1a58b201b3276966aaade8ac3ac4705aba96c2Douglas Gregor    if (isThisDeclarationADefinition())
1495ec1a58b201b3276966aaade8ac3ac4705aba96c2Douglas Gregor      return ObjCContainerDecl::getSourceRange();
1496ec1a58b201b3276966aaade8ac3ac4705aba96c2Douglas Gregor
1497ec1a58b201b3276966aaade8ac3ac4705aba96c2Douglas Gregor    return SourceRange(getAtStartLoc(), getLocation());
1498ec1a58b201b3276966aaade8ac3ac4705aba96c2Douglas Gregor  }
1499f785a7d611404cf4747287a2bbc59b4d0e6a5a8cDouglas Gregor
1500a54fbf2499c7cc999e22abb9be484ce976ed9689Douglas Gregor  typedef redeclarable_base::redecl_iterator redecl_iterator;
1501ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor  using redeclarable_base::redecls_begin;
1502ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor  using redeclarable_base::redecls_end;
1503ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor  using redeclarable_base::getPreviousDecl;
1504ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor  using redeclarable_base::getMostRecentDecl;
1505f785a7d611404cf4747287a2bbc59b4d0e6a5a8cDouglas Gregor
15063fc73ee0c613715ebce78e30b4d050ea715a007dDouglas Gregor  /// Retrieves the canonical declaration of this Objective-C protocol.
15073fc73ee0c613715ebce78e30b4d050ea715a007dDouglas Gregor  ObjCProtocolDecl *getCanonicalDecl() {
15081d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor    return getFirstDeclaration();
15093fc73ee0c613715ebce78e30b4d050ea715a007dDouglas Gregor  }
15103fc73ee0c613715ebce78e30b4d050ea715a007dDouglas Gregor  const ObjCProtocolDecl *getCanonicalDecl() const {
15111d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor    return getFirstDeclaration();
15123fc73ee0c613715ebce78e30b4d050ea715a007dDouglas Gregor  }
15133fc73ee0c613715ebce78e30b4d050ea715a007dDouglas Gregor
1514cfaed8d399a34e79fbab9f70eb4ea1bbeb81a02bFariborz Jahanian  virtual void collectPropertiesToImplement(PropertyMap &PM,
1515cfaed8d399a34e79fbab9f70eb4ea1bbeb81a02bFariborz Jahanian                                            PropertyDeclOrder &PO) const;
1516b36ea375e20f71df19c101fa2399b7ea3a607e04Anna Zaks
151780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
151880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCProtocol; }
1519b05d7b20171bbd2feb14b059f39332cbe1bf1014Argyrios Kyrtzidis
15205e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  friend class ASTReader;
1521b05d7b20171bbd2feb14b059f39332cbe1bf1014Argyrios Kyrtzidis  friend class ASTDeclReader;
1522b05d7b20171bbd2feb14b059f39332cbe1bf1014Argyrios Kyrtzidis  friend class ASTDeclWriter;
1523980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
15241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1525a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCCategoryDecl - Represents a category declaration. A category allows
15260c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// you to add methods to an existing class (without subclassing or modifying
15271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// the original class interface or implementation:-). Categories don't allow
15280c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// you to add instance data. The following example adds "myMethod" to all
15290c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// NSView's within a process:
15300c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
153141c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth/// \@interface NSView (MyViewMethods)
15320c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - myMethod;
153341c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth/// \@end
15340c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
153533ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor/// Categories also allow you to split the implementation of a class across
15360c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// several files (a feature more naturally supported in C++).
15370c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
15380c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// Categories were originally inspired by dynamic languages such as Common
15391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Lisp and Smalltalk.  More traditional class-based languages (C++, Java)
15400c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// don't support this level of dynamism, which is both powerful and dangerous.
15410c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
1542e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroffclass ObjCCategoryDecl : public ObjCContainerDecl {
154399ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
154499ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie
1545980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  /// Interface belonging to this category
1546a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *ClassInterface;
15471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
154868c82cf61228102aba1194efef222fa1478af2a8Chris Lattner  /// referenced protocols in this category.
154918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  ObjCProtocolList ReferencedProtocols;
15501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1551a8ff9f455d94d9609766cfd5186b6e21dc2102f1Chris Lattner  /// Next category belonging to this class.
1552a8ff9f455d94d9609766cfd5186b6e21dc2102f1Chris Lattner  /// FIXME: this should not be a singly-linked list.  Move storage elsewhere.
1553a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCCategoryDecl *NextClassCategory;
15541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15553db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  /// \brief The location of the category name in this declaration.
15563db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  SourceLocation CategoryNameLoc;
15571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1558af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian  /// class extension may have private ivars.
1559af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian  SourceLocation IvarLBraceLoc;
1560af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian  SourceLocation IvarRBraceLoc;
1561af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian
1562ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  ObjCCategoryDecl(DeclContext *DC, SourceLocation AtLoc,
15633db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor                   SourceLocation ClassNameLoc, SourceLocation CategoryNameLoc,
1564af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian                   IdentifierInfo *Id, ObjCInterfaceDecl *IDecl,
1565af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian                   SourceLocation IvarLBraceLoc=SourceLocation(),
1566af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian                   SourceLocation IvarRBraceLoc=SourceLocation())
15671711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis    : ObjCContainerDecl(ObjCCategory, DC, Id, ClassNameLoc, AtLoc),
1568ffb0c3adc27d257c8453886957b8d220d1ad14d8Eric Christopher      ClassInterface(IDecl), NextClassCategory(0),
1569af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian      CategoryNameLoc(CategoryNameLoc),
1570af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian      IvarLBraceLoc(IvarLBraceLoc), IvarRBraceLoc(IvarRBraceLoc) {
1571a906135721c350435319347d2672bbb3bf494f91Chris Lattner  }
1572d329724745b49f894b768d47275b7c2713106e89Douglas Gregor
157361f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattnerpublic:
15741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1575d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCCategoryDecl *Create(ASTContext &C, DeclContext *DC,
1576ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                  SourceLocation AtLoc,
15773db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor                                  SourceLocation ClassNameLoc,
15783db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor                                  SourceLocation CategoryNameLoc,
1579955fadbdfecfa24a590febe66a86519096787f2dArgyrios Kyrtzidis                                  IdentifierInfo *Id,
1580af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian                                  ObjCInterfaceDecl *IDecl,
1581af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian                                  SourceLocation IvarLBraceLoc=SourceLocation(),
1582af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian                                  SourceLocation IvarRBraceLoc=SourceLocation());
15831e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor  static ObjCCategoryDecl *CreateDeserialized(ASTContext &C, unsigned ID);
15841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1585e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
1586e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; }
15878a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis
15888a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis  ObjCCategoryImplDecl *getImplementation() const;
15898a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis  void setImplementation(ObjCCategoryImplDecl *ImplD);
15908a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis
159138af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  /// setProtocolList - Set the list of protocols that this interface
1592f7b2c98c16dfb2261ea57d40a1d5bc4738e73175Chris Lattner  /// implements.
159338af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num,
159418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                       const SourceLocation *Locs, ASTContext &C) {
159518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    ReferencedProtocols.set(List, Num, Locs, C);
1596780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  }
15971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
159818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  const ObjCProtocolList &getReferencedProtocols() const {
1599780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner    return ReferencedProtocols;
16008f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian  }
16011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
160218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::iterator protocol_iterator;
1603780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();}
1604780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  protocol_iterator protocol_end() const { return ReferencedProtocols.end(); }
160530833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  unsigned protocol_size() const { return ReferencedProtocols.size(); }
160618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
1607ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  protocol_loc_iterator protocol_loc_begin() const {
1608ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return ReferencedProtocols.loc_begin();
160918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
1610ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  protocol_loc_iterator protocol_loc_end() const {
1611ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return ReferencedProtocols.loc_end();
161218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
16131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1614a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCCategoryDecl *getNextClassCategory() const { return NextClassCategory; }
16153db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor
1616d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// \brief Retrieve the pointer to the next stored category (or extension),
1617d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  /// which may be hidden.
1618d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  ObjCCategoryDecl *getNextClassCategoryRaw() const {
1619d329724745b49f894b768d47275b7c2713106e89Douglas Gregor    return NextClassCategory;
1620d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  }
1621d329724745b49f894b768d47275b7c2713106e89Douglas Gregor
162225760611365be23556b32332f8a66ae21ea93ecfFariborz Jahanian  bool IsClassExtension() const { return getIdentifier() == 0; }
1623ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
16240e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
16250e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  ivar_iterator ivar_begin() const {
16260e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian    return ivar_iterator(decls_begin());
16270e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  }
16280e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  ivar_iterator ivar_end() const {
16290e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian    return ivar_iterator(decls_end());
16300e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  }
16310e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  unsigned ivar_size() const {
16320e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian    return std::distance(ivar_begin(), ivar_end());
16330e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  }
16340e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  bool ivar_empty() const {
16350e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian    return ivar_begin() == ivar_end();
16360e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  }
16373db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor
16383db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  SourceLocation getCategoryNameLoc() const { return CategoryNameLoc; }
16393db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  void setCategoryNameLoc(SourceLocation Loc) { CategoryNameLoc = Loc; }
1640af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian
1641af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian  void setIvarLBraceLoc(SourceLocation Loc) { IvarLBraceLoc = Loc; }
1642af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian  SourceLocation getIvarLBraceLoc() const { return IvarLBraceLoc; }
1643af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian  void setIvarRBraceLoc(SourceLocation Loc) { IvarRBraceLoc = Loc; }
1644af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian  SourceLocation getIvarRBraceLoc() const { return IvarRBraceLoc; }
16453db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor
164680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
164780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCCategory; }
1648955fadbdfecfa24a590febe66a86519096787f2dArgyrios Kyrtzidis
1649955fadbdfecfa24a590febe66a86519096787f2dArgyrios Kyrtzidis  friend class ASTDeclReader;
1650955fadbdfecfa24a590febe66a86519096787f2dArgyrios Kyrtzidis  friend class ASTDeclWriter;
1651980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
16520c6b6243d3efd958c17943130e2a773653511edcSteve Naroff
1653aecae629269fae3bf484baf1d109e9a89d14eeadArgyrios Kyrtzidisclass ObjCImplDecl : public ObjCContainerDecl {
165499ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
165599ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie
16560d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// Class interface for this class/category implementation
1657a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *ClassInterface;
16581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16593aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattnerprotected:
16601711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis  ObjCImplDecl(Kind DK, DeclContext *DC,
16611711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis               ObjCInterfaceDecl *classInterface,
16621711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis               SourceLocation nameLoc, SourceLocation atStartLoc)
16631711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis    : ObjCContainerDecl(DK, DC,
16641711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                        classInterface? classInterface->getIdentifier() : 0,
16651711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                        nameLoc, atStartLoc),
1666aecae629269fae3bf484baf1d109e9a89d14eeadArgyrios Kyrtzidis      ClassInterface(classInterface) {}
16671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
166875c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattnerpublic:
1669e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; }
1670e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
16718a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis  void setClassInterface(ObjCInterfaceDecl *IFace);
16722c2d43c557beca1b4ba4bd743f33978aecb46a97Douglas Gregor
16731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void addInstanceMethod(ObjCMethodDecl *method) {
16742c2d43c557beca1b4ba4bd743f33978aecb46a97Douglas Gregor    // FIXME: Context should be set correctly before we get here.
1675653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor    method->setLexicalDeclContext(this);
16761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    addDecl(method);
1677e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff  }
16781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void addClassMethod(ObjCMethodDecl *method) {
16792c2d43c557beca1b4ba4bd743f33978aecb46a97Douglas Gregor    // FIXME: Context should be set correctly before we get here.
1680653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor    method->setLexicalDeclContext(this);
16811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    addDecl(method);
168253df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner  }
16831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
168417945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  void addPropertyImplementation(ObjCPropertyImplDecl *property);
16851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
168617945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  ObjCPropertyImplDecl *FindPropertyImplDecl(IdentifierInfo *propertyId) const;
168717945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  ObjCPropertyImplDecl *FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const;
1688653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor
1689653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor  // Iterator access to properties.
1690653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor  typedef specific_decl_iterator<ObjCPropertyImplDecl> propimpl_iterator;
16911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  propimpl_iterator propimpl_begin() const {
169217945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return propimpl_iterator(decls_begin());
1693559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  }
16941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  propimpl_iterator propimpl_end() const {
169517945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return propimpl_iterator(decls_end());
1696559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  }
1697653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor
169880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
169980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) {
17009a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt    return K >= firstObjCImpl && K <= lastObjCImpl;
170180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  }
17023aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner};
17031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ObjCCategoryImplDecl - An object of this class encapsulates a category
170541c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth/// \@implementation declaration. If a category class has declaration of a
17061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// property, its implementation must be specified in the category's
170741c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth/// \@implementation declaration. Example:
170841c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth/// \@interface I \@end
170941c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth/// \@interface I(CATEGORY)
171041c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth///    \@property int p1, d1;
171141c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth/// \@end
171241c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth/// \@implementation I(CATEGORY)
171341c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth///  \@dynamic p1,d1;
171441c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth/// \@end
17153aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner///
17163aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// ObjCCategoryImplDecl
17173aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattnerclass ObjCCategoryImplDecl : public ObjCImplDecl {
171899ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
171999ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie
17203aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  // Category name
17213aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  IdentifierInfo *Id;
17223aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner
1723c6994005dc9f677c831b8e90bdab483cc2197c29Argyrios Kyrtzidis  // Category name location
1724c6994005dc9f677c831b8e90bdab483cc2197c29Argyrios Kyrtzidis  SourceLocation CategoryNameLoc;
1725c6994005dc9f677c831b8e90bdab483cc2197c29Argyrios Kyrtzidis
17261711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis  ObjCCategoryImplDecl(DeclContext *DC, IdentifierInfo *Id,
17271711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                       ObjCInterfaceDecl *classInterface,
1728c6994005dc9f677c831b8e90bdab483cc2197c29Argyrios Kyrtzidis                       SourceLocation nameLoc, SourceLocation atStartLoc,
1729c6994005dc9f677c831b8e90bdab483cc2197c29Argyrios Kyrtzidis                       SourceLocation CategoryNameLoc)
17301711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis    : ObjCImplDecl(ObjCCategoryImpl, DC, classInterface, nameLoc, atStartLoc),
1731c6994005dc9f677c831b8e90bdab483cc2197c29Argyrios Kyrtzidis      Id(Id), CategoryNameLoc(CategoryNameLoc) {}
17323aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattnerpublic:
17333aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  static ObjCCategoryImplDecl *Create(ASTContext &C, DeclContext *DC,
17341711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                                      IdentifierInfo *Id,
17351711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                                      ObjCInterfaceDecl *classInterface,
17361711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                                      SourceLocation nameLoc,
1737c6994005dc9f677c831b8e90bdab483cc2197c29Argyrios Kyrtzidis                                      SourceLocation atStartLoc,
1738c6994005dc9f677c831b8e90bdab483cc2197c29Argyrios Kyrtzidis                                      SourceLocation CategoryNameLoc);
17391e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor  static ObjCCategoryImplDecl *CreateDeserialized(ASTContext &C, unsigned ID);
17401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17410d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// getIdentifier - Get the identifier that names the category
17423aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  /// interface associated with this implementation.
17430d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// FIXME: This is a bad API, we are overriding the NamedDecl::getIdentifier()
17440d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// to mean something different. For example:
1745ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// ((NamedDecl *)SomeCategoryImplDecl)->getIdentifier()
1746ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// returns the class interface name, whereas
1747ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// ((ObjCCategoryImplDecl *)SomeCategoryImplDecl)->getIdentifier()
17480d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// returns the category name.
17491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  IdentifierInfo *getIdentifier() const {
17501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return Id;
17513aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  }
175210b0e1fa3aabd8877dbbc0df1f2414e04afd5fddDouglas Gregor  void setIdentifier(IdentifierInfo *II) { Id = II; }
17531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17540d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  ObjCCategoryDecl *getCategoryDecl() const;
175510b0e1fa3aabd8877dbbc0df1f2414e04afd5fddDouglas Gregor
1756c6994005dc9f677c831b8e90bdab483cc2197c29Argyrios Kyrtzidis  SourceLocation getCategoryNameLoc() const { return CategoryNameLoc; }
1757c6994005dc9f677c831b8e90bdab483cc2197c29Argyrios Kyrtzidis
1758b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  /// getName - Get the name of identifier for the class interface associated
1759b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  /// with this implementation as a StringRef.
1760b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  //
1761b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  // FIXME: This is a bad API, we are overriding the NamedDecl::getName, to mean
1762b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  // something different.
1763686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getName() const {
1764b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar    return Id ? Id->getNameStart() : "";
1765b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  }
1766b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar
17673aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  /// @brief Get the name of the class associated with this interface.
17687fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar  //
1769b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  // FIXME: Deprecated, move clients to getName().
17703aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  std::string getNameAsString() const {
1771b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar    return getName();
17723aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  }
17731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
177480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
177580cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCCategoryImpl;}
1776c6994005dc9f677c831b8e90bdab483cc2197c29Argyrios Kyrtzidis
1777c6994005dc9f677c831b8e90bdab483cc2197c29Argyrios Kyrtzidis  friend class ASTDeclReader;
1778c6994005dc9f677c831b8e90bdab483cc2197c29Argyrios Kyrtzidis  friend class ASTDeclWriter;
17798f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian};
17808f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian
1781f978059b82db8c0d849c5f992036210b5ca53200Benjamin Kramerraw_ostream &operator<<(raw_ostream &OS, const ObjCCategoryImplDecl &CID);
1782900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer
1783a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCImplementationDecl - Represents a class definition - this is where
17840c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// method definitions are specified. For example:
17850c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
178698abf4bd3526a00a0e5cf71a9462c181f97b1c81Fariborz Jahanian/// @code
178741c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth/// \@implementation MyClass
17880c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (void)myMethod { /* do something */ }
178941c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth/// \@end
179098abf4bd3526a00a0e5cf71a9462c181f97b1c81Fariborz Jahanian/// @endcode
17910c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
17921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Typically, instance variables are specified in the class interface,
1793ec0d7a6f4b0699cc9960e6d9fee0f957c64d1cf9Douglas Gregor/// *not* in the implementation. Nevertheless (for legacy reasons), we
179453df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner/// allow instance variables to be specified in the implementation.  When
179553df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner/// specified, they need to be *identical* to the interface.
17960c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
17971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ObjCImplementationDecl : public ObjCImplDecl {
179899ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
1799980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  /// Implementation Class's super class.
1800a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *SuperClass;
1801634c5634817b9ad384a706fe87ab302985566bbaArgyrios Kyrtzidis  SourceLocation SuperLoc;
1802634c5634817b9ad384a706fe87ab302985566bbaArgyrios Kyrtzidis
180341c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  /// \@implementation may have private ivars.
1804af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian  SourceLocation IvarLBraceLoc;
1805af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian  SourceLocation IvarRBraceLoc;
1806af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian
1807e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// Support for ivar initialization.
1808e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// IvarInitializers - The arguments used to initialize the ivars
1809cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt  CXXCtorInitializer **IvarInitializers;
1810e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  unsigned NumIvarInitializers;
1811f85e193739c953358c865005855253af4f68a497John McCall
1812b03527a9a395168762ad8e25e59a7a272dd74561John McCall  /// Do the ivars of this class require initialization other than
1813b03527a9a395168762ad8e25e59a7a272dd74561John McCall  /// zero-initialization?
1814b03527a9a395168762ad8e25e59a7a272dd74561John McCall  bool HasNonZeroConstructors : 1;
1815b03527a9a395168762ad8e25e59a7a272dd74561John McCall
1816b03527a9a395168762ad8e25e59a7a272dd74561John McCall  /// Do the ivars of this class require non-trivial destruction?
1817b03527a9a395168762ad8e25e59a7a272dd74561John McCall  bool HasDestructors : 1;
1818ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
18191711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis  ObjCImplementationDecl(DeclContext *DC,
1820a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek                         ObjCInterfaceDecl *classInterface,
18211711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                         ObjCInterfaceDecl *superDecl,
1822af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian                         SourceLocation nameLoc, SourceLocation atStartLoc,
1823634c5634817b9ad384a706fe87ab302985566bbaArgyrios Kyrtzidis                         SourceLocation superLoc = SourceLocation(),
1824af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian                         SourceLocation IvarLBraceLoc=SourceLocation(),
1825af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian                         SourceLocation IvarRBraceLoc=SourceLocation())
18261711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis    : ObjCImplDecl(ObjCImplementation, DC, classInterface, nameLoc, atStartLoc),
1827634c5634817b9ad384a706fe87ab302985566bbaArgyrios Kyrtzidis       SuperClass(superDecl), SuperLoc(superLoc), IvarLBraceLoc(IvarLBraceLoc),
1828af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian       IvarRBraceLoc(IvarRBraceLoc),
1829af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian       IvarInitializers(0), NumIvarInitializers(0),
1830b03527a9a395168762ad8e25e59a7a272dd74561John McCall       HasNonZeroConstructors(false), HasDestructors(false) {}
18311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
18321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static ObjCImplementationDecl *Create(ASTContext &C, DeclContext *DC,
183375c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner                                        ObjCInterfaceDecl *classInterface,
18341711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                                        ObjCInterfaceDecl *superDecl,
18351711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                                        SourceLocation nameLoc,
1836af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian                                        SourceLocation atStartLoc,
1837634c5634817b9ad384a706fe87ab302985566bbaArgyrios Kyrtzidis                                     SourceLocation superLoc = SourceLocation(),
1838af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian                                        SourceLocation IvarLBraceLoc=SourceLocation(),
1839af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian                                        SourceLocation IvarRBraceLoc=SourceLocation());
1840ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
18411e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor  static ObjCImplementationDecl *CreateDeserialized(ASTContext &C, unsigned ID);
18421e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor
1843e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// init_iterator - Iterates through the ivar initializer list.
1844cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt  typedef CXXCtorInitializer **init_iterator;
1845ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1846e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// init_const_iterator - Iterates through the ivar initializer list.
1847cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt  typedef CXXCtorInitializer * const * init_const_iterator;
1848ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1849e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// init_begin() - Retrieve an iterator to the first initializer.
1850e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  init_iterator       init_begin()       { return IvarInitializers; }
1851e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// begin() - Retrieve an iterator to the first initializer.
1852e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  init_const_iterator init_begin() const { return IvarInitializers; }
1853ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1854e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// init_end() - Retrieve an iterator past the last initializer.
1855e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  init_iterator       init_end()       {
1856e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian    return IvarInitializers + NumIvarInitializers;
1857e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  }
1858e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// end() - Retrieve an iterator past the last initializer.
1859e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  init_const_iterator init_end() const {
1860e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian    return IvarInitializers + NumIvarInitializers;
1861e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  }
1862e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// getNumArgs - Number of ivars which must be initialized.
1863e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  unsigned getNumIvarInitializers() const {
1864e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian    return NumIvarInitializers;
1865e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  }
1866ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1867e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  void setNumIvarInitializers(unsigned numNumIvarInitializers) {
1868e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian    NumIvarInitializers = numNumIvarInitializers;
1869e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  }
1870ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1871e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  void setIvarInitializers(ASTContext &C,
1872cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt                           CXXCtorInitializer ** initializers,
1873e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian                           unsigned numInitializers);
1874f85e193739c953358c865005855253af4f68a497John McCall
1875b03527a9a395168762ad8e25e59a7a272dd74561John McCall  /// Do any of the ivars of this class (not counting its base classes)
1876b03527a9a395168762ad8e25e59a7a272dd74561John McCall  /// require construction other than zero-initialization?
1877b03527a9a395168762ad8e25e59a7a272dd74561John McCall  bool hasNonZeroConstructors() const { return HasNonZeroConstructors; }
1878b03527a9a395168762ad8e25e59a7a272dd74561John McCall  void setHasNonZeroConstructors(bool val) { HasNonZeroConstructors = val; }
1879b03527a9a395168762ad8e25e59a7a272dd74561John McCall
1880b03527a9a395168762ad8e25e59a7a272dd74561John McCall  /// Do any of the ivars of this class (not counting its base classes)
1881b03527a9a395168762ad8e25e59a7a272dd74561John McCall  /// require non-trivial destruction?
1882b03527a9a395168762ad8e25e59a7a272dd74561John McCall  bool hasDestructors() const { return HasDestructors; }
1883b03527a9a395168762ad8e25e59a7a272dd74561John McCall  void setHasDestructors(bool val) { HasDestructors = val; }
1884ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
18854afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  /// getIdentifier - Get the identifier that names the class
18864afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  /// interface associated with this implementation.
18871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  IdentifierInfo *getIdentifier() const {
18881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return getClassInterface()->getIdentifier();
18894afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  }
18904afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor
1891d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  /// getName - Get the name of identifier for the class interface associated
1892d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  /// with this implementation as a StringRef.
1893d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  //
1894d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  // FIXME: This is a bad API, we are overriding the NamedDecl::getName, to mean
1895d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  // something different.
1896686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getName() const {
1897d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar    assert(getIdentifier() && "Name is not a simple identifier");
1898d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar    return getIdentifier()->getName();
1899d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  }
1900d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar
19014afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  /// @brief Get the name of the class associated with this interface.
19027fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar  //
19037fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar  // FIXME: Move to StringRef API.
19044afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  std::string getNameAsString() const {
1905d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar    return getName();
19064afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  }
19074afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor
1908e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  const ObjCInterfaceDecl *getSuperClass() const { return SuperClass; }
1909e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  ObjCInterfaceDecl *getSuperClass() { return SuperClass; }
1910634c5634817b9ad384a706fe87ab302985566bbaArgyrios Kyrtzidis  SourceLocation getSuperLoc() const { return SuperLoc; }
19111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1912f3a7af901231535191d14cb524d58f22907ac4d2Chris Lattner  void setSuperClass(ObjCInterfaceDecl * superCls) { SuperClass = superCls; }
19131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1914af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian  void setIvarLBraceLoc(SourceLocation Loc) { IvarLBraceLoc = Loc; }
1915af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian  SourceLocation getIvarLBraceLoc() const { return IvarLBraceLoc; }
1916af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian  void setIvarRBraceLoc(SourceLocation Loc) { IvarRBraceLoc = Loc; }
1917af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian  SourceLocation getIvarRBraceLoc() const { return IvarRBraceLoc; }
1918af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian
19198f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor  typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
19201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ivar_iterator ivar_begin() const {
19211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return ivar_iterator(decls_begin());
19228f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor  }
19231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ivar_iterator ivar_end() const {
192417945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return ivar_iterator(decls_end());
19258f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor  }
19261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  unsigned ivar_size() const {
192717945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return std::distance(ivar_begin(), ivar_end());
19288f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor  }
19291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool ivar_empty() const {
193017945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return ivar_begin() == ivar_end();
19318f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor  }
19321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
193380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
193480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCImplementation; }
19359d50c0635fb213b2a1857e3f8488580f0dab2f98Argyrios Kyrtzidis
1936d527cc06d78fe5afa5f20105b51697637eb02c56Sebastian Redl  friend class ASTDeclReader;
19373397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl  friend class ASTDeclWriter;
1938980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
1939243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian
1940f978059b82db8c0d849c5f992036210b5ca53200Benjamin Kramerraw_ostream &operator<<(raw_ostream &OS, const ObjCImplementationDecl &ID);
1941900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer
19421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ObjCCompatibleAliasDecl - Represents alias of a class. This alias is
194341c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth/// declared as \@compatibility_alias alias class.
19444afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCCompatibleAliasDecl : public NamedDecl {
194599ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
1946243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian  /// Class that this is an alias of.
1947a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *AliasedClass;
19481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1949d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  ObjCCompatibleAliasDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
1950e8043c39176e7f253fbd92982b077eca6bf2fd59Steve Naroff                          ObjCInterfaceDecl* aliasedClass)
19514afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor    : NamedDecl(ObjCCompatibleAlias, DC, L, Id), AliasedClass(aliasedClass) {}
1952f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattnerpublic:
1953d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCCompatibleAliasDecl *Create(ASTContext &C, DeclContext *DC,
19540ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner                                         SourceLocation L, IdentifierInfo *Id,
1955f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner                                         ObjCInterfaceDecl* aliasedClass);
1956f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner
19571e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor  static ObjCCompatibleAliasDecl *CreateDeserialized(ASTContext &C,
19581e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor                                                     unsigned ID);
19591e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor
1960f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner  const ObjCInterfaceDecl *getClassInterface() const { return AliasedClass; }
1961f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner  ObjCInterfaceDecl *getClassInterface() { return AliasedClass; }
196230833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  void setClassInterface(ObjCInterfaceDecl *D) { AliasedClass = D; }
19631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
196480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
196580cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCCompatibleAlias; }
19661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1967243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian};
19681de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian
19690982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief Represents one property declaration in an Objective-C interface.
19700982205bade2fb4fc984c27b2ab401e683963b10James Dennett///
19711de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian/// For example:
19720982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \code{.mm}
197341c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth/// \@property (assign, readwrite) int MyProperty;
19740982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \endcode
19754afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCPropertyDecl : public NamedDecl {
197699ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
197782a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanianpublic:
1978a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner  enum PropertyAttributeKind {
19791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    OBJC_PR_noattr    = 0x00,
19801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    OBJC_PR_readonly  = 0x01,
1981a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_getter    = 0x02,
19821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    OBJC_PR_assign    = 0x04,
19831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    OBJC_PR_readwrite = 0x08,
1984a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_retain    = 0x10,
19851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    OBJC_PR_copy      = 0x20,
1986a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_nonatomic = 0x40,
198745937ae10a0f70f74508165aab4f2b63e18ea747Fariborz Jahanian    OBJC_PR_setter    = 0x80,
1988f85e193739c953358c865005855253af4f68a497John McCall    OBJC_PR_atomic    = 0x100,
1989f85e193739c953358c865005855253af4f68a497John McCall    OBJC_PR_weak      = 0x200,
1990f85e193739c953358c865005855253af4f68a497John McCall    OBJC_PR_strong    = 0x400,
19919f3480bab8fcb6547978f8ad9e2b8f468e3658eeArgyrios Kyrtzidis    OBJC_PR_unsafe_unretained = 0x800
19929f3480bab8fcb6547978f8ad9e2b8f468e3658eeArgyrios Kyrtzidis    // Adding a property should change NumPropertyAttrsBits
19939f3480bab8fcb6547978f8ad9e2b8f468e3658eeArgyrios Kyrtzidis  };
19940a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis
19959f3480bab8fcb6547978f8ad9e2b8f468e3658eeArgyrios Kyrtzidis  enum {
19960a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis    /// \brief Number of bits fitting all the property attributes.
19979f3480bab8fcb6547978f8ad9e2b8f468e3658eeArgyrios Kyrtzidis    NumPropertyAttrsBits = 12
1998a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner  };
1999af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
20003a02b44e3948f7762dbfba94b7961281ca29d022Fariborz Jahanian  enum SetterKind { Assign, Retain, Copy, Weak };
200146b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  enum PropertyControl { None, Required, Optional };
200282a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanianprivate:
200341c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  SourceLocation AtLoc;   // location of \@property
200477bfb8b43ec3f7dee3a71f6e854b03ad29dab84fFariborz Jahanian  SourceLocation LParenLoc; // location of '(' starting attribute list or null.
200583a230c83a54190366138c1a4f4310ef838b88fcJohn McCall  TypeSourceInfo *DeclType;
20069f3480bab8fcb6547978f8ad9e2b8f468e3658eeArgyrios Kyrtzidis  unsigned PropertyAttributes : NumPropertyAttrsBits;
20079f3480bab8fcb6547978f8ad9e2b8f468e3658eeArgyrios Kyrtzidis  unsigned PropertyAttributesAsWritten : NumPropertyAttrsBits;
200841c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  // \@required/\@optional
200946b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  unsigned PropertyImplementation : 2;
20101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20115251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  Selector GetterName;    // getter name of NULL if no getter
20125251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  Selector SetterName;    // setter name of NULL if no setter
20131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
201433de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  ObjCMethodDecl *GetterMethodDecl; // Declaration of getter instance method
201533de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  ObjCMethodDecl *SetterMethodDecl; // Declaration of setter instance method
2016af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian  ObjCIvarDecl *PropertyIvarDecl;   // Synthesize ivar for this property
201733de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian
20181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ObjCPropertyDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
201977bfb8b43ec3f7dee3a71f6e854b03ad29dab84fFariborz Jahanian                   SourceLocation AtLocation,  SourceLocation LParenLocation,
202077bfb8b43ec3f7dee3a71f6e854b03ad29dab84fFariborz Jahanian                   TypeSourceInfo *T)
202177bfb8b43ec3f7dee3a71f6e854b03ad29dab84fFariborz Jahanian    : NamedDecl(ObjCProperty, DC, L, Id), AtLoc(AtLocation),
202277bfb8b43ec3f7dee3a71f6e854b03ad29dab84fFariborz Jahanian      LParenLoc(LParenLocation), DeclType(T),
2023ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie      PropertyAttributes(OBJC_PR_noattr),
202480aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian      PropertyAttributesAsWritten(OBJC_PR_noattr),
202580aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian      PropertyImplementation(None),
20261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      GetterName(Selector()),
202733de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian      SetterName(Selector()),
2028af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian      GetterMethodDecl(0), SetterMethodDecl(0) , PropertyIvarDecl(0) {}
2029f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattnerpublic:
20301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static ObjCPropertyDecl *Create(ASTContext &C, DeclContext *DC,
20311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                  SourceLocation L,
2032d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian                                  IdentifierInfo *Id, SourceLocation AtLocation,
203377bfb8b43ec3f7dee3a71f6e854b03ad29dab84fFariborz Jahanian                                  SourceLocation LParenLocation,
203483a230c83a54190366138c1a4f4310ef838b88fcJohn McCall                                  TypeSourceInfo *T,
203546b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian                                  PropertyControl propControl = None);
20361e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor
20371e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor  static ObjCPropertyDecl *CreateDeserialized(ASTContext &C, unsigned ID);
20381e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor
2039d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian  SourceLocation getAtLoc() const { return AtLoc; }
2040d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian  void setAtLoc(SourceLocation L) { AtLoc = L; }
204177bfb8b43ec3f7dee3a71f6e854b03ad29dab84fFariborz Jahanian
204277bfb8b43ec3f7dee3a71f6e854b03ad29dab84fFariborz Jahanian  SourceLocation getLParenLoc() const { return LParenLoc; }
204377bfb8b43ec3f7dee3a71f6e854b03ad29dab84fFariborz Jahanian  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2044ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
204583a230c83a54190366138c1a4f4310ef838b88fcJohn McCall  TypeSourceInfo *getTypeSourceInfo() const { return DeclType; }
204683a230c83a54190366138c1a4f4310ef838b88fcJohn McCall  QualType getType() const { return DeclType->getType(); }
204783a230c83a54190366138c1a4f4310ef838b88fcJohn McCall  void setType(TypeSourceInfo *T) { DeclType = T; }
204870e5a14c6076d63833c62d1d6d628c26309897c1Douglas Gregor
2049a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner  PropertyAttributeKind getPropertyAttributes() const {
2050f4af5154571e0c5eadb19df10e65464766ef6683Chris Lattner    return PropertyAttributeKind(PropertyAttributes);
2051f4af5154571e0c5eadb19df10e65464766ef6683Chris Lattner  }
20521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setPropertyAttributes(PropertyAttributeKind PRVal) {
2053a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    PropertyAttributes |= PRVal;
205482a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian  }
2055394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar
205680aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  PropertyAttributeKind getPropertyAttributesAsWritten() const {
205780aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian    return PropertyAttributeKind(PropertyAttributesAsWritten);
205880aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  }
20590a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis
20600a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis  bool hasWrittenStorageAttribute() const {
20610a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis    return PropertyAttributesAsWritten & (OBJC_PR_assign | OBJC_PR_copy |
20620a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis        OBJC_PR_unsafe_unretained | OBJC_PR_retain | OBJC_PR_strong |
20630a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis        OBJC_PR_weak);
20640a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis  }
2065ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
206680aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  void setPropertyAttributesAsWritten(PropertyAttributeKind PRVal) {
206780aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian    PropertyAttributesAsWritten = PRVal;
206880aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  }
2069ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2070c4a77906c259cba58c147d8468c406a430ecdcbbDmitri Gribenko void makeitReadWriteAttribute() {
20718cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian    PropertyAttributes &= ~OBJC_PR_readonly;
20728cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian    PropertyAttributes |= OBJC_PR_readwrite;
20731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump }
20748cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian
2075af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  // Helper methods for accessing attributes.
2076af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
2077f3477c13eeaf11b32a41f181398fb5deffd0dd73Sylvestre Ledru  /// isReadOnly - Return true iff the property has a setter.
2078394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar  bool isReadOnly() const {
2079394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar    return (PropertyAttributes & OBJC_PR_readonly);
2080394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar  }
2081af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
2082265941bc308d65cc270d5c4de5806f37ce405606John McCall  /// isAtomic - Return true if the property is atomic.
2083265941bc308d65cc270d5c4de5806f37ce405606John McCall  bool isAtomic() const {
2084265941bc308d65cc270d5c4de5806f37ce405606John McCall    return (PropertyAttributes & OBJC_PR_atomic);
2085265941bc308d65cc270d5c4de5806f37ce405606John McCall  }
2086265941bc308d65cc270d5c4de5806f37ce405606John McCall
2087265941bc308d65cc270d5c4de5806f37ce405606John McCall  /// isRetaining - Return true if the property retains its value.
2088265941bc308d65cc270d5c4de5806f37ce405606John McCall  bool isRetaining() const {
2089265941bc308d65cc270d5c4de5806f37ce405606John McCall    return (PropertyAttributes &
2090265941bc308d65cc270d5c4de5806f37ce405606John McCall            (OBJC_PR_retain | OBJC_PR_strong | OBJC_PR_copy));
2091265941bc308d65cc270d5c4de5806f37ce405606John McCall  }
2092265941bc308d65cc270d5c4de5806f37ce405606John McCall
2093af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  /// getSetterKind - Return the method used for doing assignment in
2094af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  /// the property setter. This is only valid if the property has been
2095af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  /// defined to have a setter.
2096af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  SetterKind getSetterKind() const {
20976dc6f008994472cf4da321855e8c51c39720f3edJohn McCall    if (PropertyAttributes & OBJC_PR_strong)
20986dc6f008994472cf4da321855e8c51c39720f3edJohn McCall      return getType()->isBlockPointerType() ? Copy : Retain;
20996dc6f008994472cf4da321855e8c51c39720f3edJohn McCall    if (PropertyAttributes & OBJC_PR_retain)
2100af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar      return Retain;
2101af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar    if (PropertyAttributes & OBJC_PR_copy)
2102af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar      return Copy;
21033a02b44e3948f7762dbfba94b7961281ca29d022Fariborz Jahanian    if (PropertyAttributes & OBJC_PR_weak)
21043a02b44e3948f7762dbfba94b7961281ca29d022Fariborz Jahanian      return Weak;
2105af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar    return Assign;
2106af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  }
2107af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
21085251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  Selector getGetterName() const { return GetterName; }
21095251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  void setGetterName(Selector Sel) { GetterName = Sel; }
21101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21115251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  Selector getSetterName() const { return SetterName; }
21125251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  void setSetterName(Selector Sel) { SetterName = Sel; }
21131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
211433de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  ObjCMethodDecl *getGetterMethodDecl() const { return GetterMethodDecl; }
211533de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  void setGetterMethodDecl(ObjCMethodDecl *gDecl) { GetterMethodDecl = gDecl; }
211633de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian
211733de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  ObjCMethodDecl *getSetterMethodDecl() const { return SetterMethodDecl; }
211833de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  void setSetterMethodDecl(ObjCMethodDecl *gDecl) { SetterMethodDecl = gDecl; }
21191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
212041c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  // Related to \@optional/\@required declared in \@protocol
212146b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  void setPropertyImplementation(PropertyControl pc) {
212246b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian    PropertyImplementation = pc;
212346b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  }
212446b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  PropertyControl getPropertyImplementation() const {
212546b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian    return PropertyControl(PropertyImplementation);
21261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
21271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2128af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian  void setPropertyIvarDecl(ObjCIvarDecl *Ivar) {
2129af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian    PropertyIvarDecl = Ivar;
2130af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian  }
2131af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian  ObjCIvarDecl *getPropertyIvarDecl() const {
2132af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian    return PropertyIvarDecl;
2133af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian  }
21341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2135aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  virtual SourceRange getSourceRange() const LLVM_READONLY {
2136e3c60a7ce9e0f42c7ca2344b33203266aceca1dbDouglas Gregor    return SourceRange(AtLoc, getLocation());
2137e3c60a7ce9e0f42c7ca2344b33203266aceca1dbDouglas Gregor  }
2138ad0ce53c8219456938405b84c5d13341a47e3d94Anna Zaks
2139ad0ce53c8219456938405b84c5d13341a47e3d94Anna Zaks  /// Get the default name of the synthesized ivar.
2140ad0ce53c8219456938405b84c5d13341a47e3d94Anna Zaks  IdentifierInfo *getDefaultSynthIvarName(ASTContext &Ctx) const;
2141e3c60a7ce9e0f42c7ca2344b33203266aceca1dbDouglas Gregor
21429f550ff05d496e6b9480e5619a21d9da0c9e27c1Ted Kremenek  /// Lookup a property by name in the specified DeclContext.
2143de09d0c9694f01a99870a8825266d44a29ebb325Ted Kremenek  static ObjCPropertyDecl *findPropertyDecl(const DeclContext *DC,
21449f550ff05d496e6b9480e5619a21d9da0c9e27c1Ted Kremenek                                            IdentifierInfo *propertyID);
21459f550ff05d496e6b9480e5619a21d9da0c9e27c1Ted Kremenek
214680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
214780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCProperty; }
214882a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian};
2149980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
21501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ObjCPropertyImplDecl - Represents implementation declaration of a property
215161d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian/// in a class or category implementation block. For example:
215241c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth/// \@synthesize prop1 = ivar1;
215361d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian///
21544afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCPropertyImplDecl : public Decl {
215561d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanianpublic:
21569f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar  enum Kind {
21579f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar    Synthesize,
21589f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar    Dynamic
215961d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  };
216061d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanianprivate:
216141c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  SourceLocation AtLoc;   // location of \@synthesize or \@dynamic
2162ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
216341c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  /// \brief For \@synthesize, the location of the ivar, if it was written in
2164a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  /// the source code.
2165a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  ///
2166a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  /// \code
216741c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  /// \@synthesize int a = b
2168a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  /// \endcode
2169a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  SourceLocation IvarLoc;
2170ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
217161d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  /// Property declaration being implemented
217261d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  ObjCPropertyDecl *PropertyDecl;
2173be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek
217441c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  /// Null for \@dynamic. Required for \@synthesize.
217561d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  ObjCIvarDecl *PropertyIvarDecl;
2176ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
217741c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  /// Null for \@dynamic. Non-null if property must be copy-constructed in
217841c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  /// getter.
217917cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  Expr *GetterCXXConstructor;
2180ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
218141c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  /// Null for \@dynamic. Non-null if property has assignment operator to call
218217cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  /// in Setter synthesis.
218317cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  Expr *SetterCXXAssignment;
2184be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek
2185d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  ObjCPropertyImplDecl(DeclContext *DC, SourceLocation atLoc, SourceLocation L,
21861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                       ObjCPropertyDecl *property,
21871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                       Kind PK,
2188a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor                       ObjCIvarDecl *ivarDecl,
2189a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor                       SourceLocation ivarLoc)
21901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : Decl(ObjCPropertyImpl, DC, L), AtLoc(atLoc),
2191ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie      IvarLoc(ivarLoc), PropertyDecl(property), PropertyIvarDecl(ivarDecl),
219217cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian      GetterCXXConstructor(0), SetterCXXAssignment(0) {
21939f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar    assert (PK == Dynamic || PropertyIvarDecl);
21949f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar  }
21951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21969f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbarpublic:
2197d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCPropertyImplDecl *Create(ASTContext &C, DeclContext *DC,
21981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                      SourceLocation atLoc, SourceLocation L,
21991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                      ObjCPropertyDecl *property,
22001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                      Kind PK,
2201a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor                                      ObjCIvarDecl *ivarDecl,
2202a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor                                      SourceLocation ivarLoc);
220361d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian
22041e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor  static ObjCPropertyImplDecl *CreateDeserialized(ASTContext &C, unsigned ID);
22051e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor
2206aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  virtual SourceRange getSourceRange() const LLVM_READONLY;
2207ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2208aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceLocation getLocStart() const LLVM_READONLY { return AtLoc; }
22098818c4fb69cb2a4eec94b217a90f94f9e075296eDouglas Gregor  void setAtLoc(SourceLocation Loc) { AtLoc = Loc; }
2210d40910b581b09c937a8c1fdcde9b8ec724398fb9Steve Naroff
2211be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek  ObjCPropertyDecl *getPropertyDecl() const {
2212be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek    return PropertyDecl;
2213be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek  }
22148818c4fb69cb2a4eec94b217a90f94f9e075296eDouglas Gregor  void setPropertyDecl(ObjCPropertyDecl *Prop) { PropertyDecl = Prop; }
22158818c4fb69cb2a4eec94b217a90f94f9e075296eDouglas Gregor
22169f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar  Kind getPropertyImplementation() const {
22179f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar    return PropertyIvarDecl ? Synthesize : Dynamic;
2218be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek  }
22191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2220af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  ObjCIvarDecl *getPropertyIvarDecl() const {
2221be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek    return PropertyIvarDecl;
2222be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek  }
2223a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  SourceLocation getPropertyIvarDeclLoc() const { return IvarLoc; }
2224ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2225a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  void setPropertyIvarDecl(ObjCIvarDecl *Ivar,
2226ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                           SourceLocation IvarLoc) {
2227ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    PropertyIvarDecl = Ivar;
2228a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor    this->IvarLoc = IvarLoc;
2229a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  }
2230ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2231135bf8ee69e2ae2daea4f713381995028c41e264Argyrios Kyrtzidis  /// \brief For \@synthesize, returns true if an ivar name was explicitly
2232135bf8ee69e2ae2daea4f713381995028c41e264Argyrios Kyrtzidis  /// specified.
2233135bf8ee69e2ae2daea4f713381995028c41e264Argyrios Kyrtzidis  ///
2234135bf8ee69e2ae2daea4f713381995028c41e264Argyrios Kyrtzidis  /// \code
2235135bf8ee69e2ae2daea4f713381995028c41e264Argyrios Kyrtzidis  /// \@synthesize int a = b; // true
2236135bf8ee69e2ae2daea4f713381995028c41e264Argyrios Kyrtzidis  /// \@synthesize int a; // false
2237135bf8ee69e2ae2daea4f713381995028c41e264Argyrios Kyrtzidis  /// \endcode
2238135bf8ee69e2ae2daea4f713381995028c41e264Argyrios Kyrtzidis  bool isIvarNameSpecified() const {
2239135bf8ee69e2ae2daea4f713381995028c41e264Argyrios Kyrtzidis    return IvarLoc.isValid() && IvarLoc != getLocation();
2240135bf8ee69e2ae2daea4f713381995028c41e264Argyrios Kyrtzidis  }
2241135bf8ee69e2ae2daea4f713381995028c41e264Argyrios Kyrtzidis
224217cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  Expr *getGetterCXXConstructor() const {
224317cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian    return GetterCXXConstructor;
224417cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  }
224517cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  void setGetterCXXConstructor(Expr *getterCXXConstructor) {
224617cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian    GetterCXXConstructor = getterCXXConstructor;
224717cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  }
22488818c4fb69cb2a4eec94b217a90f94f9e075296eDouglas Gregor
224917cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  Expr *getSetterCXXAssignment() const {
225017cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian    return SetterCXXAssignment;
225117cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  }
225217cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  void setSetterCXXAssignment(Expr *setterCXXAssignment) {
225317cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian    SetterCXXAssignment = setterCXXAssignment;
225417cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  }
2255ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
225680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
225780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Decl::Kind K) { return K == ObjCPropertyImpl; }
2258ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2259a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  friend class ASTDeclReader;
226061d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian};
226161d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian
2262d329724745b49f894b768d47275b7c2713106e89Douglas Gregortemplate<bool (*Filter)(ObjCCategoryDecl *)>
2263d329724745b49f894b768d47275b7c2713106e89Douglas Gregorvoid
2264d329724745b49f894b768d47275b7c2713106e89Douglas GregorObjCInterfaceDecl::filtered_category_iterator<Filter>::
2265d329724745b49f894b768d47275b7c2713106e89Douglas GregorfindAcceptableCategory() {
2266d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  while (Current && !Filter(Current))
2267d329724745b49f894b768d47275b7c2713106e89Douglas Gregor    Current = Current->getNextClassCategoryRaw();
2268d329724745b49f894b768d47275b7c2713106e89Douglas Gregor}
2269d329724745b49f894b768d47275b7c2713106e89Douglas Gregor
2270d329724745b49f894b768d47275b7c2713106e89Douglas Gregortemplate<bool (*Filter)(ObjCCategoryDecl *)>
2271d329724745b49f894b768d47275b7c2713106e89Douglas Gregorinline ObjCInterfaceDecl::filtered_category_iterator<Filter> &
2272d329724745b49f894b768d47275b7c2713106e89Douglas GregorObjCInterfaceDecl::filtered_category_iterator<Filter>::operator++() {
2273d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  Current = Current->getNextClassCategoryRaw();
2274d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  findAcceptableCategory();
2275d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  return *this;
2276d329724745b49f894b768d47275b7c2713106e89Douglas Gregor}
2277d329724745b49f894b768d47275b7c2713106e89Douglas Gregor
2278d329724745b49f894b768d47275b7c2713106e89Douglas Gregorinline bool ObjCInterfaceDecl::isVisibleCategory(ObjCCategoryDecl *Cat) {
2279d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  return !Cat->isHidden();
2280d329724745b49f894b768d47275b7c2713106e89Douglas Gregor}
2281d329724745b49f894b768d47275b7c2713106e89Douglas Gregor
2282d329724745b49f894b768d47275b7c2713106e89Douglas Gregorinline bool ObjCInterfaceDecl::isVisibleExtension(ObjCCategoryDecl *Cat) {
2283d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  return Cat->IsClassExtension() && !Cat->isHidden();
2284d329724745b49f894b768d47275b7c2713106e89Douglas Gregor}
2285d329724745b49f894b768d47275b7c2713106e89Douglas Gregor
2286d329724745b49f894b768d47275b7c2713106e89Douglas Gregorinline bool ObjCInterfaceDecl::isKnownExtension(ObjCCategoryDecl *Cat) {
2287d329724745b49f894b768d47275b7c2713106e89Douglas Gregor  return Cat->IsClassExtension();
2288d329724745b49f894b768d47275b7c2713106e89Douglas Gregor}
2289d329724745b49f894b768d47275b7c2713106e89Douglas Gregor
2290980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff}  // end namespace clang
2291980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff#endif
2292