DeclObjC.h revision 71207fc0470e1eee40a2951cd5cc3ff47725b755
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"
20980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
21980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffnamespace clang {
22980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffclass Expr;
23980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffclass Stmt;
24980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffclass FunctionDecl;
2560f8c868ffb346b78451a3eccaecd0461d2ae498Fariborz Jahanianclass RecordDecl;
26a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCIvarDecl;
27a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCMethodDecl;
28a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCProtocolDecl;
29a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCCategoryDecl;
30a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCPropertyDecl;
31f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanianclass ObjCPropertyImplDecl;
32cbb67480094b3bcb5b715acd827cbad55e2a204cSean Huntclass CXXCtorInitializer;
3368835718c4125f2f66740cd04de7088645ec695dChris Lattner
34793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnerclass ObjCListBase {
35793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  void operator=(const ObjCListBase &);     // DO NOT IMPLEMENT
36793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  ObjCListBase(const ObjCListBase&);        // DO NOT IMPLEMENT
37793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnerprotected:
38793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  /// List is an array of pointers to objects that are not owned by this object.
39793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  void **List;
403db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  unsigned NumElts;
41793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner
423db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattnerpublic:
43793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  ObjCListBase() : List(0), NumElts(0) {}
44793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  unsigned size() const { return NumElts; }
45793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  bool empty() const { return NumElts == 0; }
461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
47793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnerprotected:
4838af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  void set(void *const* InList, unsigned Elts, ASTContext &Ctx);
49793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner};
501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
52793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner/// ObjCList - This is a simple template class used to hold various lists of
53793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner/// decls etc, which is heavily used by the ObjC front-end.  This only use case
54793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner/// this supports is setting the list all at once and then reading elements out
55793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner/// of it.
56793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnertemplate <typename T>
57793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnerclass ObjCList : public ObjCListBase {
58793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnerpublic:
5938af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  void set(T* const* InList, unsigned Elts, ASTContext &Ctx) {
6038af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner    ObjCListBase::set(reinterpret_cast<void*const*>(InList), Elts, Ctx);
61793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  }
621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
63793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  typedef T* const * iterator;
64793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  iterator begin() const { return (iterator)List; }
65793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  iterator end() const { return (iterator)List+NumElts; }
661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
67793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  T* operator[](unsigned Idx) const {
68793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner    assert(Idx < NumElts && "Invalid access");
69793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner    return (T*)List[Idx];
703db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  }
713db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner};
723db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner
7318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor/// \brief A list of Objective-C protocols, along with the source
7418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor/// locations at which they were referenced.
7518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregorclass ObjCProtocolList : public ObjCList<ObjCProtocolDecl> {
7618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  SourceLocation *Locations;
7718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor
7818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  using ObjCList<ObjCProtocolDecl>::set;
7918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor
8018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregorpublic:
8118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  ObjCProtocolList() : ObjCList<ObjCProtocolDecl>(), Locations(0) { }
8218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor
8318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef const SourceLocation *loc_iterator;
8418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  loc_iterator loc_begin() const { return Locations; }
8518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  loc_iterator loc_end() const { return Locations + size(); }
8618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor
87ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  void set(ObjCProtocolDecl* const* InList, unsigned Elts,
8818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor           const SourceLocation *Locs, ASTContext &Ctx);
8918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor};
901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff
92a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCMethodDecl - Represents an instance or class method declaration.
9358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// ObjC methods can be declared within 4 contexts: class interfaces,
9458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// categories, protocols, and class implementations. While C++ member
951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// functions leverage C syntax, Objective-C method syntax is modeled after
961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Smalltalk (using colons to specify argument types/expressions).
9758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Here are some brief examples:
9858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff///
9958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Setter/getter instance methods:
10058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// - (void)setMenu:(NSMenu *)menu;
1011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// - (NSMenu *)menu;
1021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
10358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Instance method that takes 2 NSView arguments:
10458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// - (void)replaceSubview:(NSView *)oldView with:(NSView *)newView;
10558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff///
10658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Getter class method:
10758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// + (NSMenu *)defaultMenu;
10858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff///
10958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// A selector represents a unique name for a method. The selector names for
11058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// the above methods are setMenu:, menu, replaceSubview:with:, and defaultMenu.
11158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff///
1124afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCMethodDecl : public NamedDecl, public DeclContext {
11358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroffpublic:
11458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  enum ImplementationControl { None, Required, Optional };
11558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroffprivate:
11685f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  // The conventional meaning of this method; an ObjCMethodFamily.
11785f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  // This is not serialized; instead, it is computed on demand and
11885f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  // cached.
11985f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  mutable unsigned Family : ObjCMethodFamilyBitWidth;
12085f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall
12158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  /// instance (true) or class (false) method.
12285f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  unsigned IsInstance : 1;
12385f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  unsigned IsVariadic : 1;
1241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1254607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian  // Synthesized declaration method for a property setter/getter
12685f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  unsigned IsSynthesized : 1;
127ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1283fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian  // Method has a definition.
12985f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  unsigned IsDefined : 1;
1301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13172b2625aa67c8213acaf4bf6209b67859d60e2cfArgyrios Kyrtzidis  /// \brief Method redeclaration in the same interface.
1323a919e7110407ae7609bb6edc57aac16a5990661Argyrios Kyrtzidis  unsigned IsRedeclaration : 1;
1333a919e7110407ae7609bb6edc57aac16a5990661Argyrios Kyrtzidis
13472b2625aa67c8213acaf4bf6209b67859d60e2cfArgyrios Kyrtzidis  /// \brief Is redeclared in the same interface.
13572b2625aa67c8213acaf4bf6209b67859d60e2cfArgyrios Kyrtzidis  mutable unsigned HasRedeclaration : 1;
13672b2625aa67c8213acaf4bf6209b67859d60e2cfArgyrios Kyrtzidis
137ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  // NOTE: VC++ treats enums as signed, avoid using ImplementationControl enum
13858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  /// @required/@optional
139ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  unsigned DeclImplementation : 2;
1401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
141ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  // NOTE: VC++ treats enums as signed, avoid using the ObjCDeclQualifier enum
14258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  /// in, inout, etc.
143ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  unsigned objcDeclQualifier : 6;
1441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
145926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor  /// \brief Indicates whether this method has a related result type.
146926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor  unsigned RelatedResultType : 1;
147ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
148491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// \brief Whether the locations of the selector identifiers are in a
149491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// "standard" position, a enum SelectorLocationsKind.
150491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  unsigned SelLocsKind : 2;
1517732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian
1524bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor  // Result type of this method.
15358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  QualType MethodDeclType;
154ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1554bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor  // Type source information for the result type.
1564bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor  TypeSourceInfo *ResultTInfo;
1574bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor
158491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// \brief Array of ParmVarDecls for the formal parameters of this method
159491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// and optionally followed by selector locations.
160491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  void *ParamsAndSelLocs;
161491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  unsigned NumParams;
1621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  /// List of attributes for this method declaration.
164a2e85ada1dfef36201a31f6646bc4ea3bd76a89aArgyrios Kyrtzidis  SourceLocation EndLoc; // the location of the ';' or '}'.
1651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  // The following are only used for method definitions, null otherwise.
16758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  // FIXME: space savings opportunity, consider a sub-class.
16858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  Stmt *Body;
169451318c08a6342c10b8986060386fd9274418437Daniel Dunbar
170451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// SelfDecl - Decl for the implicit self parameter. This is lazily
171451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// constructed by createImplicitParams.
1724111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  ImplicitParamDecl *SelfDecl;
173451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// CmdDecl - Decl for the implicit _cmd parameter. This is lazily
174451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// constructed by createImplicitParams.
1754111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  ImplicitParamDecl *CmdDecl;
1761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
177491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  SelectorLocationsKind getSelLocsKind() const {
178491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    return (SelectorLocationsKind)SelLocsKind;
179491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  }
180491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  bool hasStandardSelLocs() const {
181491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    return getSelLocsKind() != SelLoc_NonStandard;
182491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  }
183491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis
184491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// \brief Get a pointer to the stored selector identifiers locations array.
185491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// No locations will be stored if HasStandardSelLocs is true.
186491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  SourceLocation *getStoredSelLocs() {
187491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    return reinterpret_cast<SourceLocation*>(getParams() + NumParams);
188491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  }
189491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  const SourceLocation *getStoredSelLocs() const {
190491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    return reinterpret_cast<const SourceLocation*>(getParams() + NumParams);
191491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  }
192491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis
193491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// \brief Get a pointer to the stored selector identifiers locations array.
194491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// No locations will be stored if HasStandardSelLocs is true.
195491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  ParmVarDecl **getParams() {
196491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    return reinterpret_cast<ParmVarDecl **>(ParamsAndSelLocs);
197491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  }
198491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  const ParmVarDecl *const *getParams() const {
199491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    return reinterpret_cast<const ParmVarDecl *const *>(ParamsAndSelLocs);
200491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  }
201491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis
202491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// \brief Get the number of stored selector identifiers locations.
203491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// No locations will be stored if HasStandardSelLocs is true.
204491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  unsigned getNumStoredSelLocs() const {
205491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    if (hasStandardSelLocs())
206491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis      return 0;
207491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    return getNumSelectorLocs();
208491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  }
209491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis
210491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  void setParamsAndSelLocs(ASTContext &C,
211491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis                           ArrayRef<ParmVarDecl*> Params,
212491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis                           ArrayRef<SourceLocation> SelLocs);
213491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis
214a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCMethodDecl(SourceLocation beginLoc, SourceLocation endLoc,
21558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff                 Selector SelInfo, QualType T,
2164bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor                 TypeSourceInfo *ResultTInfo,
2170701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff                 DeclContext *contextDecl,
218f6414927e67e27d9324d8d179c5f7ea620443924Daniel Dunbar                 bool isInstance = true,
21958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff                 bool isVariadic = false,
2204607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian                 bool isSynthesized = false,
22175cf3e86d33ce810c12084126385371b335c30baArgyrios Kyrtzidis                 bool isImplicitlyDeclared = false,
2223fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian                 bool isDefined = false,
2237732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian                 ImplementationControl impControl = None,
224da92a7f91cf88f49e02050919676f7fb8e3bdff8Argyrios Kyrtzidis                 bool HasRelatedResultType = false)
2254afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  : NamedDecl(ObjCMethod, contextDecl, beginLoc, SelInfo),
22685f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall    DeclContext(ObjCMethod), Family(InvalidObjCMethodFamily),
22758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff    IsInstance(isInstance), IsVariadic(isVariadic),
2284607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian    IsSynthesized(isSynthesized),
22972b2625aa67c8213acaf4bf6209b67859d60e2cfArgyrios Kyrtzidis    IsDefined(isDefined), IsRedeclaration(0), HasRedeclaration(0),
23058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff    DeclImplementation(impControl), objcDeclQualifier(OBJC_TQ_None),
231da92a7f91cf88f49e02050919676f7fb8e3bdff8Argyrios Kyrtzidis    RelatedResultType(HasRelatedResultType),
232491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    SelLocsKind(SelLoc_StandardNoSpace),
233926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor    MethodDeclType(T), ResultTInfo(ResultTInfo),
234491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    ParamsAndSelLocs(0), NumParams(0),
23575cf3e86d33ce810c12084126385371b335c30baArgyrios Kyrtzidis    EndLoc(endLoc), Body(0), SelfDecl(0), CmdDecl(0) {
23675cf3e86d33ce810c12084126385371b335c30baArgyrios Kyrtzidis    setImplicit(isImplicitlyDeclared);
23775cf3e86d33ce810c12084126385371b335c30baArgyrios Kyrtzidis  }
2388a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek
23957ea6bee79cc60ba20c7886b453f40f380dce1b1Argyrios Kyrtzidis  /// \brief A definition will return its interface declaration.
24057ea6bee79cc60ba20c7886b453f40f380dce1b1Argyrios Kyrtzidis  /// An interface declaration will return its definition.
24157ea6bee79cc60ba20c7886b453f40f380dce1b1Argyrios Kyrtzidis  /// Otherwise it will return itself.
242da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor  virtual ObjCMethodDecl *getNextRedeclaration();
243da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor
2446c4ae5de0c356777446f823b573821fb95560d91Chris Lattnerpublic:
2450ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner  static ObjCMethodDecl *Create(ASTContext &C,
2461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                SourceLocation beginLoc,
24711d77169555480ee0a04c6e5bc390d8fde41175dArgyrios Kyrtzidis                                SourceLocation endLoc,
24811d77169555480ee0a04c6e5bc390d8fde41175dArgyrios Kyrtzidis                                Selector SelInfo,
249ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                QualType T,
2504bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor                                TypeSourceInfo *ResultTInfo,
2514bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor                                DeclContext *contextDecl,
252f6414927e67e27d9324d8d179c5f7ea620443924Daniel Dunbar                                bool isInstance = true,
2536c4ae5de0c356777446f823b573821fb95560d91Chris Lattner                                bool isVariadic = false,
2544607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian                                bool isSynthesized = false,
25575cf3e86d33ce810c12084126385371b335c30baArgyrios Kyrtzidis                                bool isImplicitlyDeclared = false,
2563fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian                                bool isDefined = false,
2577732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian                                ImplementationControl impControl = None,
258da92a7f91cf88f49e02050919676f7fb8e3bdff8Argyrios Kyrtzidis                                bool HasRelatedResultType = false);
259e7f9d301a10b4b3223e91d9be4362b44cba0a212Argyrios Kyrtzidis
2601e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor  static ObjCMethodDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2611e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor
262da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor  virtual ObjCMethodDecl *getCanonicalDecl();
26313e635c55eb23f736d38abf9c954801bd6482db4Ted Kremenek  const ObjCMethodDecl *getCanonicalDecl() const {
26413e635c55eb23f736d38abf9c954801bd6482db4Ted Kremenek    return const_cast<ObjCMethodDecl*>(this)->getCanonicalDecl();
26513e635c55eb23f736d38abf9c954801bd6482db4Ted Kremenek  }
266e7f9d301a10b4b3223e91d9be4362b44cba0a212Argyrios Kyrtzidis
267ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  ObjCDeclQualifier getObjCDeclQualifier() const {
268ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek    return ObjCDeclQualifier(objcDeclQualifier);
269ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  }
270a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void setObjCDeclQualifier(ObjCDeclQualifier QV) { objcDeclQualifier = QV; }
2711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
272926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor  /// \brief Determine whether this method has a result type that is related
273926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor  /// to the message receiver's type.
274926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor  bool hasRelatedResultType() const { return RelatedResultType; }
275ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
276926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor  /// \brief Note whether this method has a related result type.
277926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor  void SetRelatedResultType(bool RRT = true) { RelatedResultType = RRT; }
2783a919e7110407ae7609bb6edc57aac16a5990661Argyrios Kyrtzidis
2793a919e7110407ae7609bb6edc57aac16a5990661Argyrios Kyrtzidis  /// \brief True if this is a method redeclaration in the same interface.
2803a919e7110407ae7609bb6edc57aac16a5990661Argyrios Kyrtzidis  bool isRedeclaration() const { return IsRedeclaration; }
2813a919e7110407ae7609bb6edc57aac16a5990661Argyrios Kyrtzidis  void setAsRedeclaration(const ObjCMethodDecl *PrevMethod);
282ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
28358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  // Location information, modeled after the Stmt API.
28458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  SourceLocation getLocStart() const { return getLocation(); }
28558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  SourceLocation getLocEnd() const { return EndLoc; }
28653c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setEndLoc(SourceLocation Loc) { EndLoc = Loc; }
287da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor  virtual SourceRange getSourceRange() const {
2881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(getLocation(), EndLoc);
2899776ba0d844cf9f6888e871e3fd246ae782f76f4Daniel Dunbar  }
2901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
291491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  SourceLocation getSelectorStartLoc() const { return getSelectorLoc(0); }
292491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  SourceLocation getSelectorLoc(unsigned Index) const {
293491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    assert(Index < getNumSelectorLocs() && "Index out of range!");
294491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    if (hasStandardSelLocs())
295491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis      return getStandardSelectorLoc(Index, getSelector(),
296491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis                                   getSelLocsKind() == SelLoc_StandardWithSpace,
297491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis                      llvm::makeArrayRef(const_cast<ParmVarDecl**>(getParams()),
298491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis                                         NumParams),
299491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis                                   EndLoc);
300491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    return getStoredSelLocs()[Index];
301491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  }
302491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis
303491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  void getSelectorLocs(SmallVectorImpl<SourceLocation> &SelLocs) const;
304491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis
305491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  unsigned getNumSelectorLocs() const {
306491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    if (isImplicit())
307491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis      return 0;
308491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    Selector Sel = getSelector();
309491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    if (Sel.isUnarySelector())
310491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis      return 1;
311491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    return Sel.getNumArgs();
312491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  }
313491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis
3145619688510185081cbb4621d703daf7ee24cf39aChris Lattner  ObjCInterfaceDecl *getClassInterface();
3155619688510185081cbb4621d703daf7ee24cf39aChris Lattner  const ObjCInterfaceDecl *getClassInterface() const {
3165619688510185081cbb4621d703daf7ee24cf39aChris Lattner    return const_cast<ObjCMethodDecl*>(this)->getClassInterface();
317e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  }
3181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3192e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  Selector getSelector() const { return getDeclName().getObjCSelector(); }
3203a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson
32158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  QualType getResultType() const { return MethodDeclType; }
32253c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setResultType(QualType T) { MethodDeclType = T; }
3231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
324ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Determine the type of an expression that sends a message to this
3255291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// function.
3265291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  QualType getSendResultType() const {
3276398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor    return getResultType().getNonLValueExprType(getASTContext());
3285291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  }
329ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3304bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor  TypeSourceInfo *getResultTypeSourceInfo() const { return ResultTInfo; }
3314bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor  void setResultTypeSourceInfo(TypeSourceInfo *TInfo) { ResultTInfo = TInfo; }
3324bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor
333d57f635d520e8cb5b93d3d770ff58db06c62de54Chris Lattner  // Iterator access to formal parameters.
334491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  unsigned param_size() const { return NumParams; }
335491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  typedef const ParmVarDecl *const *param_const_iterator;
336491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  typedef ParmVarDecl *const *param_iterator;
337491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  param_const_iterator param_begin() const { return getParams(); }
338491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  param_const_iterator param_end() const { return getParams() + NumParams; }
339491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  param_iterator param_begin() { return getParams(); }
340491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  param_iterator param_end() { return getParams() + NumParams; }
3417732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian  // This method returns and of the parameters which are part of the selector
3427732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian  // name mangling requirements.
343ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  param_const_iterator sel_param_end() const {
344ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return param_begin() + getSelector().getNumArgs();
3457732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian  }
34689951a86b594513c2a013532ed45d197413b1087Chris Lattner
3479dd0065e61ea4b48b19eee550704ce964e64e946Argyrios Kyrtzidis  /// \brief Sets the method's parameters and selector source locations.
3489dd0065e61ea4b48b19eee550704ce964e64e946Argyrios Kyrtzidis  /// If the method is implicit (not coming from source) \arg SelLocs is
3499dd0065e61ea4b48b19eee550704ce964e64e946Argyrios Kyrtzidis  /// ignored.
350491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  void setMethodParams(ASTContext &C,
351491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis                       ArrayRef<ParmVarDecl*> Params,
3529dd0065e61ea4b48b19eee550704ce964e64e946Argyrios Kyrtzidis                       ArrayRef<SourceLocation> SelLocs =
3539dd0065e61ea4b48b19eee550704ce964e64e946Argyrios Kyrtzidis                           ArrayRef<SourceLocation>());
3544111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner
3556ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson  // Iterator access to parameter types.
3566ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson  typedef std::const_mem_fun_t<QualType, ParmVarDecl> deref_fun;
357491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  typedef llvm::mapped_iterator<param_const_iterator, deref_fun>
358491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis      arg_type_iterator;
3596ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson
3606ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson  arg_type_iterator arg_type_begin() const {
3616ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson    return llvm::map_iterator(param_begin(), deref_fun(&ParmVarDecl::getType));
3626ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson  }
3636ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson  arg_type_iterator arg_type_end() const {
3646ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson    return llvm::map_iterator(param_end(), deref_fun(&ParmVarDecl::getType));
3656ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson  }
3661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
367451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// createImplicitParams - Used to lazily create the self and cmd
368451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// implict parameters. This must be called prior to using getSelfDecl()
369451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// or getCmdDecl(). The call is ignored if the implicit paramters
370451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// have already been created.
371fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian  void createImplicitParams(ASTContext &Context, const ObjCInterfaceDecl *ID);
372451318c08a6342c10b8986060386fd9274418437Daniel Dunbar
3734111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  ImplicitParamDecl * getSelfDecl() const { return SelfDecl; }
37453c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setSelfDecl(ImplicitParamDecl *SD) { SelfDecl = SD; }
3754111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  ImplicitParamDecl * getCmdDecl() const { return CmdDecl; }
37653c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setCmdDecl(ImplicitParamDecl *CD) { CmdDecl = CD; }
3771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
37885f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  /// Determines the family of this method.
37985f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  ObjCMethodFamily getMethodFamily() const;
38085f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall
381f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor  bool isInstanceMethod() const { return IsInstance; }
38253c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setInstanceMethod(bool isInst) { IsInstance = isInst; }
38358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  bool isVariadic() const { return IsVariadic; }
38453c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setVariadic(bool isVar) { IsVariadic = isVar; }
3851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
386f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor  bool isClassMethod() const { return !IsInstance; }
387f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor
3884607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian  bool isSynthesized() const { return IsSynthesized; }
38953c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setSynthesized(bool isSynth) { IsSynthesized = isSynth; }
390ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3913fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian  bool isDefined() const { return IsDefined; }
3923fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian  void setDefined(bool isDefined) { IsDefined = isDefined; }
3931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
39458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  // Related to protocols declared in  @protocol
3951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setDeclImplementation(ImplementationControl ic) {
3961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    DeclImplementation = ic;
39758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  }
3981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ImplementationControl getImplementationControl() const {
3991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return ImplementationControl(DeclImplementation);
40058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  }
401792481eec23d8c1aa92173be589e2ae9d02514a5Ted Kremenek
402da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor  virtual Stmt *getBody() const {
4031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return (Stmt*) Body;
4047297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor  }
4056fb0aee4f9dc261bbec72e1283ad8dc0557a6d96Argyrios Kyrtzidis  CompoundStmt *getCompoundBody() { return (CompoundStmt*)Body; }
406d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl  void setBody(Stmt *B) { Body = B; }
40758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff
40866570b230941651245accbc5680b60e904eb993cArgyrios Kyrtzidis  /// \brief Returns whether this specific method is a definition.
40966570b230941651245accbc5680b60e904eb993cArgyrios Kyrtzidis  bool isThisDeclarationADefinition() const { return Body; }
41066570b230941651245accbc5680b60e904eb993cArgyrios Kyrtzidis
41158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  // Implement isa/cast/dyncast/etc.
41280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
413a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCMethodDecl *D) { return true; }
41480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCMethod; }
41542220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  static DeclContext *castToDeclContext(const ObjCMethodDecl *D) {
41642220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis    return static_cast<DeclContext *>(const_cast<ObjCMethodDecl*>(D));
41742220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  }
41842220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  static ObjCMethodDecl *castFromDeclContext(const DeclContext *DC) {
41942220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis    return static_cast<ObjCMethodDecl *>(const_cast<DeclContext*>(DC));
42042220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  }
421491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis
422491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  friend class ASTDeclReader;
423491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  friend class ASTDeclWriter;
42458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff};
425e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
426e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff/// ObjCContainerDecl - Represents a container for method declarations.
427aecae629269fae3bf484baf1d109e9a89d14eeadArgyrios Kyrtzidis/// Current sub-classes are ObjCInterfaceDecl, ObjCCategoryDecl,
4281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ObjCProtocolDecl, and ObjCImplDecl.
429e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff///
4304afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCContainerDecl : public NamedDecl, public DeclContext {
43199ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
43299ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie
4331711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis  SourceLocation AtStart;
4341711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis
435782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  // These two locations in the range mark the end of the method container.
436782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  // The first points to the '@' token, and the second to the 'end' token.
437782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  SourceRange AtEnd;
438e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroffpublic:
439e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
4401711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis  ObjCContainerDecl(Kind DK, DeclContext *DC,
4411711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                    IdentifierInfo *Id, SourceLocation nameLoc,
4421711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                    SourceLocation atStartLoc)
4431711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis    : NamedDecl(DK, DC, nameLoc, Id), DeclContext(DK), AtStart(atStartLoc) {}
444e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
44593983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff  // Iterator access to properties.
44693983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff  typedef specific_decl_iterator<ObjCPropertyDecl> prop_iterator;
4471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  prop_iterator prop_begin() const {
44817945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return prop_iterator(decls_begin());
44993983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff  }
4501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  prop_iterator prop_end() const {
45117945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return prop_iterator(decls_end());
45209c4719788a5cea09897525e528fa00420f1677bSteve Naroff  }
4531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4540701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  // Iterator access to instance/class methods.
455f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor  typedef specific_decl_iterator<ObjCMethodDecl> method_iterator;
4561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  method_iterator meth_begin() const {
45717945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return method_iterator(decls_begin());
4587ed4faca5162b3ab85be7f7e57aa40e6ec170971Ted Kremenek  }
4591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  method_iterator meth_end() const {
46017945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return method_iterator(decls_end());
4617ed4faca5162b3ab85be7f7e57aa40e6ec170971Ted Kremenek  }
4620701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
4631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  typedef filtered_decl_iterator<ObjCMethodDecl,
4641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                 &ObjCMethodDecl::isInstanceMethod>
465669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor    instmeth_iterator;
46617945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  instmeth_iterator instmeth_begin() const {
46717945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return instmeth_iterator(decls_begin());
468e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff  }
46917945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  instmeth_iterator instmeth_end() const {
47017945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return instmeth_iterator(decls_end());
471e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff  }
472e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
4731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  typedef filtered_decl_iterator<ObjCMethodDecl,
4741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                 &ObjCMethodDecl::isClassMethod>
475669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor    classmeth_iterator;
47617945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  classmeth_iterator classmeth_begin() const {
47717945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return classmeth_iterator(decls_begin());
478e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff  }
47917945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  classmeth_iterator classmeth_end() const {
48017945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return classmeth_iterator(decls_end());
4810701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  }
4820701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
4830701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  // Get the local instance/class method declared in this interface.
484467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis  ObjCMethodDecl *getMethod(Selector Sel, bool isInstance) const;
485467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis  ObjCMethodDecl *getInstanceMethod(Selector Sel) const {
486467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis    return getMethod(Sel, true/*isInstance*/);
48753df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner  }
488467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis  ObjCMethodDecl *getClassMethod(Selector Sel) const {
489467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis    return getMethod(Sel, false/*isInstance*/);
490467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis  }
491467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis  ObjCIvarDecl *getIvarDecl(IdentifierInfo *Id) const;
4921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
49317945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  ObjCPropertyDecl *FindPropertyDeclaration(IdentifierInfo *PropertyId) const;
49493983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff
4951711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis  SourceLocation getAtStartLoc() const { return AtStart; }
4961711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis  void setAtStartLoc(SourceLocation Loc) { AtStart = Loc; }
4971711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis
498e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff  // Marks the end of the container.
499782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  SourceRange getAtEndRange() const {
500782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek    return AtEnd;
501782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  }
502782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  void setAtEndRange(SourceRange atEnd) {
503782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek    AtEnd = atEnd;
504782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  }
505ddfd4c9eda34765b08fae4cb31ad5a365face107Argyrios Kyrtzidis
506da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor  virtual SourceRange getSourceRange() const {
5071711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis    return SourceRange(AtStart, getAtEndRange().getEnd());
508ddfd4c9eda34765b08fae4cb31ad5a365face107Argyrios Kyrtzidis  }
5091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
51009c4719788a5cea09897525e528fa00420f1677bSteve Naroff  // Implement isa/cast/dyncast/etc.
51180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
51209c4719788a5cea09897525e528fa00420f1677bSteve Naroff  static bool classof(const ObjCContainerDecl *D) { return true; }
51380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) {
5149a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt    return K >= firstObjCContainer &&
5159a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt           K <= lastObjCContainer;
51680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  }
51709c4719788a5cea09897525e528fa00420f1677bSteve Naroff
51809c4719788a5cea09897525e528fa00420f1677bSteve Naroff  static DeclContext *castToDeclContext(const ObjCContainerDecl *D) {
51909c4719788a5cea09897525e528fa00420f1677bSteve Naroff    return static_cast<DeclContext *>(const_cast<ObjCContainerDecl*>(D));
52009c4719788a5cea09897525e528fa00420f1677bSteve Naroff  }
52109c4719788a5cea09897525e528fa00420f1677bSteve Naroff  static ObjCContainerDecl *castFromDeclContext(const DeclContext *DC) {
52209c4719788a5cea09897525e528fa00420f1677bSteve Naroff    return static_cast<ObjCContainerDecl *>(const_cast<DeclContext*>(DC));
52309c4719788a5cea09897525e528fa00420f1677bSteve Naroff  }
524e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff};
525e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
526a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCInterfaceDecl - Represents an ObjC class declaration. For example:
5270c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
5280c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   // MostPrimitive declares no super class (not particularly useful).
5291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///   @interface MostPrimitive
5300c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     // no instance variables or methods.
5310c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @end
5320c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
5331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///   // NSResponder inherits from NSObject & implements NSCoding (a protocol).
5340c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @interface NSResponder : NSObject <NSCoding>
535a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek///   { // instance variables are represented by ObjCIvarDecl.
5360c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     id nextResponder; // nextResponder instance variable.
5370c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   }
5380c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   - (NSResponder *)nextResponder; // return a pointer to NSResponder.
5390c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   - (void)mouseMoved:(NSEvent *)theEvent; // return void, takes a pointer
5400c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @end                                    // to an NSEvent.
5410c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
5420c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   Unlike C/C++, forward class declarations are accomplished with @class.
5430c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   Unlike C/C++, @class allows for a list of classes to be forward declared.
5440c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   Unlike C++, ObjC is a single-rooted class model. In Cocoa, classes
5450c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   typically inherit from NSObject (an exception is NSProxy).
5460c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
54753df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregorclass ObjCInterfaceDecl : public ObjCContainerDecl
54853df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor                        , public Redeclarable<ObjCInterfaceDecl> {
54999ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
55099ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie
5513110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff  /// TypeForDecl - This indicates the Type object that represents this
5523110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff  /// TypeDecl.  It is a cache maintained by ASTContext::getObjCInterfaceType
553f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  mutable const Type *TypeForDecl;
5543110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff  friend class ASTContext;
5552e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
5562e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  struct DefinitionData {
55726fec63b14565e9e2d8c9935b276b99be950444aDouglas Gregor    /// \brief The definition of this class, for quick access from any
55826fec63b14565e9e2d8c9935b276b99be950444aDouglas Gregor    /// declaration.
55926fec63b14565e9e2d8c9935b276b99be950444aDouglas Gregor    ObjCInterfaceDecl *Definition;
56026fec63b14565e9e2d8c9935b276b99be950444aDouglas Gregor
5612e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    /// Class's super class.
5622e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    ObjCInterfaceDecl *SuperClass;
5631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5642e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    /// Protocols referenced in the @interface  declaration
5652e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    ObjCProtocolList ReferencedProtocols;
5661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5672e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    /// Protocols reference in both the @interface and class extensions.
5682e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    ObjCList<ObjCProtocolDecl> AllReferencedProtocols;
569ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
5702e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    /// \brief List of categories and class extensions defined for this class.
5712e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    ///
5722e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    /// Categories are stored as a linked list in the AST, since the categories
5732e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    /// and class extensions come long after the initial interface declaration,
5742e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    /// and we avoid dynamically-resized arrays in the AST wherever possible.
5752e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    ObjCCategoryDecl *CategoryList;
5761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5772e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    /// IvarList - List of all ivars defined by this class; including class
5782e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    /// extensions and implementation. This list is built lazily.
5792e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    ObjCIvarDecl *IvarList;
580ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
5812e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    /// \brief Indicates that the contents of this Objective-C class will be
5822e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    /// completed by the external AST source when required.
5832e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    mutable bool ExternallyCompleted : 1;
5842e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
58505c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor    /// \brief The location of the superclass, if any.
58605c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor    SourceLocation SuperClassLoc;
587161794732195881c33305f701f6e58721998541fDouglas Gregor
58805c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor    /// \brief The location of the last location in this declaration, before
58905c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor    /// the properties/methods. For example, this will be the '>', '}', or
59005c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor    /// identifier,
59105c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor    SourceLocation EndLoc;
59205c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor
59326fec63b14565e9e2d8c9935b276b99be950444aDouglas Gregor    DefinitionData() : Definition(), SuperClass(), CategoryList(), IvarList(),
594161794732195881c33305f701f6e58721998541fDouglas Gregor                       ExternallyCompleted() { }
5952e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  };
5962e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
5972e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id,
59837f953f021c67e3b97f1ef38e1ef3cb08bd9d146Douglas Gregor                    SourceLocation CLoc, ObjCInterfaceDecl *PrevDecl,
59937f953f021c67e3b97f1ef38e1ef3cb08bd9d146Douglas Gregor                    bool isInternal);
6002e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
6012e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  void LoadExternalDefinition() const;
6022e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
6032e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  /// \brief Contains a pointer to the data associated with this class,
6042e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  /// which will be NULL if this class has not yet been defined.
60526fec63b14565e9e2d8c9935b276b99be950444aDouglas Gregor  DefinitionData *Data;
6062e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
6072e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  DefinitionData &data() const {
60826fec63b14565e9e2d8c9935b276b99be950444aDouglas Gregor    assert(Data != 0 && "Declaration has no definition!");
60926fec63b14565e9e2d8c9935b276b99be950444aDouglas Gregor    return *Data;
6102e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  }
6111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6122e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  /// \brief Allocate the definition data for this class.
6132e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  void allocateDefinitionData();
6142e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
61553df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor  typedef Redeclarable<ObjCInterfaceDecl> redeclarable_base;
61653df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor  virtual ObjCInterfaceDecl *getNextRedeclaration() {
61753df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor    return RedeclLink.getNext();
61853df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor  }
61953df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor
6200e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattnerpublic:
621d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCInterfaceDecl *Create(ASTContext &C, DeclContext *DC,
6220ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner                                   SourceLocation atLoc,
6231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                   IdentifierInfo *Id,
6240af550115df1f57f17a4f125ff0e8b34820c65d1Douglas Gregor                                   ObjCInterfaceDecl *PrevDecl,
625deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor                                   SourceLocation ClassLoc = SourceLocation(),
6260e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner                                   bool isInternal = false);
627d1cf3ff6c7e34fce764293cd2900fce99a60ed69Argyrios Kyrtzidis
6281e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor  static ObjCInterfaceDecl *CreateDeserialized(ASTContext &C, unsigned ID);
6290af550115df1f57f17a4f125ff0e8b34820c65d1Douglas Gregor
630d1cf3ff6c7e34fce764293cd2900fce99a60ed69Argyrios Kyrtzidis  virtual SourceRange getSourceRange() const {
6317723fec9b45b7258c0eddf4cbfd0d335348f5edcDouglas Gregor    if (isThisDeclarationADefinition())
6327723fec9b45b7258c0eddf4cbfd0d335348f5edcDouglas Gregor      return ObjCContainerDecl::getSourceRange();
6337723fec9b45b7258c0eddf4cbfd0d335348f5edcDouglas Gregor
6347723fec9b45b7258c0eddf4cbfd0d335348f5edcDouglas Gregor    return SourceRange(getAtStartLoc(), getLocation());
635d1cf3ff6c7e34fce764293cd2900fce99a60ed69Argyrios Kyrtzidis  }
636ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
63726ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  /// \brief Indicate that this Objective-C class is complete, but that
63826ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  /// the external AST source will be responsible for filling in its contents
63926ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  /// when a complete class is required.
64026ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  void setExternallyCompleted();
641ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
64218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  const ObjCProtocolList &getReferencedProtocols() const {
6432e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (data().ExternallyCompleted)
64426ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
645ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
6462e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    return data().ReferencedProtocols;
6477ed9e0f97f4645edc5d4670385b985ea4c617ce7Fariborz Jahanian  }
6488a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis
6498a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis  ObjCImplementationDecl *getImplementation() const;
6508a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis  void setImplementation(ObjCImplementationDecl *ImplD);
6518a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis
652559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  ObjCCategoryDecl *FindCategoryDeclaration(IdentifierInfo *CategoryId) const;
6531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6541cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis  // Get the local instance/class method declared in a category.
6551cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis  ObjCMethodDecl *getCategoryInstanceMethod(Selector Sel) const;
6561cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis  ObjCMethodDecl *getCategoryClassMethod(Selector Sel) const;
6571cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis  ObjCMethodDecl *getCategoryMethod(Selector Sel, bool isInstance) const {
6581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return isInstance ? getInstanceMethod(Sel)
6591cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis                      : getClassMethod(Sel);
6601cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis  }
6613db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner
66218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::iterator protocol_iterator;
663ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
66453b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  protocol_iterator protocol_begin() const {
6652e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    // FIXME: Should make sure no callers ever do this.
6662e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (!hasDefinition())
6672e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor      return protocol_iterator();
6682e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
6692e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (data().ExternallyCompleted)
67026ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
67126ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
6722e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    return data().ReferencedProtocols.begin();
67353b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  }
67453b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  protocol_iterator protocol_end() const {
6752e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    // FIXME: Should make sure no callers ever do this.
6762e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (!hasDefinition())
6772e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor      return protocol_iterator();
6782e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
6792e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (data().ExternallyCompleted)
68026ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
68126ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
6822e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    return data().ReferencedProtocols.end();
68353b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  }
68453b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
68518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
68653b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
687ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  protocol_loc_iterator protocol_loc_begin() const {
6882e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    // FIXME: Should make sure no callers ever do this.
6892e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (!hasDefinition())
6902e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor      return protocol_loc_iterator();
6912e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
6922e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (data().ExternallyCompleted)
69326ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
69426ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
6952e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    return data().ReferencedProtocols.loc_begin();
69618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
69753b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
698ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  protocol_loc_iterator protocol_loc_end() const {
6992e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    // FIXME: Should make sure no callers ever do this.
7002e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (!hasDefinition())
7012e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor      return protocol_loc_iterator();
7022e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
7032e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (data().ExternallyCompleted)
70426ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
70526ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
7062e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    return data().ReferencedProtocols.loc_end();
70718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
708ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
70953b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  typedef ObjCList<ObjCProtocolDecl>::iterator all_protocol_iterator;
710ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
71153b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  all_protocol_iterator all_referenced_protocol_begin() const {
7122e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    // FIXME: Should make sure no callers ever do this.
7132e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (!hasDefinition())
7142e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor      return all_protocol_iterator();
7152e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
7162e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (data().ExternallyCompleted)
71726ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
71826ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
7192e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    return data().AllReferencedProtocols.empty()
7202e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor             ? protocol_begin()
7212e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor             : data().AllReferencedProtocols.begin();
72253b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  }
72353b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  all_protocol_iterator all_referenced_protocol_end() const {
7242e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    // FIXME: Should make sure no callers ever do this.
7252e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (!hasDefinition())
7262e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor      return all_protocol_iterator();
7272e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
7282e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (data().ExternallyCompleted)
72926ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
73026ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
7312e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    return data().AllReferencedProtocols.empty()
7322e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor             ? protocol_end()
7332e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor             : data().AllReferencedProtocols.end();
73453b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  }
735291be393aa33759e6e34b6429c5ffa206ba50115Douglas Gregor
73611062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian  typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
73753b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
7382e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  ivar_iterator ivar_begin() const {
7392e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (const ObjCInterfaceDecl *Def = getDefinition())
7402e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor      return ivar_iterator(Def->decls_begin());
7412e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
7422e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    // FIXME: Should make sure no callers ever do this.
7432e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    return ivar_iterator();
7442e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  }
7452e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  ivar_iterator ivar_end() const {
7462e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (const ObjCInterfaceDecl *Def = getDefinition())
7472e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor      return ivar_iterator(Def->decls_end());
7482e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
7492e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    // FIXME: Should make sure no callers ever do this.
7502e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    return ivar_iterator();
7512e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  }
75253b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
75311062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian  unsigned ivar_size() const {
75411062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian    return std::distance(ivar_begin(), ivar_end());
75511062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian  }
756ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
75711062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian  bool ivar_empty() const { return ivar_begin() == ivar_end(); }
758ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
759db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose  ObjCIvarDecl *all_declared_ivar_begin();
760db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose  const ObjCIvarDecl *all_declared_ivar_begin() const {
761db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose    // Even though this modifies IvarList, it's conceptually const:
762db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose    // the ivar chain is essentially a cached property of ObjCInterfaceDecl.
763db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose    return const_cast<ObjCInterfaceDecl *>(this)->all_declared_ivar_begin();
764db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose  }
7652e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  void setIvarList(ObjCIvarDecl *ivar) { data().IvarList = ivar; }
766ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
76738af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  /// setProtocolList - Set the list of protocols that this interface
768b752f289026ad8e5f44851b20e009a27ed61eefcChris Lattner  /// implements.
76938af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  void setProtocolList(ObjCProtocolDecl *const* List, unsigned Num,
77018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                       const SourceLocation *Locs, ASTContext &C) {
7712e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    data().ReferencedProtocols.set(List, Num, Locs, C);
7723db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  }
7731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
774339798eae1eb61c50ca68766ed028c0a16d0a284Fariborz Jahanian  /// mergeClassExtensionProtocolList - Merge class extension's protocol list
775339798eae1eb61c50ca68766ed028c0a16d0a284Fariborz Jahanian  /// into the protocol list for this class.
776ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  void mergeClassExtensionProtocolList(ObjCProtocolDecl *const* List,
77718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                                       unsigned Num,
77818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                                       ASTContext &C);
779339798eae1eb61c50ca68766ed028c0a16d0a284Fariborz Jahanian
78053df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor  /// \brief Determine whether this particular declaration of this class is
78153df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor  /// actually also a definition.
78226fec63b14565e9e2d8c9935b276b99be950444aDouglas Gregor  bool isThisDeclarationADefinition() const {
7837723fec9b45b7258c0eddf4cbfd0d335348f5edcDouglas Gregor    return Data && Data->Definition == this;
78426fec63b14565e9e2d8c9935b276b99be950444aDouglas Gregor  }
78553df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor
7862e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  /// \brief Determine whether this class has been defined.
78726fec63b14565e9e2d8c9935b276b99be950444aDouglas Gregor  bool hasDefinition() const { return Data; }
78853df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor
7892e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  /// \brief Retrieve the definition of this class, or NULL if this class
7902e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  /// has been forward-declared (with @class) but not yet defined (with
7912e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  /// @interface).
7922e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  ObjCInterfaceDecl *getDefinition() {
79326fec63b14565e9e2d8c9935b276b99be950444aDouglas Gregor    return hasDefinition()? Data->Definition : 0;
7942e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  }
795ad834d534e9a5db3d3baa09593775f83ceaff1f2Argyrios Kyrtzidis
7962e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  /// \brief Retrieve the definition of this class, or NULL if this class
7972e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  /// has been forward-declared (with @class) but not yet defined (with
7982e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  /// @interface).
7992e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  const ObjCInterfaceDecl *getDefinition() const {
80026fec63b14565e9e2d8c9935b276b99be950444aDouglas Gregor    return hasDefinition()? Data->Definition : 0;
8012e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  }
8021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8032e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  /// \brief Starts the definition of this Objective-C class, taking it from
8042e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  /// a forward declaration (@class) to a definition (@interface).
8052e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  void startDefinition();
8062e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
807ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  ObjCInterfaceDecl *getSuperClass() const {
8082e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    // FIXME: Should make sure no callers ever do this.
8092e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (!hasDefinition())
8102e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor      return 0;
8112e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
8122e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (data().ExternallyCompleted)
81326ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
81426ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
8152e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    return data().SuperClass;
81626ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  }
817ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
8182e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  void setSuperClass(ObjCInterfaceDecl * superCls) {
819712ef874534ee1bef41d1aa4664ae36148ec8b12Fariborz Jahanian    data().SuperClass =
820712ef874534ee1bef41d1aa4664ae36148ec8b12Fariborz Jahanian      (superCls && superCls->hasDefinition()) ? superCls->getDefinition()
821712ef874534ee1bef41d1aa4664ae36148ec8b12Fariborz Jahanian                                              : superCls;
8222e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  }
8231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
824ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  ObjCCategoryDecl* getCategoryList() const {
8252e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    // FIXME: Should make sure no callers ever do this.
8262e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (!hasDefinition())
8272e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor      return 0;
8282e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
8292e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (data().ExternallyCompleted)
83026ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
83126ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
8322e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    return data().CategoryList;
83326ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  }
834ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
8351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setCategoryList(ObjCCategoryDecl *category) {
8362e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    data().CategoryList = category;
837980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  }
838ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
83980aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  ObjCCategoryDecl* getFirstClassExtension() const;
84037cafb077ad5b170acae77e566638603011ef4c0Ted Kremenek
84137cafb077ad5b170acae77e566638603011ef4c0Ted Kremenek  ObjCPropertyDecl
84237cafb077ad5b170acae77e566638603011ef4c0Ted Kremenek    *FindPropertyVisibleInPrimaryClass(IdentifierInfo *PropertyId) const;
84337cafb077ad5b170acae77e566638603011ef4c0Ted Kremenek
84453efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner  /// isSuperClassOf - Return true if this class is the specified class or is a
84553efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner  /// super class of the specified interface class.
84653efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner  bool isSuperClassOf(const ObjCInterfaceDecl *I) const {
84753efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    // If RHS is derived from LHS it is OK; else it is not OK.
84853efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    while (I != NULL) {
84960ef308e51c71b760d7f598c1b763ceb7b768148Douglas Gregor      if (declaresSameEntity(this, I))
85053efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner        return true;
8512e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
85253efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner      I = I->getSuperClass();
85353efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    }
85453efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    return false;
85553efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner  }
8561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8577263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian  /// isArcWeakrefUnavailable - Checks for a class or one of its super classes
8587263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian  /// to be incompatible with __weak references. Returns true if it is.
8597263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian  bool isArcWeakrefUnavailable() const {
8607263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian    const ObjCInterfaceDecl *Class = this;
8617263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian    while (Class) {
8627263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian      if (Class->hasAttr<ArcWeakrefUnavailableAttr>())
8637263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian        return true;
8647263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian      Class = Class->getSuperClass();
8657263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian   }
866ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie   return false;
8677263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian  }
8687263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian
86971207fc0470e1eee40a2951cd5cc3ff47725b755Ted Kremenek  /// isObjCRequiresPropertyDefs - Checks that a class or one of its super
870da611a74c408af0f9526acc690b85214bf180852Fariborz Jahanian  /// classes must not be auto-synthesized. Returns class decl. if it must not be;
871da611a74c408af0f9526acc690b85214bf180852Fariborz Jahanian  /// 0, otherwise.
87271207fc0470e1eee40a2951cd5cc3ff47725b755Ted Kremenek  const ObjCInterfaceDecl *isObjCRequiresPropertyDefs() const {
873e23dcf3524fe01208cc79e707412f0a5dd8eed7bFariborz Jahanian    const ObjCInterfaceDecl *Class = this;
874e23dcf3524fe01208cc79e707412f0a5dd8eed7bFariborz Jahanian    while (Class) {
87571207fc0470e1eee40a2951cd5cc3ff47725b755Ted Kremenek      if (Class->hasAttr<ObjCRequiresPropertyDefsAttr>())
876da611a74c408af0f9526acc690b85214bf180852Fariborz Jahanian        return Class;
877e23dcf3524fe01208cc79e707412f0a5dd8eed7bFariborz Jahanian      Class = Class->getSuperClass();
878e23dcf3524fe01208cc79e707412f0a5dd8eed7bFariborz Jahanian   }
879da611a74c408af0f9526acc690b85214bf180852Fariborz Jahanian   return 0;
880e23dcf3524fe01208cc79e707412f0a5dd8eed7bFariborz Jahanian  }
881e23dcf3524fe01208cc79e707412f0a5dd8eed7bFariborz Jahanian
88217945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName,
88368a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner                                       ObjCInterfaceDecl *&ClassDeclared);
88417945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName) {
88568a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner    ObjCInterfaceDecl *ClassDeclared;
88617945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return lookupInstanceVariable(IVarName, ClassDeclared);
88768a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner  }
88868a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner
88994a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // Lookup a method. First, we search locally. If a method isn't
89094a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // found, we search referenced protocols and class categories.
891aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis  ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance) const;
892aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis  ObjCMethodDecl *lookupInstanceMethod(Selector Sel) const {
893aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis    return lookupMethod(Sel, true/*isInstance*/);
894aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis  }
895aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis  ObjCMethodDecl *lookupClassMethod(Selector Sel) const {
896aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis    return lookupMethod(Sel, false/*isInstance*/);
897aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis  }
898cd1876207f5564beba74e4b2524b664bdba0ba9fFariborz Jahanian  ObjCInterfaceDecl *lookupInheritedClass(const IdentifierInfo *ICName);
899ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
900d789d3d985e28c9404e62157af46dcb7331920e0Steve Naroff  // Lookup a method in the classes implementation hierarchy.
90174b2756bc1f1f5f7c189996fe7e4cd3efef70263Fariborz Jahanian  ObjCMethodDecl *lookupPrivateMethod(const Selector &Sel, bool Instance=true);
90260fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff
90305c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor  SourceLocation getEndOfDefinitionLoc() const {
90405c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor    if (!hasDefinition())
90505c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor      return getLocation();
90605c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor
90705c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor    return data().EndLoc;
90805c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor  }
90905c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor
91005c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor  void setEndOfDefinitionLoc(SourceLocation LE) { data().EndLoc = LE; }
9111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9122e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  void setSuperClassLoc(SourceLocation Loc) { data().SuperClassLoc = Loc; }
9132e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  SourceLocation getSuperClassLoc() const { return data().SuperClassLoc; }
9141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
91528e71cf851b73a67604735a9a95aef800b144e2eSteve Naroff  /// isImplicitInterfaceDecl - check that this is an implicitly declared
916a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  /// ObjCInterfaceDecl node. This is for legacy objective-c @implementation
9174b6df3fa953267c5d755628c8afd818bb571e579Fariborz Jahanian  /// declaration without an @interface declaration.
91897bbab2df74cbfe221fb20454738d607a41f3ca4Fariborz Jahanian  bool isImplicitInterfaceDecl() const {
91997bbab2df74cbfe221fb20454738d607a41f3ca4Fariborz Jahanian    return hasDefinition() ? Data->Definition->isImplicit() : isImplicit();
92097bbab2df74cbfe221fb20454738d607a41f3ca4Fariborz Jahanian  }
9211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9220fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian  /// ClassImplementsProtocol - Checks that 'lProto' protocol
9230fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian  /// has been implemented in IDecl class, its super class or categories (if
9240fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian  /// lookupCategory is true).
9250fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian  bool ClassImplementsProtocol(ObjCProtocolDecl *lProto,
9260fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian                               bool lookupCategory,
9270fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian                               bool RHSIsQualifiedID = false);
9281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
92953df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor  typedef redeclarable_base::redecl_iterator redecl_iterator;
93053df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor  redecl_iterator redecls_begin() const {
93153df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor    return redeclarable_base::redecls_begin();
93253df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor  }
93353df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor  redecl_iterator redecls_end() const {
93453df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor    return redeclarable_base::redecls_end();
93553df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor  }
93653df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor
93753df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor  /// Retrieves the canonical declaration of this Objective-C class.
93853df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor  ObjCInterfaceDecl *getCanonicalDecl() {
93953df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor    return getFirstDeclaration();
94053df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor  }
94153df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor  const ObjCInterfaceDecl *getCanonicalDecl() const {
94253df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor    return getFirstDeclaration();
94353df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor  }
94453df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor
94533feeb019a5742b286eededd5446ec0fe87c5a61Steve Naroff  // Low-level accessor
946f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const Type *getTypeForDecl() const { return TypeForDecl; }
947f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  void setTypeForDecl(const Type *TD) const { TypeForDecl = TD; }
94833feeb019a5742b286eededd5446ec0fe87c5a61Steve Naroff
94980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
950a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCInterfaceDecl *D) { return true; }
95180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCInterface; }
95253b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
953fc529f7fcafe7da0b8a32621e13685891e8ce52aDouglas Gregor  friend class ASTReader;
95453b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  friend class ASTDeclReader;
95553b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  friend class ASTDeclWriter;
956980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
957980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
958a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCIvarDecl - Represents an ObjC instance variable. In general, ObjC
9590c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// instance variables are identical to C. The only exception is Objective-C
9600c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// supports C++ style access control. For example:
9610c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
9620c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @interface IvarExample : NSObject
9630c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   {
964f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek///     id defaultToProtected;
9650c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @public:
9660c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     id canBePublic; // same as C++.
9670c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @protected:
9680c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     id canBeProtected; // same as C++.
9690c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @package:
9700c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     id canBePackage; // framework visibility (not available in C++).
9710c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   }
9720c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
973a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCIvarDecl : public FieldDecl {
97499ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
97599ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie
9760e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattnerpublic:
977980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  enum AccessControl {
978980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff    None, Private, Protected, Public, Package
979980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  };
9801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
981b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenekprivate:
982ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara  ObjCIvarDecl(ObjCContainerDecl *DC, SourceLocation StartLoc,
983ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara               SourceLocation IdLoc, IdentifierInfo *Id,
984ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian               QualType T, TypeSourceInfo *TInfo, AccessControl ac, Expr *BW,
985ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian               bool synthesized)
986ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara    : FieldDecl(ObjCIvar, DC, StartLoc, IdLoc, Id, T, TInfo, BW,
9877a614d8380297fcd2bc23986241905d97222948cRichard Smith                /*Mutable=*/false, /*HasInit=*/false),
988ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara      NextIvar(0), DeclAccess(ac), Synthesized(synthesized) {}
9891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
990b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenekpublic:
991a06549226f45d5b72169a3d054415616dd1014a2Daniel Dunbar  static ObjCIvarDecl *Create(ASTContext &C, ObjCContainerDecl *DC,
992ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                              SourceLocation StartLoc, SourceLocation IdLoc,
993ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                              IdentifierInfo *Id, QualType T,
994a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall                              TypeSourceInfo *TInfo,
995ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian                              AccessControl ac, Expr *BW = NULL,
996ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian                              bool synthesized=false);
9971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9981e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor  static ObjCIvarDecl *CreateDeserialized(ASTContext &C, unsigned ID);
9991e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor
100027a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar  /// \brief Return the class interface that this ivar is logically contained
100127a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar  /// in; this is either the interface where the ivar was declared, or the
100227a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar  /// interface the ivar is conceptually a part of in the case of synthesized
100327a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar  /// ivars.
100427a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar  const ObjCInterfaceDecl *getContainingInterface() const;
1005ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
10062c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  ObjCIvarDecl *getNextIvar() { return NextIvar; }
1007db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose  const ObjCIvarDecl *getNextIvar() const { return NextIvar; }
10082c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  void setNextIvar(ObjCIvarDecl *ivar) { NextIvar = ivar; }
100927a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar
1010980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  void setAccessControl(AccessControl ac) { DeclAccess = ac; }
1011f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek
1012ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  AccessControl getAccessControl() const { return AccessControl(DeclAccess); }
1013f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek
1014f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek  AccessControl getCanonicalAccessControl() const {
1015f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek    return DeclAccess == None ? Protected : AccessControl(DeclAccess);
1016f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek  }
10171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1018ac0021ba802e193e0f9f8207768c7862c7603bc0Fariborz Jahanian  void setSynthesize(bool synth) { Synthesized = synth; }
1019ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian  bool getSynthesize() const { return Synthesized; }
1020ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1021980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  // Implement isa/cast/dyncast/etc.
102280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1023a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCIvarDecl *D) { return true; }
102480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCIvar; }
1025980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffprivate:
1026ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// NextIvar - Next Ivar in the list of ivars declared in class; class's
10272c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  /// extensions and class's implementation
10282c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  ObjCIvarDecl *NextIvar;
1029ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1030ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  // NOTE: VC++ treats enums as signed, avoid using the AccessControl enum
1031ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  unsigned DeclAccess : 3;
1032ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian  unsigned Synthesized : 1;
1033980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
1034980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
10351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
103601e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek/// ObjCAtDefsFieldDecl - Represents a field declaration created by an
103701e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek///  @defs(...).
103801e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenekclass ObjCAtDefsFieldDecl : public FieldDecl {
103999ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
1040ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara  ObjCAtDefsFieldDecl(DeclContext *DC, SourceLocation StartLoc,
1041ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                      SourceLocation IdLoc, IdentifierInfo *Id,
104201e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek                      QualType T, Expr *BW)
1043ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara    : FieldDecl(ObjCAtDefsField, DC, StartLoc, IdLoc, Id, T,
1044a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall                /*TInfo=*/0, // FIXME: Do ObjCAtDefs have declarators ?
10457a614d8380297fcd2bc23986241905d97222948cRichard Smith                BW, /*Mutable=*/false, /*HasInit=*/false) {}
10461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
104701e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenekpublic:
104844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor  static ObjCAtDefsFieldDecl *Create(ASTContext &C, DeclContext *DC,
1049ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                     SourceLocation StartLoc,
1050ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                     SourceLocation IdLoc, IdentifierInfo *Id,
1051ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                     QualType T, Expr *BW);
10521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10531e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor  static ObjCAtDefsFieldDecl *CreateDeserialized(ASTContext &C, unsigned ID);
10541e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor
105501e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek  // Implement isa/cast/dyncast/etc.
105680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
105701e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek  static bool classof(const ObjCAtDefsFieldDecl *D) { return true; }
105880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCAtDefsField; }
105901e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek};
1060980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
1061a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCProtocolDecl - Represents a protocol declaration. ObjC protocols
10621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// declare a pure abstract type (i.e no instance variables are permitted).
1063fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner/// Protocols originally drew inspiration from C++ pure virtual functions (a C++
10640c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// feature with nice semantics and lousy syntax:-). Here is an example:
10650c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
1066eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// @protocol NSDraggingInfo <refproto1, refproto2>
10670c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (NSWindow *)draggingDestinationWindow;
10680c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (NSImage *)draggedImage;
10690c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end
10700c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
1071eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// This says that NSDraggingInfo requires two methods and requires everything
1072eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// that the two "referenced protocols" 'refproto1' and 'refproto2' require as
1073eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// well.
1074eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner///
10750c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @interface ImplementsNSDraggingInfo : NSObject <NSDraggingInfo>
10760c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end
10770c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
1078a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjC protocols inspired Java interfaces. Unlike Java, ObjC classes and
10790c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// protocols are in distinct namespaces. For example, Cocoa defines both
10801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// an NSObject protocol and class (which isn't allowed in Java). As a result,
10810c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// protocols are referenced using angle brackets as follows:
10820c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
10830c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// id <NSDraggingInfo> anyObjectThatImplementsNSDraggingInfo;
10840c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
10851d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregorclass ObjCProtocolDecl : public ObjCContainerDecl,
10861d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor                         public Redeclarable<ObjCProtocolDecl> {
108799ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
108899ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie
10895e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  struct DefinitionData {
10901d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor    // \brief The declaration that defines this protocol.
10911d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor    ObjCProtocolDecl *Definition;
10921d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor
1093ec1a58b201b3276966aaade8ac3ac4705aba96c2Douglas Gregor    /// \brief Referenced protocols
10945e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    ObjCProtocolList ReferencedProtocols;
10955e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  };
10965e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor
10975e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  DefinitionData *Data;
10981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10995e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  DefinitionData &data() const {
11005e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    assert(Data && "Objective-C protocol has no definition!");
11015e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    return *Data;
11025e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  }
11035e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor
11041711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis  ObjCProtocolDecl(DeclContext *DC, IdentifierInfo *Id,
1105b05d7b20171bbd2feb14b059f39332cbe1bf1014Argyrios Kyrtzidis                   SourceLocation nameLoc, SourceLocation atStartLoc,
1106c9d3c7edb513e9b8a6ab65b04133653e71d7a72bDouglas Gregor                   ObjCProtocolDecl *PrevDecl);
11071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11085e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  void allocateDefinitionData();
11091d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor
11101d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor  typedef Redeclarable<ObjCProtocolDecl> redeclarable_base;
11111d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor  virtual ObjCProtocolDecl *getNextRedeclaration() {
11121d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor    return RedeclLink.getNext();
11131d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor  }
11141d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor
1115cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattnerpublic:
11161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static ObjCProtocolDecl *Create(ASTContext &C, DeclContext *DC,
11171711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                                  IdentifierInfo *Id,
11181711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                                  SourceLocation nameLoc,
1119b05d7b20171bbd2feb14b059f39332cbe1bf1014Argyrios Kyrtzidis                                  SourceLocation atStartLoc,
1120c9d3c7edb513e9b8a6ab65b04133653e71d7a72bDouglas Gregor                                  ObjCProtocolDecl *PrevDecl);
1121cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattner
11221e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor  static ObjCProtocolDecl *CreateDeserialized(ASTContext &C, unsigned ID);
11231e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor
112418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  const ObjCProtocolList &getReferencedProtocols() const {
11255e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    assert(hasDefinition() && "No definition available!");
11265e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    return data().ReferencedProtocols;
1127980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  }
112818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::iterator protocol_iterator;
11295e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  protocol_iterator protocol_begin() const {
11305e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    if (!hasDefinition())
11315e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor      return protocol_iterator();
11325e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor
11335e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    return data().ReferencedProtocols.begin();
11345e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  }
11355e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  protocol_iterator protocol_end() const {
11365e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    if (!hasDefinition())
11375e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor      return protocol_iterator();
11385e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor
11395e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    return data().ReferencedProtocols.end();
11405e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  }
114118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
1142ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  protocol_loc_iterator protocol_loc_begin() const {
11435e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    if (!hasDefinition())
11445e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor      return protocol_loc_iterator();
11455e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor
11465e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    return data().ReferencedProtocols.loc_begin();
114718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
1148ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  protocol_loc_iterator protocol_loc_end() const {
11495e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    if (!hasDefinition())
11505e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor      return protocol_loc_iterator();
11515e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor
11525e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    return data().ReferencedProtocols.loc_end();
11535e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  }
11545e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  unsigned protocol_size() const {
11555e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    if (!hasDefinition())
11565e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor      return 0;
11575e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor
11585e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    return data().ReferencedProtocols.size();
115918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
11601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
116138af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  /// setProtocolList - Set the list of protocols that this interface
1162780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  /// implements.
116338af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num,
116418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                       const SourceLocation *Locs, ASTContext &C) {
11655e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    assert(Data && "Protocol is not defined");
11665e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    data().ReferencedProtocols.set(List, Num, Locs, C);
1167aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian  }
11681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
116991b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff  ObjCProtocolDecl *lookupProtocolNamed(IdentifierInfo *PName);
11701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
117194a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // Lookup a method. First, we search locally. If a method isn't
117294a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // found, we search referenced protocols and class categories.
1173094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis  ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance) const;
1174094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis  ObjCMethodDecl *lookupInstanceMethod(Selector Sel) const {
1175094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis    return lookupMethod(Sel, true/*isInstance*/);
1176094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis  }
1177094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis  ObjCMethodDecl *lookupClassMethod(Selector Sel) const {
1178094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis    return lookupMethod(Sel, false/*isInstance*/);
1179094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis  }
1180b05d7b20171bbd2feb14b059f39332cbe1bf1014Argyrios Kyrtzidis
11815e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  /// \brief Determine whether this protocol has a definition.
11825e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  bool hasDefinition() const { return Data != 0; }
11835e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor
11845e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  /// \brief Retrieve the definition of this protocol, if any.
11855e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  ObjCProtocolDecl *getDefinition() {
11861d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor    return Data? Data->Definition : 0;
11875e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  }
11885e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor
11895e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  /// \brief Retrieve the definition of this protocol, if any.
11905e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  const ObjCProtocolDecl *getDefinition() const {
11911d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor    return Data? Data->Definition : 0;
11925e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  }
11935e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor
11945e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  /// \brief Determine whether this particular declaration is also the
11955e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  /// definition.
11965e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  bool isThisDeclarationADefinition() const {
11975e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    return getDefinition() == this;
11985e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  }
11995e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor
12005e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  /// \brief Starts the definition of this Objective-C protocol.
12015e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  void startDefinition();
12025e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor
1203ec1a58b201b3276966aaade8ac3ac4705aba96c2Douglas Gregor  virtual SourceRange getSourceRange() const {
1204ec1a58b201b3276966aaade8ac3ac4705aba96c2Douglas Gregor    if (isThisDeclarationADefinition())
1205ec1a58b201b3276966aaade8ac3ac4705aba96c2Douglas Gregor      return ObjCContainerDecl::getSourceRange();
1206ec1a58b201b3276966aaade8ac3ac4705aba96c2Douglas Gregor
1207ec1a58b201b3276966aaade8ac3ac4705aba96c2Douglas Gregor    return SourceRange(getAtStartLoc(), getLocation());
1208ec1a58b201b3276966aaade8ac3ac4705aba96c2Douglas Gregor  }
1209ec1a58b201b3276966aaade8ac3ac4705aba96c2Douglas Gregor
12101d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor  typedef redeclarable_base::redecl_iterator redecl_iterator;
12111d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor  redecl_iterator redecls_begin() const {
12121d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor    return redeclarable_base::redecls_begin();
12131d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor  }
12141d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor  redecl_iterator redecls_end() const {
12151d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor    return redeclarable_base::redecls_end();
12161d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor  }
12171d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor
12183fc73ee0c613715ebce78e30b4d050ea715a007dDouglas Gregor  /// Retrieves the canonical declaration of this Objective-C protocol.
12193fc73ee0c613715ebce78e30b4d050ea715a007dDouglas Gregor  ObjCProtocolDecl *getCanonicalDecl() {
12201d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor    return getFirstDeclaration();
12213fc73ee0c613715ebce78e30b4d050ea715a007dDouglas Gregor  }
12223fc73ee0c613715ebce78e30b4d050ea715a007dDouglas Gregor  const ObjCProtocolDecl *getCanonicalDecl() const {
12231d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor    return getFirstDeclaration();
12243fc73ee0c613715ebce78e30b4d050ea715a007dDouglas Gregor  }
12253fc73ee0c613715ebce78e30b4d050ea715a007dDouglas Gregor
122680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1227a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCProtocolDecl *D) { return true; }
122880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCProtocol; }
1229b05d7b20171bbd2feb14b059f39332cbe1bf1014Argyrios Kyrtzidis
12305e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  friend class ASTReader;
1231b05d7b20171bbd2feb14b059f39332cbe1bf1014Argyrios Kyrtzidis  friend class ASTDeclReader;
1232b05d7b20171bbd2feb14b059f39332cbe1bf1014Argyrios Kyrtzidis  friend class ASTDeclWriter;
1233980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
12341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1235a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCCategoryDecl - Represents a category declaration. A category allows
12360c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// you to add methods to an existing class (without subclassing or modifying
12371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// the original class interface or implementation:-). Categories don't allow
12380c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// you to add instance data. The following example adds "myMethod" to all
12390c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// NSView's within a process:
12400c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
12410c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @interface NSView (MyViewMethods)
12420c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - myMethod;
12430c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end
12440c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
124533ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor/// Categories also allow you to split the implementation of a class across
12460c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// several files (a feature more naturally supported in C++).
12470c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
12480c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// Categories were originally inspired by dynamic languages such as Common
12491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Lisp and Smalltalk.  More traditional class-based languages (C++, Java)
12500c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// don't support this level of dynamism, which is both powerful and dangerous.
12510c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
1252e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroffclass ObjCCategoryDecl : public ObjCContainerDecl {
125399ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
125499ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie
1255980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  /// Interface belonging to this category
1256a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *ClassInterface;
12571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
125868c82cf61228102aba1194efef222fa1478af2a8Chris Lattner  /// referenced protocols in this category.
125918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  ObjCProtocolList ReferencedProtocols;
12601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1261a8ff9f455d94d9609766cfd5186b6e21dc2102f1Chris Lattner  /// Next category belonging to this class.
1262a8ff9f455d94d9609766cfd5186b6e21dc2102f1Chris Lattner  /// FIXME: this should not be a singly-linked list.  Move storage elsewhere.
1263a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCCategoryDecl *NextClassCategory;
12641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1265000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  /// true of class extension has at least one bitfield ivar.
1266000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  bool HasSynthBitfield : 1;
12673db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor
12683db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  /// \brief The location of the category name in this declaration.
12693db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  SourceLocation CategoryNameLoc;
12701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1271ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  ObjCCategoryDecl(DeclContext *DC, SourceLocation AtLoc,
12723db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor                   SourceLocation ClassNameLoc, SourceLocation CategoryNameLoc,
1273955fadbdfecfa24a590febe66a86519096787f2dArgyrios Kyrtzidis                   IdentifierInfo *Id, ObjCInterfaceDecl *IDecl)
12741711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis    : ObjCContainerDecl(ObjCCategory, DC, Id, ClassNameLoc, AtLoc),
1275955fadbdfecfa24a590febe66a86519096787f2dArgyrios Kyrtzidis      ClassInterface(IDecl), NextClassCategory(0), HasSynthBitfield(false),
12761711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis      CategoryNameLoc(CategoryNameLoc) {
1277a906135721c350435319347d2672bbb3bf494f91Chris Lattner  }
127861f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattnerpublic:
12791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1280d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCCategoryDecl *Create(ASTContext &C, DeclContext *DC,
1281ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                  SourceLocation AtLoc,
12823db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor                                  SourceLocation ClassNameLoc,
12833db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor                                  SourceLocation CategoryNameLoc,
1284955fadbdfecfa24a590febe66a86519096787f2dArgyrios Kyrtzidis                                  IdentifierInfo *Id,
1285955fadbdfecfa24a590febe66a86519096787f2dArgyrios Kyrtzidis                                  ObjCInterfaceDecl *IDecl);
12861e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor  static ObjCCategoryDecl *CreateDeserialized(ASTContext &C, unsigned ID);
12871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1288e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
1289e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; }
12908a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis
12918a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis  ObjCCategoryImplDecl *getImplementation() const;
12928a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis  void setImplementation(ObjCCategoryImplDecl *ImplD);
12938a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis
129438af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  /// setProtocolList - Set the list of protocols that this interface
1295f7b2c98c16dfb2261ea57d40a1d5bc4738e73175Chris Lattner  /// implements.
129638af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num,
129718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                       const SourceLocation *Locs, ASTContext &C) {
129818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    ReferencedProtocols.set(List, Num, Locs, C);
1299780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  }
13001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
130118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  const ObjCProtocolList &getReferencedProtocols() const {
1302780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner    return ReferencedProtocols;
13038f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian  }
13041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
130518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::iterator protocol_iterator;
1306780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();}
1307780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  protocol_iterator protocol_end() const { return ReferencedProtocols.end(); }
130830833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  unsigned protocol_size() const { return ReferencedProtocols.size(); }
130918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
1310ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  protocol_loc_iterator protocol_loc_begin() const {
1311ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return ReferencedProtocols.loc_begin();
131218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
1313ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  protocol_loc_iterator protocol_loc_end() const {
1314ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return ReferencedProtocols.loc_end();
131518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
13161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1317a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCCategoryDecl *getNextClassCategory() const { return NextClassCategory; }
13183db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor
131925760611365be23556b32332f8a66ae21ea93ecfFariborz Jahanian  bool IsClassExtension() const { return getIdentifier() == 0; }
132080aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  const ObjCCategoryDecl *getNextClassExtension() const;
1321ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1322000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  bool hasSynthBitfield() const { return HasSynthBitfield; }
1323000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  void setHasSynthBitfield (bool val) { HasSynthBitfield = val; }
1324ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
13250e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
13260e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  ivar_iterator ivar_begin() const {
13270e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian    return ivar_iterator(decls_begin());
13280e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  }
13290e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  ivar_iterator ivar_end() const {
13300e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian    return ivar_iterator(decls_end());
13310e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  }
13320e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  unsigned ivar_size() const {
13330e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian    return std::distance(ivar_begin(), ivar_end());
13340e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  }
13350e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  bool ivar_empty() const {
13360e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian    return ivar_begin() == ivar_end();
13370e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  }
13383db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor
13393db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  SourceLocation getCategoryNameLoc() const { return CategoryNameLoc; }
13403db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  void setCategoryNameLoc(SourceLocation Loc) { CategoryNameLoc = Loc; }
13413db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor
134280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1343a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCCategoryDecl *D) { return true; }
134480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCCategory; }
1345955fadbdfecfa24a590febe66a86519096787f2dArgyrios Kyrtzidis
1346955fadbdfecfa24a590febe66a86519096787f2dArgyrios Kyrtzidis  friend class ASTDeclReader;
1347955fadbdfecfa24a590febe66a86519096787f2dArgyrios Kyrtzidis  friend class ASTDeclWriter;
1348980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
13490c6b6243d3efd958c17943130e2a773653511edcSteve Naroff
1350aecae629269fae3bf484baf1d109e9a89d14eeadArgyrios Kyrtzidisclass ObjCImplDecl : public ObjCContainerDecl {
135199ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
135299ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie
13530d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// Class interface for this class/category implementation
1354a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *ClassInterface;
13551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13563aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattnerprotected:
13571711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis  ObjCImplDecl(Kind DK, DeclContext *DC,
13581711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis               ObjCInterfaceDecl *classInterface,
13591711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis               SourceLocation nameLoc, SourceLocation atStartLoc)
13601711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis    : ObjCContainerDecl(DK, DC,
13611711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                        classInterface? classInterface->getIdentifier() : 0,
13621711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                        nameLoc, atStartLoc),
1363aecae629269fae3bf484baf1d109e9a89d14eeadArgyrios Kyrtzidis      ClassInterface(classInterface) {}
13641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
136575c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattnerpublic:
1366e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; }
1367e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
13688a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis  void setClassInterface(ObjCInterfaceDecl *IFace);
13692c2d43c557beca1b4ba4bd743f33978aecb46a97Douglas Gregor
13701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void addInstanceMethod(ObjCMethodDecl *method) {
13712c2d43c557beca1b4ba4bd743f33978aecb46a97Douglas Gregor    // FIXME: Context should be set correctly before we get here.
1372653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor    method->setLexicalDeclContext(this);
13731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    addDecl(method);
1374e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff  }
13751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void addClassMethod(ObjCMethodDecl *method) {
13762c2d43c557beca1b4ba4bd743f33978aecb46a97Douglas Gregor    // FIXME: Context should be set correctly before we get here.
1377653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor    method->setLexicalDeclContext(this);
13781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    addDecl(method);
137953df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner  }
13801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
138117945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  void addPropertyImplementation(ObjCPropertyImplDecl *property);
13821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
138317945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  ObjCPropertyImplDecl *FindPropertyImplDecl(IdentifierInfo *propertyId) const;
138417945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  ObjCPropertyImplDecl *FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const;
1385653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor
1386653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor  // Iterator access to properties.
1387653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor  typedef specific_decl_iterator<ObjCPropertyImplDecl> propimpl_iterator;
13881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  propimpl_iterator propimpl_begin() const {
138917945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return propimpl_iterator(decls_begin());
1390559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  }
13911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  propimpl_iterator propimpl_end() const {
139217945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return propimpl_iterator(decls_end());
1393559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  }
1394653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor
139580cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1396bfb498d0996ef049efe9476f2802976fd145cd60Argyrios Kyrtzidis  static bool classof(const ObjCImplDecl *D) { return true; }
139780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) {
13989a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt    return K >= firstObjCImpl && K <= lastObjCImpl;
139980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  }
14003aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner};
14011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ObjCCategoryImplDecl - An object of this class encapsulates a category
14031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// @implementation declaration. If a category class has declaration of a
14041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// property, its implementation must be specified in the category's
14053aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @implementation declaration. Example:
14063aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @interface I @end
14073aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @interface I(CATEGORY)
14083aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner///    @property int p1, d1;
14093aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @end
14103aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @implementation I(CATEGORY)
14113aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner///  @dynamic p1,d1;
14123aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @end
14133aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner///
14143aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// ObjCCategoryImplDecl
14153aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattnerclass ObjCCategoryImplDecl : public ObjCImplDecl {
141699ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
141799ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie
14183aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  // Category name
14193aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  IdentifierInfo *Id;
14203aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner
1421c6994005dc9f677c831b8e90bdab483cc2197c29Argyrios Kyrtzidis  // Category name location
1422c6994005dc9f677c831b8e90bdab483cc2197c29Argyrios Kyrtzidis  SourceLocation CategoryNameLoc;
1423c6994005dc9f677c831b8e90bdab483cc2197c29Argyrios Kyrtzidis
14241711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis  ObjCCategoryImplDecl(DeclContext *DC, IdentifierInfo *Id,
14251711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                       ObjCInterfaceDecl *classInterface,
1426c6994005dc9f677c831b8e90bdab483cc2197c29Argyrios Kyrtzidis                       SourceLocation nameLoc, SourceLocation atStartLoc,
1427c6994005dc9f677c831b8e90bdab483cc2197c29Argyrios Kyrtzidis                       SourceLocation CategoryNameLoc)
14281711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis    : ObjCImplDecl(ObjCCategoryImpl, DC, classInterface, nameLoc, atStartLoc),
1429c6994005dc9f677c831b8e90bdab483cc2197c29Argyrios Kyrtzidis      Id(Id), CategoryNameLoc(CategoryNameLoc) {}
14303aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattnerpublic:
14313aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  static ObjCCategoryImplDecl *Create(ASTContext &C, DeclContext *DC,
14321711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                                      IdentifierInfo *Id,
14331711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                                      ObjCInterfaceDecl *classInterface,
14341711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                                      SourceLocation nameLoc,
1435c6994005dc9f677c831b8e90bdab483cc2197c29Argyrios Kyrtzidis                                      SourceLocation atStartLoc,
1436c6994005dc9f677c831b8e90bdab483cc2197c29Argyrios Kyrtzidis                                      SourceLocation CategoryNameLoc);
14371e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor  static ObjCCategoryImplDecl *CreateDeserialized(ASTContext &C, unsigned ID);
14381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14390d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// getIdentifier - Get the identifier that names the category
14403aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  /// interface associated with this implementation.
14410d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// FIXME: This is a bad API, we are overriding the NamedDecl::getIdentifier()
14420d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// to mean something different. For example:
1443ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// ((NamedDecl *)SomeCategoryImplDecl)->getIdentifier()
1444ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// returns the class interface name, whereas
1445ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// ((ObjCCategoryImplDecl *)SomeCategoryImplDecl)->getIdentifier()
14460d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// returns the category name.
14471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  IdentifierInfo *getIdentifier() const {
14481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return Id;
14493aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  }
145010b0e1fa3aabd8877dbbc0df1f2414e04afd5fddDouglas Gregor  void setIdentifier(IdentifierInfo *II) { Id = II; }
14511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14520d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  ObjCCategoryDecl *getCategoryDecl() const;
145310b0e1fa3aabd8877dbbc0df1f2414e04afd5fddDouglas Gregor
1454c6994005dc9f677c831b8e90bdab483cc2197c29Argyrios Kyrtzidis  SourceLocation getCategoryNameLoc() const { return CategoryNameLoc; }
1455c6994005dc9f677c831b8e90bdab483cc2197c29Argyrios Kyrtzidis
1456b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  /// getName - Get the name of identifier for the class interface associated
1457b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  /// with this implementation as a StringRef.
1458b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  //
1459b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  // FIXME: This is a bad API, we are overriding the NamedDecl::getName, to mean
1460b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  // something different.
1461686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getName() const {
1462b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar    return Id ? Id->getNameStart() : "";
1463b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  }
1464b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar
14653aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  /// getNameAsCString - Get the name of identifier for the class
14663aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  /// interface associated with this implementation as a C string
14673aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  /// (const char*).
14687fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar  //
1469b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  // FIXME: Deprecated, move clients to getName().
14703aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  const char *getNameAsCString() const {
14717fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar    return Id ? Id->getNameStart() : "";
14723aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  }
14731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14743aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  /// @brief Get the name of the class associated with this interface.
14757fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar  //
1476b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  // FIXME: Deprecated, move clients to getName().
14773aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  std::string getNameAsString() const {
1478b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar    return getName();
14793aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  }
14801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
148180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1482a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCCategoryImplDecl *D) { return true; }
148380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCCategoryImpl;}
1484c6994005dc9f677c831b8e90bdab483cc2197c29Argyrios Kyrtzidis
1485c6994005dc9f677c831b8e90bdab483cc2197c29Argyrios Kyrtzidis  friend class ASTDeclReader;
1486c6994005dc9f677c831b8e90bdab483cc2197c29Argyrios Kyrtzidis  friend class ASTDeclWriter;
14878f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian};
14888f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian
14898cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattnerraw_ostream &operator<<(raw_ostream &OS,
1490900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer                              const ObjCCategoryImplDecl *CID);
1491900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer
1492a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCImplementationDecl - Represents a class definition - this is where
14930c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// method definitions are specified. For example:
14940c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
149598abf4bd3526a00a0e5cf71a9462c181f97b1c81Fariborz Jahanian/// @code
14960c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @implementation MyClass
14970c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (void)myMethod { /* do something */ }
14980c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end
149998abf4bd3526a00a0e5cf71a9462c181f97b1c81Fariborz Jahanian/// @endcode
15000c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
15011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Typically, instance variables are specified in the class interface,
1502ec0d7a6f4b0699cc9960e6d9fee0f957c64d1cf9Douglas Gregor/// *not* in the implementation. Nevertheless (for legacy reasons), we
150353df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner/// allow instance variables to be specified in the implementation.  When
150453df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner/// specified, they need to be *identical* to the interface.
15050c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
15061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ObjCImplementationDecl : public ObjCImplDecl {
150799ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
1508980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  /// Implementation Class's super class.
1509a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *SuperClass;
1510e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// Support for ivar initialization.
1511e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// IvarInitializers - The arguments used to initialize the ivars
1512cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt  CXXCtorInitializer **IvarInitializers;
1513e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  unsigned NumIvarInitializers;
1514f85e193739c953358c865005855253af4f68a497John McCall
1515f85e193739c953358c865005855253af4f68a497John McCall  /// true if class has a .cxx_[construct,destruct] method.
1516f85e193739c953358c865005855253af4f68a497John McCall  bool HasCXXStructors : 1;
1517ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1518000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  /// true of class extension has at least one bitfield ivar.
1519000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  bool HasSynthBitfield : 1;
1520ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
15211711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis  ObjCImplementationDecl(DeclContext *DC,
1522a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek                         ObjCInterfaceDecl *classInterface,
15231711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                         ObjCInterfaceDecl *superDecl,
15241711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                         SourceLocation nameLoc, SourceLocation atStartLoc)
15251711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis    : ObjCImplDecl(ObjCImplementation, DC, classInterface, nameLoc, atStartLoc),
1526000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian       SuperClass(superDecl), IvarInitializers(0), NumIvarInitializers(0),
1527f85e193739c953358c865005855253af4f68a497John McCall       HasCXXStructors(false), HasSynthBitfield(false) {}
15281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
15291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static ObjCImplementationDecl *Create(ASTContext &C, DeclContext *DC,
153075c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner                                        ObjCInterfaceDecl *classInterface,
15311711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                                        ObjCInterfaceDecl *superDecl,
15321711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                                        SourceLocation nameLoc,
15331711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                                        SourceLocation atStartLoc);
1534ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
15351e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor  static ObjCImplementationDecl *CreateDeserialized(ASTContext &C, unsigned ID);
15361e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor
1537e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// init_iterator - Iterates through the ivar initializer list.
1538cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt  typedef CXXCtorInitializer **init_iterator;
1539ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1540e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// init_const_iterator - Iterates through the ivar initializer list.
1541cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt  typedef CXXCtorInitializer * const * init_const_iterator;
1542ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1543e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// init_begin() - Retrieve an iterator to the first initializer.
1544e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  init_iterator       init_begin()       { return IvarInitializers; }
1545e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// begin() - Retrieve an iterator to the first initializer.
1546e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  init_const_iterator init_begin() const { return IvarInitializers; }
1547ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1548e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// init_end() - Retrieve an iterator past the last initializer.
1549e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  init_iterator       init_end()       {
1550e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian    return IvarInitializers + NumIvarInitializers;
1551e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  }
1552e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// end() - Retrieve an iterator past the last initializer.
1553e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  init_const_iterator init_end() const {
1554e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian    return IvarInitializers + NumIvarInitializers;
1555e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  }
1556e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// getNumArgs - Number of ivars which must be initialized.
1557e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  unsigned getNumIvarInitializers() const {
1558e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian    return NumIvarInitializers;
1559e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  }
1560ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1561e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  void setNumIvarInitializers(unsigned numNumIvarInitializers) {
1562e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian    NumIvarInitializers = numNumIvarInitializers;
1563e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  }
1564ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1565e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  void setIvarInitializers(ASTContext &C,
1566cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt                           CXXCtorInitializer ** initializers,
1567e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian                           unsigned numInitializers);
1568f85e193739c953358c865005855253af4f68a497John McCall
1569f85e193739c953358c865005855253af4f68a497John McCall  bool hasCXXStructors() const { return HasCXXStructors; }
1570f85e193739c953358c865005855253af4f68a497John McCall  void setHasCXXStructors(bool val) { HasCXXStructors = val; }
1571ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1572000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  bool hasSynthBitfield() const { return HasSynthBitfield; }
1573000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  void setHasSynthBitfield (bool val) { HasSynthBitfield = val; }
1574ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
15754afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  /// getIdentifier - Get the identifier that names the class
15764afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  /// interface associated with this implementation.
15771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  IdentifierInfo *getIdentifier() const {
15781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return getClassInterface()->getIdentifier();
15794afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  }
15804afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor
1581d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  /// getName - Get the name of identifier for the class interface associated
1582d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  /// with this implementation as a StringRef.
1583d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  //
1584d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  // FIXME: This is a bad API, we are overriding the NamedDecl::getName, to mean
1585d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  // something different.
1586686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getName() const {
1587d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar    assert(getIdentifier() && "Name is not a simple identifier");
1588d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar    return getIdentifier()->getName();
1589d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  }
1590d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar
15914afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  /// getNameAsCString - Get the name of identifier for the class
15924afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  /// interface associated with this implementation as a C string
15934afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  /// (const char*).
15947fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar  //
15957fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar  // FIXME: Move to StringRef API.
15964afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  const char *getNameAsCString() const {
1597d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar    return getName().data();
15984afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  }
15994afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor
16004afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  /// @brief Get the name of the class associated with this interface.
16017fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar  //
16027fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar  // FIXME: Move to StringRef API.
16034afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  std::string getNameAsString() const {
1604d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar    return getName();
16054afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  }
16064afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor
1607e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  const ObjCInterfaceDecl *getSuperClass() const { return SuperClass; }
1608e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  ObjCInterfaceDecl *getSuperClass() { return SuperClass; }
16091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1610f3a7af901231535191d14cb524d58f22907ac4d2Chris Lattner  void setSuperClass(ObjCInterfaceDecl * superCls) { SuperClass = superCls; }
16111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16128f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor  typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
16131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ivar_iterator ivar_begin() const {
16141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return ivar_iterator(decls_begin());
16158f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor  }
16161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ivar_iterator ivar_end() const {
161717945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return ivar_iterator(decls_end());
16188f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor  }
16191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  unsigned ivar_size() const {
162017945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return std::distance(ivar_begin(), ivar_end());
16218f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor  }
16221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool ivar_empty() const {
162317945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return ivar_begin() == ivar_end();
16248f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor  }
16251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
162680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1627a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCImplementationDecl *D) { return true; }
162880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCImplementation; }
16299d50c0635fb213b2a1857e3f8488580f0dab2f98Argyrios Kyrtzidis
1630d527cc06d78fe5afa5f20105b51697637eb02c56Sebastian Redl  friend class ASTDeclReader;
16313397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl  friend class ASTDeclWriter;
1632980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
1633243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian
16348cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattnerraw_ostream &operator<<(raw_ostream &OS,
1635900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer                              const ObjCImplementationDecl *ID);
1636900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer
16371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ObjCCompatibleAliasDecl - Represents alias of a class. This alias is
1638243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian/// declared as @compatibility_alias alias class.
16394afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCCompatibleAliasDecl : public NamedDecl {
164099ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
1641243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian  /// Class that this is an alias of.
1642a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *AliasedClass;
16431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1644d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  ObjCCompatibleAliasDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
1645e8043c39176e7f253fbd92982b077eca6bf2fd59Steve Naroff                          ObjCInterfaceDecl* aliasedClass)
16464afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor    : NamedDecl(ObjCCompatibleAlias, DC, L, Id), AliasedClass(aliasedClass) {}
1647f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattnerpublic:
1648d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCCompatibleAliasDecl *Create(ASTContext &C, DeclContext *DC,
16490ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner                                         SourceLocation L, IdentifierInfo *Id,
1650f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner                                         ObjCInterfaceDecl* aliasedClass);
1651f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner
16521e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor  static ObjCCompatibleAliasDecl *CreateDeserialized(ASTContext &C,
16531e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor                                                     unsigned ID);
16541e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor
1655f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner  const ObjCInterfaceDecl *getClassInterface() const { return AliasedClass; }
1656f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner  ObjCInterfaceDecl *getClassInterface() { return AliasedClass; }
165730833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  void setClassInterface(ObjCInterfaceDecl *D) { AliasedClass = D; }
16581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
165980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1660a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCCompatibleAliasDecl *D) { return true; }
166180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCCompatibleAlias; }
16621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1663243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian};
16641de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian
16651de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian/// ObjCPropertyDecl - Represents one property declaration in an interface.
16661de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian/// For example:
16671de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian/// @property (assign, readwrite) int MyProperty;
16681de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian///
16694afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCPropertyDecl : public NamedDecl {
167099ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
167182a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanianpublic:
1672a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner  enum PropertyAttributeKind {
16731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    OBJC_PR_noattr    = 0x00,
16741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    OBJC_PR_readonly  = 0x01,
1675a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_getter    = 0x02,
16761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    OBJC_PR_assign    = 0x04,
16771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    OBJC_PR_readwrite = 0x08,
1678a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_retain    = 0x10,
16791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    OBJC_PR_copy      = 0x20,
1680a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_nonatomic = 0x40,
168145937ae10a0f70f74508165aab4f2b63e18ea747Fariborz Jahanian    OBJC_PR_setter    = 0x80,
1682f85e193739c953358c865005855253af4f68a497John McCall    OBJC_PR_atomic    = 0x100,
1683f85e193739c953358c865005855253af4f68a497John McCall    OBJC_PR_weak      = 0x200,
1684f85e193739c953358c865005855253af4f68a497John McCall    OBJC_PR_strong    = 0x400,
16859f3480bab8fcb6547978f8ad9e2b8f468e3658eeArgyrios Kyrtzidis    OBJC_PR_unsafe_unretained = 0x800
16869f3480bab8fcb6547978f8ad9e2b8f468e3658eeArgyrios Kyrtzidis    // Adding a property should change NumPropertyAttrsBits
16879f3480bab8fcb6547978f8ad9e2b8f468e3658eeArgyrios Kyrtzidis  };
16880a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis
16899f3480bab8fcb6547978f8ad9e2b8f468e3658eeArgyrios Kyrtzidis  enum {
16900a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis    /// \brief Number of bits fitting all the property attributes.
16919f3480bab8fcb6547978f8ad9e2b8f468e3658eeArgyrios Kyrtzidis    NumPropertyAttrsBits = 12
1692a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner  };
1693af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
16943a02b44e3948f7762dbfba94b7961281ca29d022Fariborz Jahanian  enum SetterKind { Assign, Retain, Copy, Weak };
169546b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  enum PropertyControl { None, Required, Optional };
169682a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanianprivate:
1697d8265b838360578032020757d9a2a84c86457edcFariborz Jahanian  SourceLocation AtLoc;   // location of @property
169883a230c83a54190366138c1a4f4310ef838b88fcJohn McCall  TypeSourceInfo *DeclType;
16999f3480bab8fcb6547978f8ad9e2b8f468e3658eeArgyrios Kyrtzidis  unsigned PropertyAttributes : NumPropertyAttrsBits;
17009f3480bab8fcb6547978f8ad9e2b8f468e3658eeArgyrios Kyrtzidis  unsigned PropertyAttributesAsWritten : NumPropertyAttrsBits;
170146b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  // @required/@optional
170246b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  unsigned PropertyImplementation : 2;
17031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17045251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  Selector GetterName;    // getter name of NULL if no getter
17055251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  Selector SetterName;    // setter name of NULL if no setter
17061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
170733de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  ObjCMethodDecl *GetterMethodDecl; // Declaration of getter instance method
170833de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  ObjCMethodDecl *SetterMethodDecl; // Declaration of setter instance method
1709af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian  ObjCIvarDecl *PropertyIvarDecl;   // Synthesize ivar for this property
171033de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian
17111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ObjCPropertyDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
171283a230c83a54190366138c1a4f4310ef838b88fcJohn McCall                   SourceLocation AtLocation, TypeSourceInfo *T)
1713d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian    : NamedDecl(ObjCProperty, DC, L, Id), AtLoc(AtLocation), DeclType(T),
1714ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie      PropertyAttributes(OBJC_PR_noattr),
171580aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian      PropertyAttributesAsWritten(OBJC_PR_noattr),
171680aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian      PropertyImplementation(None),
17171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      GetterName(Selector()),
171833de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian      SetterName(Selector()),
1719af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian      GetterMethodDecl(0), SetterMethodDecl(0) , PropertyIvarDecl(0) {}
1720f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattnerpublic:
17211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static ObjCPropertyDecl *Create(ASTContext &C, DeclContext *DC,
17221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                  SourceLocation L,
1723d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian                                  IdentifierInfo *Id, SourceLocation AtLocation,
172483a230c83a54190366138c1a4f4310ef838b88fcJohn McCall                                  TypeSourceInfo *T,
172546b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian                                  PropertyControl propControl = None);
17261e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor
17271e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor  static ObjCPropertyDecl *CreateDeserialized(ASTContext &C, unsigned ID);
17281e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor
1729d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian  SourceLocation getAtLoc() const { return AtLoc; }
1730d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian  void setAtLoc(SourceLocation L) { AtLoc = L; }
1731ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
173283a230c83a54190366138c1a4f4310ef838b88fcJohn McCall  TypeSourceInfo *getTypeSourceInfo() const { return DeclType; }
173383a230c83a54190366138c1a4f4310ef838b88fcJohn McCall  QualType getType() const { return DeclType->getType(); }
173483a230c83a54190366138c1a4f4310ef838b88fcJohn McCall  void setType(TypeSourceInfo *T) { DeclType = T; }
173570e5a14c6076d63833c62d1d6d628c26309897c1Douglas Gregor
1736a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner  PropertyAttributeKind getPropertyAttributes() const {
1737f4af5154571e0c5eadb19df10e65464766ef6683Chris Lattner    return PropertyAttributeKind(PropertyAttributes);
1738f4af5154571e0c5eadb19df10e65464766ef6683Chris Lattner  }
17391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setPropertyAttributes(PropertyAttributeKind PRVal) {
1740a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    PropertyAttributes |= PRVal;
174182a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian  }
1742394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar
174380aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  PropertyAttributeKind getPropertyAttributesAsWritten() const {
174480aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian    return PropertyAttributeKind(PropertyAttributesAsWritten);
174580aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  }
17460a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis
17470a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis  bool hasWrittenStorageAttribute() const {
17480a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis    return PropertyAttributesAsWritten & (OBJC_PR_assign | OBJC_PR_copy |
17490a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis        OBJC_PR_unsafe_unretained | OBJC_PR_retain | OBJC_PR_strong |
17500a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis        OBJC_PR_weak);
17510a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis  }
1752ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
175380aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  void setPropertyAttributesAsWritten(PropertyAttributeKind PRVal) {
175480aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian    PropertyAttributesAsWritten = PRVal;
175580aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  }
1756ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
17578cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian void makeitReadWriteAttribute(void) {
17588cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian    PropertyAttributes &= ~OBJC_PR_readonly;
17598cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian    PropertyAttributes |= OBJC_PR_readwrite;
17601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump }
17618cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian
1762af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  // Helper methods for accessing attributes.
1763af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
1764af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  /// isReadOnly - Return true iff the property has a setter.
1765394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar  bool isReadOnly() const {
1766394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar    return (PropertyAttributes & OBJC_PR_readonly);
1767394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar  }
1768af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
1769265941bc308d65cc270d5c4de5806f37ce405606John McCall  /// isAtomic - Return true if the property is atomic.
1770265941bc308d65cc270d5c4de5806f37ce405606John McCall  bool isAtomic() const {
1771265941bc308d65cc270d5c4de5806f37ce405606John McCall    return (PropertyAttributes & OBJC_PR_atomic);
1772265941bc308d65cc270d5c4de5806f37ce405606John McCall  }
1773265941bc308d65cc270d5c4de5806f37ce405606John McCall
1774265941bc308d65cc270d5c4de5806f37ce405606John McCall  /// isRetaining - Return true if the property retains its value.
1775265941bc308d65cc270d5c4de5806f37ce405606John McCall  bool isRetaining() const {
1776265941bc308d65cc270d5c4de5806f37ce405606John McCall    return (PropertyAttributes &
1777265941bc308d65cc270d5c4de5806f37ce405606John McCall            (OBJC_PR_retain | OBJC_PR_strong | OBJC_PR_copy));
1778265941bc308d65cc270d5c4de5806f37ce405606John McCall  }
1779265941bc308d65cc270d5c4de5806f37ce405606John McCall
1780af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  /// getSetterKind - Return the method used for doing assignment in
1781af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  /// the property setter. This is only valid if the property has been
1782af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  /// defined to have a setter.
1783af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  SetterKind getSetterKind() const {
17846dc6f008994472cf4da321855e8c51c39720f3edJohn McCall    if (PropertyAttributes & OBJC_PR_strong)
17856dc6f008994472cf4da321855e8c51c39720f3edJohn McCall      return getType()->isBlockPointerType() ? Copy : Retain;
17866dc6f008994472cf4da321855e8c51c39720f3edJohn McCall    if (PropertyAttributes & OBJC_PR_retain)
1787af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar      return Retain;
1788af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar    if (PropertyAttributes & OBJC_PR_copy)
1789af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar      return Copy;
17903a02b44e3948f7762dbfba94b7961281ca29d022Fariborz Jahanian    if (PropertyAttributes & OBJC_PR_weak)
17913a02b44e3948f7762dbfba94b7961281ca29d022Fariborz Jahanian      return Weak;
1792af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar    return Assign;
1793af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  }
1794af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
17955251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  Selector getGetterName() const { return GetterName; }
17965251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  void setGetterName(Selector Sel) { GetterName = Sel; }
17971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17985251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  Selector getSetterName() const { return SetterName; }
17995251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  void setSetterName(Selector Sel) { SetterName = Sel; }
18001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
180133de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  ObjCMethodDecl *getGetterMethodDecl() const { return GetterMethodDecl; }
180233de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  void setGetterMethodDecl(ObjCMethodDecl *gDecl) { GetterMethodDecl = gDecl; }
180333de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian
180433de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  ObjCMethodDecl *getSetterMethodDecl() const { return SetterMethodDecl; }
180533de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  void setSetterMethodDecl(ObjCMethodDecl *gDecl) { SetterMethodDecl = gDecl; }
18061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
180746b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  // Related to @optional/@required declared in @protocol
180846b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  void setPropertyImplementation(PropertyControl pc) {
180946b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian    PropertyImplementation = pc;
181046b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  }
181146b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  PropertyControl getPropertyImplementation() const {
181246b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian    return PropertyControl(PropertyImplementation);
18131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
18141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1815af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian  void setPropertyIvarDecl(ObjCIvarDecl *Ivar) {
1816af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian    PropertyIvarDecl = Ivar;
1817af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian  }
1818af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian  ObjCIvarDecl *getPropertyIvarDecl() const {
1819af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian    return PropertyIvarDecl;
1820af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian  }
18211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1822da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor  virtual SourceRange getSourceRange() const {
1823e3c60a7ce9e0f42c7ca2344b33203266aceca1dbDouglas Gregor    return SourceRange(AtLoc, getLocation());
1824e3c60a7ce9e0f42c7ca2344b33203266aceca1dbDouglas Gregor  }
1825e3c60a7ce9e0f42c7ca2344b33203266aceca1dbDouglas Gregor
18269f550ff05d496e6b9480e5619a21d9da0c9e27c1Ted Kremenek  /// Lookup a property by name in the specified DeclContext.
1827de09d0c9694f01a99870a8825266d44a29ebb325Ted Kremenek  static ObjCPropertyDecl *findPropertyDecl(const DeclContext *DC,
18289f550ff05d496e6b9480e5619a21d9da0c9e27c1Ted Kremenek                                            IdentifierInfo *propertyID);
18299f550ff05d496e6b9480e5619a21d9da0c9e27c1Ted Kremenek
183080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1831a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCPropertyDecl *D) { return true; }
183280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCProperty; }
183382a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian};
1834980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
18351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ObjCPropertyImplDecl - Represents implementation declaration of a property
183661d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian/// in a class or category implementation block. For example:
183761d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian/// @synthesize prop1 = ivar1;
183861d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian///
18394afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCPropertyImplDecl : public Decl {
184061d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanianpublic:
18419f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar  enum Kind {
18429f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar    Synthesize,
18439f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar    Dynamic
184461d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  };
184561d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanianprivate:
1846559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  SourceLocation AtLoc;   // location of @synthesize or @dynamic
1847ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1848a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  /// \brief For @synthesize, the location of the ivar, if it was written in
1849a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  /// the source code.
1850a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  ///
1851a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  /// \code
1852a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  /// @synthesize int a = b
1853a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  /// \endcode
1854a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  SourceLocation IvarLoc;
1855ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
185661d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  /// Property declaration being implemented
185761d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  ObjCPropertyDecl *PropertyDecl;
1858be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek
185961d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  /// Null for @dynamic. Required for @synthesize.
186061d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  ObjCIvarDecl *PropertyIvarDecl;
1861ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
186217cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  /// Null for @dynamic. Non-null if property must be copy-constructed in getter
186317cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  Expr *GetterCXXConstructor;
1864ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
186517cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  /// Null for @dynamic. Non-null if property has assignment operator to call
186617cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  /// in Setter synthesis.
186717cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  Expr *SetterCXXAssignment;
1868be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek
1869d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  ObjCPropertyImplDecl(DeclContext *DC, SourceLocation atLoc, SourceLocation L,
18701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                       ObjCPropertyDecl *property,
18711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                       Kind PK,
1872a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor                       ObjCIvarDecl *ivarDecl,
1873a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor                       SourceLocation ivarLoc)
18741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : Decl(ObjCPropertyImpl, DC, L), AtLoc(atLoc),
1875ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie      IvarLoc(ivarLoc), PropertyDecl(property), PropertyIvarDecl(ivarDecl),
187617cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian      GetterCXXConstructor(0), SetterCXXAssignment(0) {
18779f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar    assert (PK == Dynamic || PropertyIvarDecl);
18789f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar  }
18791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18809f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbarpublic:
1881d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCPropertyImplDecl *Create(ASTContext &C, DeclContext *DC,
18821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                      SourceLocation atLoc, SourceLocation L,
18831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                      ObjCPropertyDecl *property,
18841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                      Kind PK,
1885a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor                                      ObjCIvarDecl *ivarDecl,
1886a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor                                      SourceLocation ivarLoc);
188761d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian
18881e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor  static ObjCPropertyImplDecl *CreateDeserialized(ASTContext &C, unsigned ID);
18891e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor
1890da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor  virtual SourceRange getSourceRange() const;
1891ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1892d40910b581b09c937a8c1fdcde9b8ec724398fb9Steve Naroff  SourceLocation getLocStart() const { return AtLoc; }
18938818c4fb69cb2a4eec94b217a90f94f9e075296eDouglas Gregor  void setAtLoc(SourceLocation Loc) { AtLoc = Loc; }
1894d40910b581b09c937a8c1fdcde9b8ec724398fb9Steve Naroff
1895be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek  ObjCPropertyDecl *getPropertyDecl() const {
1896be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek    return PropertyDecl;
1897be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek  }
18988818c4fb69cb2a4eec94b217a90f94f9e075296eDouglas Gregor  void setPropertyDecl(ObjCPropertyDecl *Prop) { PropertyDecl = Prop; }
18998818c4fb69cb2a4eec94b217a90f94f9e075296eDouglas Gregor
19009f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar  Kind getPropertyImplementation() const {
19019f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar    return PropertyIvarDecl ? Synthesize : Dynamic;
1902be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek  }
19031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1904af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  ObjCIvarDecl *getPropertyIvarDecl() const {
1905be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek    return PropertyIvarDecl;
1906be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek  }
1907a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  SourceLocation getPropertyIvarDeclLoc() const { return IvarLoc; }
1908ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1909a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  void setPropertyIvarDecl(ObjCIvarDecl *Ivar,
1910ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                           SourceLocation IvarLoc) {
1911ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    PropertyIvarDecl = Ivar;
1912a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor    this->IvarLoc = IvarLoc;
1913a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  }
1914ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
191517cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  Expr *getGetterCXXConstructor() const {
191617cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian    return GetterCXXConstructor;
191717cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  }
191817cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  void setGetterCXXConstructor(Expr *getterCXXConstructor) {
191917cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian    GetterCXXConstructor = getterCXXConstructor;
192017cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  }
19218818c4fb69cb2a4eec94b217a90f94f9e075296eDouglas Gregor
192217cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  Expr *getSetterCXXAssignment() const {
192317cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian    return SetterCXXAssignment;
192417cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  }
192517cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  void setSetterCXXAssignment(Expr *setterCXXAssignment) {
192617cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian    SetterCXXAssignment = setterCXXAssignment;
192717cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  }
1928ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
192980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
19301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const ObjCPropertyImplDecl *D) { return true; }
193180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Decl::Kind K) { return K == ObjCPropertyImpl; }
1932ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1933a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  friend class ASTDeclReader;
193461d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian};
193561d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian
1936980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff}  // end namespace clang
1937980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff#endif
1938