DeclObjC.h revision 1711fc91efb36d131f7ba771f73f0154dc1abd1f
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
8718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  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;
1273fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian
1283fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian  // Method has a definition.
12985f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  unsigned IsDefined : 1;
1301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
131ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  // NOTE: VC++ treats enums as signed, avoid using ImplementationControl enum
13258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  /// @required/@optional
133ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  unsigned DeclImplementation : 2;
1341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
135ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  // NOTE: VC++ treats enums as signed, avoid using the ObjCDeclQualifier enum
13658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  /// in, inout, etc.
137ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  unsigned objcDeclQualifier : 6;
1381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
139926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor  /// \brief Indicates whether this method has a related result type.
140926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor  unsigned RelatedResultType : 1;
141491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis
142491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// \brief Whether the locations of the selector identifiers are in a
143491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// "standard" position, a enum SelectorLocationsKind.
144491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  unsigned SelLocsKind : 2;
1457732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian
1464bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor  // Result type of this method.
14758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  QualType MethodDeclType;
1484bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor
1494bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor  // Type source information for the result type.
1504bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor  TypeSourceInfo *ResultTInfo;
1514bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor
152491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// \brief Array of ParmVarDecls for the formal parameters of this method
153491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// and optionally followed by selector locations.
154491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  void *ParamsAndSelLocs;
155491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  unsigned NumParams;
1561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  /// List of attributes for this method declaration.
158a2e85ada1dfef36201a31f6646bc4ea3bd76a89aArgyrios Kyrtzidis  SourceLocation EndLoc; // the location of the ';' or '}'.
1591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  // The following are only used for method definitions, null otherwise.
16158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  // FIXME: space savings opportunity, consider a sub-class.
16258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  Stmt *Body;
163451318c08a6342c10b8986060386fd9274418437Daniel Dunbar
164451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// SelfDecl - Decl for the implicit self parameter. This is lazily
165451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// constructed by createImplicitParams.
1664111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  ImplicitParamDecl *SelfDecl;
167451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// CmdDecl - Decl for the implicit _cmd parameter. This is lazily
168451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// constructed by createImplicitParams.
1694111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  ImplicitParamDecl *CmdDecl;
1701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
171491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  SelectorLocationsKind getSelLocsKind() const {
172491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    return (SelectorLocationsKind)SelLocsKind;
173491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  }
174491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  bool hasStandardSelLocs() const {
175491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    return getSelLocsKind() != SelLoc_NonStandard;
176491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  }
177491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis
178491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// \brief Get a pointer to the stored selector identifiers locations array.
179491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// No locations will be stored if HasStandardSelLocs is true.
180491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  SourceLocation *getStoredSelLocs() {
181491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    return reinterpret_cast<SourceLocation*>(getParams() + NumParams);
182491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  }
183491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  const SourceLocation *getStoredSelLocs() const {
184491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    return reinterpret_cast<const SourceLocation*>(getParams() + NumParams);
185491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  }
186491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis
187491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// \brief Get a pointer to the stored selector identifiers locations array.
188491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// No locations will be stored if HasStandardSelLocs is true.
189491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  ParmVarDecl **getParams() {
190491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    return reinterpret_cast<ParmVarDecl **>(ParamsAndSelLocs);
191491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  }
192491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  const ParmVarDecl *const *getParams() const {
193491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    return reinterpret_cast<const ParmVarDecl *const *>(ParamsAndSelLocs);
194491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  }
195491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis
196491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// \brief Get the number of stored selector identifiers locations.
197491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// No locations will be stored if HasStandardSelLocs is true.
198491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  unsigned getNumStoredSelLocs() const {
199491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    if (hasStandardSelLocs())
200491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis      return 0;
201491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    return getNumSelectorLocs();
202491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  }
203491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis
204491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  void setParamsAndSelLocs(ASTContext &C,
205491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis                           ArrayRef<ParmVarDecl*> Params,
206491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis                           ArrayRef<SourceLocation> SelLocs);
207491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis
208a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCMethodDecl(SourceLocation beginLoc, SourceLocation endLoc,
20958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff                 Selector SelInfo, QualType T,
2104bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor                 TypeSourceInfo *ResultTInfo,
2110701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff                 DeclContext *contextDecl,
212f6414927e67e27d9324d8d179c5f7ea620443924Daniel Dunbar                 bool isInstance = true,
21358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff                 bool isVariadic = false,
2144607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian                 bool isSynthesized = false,
21575cf3e86d33ce810c12084126385371b335c30baArgyrios Kyrtzidis                 bool isImplicitlyDeclared = false,
2163fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian                 bool isDefined = false,
2177732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian                 ImplementationControl impControl = None,
218da92a7f91cf88f49e02050919676f7fb8e3bdff8Argyrios Kyrtzidis                 bool HasRelatedResultType = false)
2194afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  : NamedDecl(ObjCMethod, contextDecl, beginLoc, SelInfo),
22085f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall    DeclContext(ObjCMethod), Family(InvalidObjCMethodFamily),
22158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff    IsInstance(isInstance), IsVariadic(isVariadic),
2224607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian    IsSynthesized(isSynthesized),
2233fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian    IsDefined(isDefined),
22458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff    DeclImplementation(impControl), objcDeclQualifier(OBJC_TQ_None),
225da92a7f91cf88f49e02050919676f7fb8e3bdff8Argyrios Kyrtzidis    RelatedResultType(HasRelatedResultType),
226491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    SelLocsKind(SelLoc_StandardNoSpace),
227926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor    MethodDeclType(T), ResultTInfo(ResultTInfo),
228491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    ParamsAndSelLocs(0), NumParams(0),
22975cf3e86d33ce810c12084126385371b335c30baArgyrios Kyrtzidis    EndLoc(endLoc), Body(0), SelfDecl(0), CmdDecl(0) {
23075cf3e86d33ce810c12084126385371b335c30baArgyrios Kyrtzidis    setImplicit(isImplicitlyDeclared);
23175cf3e86d33ce810c12084126385371b335c30baArgyrios Kyrtzidis  }
2328a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek
23357ea6bee79cc60ba20c7886b453f40f380dce1b1Argyrios Kyrtzidis  /// \brief A definition will return its interface declaration.
23457ea6bee79cc60ba20c7886b453f40f380dce1b1Argyrios Kyrtzidis  /// An interface declaration will return its definition.
23557ea6bee79cc60ba20c7886b453f40f380dce1b1Argyrios Kyrtzidis  /// Otherwise it will return itself.
236da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor  virtual ObjCMethodDecl *getNextRedeclaration();
237da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor
2386c4ae5de0c356777446f823b573821fb95560d91Chris Lattnerpublic:
2390ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner  static ObjCMethodDecl *Create(ASTContext &C,
2401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                SourceLocation beginLoc,
24111d77169555480ee0a04c6e5bc390d8fde41175dArgyrios Kyrtzidis                                SourceLocation endLoc,
24211d77169555480ee0a04c6e5bc390d8fde41175dArgyrios Kyrtzidis                                Selector SelInfo,
2434bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor                                QualType T,
2444bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor                                TypeSourceInfo *ResultTInfo,
2454bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor                                DeclContext *contextDecl,
246f6414927e67e27d9324d8d179c5f7ea620443924Daniel Dunbar                                bool isInstance = true,
2476c4ae5de0c356777446f823b573821fb95560d91Chris Lattner                                bool isVariadic = false,
2484607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian                                bool isSynthesized = false,
24975cf3e86d33ce810c12084126385371b335c30baArgyrios Kyrtzidis                                bool isImplicitlyDeclared = false,
2503fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian                                bool isDefined = false,
2517732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian                                ImplementationControl impControl = None,
252da92a7f91cf88f49e02050919676f7fb8e3bdff8Argyrios Kyrtzidis                                bool HasRelatedResultType = false);
253e7f9d301a10b4b3223e91d9be4362b44cba0a212Argyrios Kyrtzidis
254da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor  virtual ObjCMethodDecl *getCanonicalDecl();
25513e635c55eb23f736d38abf9c954801bd6482db4Ted Kremenek  const ObjCMethodDecl *getCanonicalDecl() const {
25613e635c55eb23f736d38abf9c954801bd6482db4Ted Kremenek    return const_cast<ObjCMethodDecl*>(this)->getCanonicalDecl();
25713e635c55eb23f736d38abf9c954801bd6482db4Ted Kremenek  }
258e7f9d301a10b4b3223e91d9be4362b44cba0a212Argyrios Kyrtzidis
259ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  ObjCDeclQualifier getObjCDeclQualifier() const {
260ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek    return ObjCDeclQualifier(objcDeclQualifier);
261ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  }
262a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void setObjCDeclQualifier(ObjCDeclQualifier QV) { objcDeclQualifier = QV; }
2631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
264926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor  /// \brief Determine whether this method has a result type that is related
265926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor  /// to the message receiver's type.
266926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor  bool hasRelatedResultType() const { return RelatedResultType; }
267926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor
268926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor  /// \brief Note whether this method has a related result type.
269926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor  void SetRelatedResultType(bool RRT = true) { RelatedResultType = RRT; }
270926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor
27158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  // Location information, modeled after the Stmt API.
27258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  SourceLocation getLocStart() const { return getLocation(); }
27358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  SourceLocation getLocEnd() const { return EndLoc; }
27453c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setEndLoc(SourceLocation Loc) { EndLoc = Loc; }
275da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor  virtual SourceRange getSourceRange() const {
2761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(getLocation(), EndLoc);
2779776ba0d844cf9f6888e871e3fd246ae782f76f4Daniel Dunbar  }
2781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
279491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  SourceLocation getSelectorStartLoc() const { return getSelectorLoc(0); }
280491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  SourceLocation getSelectorLoc(unsigned Index) const {
281491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    assert(Index < getNumSelectorLocs() && "Index out of range!");
282491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    if (hasStandardSelLocs())
283491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis      return getStandardSelectorLoc(Index, getSelector(),
284491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis                                   getSelLocsKind() == SelLoc_StandardWithSpace,
285491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis                      llvm::makeArrayRef(const_cast<ParmVarDecl**>(getParams()),
286491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis                                         NumParams),
287491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis                                   EndLoc);
288491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    return getStoredSelLocs()[Index];
289491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  }
290491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis
291491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  void getSelectorLocs(SmallVectorImpl<SourceLocation> &SelLocs) const;
292491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis
293491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  unsigned getNumSelectorLocs() const {
294491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    if (isImplicit())
295491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis      return 0;
296491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    Selector Sel = getSelector();
297491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    if (Sel.isUnarySelector())
298491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis      return 1;
299491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    return Sel.getNumArgs();
300491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  }
301491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis
3025619688510185081cbb4621d703daf7ee24cf39aChris Lattner  ObjCInterfaceDecl *getClassInterface();
3035619688510185081cbb4621d703daf7ee24cf39aChris Lattner  const ObjCInterfaceDecl *getClassInterface() const {
3045619688510185081cbb4621d703daf7ee24cf39aChris Lattner    return const_cast<ObjCMethodDecl*>(this)->getClassInterface();
305e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  }
3061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3072e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  Selector getSelector() const { return getDeclName().getObjCSelector(); }
3083a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson
30958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  QualType getResultType() const { return MethodDeclType; }
31053c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setResultType(QualType T) { MethodDeclType = T; }
3111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3125291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// \brief Determine the type of an expression that sends a message to this
3135291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// function.
3145291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  QualType getSendResultType() const {
3156398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor    return getResultType().getNonLValueExprType(getASTContext());
3165291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  }
3175291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor
3184bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor  TypeSourceInfo *getResultTypeSourceInfo() const { return ResultTInfo; }
3194bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor  void setResultTypeSourceInfo(TypeSourceInfo *TInfo) { ResultTInfo = TInfo; }
3204bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor
321d57f635d520e8cb5b93d3d770ff58db06c62de54Chris Lattner  // Iterator access to formal parameters.
322491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  unsigned param_size() const { return NumParams; }
323491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  typedef const ParmVarDecl *const *param_const_iterator;
324491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  typedef ParmVarDecl *const *param_iterator;
325491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  param_const_iterator param_begin() const { return getParams(); }
326491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  param_const_iterator param_end() const { return getParams() + NumParams; }
327491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  param_iterator param_begin() { return getParams(); }
328491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  param_iterator param_end() { return getParams() + NumParams; }
3297732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian  // This method returns and of the parameters which are part of the selector
3307732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian  // name mangling requirements.
331491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  param_const_iterator sel_param_end() const {
332491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    return param_begin() + getSelector().getNumArgs();
3337732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian  }
33489951a86b594513c2a013532ed45d197413b1087Chris Lattner
335491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  void setMethodParams(ASTContext &C,
336491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis                       ArrayRef<ParmVarDecl*> Params,
337491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis                       ArrayRef<SourceLocation> SelLocs);
3384111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner
3396ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson  // Iterator access to parameter types.
3406ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson  typedef std::const_mem_fun_t<QualType, ParmVarDecl> deref_fun;
341491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  typedef llvm::mapped_iterator<param_const_iterator, deref_fun>
342491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis      arg_type_iterator;
3436ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson
3446ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson  arg_type_iterator arg_type_begin() const {
3456ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson    return llvm::map_iterator(param_begin(), deref_fun(&ParmVarDecl::getType));
3466ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson  }
3476ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson  arg_type_iterator arg_type_end() const {
3486ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson    return llvm::map_iterator(param_end(), deref_fun(&ParmVarDecl::getType));
3496ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson  }
3501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
351451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// createImplicitParams - Used to lazily create the self and cmd
352451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// implict parameters. This must be called prior to using getSelfDecl()
353451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// or getCmdDecl(). The call is ignored if the implicit paramters
354451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// have already been created.
355fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian  void createImplicitParams(ASTContext &Context, const ObjCInterfaceDecl *ID);
356451318c08a6342c10b8986060386fd9274418437Daniel Dunbar
3574111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  ImplicitParamDecl * getSelfDecl() const { return SelfDecl; }
35853c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setSelfDecl(ImplicitParamDecl *SD) { SelfDecl = SD; }
3594111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  ImplicitParamDecl * getCmdDecl() const { return CmdDecl; }
36053c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setCmdDecl(ImplicitParamDecl *CD) { CmdDecl = CD; }
3611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
36285f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  /// Determines the family of this method.
36385f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  ObjCMethodFamily getMethodFamily() const;
36485f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall
365f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor  bool isInstanceMethod() const { return IsInstance; }
36653c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setInstanceMethod(bool isInst) { IsInstance = isInst; }
36758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  bool isVariadic() const { return IsVariadic; }
36853c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setVariadic(bool isVar) { IsVariadic = isVar; }
3691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
370f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor  bool isClassMethod() const { return !IsInstance; }
371f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor
3724607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian  bool isSynthesized() const { return IsSynthesized; }
37353c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setSynthesized(bool isSynth) { IsSynthesized = isSynth; }
3743fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian
3753fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian  bool isDefined() const { return IsDefined; }
3763fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian  void setDefined(bool isDefined) { IsDefined = isDefined; }
3771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
37858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  // Related to protocols declared in  @protocol
3791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setDeclImplementation(ImplementationControl ic) {
3801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    DeclImplementation = ic;
38158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  }
3821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ImplementationControl getImplementationControl() const {
3831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return ImplementationControl(DeclImplementation);
38458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  }
385792481eec23d8c1aa92173be589e2ae9d02514a5Ted Kremenek
386da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor  virtual Stmt *getBody() const {
3871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return (Stmt*) Body;
3887297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor  }
3896fb0aee4f9dc261bbec72e1283ad8dc0557a6d96Argyrios Kyrtzidis  CompoundStmt *getCompoundBody() { return (CompoundStmt*)Body; }
390d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl  void setBody(Stmt *B) { Body = B; }
39158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff
39266570b230941651245accbc5680b60e904eb993cArgyrios Kyrtzidis  /// \brief Returns whether this specific method is a definition.
39366570b230941651245accbc5680b60e904eb993cArgyrios Kyrtzidis  bool isThisDeclarationADefinition() const { return Body; }
39466570b230941651245accbc5680b60e904eb993cArgyrios Kyrtzidis
39558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  // Implement isa/cast/dyncast/etc.
39680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
397a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCMethodDecl *D) { return true; }
39880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCMethod; }
39942220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  static DeclContext *castToDeclContext(const ObjCMethodDecl *D) {
40042220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis    return static_cast<DeclContext *>(const_cast<ObjCMethodDecl*>(D));
40142220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  }
40242220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  static ObjCMethodDecl *castFromDeclContext(const DeclContext *DC) {
40342220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis    return static_cast<ObjCMethodDecl *>(const_cast<DeclContext*>(DC));
40442220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  }
405491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis
406491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  friend class ASTDeclReader;
407491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  friend class ASTDeclWriter;
40858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff};
409e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
410e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff/// ObjCContainerDecl - Represents a container for method declarations.
411aecae629269fae3bf484baf1d109e9a89d14eeadArgyrios Kyrtzidis/// Current sub-classes are ObjCInterfaceDecl, ObjCCategoryDecl,
4121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ObjCProtocolDecl, and ObjCImplDecl.
413e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff///
4144afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCContainerDecl : public NamedDecl, public DeclContext {
4151711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis  SourceLocation AtStart;
4161711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis
417782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  // These two locations in the range mark the end of the method container.
418782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  // The first points to the '@' token, and the second to the 'end' token.
419782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  SourceRange AtEnd;
420e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroffpublic:
421e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
4221711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis  ObjCContainerDecl(Kind DK, DeclContext *DC,
4231711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                    IdentifierInfo *Id, SourceLocation nameLoc,
4241711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                    SourceLocation atStartLoc)
4251711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis    : NamedDecl(DK, DC, nameLoc, Id), DeclContext(DK), AtStart(atStartLoc) {}
426e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
42793983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff  // Iterator access to properties.
42893983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff  typedef specific_decl_iterator<ObjCPropertyDecl> prop_iterator;
4291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  prop_iterator prop_begin() const {
43017945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return prop_iterator(decls_begin());
43193983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff  }
4321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  prop_iterator prop_end() const {
43317945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return prop_iterator(decls_end());
43409c4719788a5cea09897525e528fa00420f1677bSteve Naroff  }
4351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4360701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  // Iterator access to instance/class methods.
437f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor  typedef specific_decl_iterator<ObjCMethodDecl> method_iterator;
4381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  method_iterator meth_begin() const {
43917945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return method_iterator(decls_begin());
4407ed4faca5162b3ab85be7f7e57aa40e6ec170971Ted Kremenek  }
4411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  method_iterator meth_end() const {
44217945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return method_iterator(decls_end());
4437ed4faca5162b3ab85be7f7e57aa40e6ec170971Ted Kremenek  }
4440701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
4451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  typedef filtered_decl_iterator<ObjCMethodDecl,
4461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                 &ObjCMethodDecl::isInstanceMethod>
447669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor    instmeth_iterator;
44817945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  instmeth_iterator instmeth_begin() const {
44917945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return instmeth_iterator(decls_begin());
450e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff  }
45117945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  instmeth_iterator instmeth_end() const {
45217945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return instmeth_iterator(decls_end());
453e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff  }
454e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
4551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  typedef filtered_decl_iterator<ObjCMethodDecl,
4561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                 &ObjCMethodDecl::isClassMethod>
457669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor    classmeth_iterator;
45817945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  classmeth_iterator classmeth_begin() const {
45917945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return classmeth_iterator(decls_begin());
460e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff  }
46117945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  classmeth_iterator classmeth_end() const {
46217945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return classmeth_iterator(decls_end());
4630701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  }
4640701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
4650701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  // Get the local instance/class method declared in this interface.
466467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis  ObjCMethodDecl *getMethod(Selector Sel, bool isInstance) const;
467467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis  ObjCMethodDecl *getInstanceMethod(Selector Sel) const {
468467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis    return getMethod(Sel, true/*isInstance*/);
46953df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner  }
470467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis  ObjCMethodDecl *getClassMethod(Selector Sel) const {
471467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis    return getMethod(Sel, false/*isInstance*/);
472467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis  }
473467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis  ObjCIvarDecl *getIvarDecl(IdentifierInfo *Id) const;
4741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
47517945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  ObjCPropertyDecl *FindPropertyDeclaration(IdentifierInfo *PropertyId) const;
47693983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff
4771711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis  SourceLocation getAtStartLoc() const { return AtStart; }
4781711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis  void setAtStartLoc(SourceLocation Loc) { AtStart = Loc; }
4791711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis
480e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff  // Marks the end of the container.
481782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  SourceRange getAtEndRange() const {
482782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek    return AtEnd;
483782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  }
484782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  void setAtEndRange(SourceRange atEnd) {
485782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek    AtEnd = atEnd;
486782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  }
487ddfd4c9eda34765b08fae4cb31ad5a365face107Argyrios Kyrtzidis
488da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor  virtual SourceRange getSourceRange() const {
4891711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis    return SourceRange(AtStart, getAtEndRange().getEnd());
490ddfd4c9eda34765b08fae4cb31ad5a365face107Argyrios Kyrtzidis  }
4911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
49209c4719788a5cea09897525e528fa00420f1677bSteve Naroff  // Implement isa/cast/dyncast/etc.
49380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
49409c4719788a5cea09897525e528fa00420f1677bSteve Naroff  static bool classof(const ObjCContainerDecl *D) { return true; }
49580cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) {
4969a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt    return K >= firstObjCContainer &&
4979a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt           K <= lastObjCContainer;
49880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  }
49909c4719788a5cea09897525e528fa00420f1677bSteve Naroff
50009c4719788a5cea09897525e528fa00420f1677bSteve Naroff  static DeclContext *castToDeclContext(const ObjCContainerDecl *D) {
50109c4719788a5cea09897525e528fa00420f1677bSteve Naroff    return static_cast<DeclContext *>(const_cast<ObjCContainerDecl*>(D));
50209c4719788a5cea09897525e528fa00420f1677bSteve Naroff  }
50309c4719788a5cea09897525e528fa00420f1677bSteve Naroff  static ObjCContainerDecl *castFromDeclContext(const DeclContext *DC) {
50409c4719788a5cea09897525e528fa00420f1677bSteve Naroff    return static_cast<ObjCContainerDecl *>(const_cast<DeclContext*>(DC));
50509c4719788a5cea09897525e528fa00420f1677bSteve Naroff  }
506e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff};
507e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
508a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCInterfaceDecl - Represents an ObjC class declaration. For example:
5090c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
5100c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   // MostPrimitive declares no super class (not particularly useful).
5111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///   @interface MostPrimitive
5120c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     // no instance variables or methods.
5130c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @end
5140c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
5151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///   // NSResponder inherits from NSObject & implements NSCoding (a protocol).
5160c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @interface NSResponder : NSObject <NSCoding>
517a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek///   { // instance variables are represented by ObjCIvarDecl.
5180c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     id nextResponder; // nextResponder instance variable.
5190c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   }
5200c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   - (NSResponder *)nextResponder; // return a pointer to NSResponder.
5210c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   - (void)mouseMoved:(NSEvent *)theEvent; // return void, takes a pointer
5220c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @end                                    // to an NSEvent.
5230c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
5240c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   Unlike C/C++, forward class declarations are accomplished with @class.
5250c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   Unlike C/C++, @class allows for a list of classes to be forward declared.
5260c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   Unlike C++, ObjC is a single-rooted class model. In Cocoa, classes
5270c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   typically inherit from NSObject (an exception is NSProxy).
5280c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
529deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregorclass ObjCInterfaceDecl : public ObjCContainerDecl {
5303110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff  /// TypeForDecl - This indicates the Type object that represents this
5313110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff  /// TypeDecl.  It is a cache maintained by ASTContext::getObjCInterfaceType
532f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  mutable const Type *TypeForDecl;
5333110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff  friend class ASTContext;
5341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
535980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  /// Class's super class.
536a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *SuperClass;
5371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
53853b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  /// Protocols referenced in the @interface  declaration
53918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  ObjCProtocolList ReferencedProtocols;
54053b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
54153b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  /// Protocols reference in both the @interface and class extensions.
54253b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  ObjCList<ObjCProtocolDecl> AllReferencedProtocols;
5431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5448c99d88a6cfa14fc2edab819d5e4325c973b2809Douglas Gregor  /// \brief List of categories and class extensions defined for this class.
5458c99d88a6cfa14fc2edab819d5e4325c973b2809Douglas Gregor  ///
5468c99d88a6cfa14fc2edab819d5e4325c973b2809Douglas Gregor  /// Categories are stored as a linked list in the AST, since the categories
5478c99d88a6cfa14fc2edab819d5e4325c973b2809Douglas Gregor  /// and class extensions come long after the initial interface declaration,
548fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner  /// and we avoid dynamically-resized arrays in the AST wherever possible.
549a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCCategoryDecl *CategoryList;
5502c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian
5512c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  /// IvarList - List of all ivars defined by this class; including class
5522c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  /// extensions and implementation. This list is built lazily.
5532c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  ObjCIvarDecl *IvarList;
5541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5553a3ca1b35a7121aea0bf465a192dce748465e10fFariborz Jahanian  bool ForwardDecl:1; // declared with @class.
5563a3ca1b35a7121aea0bf465a192dce748465e10fFariborz Jahanian  bool InternalInterface:1; // true - no @interface for @implementation
55726ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
55826ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  /// \brief Indicates that the contents of this Objective-C class will be
55926ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  /// completed by the external AST source when required.
56026ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  mutable bool ExternallyCompleted : 1;
56126ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
562d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff  SourceLocation SuperClassLoc; // location of the super class identifier.
563f908a87299d278164540f90b5b6e6cab7b14fb41Steve Naroff  SourceLocation EndLoc; // marks the '>', '}', or identifier.
5640e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner
565d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id,
566deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor                    SourceLocation CLoc, bool FD, bool isInternal);
5671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
56826ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  void LoadExternalDefinition() const;
5690e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattnerpublic:
570d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCInterfaceDecl *Create(ASTContext &C, DeclContext *DC,
5710ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner                                   SourceLocation atLoc,
5721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                   IdentifierInfo *Id,
573deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor                                   SourceLocation ClassLoc = SourceLocation(),
5740e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner                                   bool ForwardDecl = false,
5750e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner                                   bool isInternal = false);
57626ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
57726ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  /// \brief Indicate that this Objective-C class is complete, but that
57826ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  /// the external AST source will be responsible for filling in its contents
57926ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  /// when a complete class is required.
58026ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  void setExternallyCompleted();
58126ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
58218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  const ObjCProtocolList &getReferencedProtocols() const {
58326ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor    if (ExternallyCompleted)
58426ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
58526ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
5861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return ReferencedProtocols;
5877ed9e0f97f4645edc5d4670385b985ea4c617ce7Fariborz Jahanian  }
5888a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis
5898a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis  ObjCImplementationDecl *getImplementation() const;
5908a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis  void setImplementation(ObjCImplementationDecl *ImplD);
5918a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis
592559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  ObjCCategoryDecl *FindCategoryDeclaration(IdentifierInfo *CategoryId) const;
5931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5941cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis  // Get the local instance/class method declared in a category.
5951cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis  ObjCMethodDecl *getCategoryInstanceMethod(Selector Sel) const;
5961cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis  ObjCMethodDecl *getCategoryClassMethod(Selector Sel) const;
5971cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis  ObjCMethodDecl *getCategoryMethod(Selector Sel, bool isInstance) const {
5981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return isInstance ? getInstanceMethod(Sel)
5991cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis                      : getClassMethod(Sel);
6001cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis  }
6013db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner
60218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::iterator protocol_iterator;
60353b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
60453b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  protocol_iterator protocol_begin() const {
60526ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor    if (ExternallyCompleted)
60626ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
60726ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
60853b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek    return ReferencedProtocols.begin();
60953b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  }
61053b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  protocol_iterator protocol_end() const {
61126ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor    if (ExternallyCompleted)
61226ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
61326ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
61453b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek    return ReferencedProtocols.end();
61553b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  }
61653b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
61718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
61853b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
61918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  protocol_loc_iterator protocol_loc_begin() const {
62026ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor    if (ExternallyCompleted)
62126ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
62226ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
62318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    return ReferencedProtocols.loc_begin();
62418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
62553b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
62618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  protocol_loc_iterator protocol_loc_end() const {
62726ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor    if (ExternallyCompleted)
62826ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
62926ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
63018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    return ReferencedProtocols.loc_end();
63118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
63253b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
63353b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  typedef ObjCList<ObjCProtocolDecl>::iterator all_protocol_iterator;
63453b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
63553b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  all_protocol_iterator all_referenced_protocol_begin() const {
63626ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor    if (ExternallyCompleted)
63726ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
63826ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
63953b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek    return AllReferencedProtocols.empty() ? protocol_begin()
64053b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek      : AllReferencedProtocols.begin();
64153b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  }
64253b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  all_protocol_iterator all_referenced_protocol_end() const {
64326ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor    if (ExternallyCompleted)
64426ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
64526ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
64653b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek    return AllReferencedProtocols.empty() ? protocol_end()
64753b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek      : AllReferencedProtocols.end();
64853b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  }
649291be393aa33759e6e34b6429c5ffa206ba50115Douglas Gregor
65011062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian  typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
65153b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
652db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose  ivar_iterator ivar_begin() const { return ivar_iterator(decls_begin()); }
65311062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian  ivar_iterator ivar_end() const { return ivar_iterator(decls_end()); }
65453b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
65511062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian  unsigned ivar_size() const {
65611062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian    return std::distance(ivar_begin(), ivar_end());
65711062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian  }
65853b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
65911062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian  bool ivar_empty() const { return ivar_begin() == ivar_end(); }
6602c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian
661db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose  ObjCIvarDecl *all_declared_ivar_begin();
662db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose  const ObjCIvarDecl *all_declared_ivar_begin() const {
663db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose    // Even though this modifies IvarList, it's conceptually const:
664db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose    // the ivar chain is essentially a cached property of ObjCInterfaceDecl.
665db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose    return const_cast<ObjCInterfaceDecl *>(this)->all_declared_ivar_begin();
666db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose  }
6672c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  void setIvarList(ObjCIvarDecl *ivar) { IvarList = ivar; }
6682c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian
66938af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  /// setProtocolList - Set the list of protocols that this interface
670b752f289026ad8e5f44851b20e009a27ed61eefcChris Lattner  /// implements.
67138af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  void setProtocolList(ObjCProtocolDecl *const* List, unsigned Num,
67218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                       const SourceLocation *Locs, ASTContext &C) {
67318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    ReferencedProtocols.set(List, Num, Locs, C);
6743db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  }
6751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
676339798eae1eb61c50ca68766ed028c0a16d0a284Fariborz Jahanian  /// mergeClassExtensionProtocolList - Merge class extension's protocol list
677339798eae1eb61c50ca68766ed028c0a16d0a284Fariborz Jahanian  /// into the protocol list for this class.
67818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  void mergeClassExtensionProtocolList(ObjCProtocolDecl *const* List,
67918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                                       unsigned Num,
68018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                                       ASTContext &C);
681339798eae1eb61c50ca68766ed028c0a16d0a284Fariborz Jahanian
682768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff  bool isForwardDecl() const { return ForwardDecl; }
683768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff  void setForwardDecl(bool val) { ForwardDecl = val; }
6841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
68526ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  ObjCInterfaceDecl *getSuperClass() const {
68626ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor    if (ExternallyCompleted)
68726ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
68826ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
68926ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor    return SuperClass;
69026ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  }
69126ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
692a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void setSuperClass(ObjCInterfaceDecl * superCls) { SuperClass = superCls; }
6931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
69426ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  ObjCCategoryDecl* getCategoryList() const {
69526ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor    if (ExternallyCompleted)
69626ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
69726ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
69826ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor    return CategoryList;
69926ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  }
70026ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
7011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setCategoryList(ObjCCategoryDecl *category) {
70253efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    CategoryList = category;
703980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  }
70480aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian
70580aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  ObjCCategoryDecl* getFirstClassExtension() const;
70637cafb077ad5b170acae77e566638603011ef4c0Ted Kremenek
70737cafb077ad5b170acae77e566638603011ef4c0Ted Kremenek  ObjCPropertyDecl
70837cafb077ad5b170acae77e566638603011ef4c0Ted Kremenek    *FindPropertyVisibleInPrimaryClass(IdentifierInfo *PropertyId) const;
70937cafb077ad5b170acae77e566638603011ef4c0Ted Kremenek
71053efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner  /// isSuperClassOf - Return true if this class is the specified class or is a
71153efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner  /// super class of the specified interface class.
71253efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner  bool isSuperClassOf(const ObjCInterfaceDecl *I) const {
71353efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    // If RHS is derived from LHS it is OK; else it is not OK.
71453efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    while (I != NULL) {
71553efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner      if (this == I)
71653efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner        return true;
71753efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner      I = I->getSuperClass();
71853efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    }
71953efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    return false;
72053efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner  }
7211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7227263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian  /// isArcWeakrefUnavailable - Checks for a class or one of its super classes
7237263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian  /// to be incompatible with __weak references. Returns true if it is.
7247263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian  bool isArcWeakrefUnavailable() const {
7257263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian    const ObjCInterfaceDecl *Class = this;
7267263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian    while (Class) {
7277263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian      if (Class->hasAttr<ArcWeakrefUnavailableAttr>())
7287263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian        return true;
7297263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian      Class = Class->getSuperClass();
7307263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian   }
7317263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian   return false;
7327263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian  }
7337263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian
73417945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName,
73568a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner                                       ObjCInterfaceDecl *&ClassDeclared);
73617945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName) {
73768a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner    ObjCInterfaceDecl *ClassDeclared;
73817945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return lookupInstanceVariable(IVarName, ClassDeclared);
73968a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner  }
74068a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner
74194a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // Lookup a method. First, we search locally. If a method isn't
74294a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // found, we search referenced protocols and class categories.
743aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis  ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance) const;
744aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis  ObjCMethodDecl *lookupInstanceMethod(Selector Sel) const {
745aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis    return lookupMethod(Sel, true/*isInstance*/);
746aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis  }
747aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis  ObjCMethodDecl *lookupClassMethod(Selector Sel) const {
748aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis    return lookupMethod(Sel, false/*isInstance*/);
749aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis  }
750cd1876207f5564beba74e4b2524b664bdba0ba9fFariborz Jahanian  ObjCInterfaceDecl *lookupInheritedClass(const IdentifierInfo *ICName);
751d789d3d985e28c9404e62157af46dcb7331920e0Steve Naroff
752d789d3d985e28c9404e62157af46dcb7331920e0Steve Naroff  // Lookup a method in the classes implementation hierarchy.
75374b2756bc1f1f5f7c189996fe7e4cd3efef70263Fariborz Jahanian  ObjCMethodDecl *lookupPrivateMethod(const Selector &Sel, bool Instance=true);
75460fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff
755ddfd4c9eda34765b08fae4cb31ad5a365face107Argyrios Kyrtzidis  // Location information, modeled after the Stmt API.
7561711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis  SourceLocation getLocStart() const { return getAtStartLoc(); } // '@'interface
757f908a87299d278164540f90b5b6e6cab7b14fb41Steve Naroff  SourceLocation getLocEnd() const { return EndLoc; }
7587177dee8aee4b432911c91f1b788963bec0cac9fDaniel Dunbar  void setLocEnd(SourceLocation LE) { EndLoc = LE; }
7591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
760d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff  void setSuperClassLoc(SourceLocation Loc) { SuperClassLoc = Loc; }
761d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff  SourceLocation getSuperClassLoc() const { return SuperClassLoc; }
7621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
76328e71cf851b73a67604735a9a95aef800b144e2eSteve Naroff  /// isImplicitInterfaceDecl - check that this is an implicitly declared
764a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  /// ObjCInterfaceDecl node. This is for legacy objective-c @implementation
7654b6df3fa953267c5d755628c8afd818bb571e579Fariborz Jahanian  /// declaration without an @interface declaration.
76633feeb019a5742b286eededd5446ec0fe87c5a61Steve Naroff  bool isImplicitInterfaceDecl() const { return InternalInterface; }
76733feeb019a5742b286eededd5446ec0fe87c5a61Steve Naroff  void setImplicitInterfaceDecl(bool val) { InternalInterface = val; }
7681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7690fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian  /// ClassImplementsProtocol - Checks that 'lProto' protocol
7700fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian  /// has been implemented in IDecl class, its super class or categories (if
7710fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian  /// lookupCategory is true).
7720fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian  bool ClassImplementsProtocol(ObjCProtocolDecl *lProto,
7730fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian                               bool lookupCategory,
7740fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian                               bool RHSIsQualifiedID = false);
7751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
77633feeb019a5742b286eededd5446ec0fe87c5a61Steve Naroff  // Low-level accessor
777f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const Type *getTypeForDecl() const { return TypeForDecl; }
778f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  void setTypeForDecl(const Type *TD) const { TypeForDecl = TD; }
77933feeb019a5742b286eededd5446ec0fe87c5a61Steve Naroff
78080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
781a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCInterfaceDecl *D) { return true; }
78280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCInterface; }
78353b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
78453b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  friend class ASTDeclReader;
78553b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  friend class ASTDeclWriter;
786980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
787980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
788a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCIvarDecl - Represents an ObjC instance variable. In general, ObjC
7890c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// instance variables are identical to C. The only exception is Objective-C
7900c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// supports C++ style access control. For example:
7910c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
7920c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @interface IvarExample : NSObject
7930c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   {
794f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek///     id defaultToProtected;
7950c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @public:
7960c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     id canBePublic; // same as C++.
7970c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @protected:
7980c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     id canBeProtected; // same as C++.
7990c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @package:
8000c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     id canBePackage; // framework visibility (not available in C++).
8010c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   }
8020c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
803a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCIvarDecl : public FieldDecl {
8040e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattnerpublic:
805980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  enum AccessControl {
806980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff    None, Private, Protected, Public, Package
807980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  };
8081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
809b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenekprivate:
810ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara  ObjCIvarDecl(ObjCContainerDecl *DC, SourceLocation StartLoc,
811ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara               SourceLocation IdLoc, IdentifierInfo *Id,
812ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian               QualType T, TypeSourceInfo *TInfo, AccessControl ac, Expr *BW,
813ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian               bool synthesized)
814ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara    : FieldDecl(ObjCIvar, DC, StartLoc, IdLoc, Id, T, TInfo, BW,
8157a614d8380297fcd2bc23986241905d97222948cRichard Smith                /*Mutable=*/false, /*HasInit=*/false),
816ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara      NextIvar(0), DeclAccess(ac), Synthesized(synthesized) {}
8171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
818b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenekpublic:
819a06549226f45d5b72169a3d054415616dd1014a2Daniel Dunbar  static ObjCIvarDecl *Create(ASTContext &C, ObjCContainerDecl *DC,
820ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                              SourceLocation StartLoc, SourceLocation IdLoc,
821ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                              IdentifierInfo *Id, QualType T,
822a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall                              TypeSourceInfo *TInfo,
823ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian                              AccessControl ac, Expr *BW = NULL,
824ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian                              bool synthesized=false);
8251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
82627a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar  /// \brief Return the class interface that this ivar is logically contained
82727a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar  /// in; this is either the interface where the ivar was declared, or the
82827a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar  /// interface the ivar is conceptually a part of in the case of synthesized
82927a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar  /// ivars.
83027a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar  const ObjCInterfaceDecl *getContainingInterface() const;
8312c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian
8322c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  ObjCIvarDecl *getNextIvar() { return NextIvar; }
833db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose  const ObjCIvarDecl *getNextIvar() const { return NextIvar; }
8342c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  void setNextIvar(ObjCIvarDecl *ivar) { NextIvar = ivar; }
83527a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar
836980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  void setAccessControl(AccessControl ac) { DeclAccess = ac; }
837f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek
838ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  AccessControl getAccessControl() const { return AccessControl(DeclAccess); }
839f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek
840f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek  AccessControl getCanonicalAccessControl() const {
841f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek    return DeclAccess == None ? Protected : AccessControl(DeclAccess);
842f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek  }
8431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
844ac0021ba802e193e0f9f8207768c7862c7603bc0Fariborz Jahanian  void setSynthesize(bool synth) { Synthesized = synth; }
845ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian  bool getSynthesize() const { return Synthesized; }
846ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian
847980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  // Implement isa/cast/dyncast/etc.
84880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
849a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCIvarDecl *D) { return true; }
85080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCIvar; }
851980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffprivate:
8522c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  /// NextIvar - Next Ivar in the list of ivars declared in class; class's
8532c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  /// extensions and class's implementation
8542c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  ObjCIvarDecl *NextIvar;
8552c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian
856ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  // NOTE: VC++ treats enums as signed, avoid using the AccessControl enum
857ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  unsigned DeclAccess : 3;
858ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian  unsigned Synthesized : 1;
859980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
860980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
8611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
86201e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek/// ObjCAtDefsFieldDecl - Represents a field declaration created by an
86301e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek///  @defs(...).
86401e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenekclass ObjCAtDefsFieldDecl : public FieldDecl {
86501e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenekprivate:
866ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara  ObjCAtDefsFieldDecl(DeclContext *DC, SourceLocation StartLoc,
867ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                      SourceLocation IdLoc, IdentifierInfo *Id,
86801e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek                      QualType T, Expr *BW)
869ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara    : FieldDecl(ObjCAtDefsField, DC, StartLoc, IdLoc, Id, T,
870a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall                /*TInfo=*/0, // FIXME: Do ObjCAtDefs have declarators ?
8717a614d8380297fcd2bc23986241905d97222948cRichard Smith                BW, /*Mutable=*/false, /*HasInit=*/false) {}
8721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
87301e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenekpublic:
87444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor  static ObjCAtDefsFieldDecl *Create(ASTContext &C, DeclContext *DC,
875ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                     SourceLocation StartLoc,
876ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                     SourceLocation IdLoc, IdentifierInfo *Id,
877ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                     QualType T, Expr *BW);
8781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
87901e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek  // Implement isa/cast/dyncast/etc.
88080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
88101e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek  static bool classof(const ObjCAtDefsFieldDecl *D) { return true; }
88280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCAtDefsField; }
88301e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek};
884980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
885a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCProtocolDecl - Represents a protocol declaration. ObjC protocols
8861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// declare a pure abstract type (i.e no instance variables are permitted).
887fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner/// Protocols originally drew inspiration from C++ pure virtual functions (a C++
8880c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// feature with nice semantics and lousy syntax:-). Here is an example:
8890c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
890eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// @protocol NSDraggingInfo <refproto1, refproto2>
8910c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (NSWindow *)draggingDestinationWindow;
8920c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (NSImage *)draggedImage;
8930c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end
8940c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
895eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// This says that NSDraggingInfo requires two methods and requires everything
896eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// that the two "referenced protocols" 'refproto1' and 'refproto2' require as
897eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// well.
898eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner///
8990c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @interface ImplementsNSDraggingInfo : NSObject <NSDraggingInfo>
9000c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end
9010c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
902a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjC protocols inspired Java interfaces. Unlike Java, ObjC classes and
9030c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// protocols are in distinct namespaces. For example, Cocoa defines both
9041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// an NSObject protocol and class (which isn't allowed in Java). As a result,
9050c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// protocols are referenced using angle brackets as follows:
9060c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
9070c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// id <NSDraggingInfo> anyObjectThatImplementsNSDraggingInfo;
9080c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
909e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroffclass ObjCProtocolDecl : public ObjCContainerDecl {
910780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  /// Referenced protocols
91118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  ObjCProtocolList ReferencedProtocols;
9121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
913980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  bool isForwardProtoDecl; // declared with @protocol.
9141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
915423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff  SourceLocation EndLoc; // marks the '>' or identifier.
9161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9171711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis  ObjCProtocolDecl(DeclContext *DC, IdentifierInfo *Id,
9181711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                   SourceLocation nameLoc, SourceLocation atStartLoc)
9191711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis    : ObjCContainerDecl(ObjCProtocol, DC, Id, nameLoc, atStartLoc),
920c858105d41602a2dadb2efbc1af80a7b791ebac3Chris Lattner      isForwardProtoDecl(true) {
921cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattner  }
9221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
923cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattnerpublic:
9241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static ObjCProtocolDecl *Create(ASTContext &C, DeclContext *DC,
9251711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                                  IdentifierInfo *Id,
9261711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                                  SourceLocation nameLoc,
9271711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                                  SourceLocation atStartLoc);
928cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattner
92918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  const ObjCProtocolList &getReferencedProtocols() const {
930780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner    return ReferencedProtocols;
931980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  }
93218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::iterator protocol_iterator;
933780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();}
934780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  protocol_iterator protocol_end() const { return ReferencedProtocols.end(); }
93518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
93618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  protocol_loc_iterator protocol_loc_begin() const {
93718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    return ReferencedProtocols.loc_begin();
93818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
93918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  protocol_loc_iterator protocol_loc_end() const {
94018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    return ReferencedProtocols.loc_end();
94118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
94230833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  unsigned protocol_size() const { return ReferencedProtocols.size(); }
9431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
94438af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  /// setProtocolList - Set the list of protocols that this interface
945780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  /// implements.
94638af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num,
94718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                       const SourceLocation *Locs, ASTContext &C) {
94818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    ReferencedProtocols.set(List, Num, Locs, C);
949aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian  }
9501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
95191b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff  ObjCProtocolDecl *lookupProtocolNamed(IdentifierInfo *PName);
9521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
95394a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // Lookup a method. First, we search locally. If a method isn't
95494a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // found, we search referenced protocols and class categories.
955094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis  ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance) const;
956094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis  ObjCMethodDecl *lookupInstanceMethod(Selector Sel) const {
957094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis    return lookupMethod(Sel, true/*isInstance*/);
958094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis  }
959094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis  ObjCMethodDecl *lookupClassMethod(Selector Sel) const {
960094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis    return lookupMethod(Sel, false/*isInstance*/);
961094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis  }
962d789d3d985e28c9404e62157af46dcb7331920e0Steve Naroff
963768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff  bool isForwardDecl() const { return isForwardProtoDecl; }
964768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff  void setForwardDecl(bool val) { isForwardProtoDecl = val; }
965980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
9661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // Location information, modeled after the Stmt API.
9671711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis  SourceLocation getLocStart() const { return getAtStartLoc(); } // '@'protocol
968423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff  SourceLocation getLocEnd() const { return EndLoc; }
9697177dee8aee4b432911c91f1b788963bec0cac9fDaniel Dunbar  void setLocEnd(SourceLocation LE) { EndLoc = LE; }
9701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
97180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
972a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCProtocolDecl *D) { return true; }
97380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCProtocol; }
974980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
9751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
976a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCClassDecl - Specifies a list of forward class declarations. For example:
97706ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff///
97806ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff/// @class NSCursor, NSImage, NSPasteboard, NSWindow;
9790c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
9804afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCClassDecl : public Decl {
981321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenekpublic:
982321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek  class ObjCClassRef {
983321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek    ObjCInterfaceDecl *ID;
984321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek    SourceLocation L;
985321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek  public:
986321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek    ObjCClassRef(ObjCInterfaceDecl *d, SourceLocation l) : ID(d), L(l) {}
987321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek    SourceLocation getLocation() const { return L; }
988321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek    ObjCInterfaceDecl *getInterface() const { return ID; }
989321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek  };
990321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenekprivate:
99195ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian  ObjCClassRef *ForwardDecl;
9921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ObjCClassDecl(DeclContext *DC, SourceLocation L,
99495ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian                ObjCInterfaceDecl *const Elt, const SourceLocation Loc,
99595ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian                ASTContext &C);
99661f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattnerpublic:
997d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCClassDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L,
99895ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian                               ObjCInterfaceDecl *const Elt = 0,
99995ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian                               const SourceLocation Locs = SourceLocation());
100095ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian
100195ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian  ObjCInterfaceDecl *getForwardInterfaceDecl() { return ForwardDecl->getInterface(); }
100295ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian  ObjCClassRef *getForwardDecl() { return ForwardDecl; }
100395ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian  void setClass(ASTContext &C, ObjCInterfaceDecl*const Cls,
100495ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian                const SourceLocation Locs);
10052dbdd622d02d1bfbe1e5bcf421b07b74c7a748f1Ted Kremenek
1006da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor  virtual SourceRange getSourceRange() const;
10071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
100880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1009a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCClassDecl *D) { return true; }
101080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCClass; }
101106ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff};
101206ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff
1013a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCForwardProtocolDecl - Specifies a list of forward protocol declarations.
101406ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff/// For example:
10151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
10160c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @protocol NSTextInput, NSChangeSpelling, NSDraggingInfo;
10171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
10184afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCForwardProtocolDecl : public Decl {
101918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  ObjCProtocolList ReferencedProtocols;
10201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1021d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  ObjCForwardProtocolDecl(DeclContext *DC, SourceLocation L,
102238af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner                          ObjCProtocolDecl *const *Elts, unsigned nElts,
102318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                          const SourceLocation *Locs, ASTContext &C);
10241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
102561f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattnerpublic:
1026d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCForwardProtocolDecl *Create(ASTContext &C, DeclContext *DC,
10271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                         SourceLocation L,
102818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                                         ObjCProtocolDecl *const *Elts,
102918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                                         unsigned Num,
103018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                                         const SourceLocation *Locs);
103118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor
103218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  static ObjCForwardProtocolDecl *Create(ASTContext &C, DeclContext *DC,
103318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                                         SourceLocation L) {
103418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    return Create(C, DC, L, 0, 0, 0);
103518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
103661f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner
103718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::iterator protocol_iterator;
103830833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();}
103930833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  protocol_iterator protocol_end() const { return ReferencedProtocols.end(); }
104018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
104118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  protocol_loc_iterator protocol_loc_begin() const {
104218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    return ReferencedProtocols.loc_begin();
104318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
104418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  protocol_loc_iterator protocol_loc_end() const {
104518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    return ReferencedProtocols.loc_end();
104618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
104718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor
104830833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  unsigned protocol_size() const { return ReferencedProtocols.size(); }
104930833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff
105030833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  /// setProtocolList - Set the list of forward protocols.
105130833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num,
105218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                       const SourceLocation *Locs, ASTContext &C) {
105318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    ReferencedProtocols.set(List, Num, Locs, C);
105430833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  }
105580cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1056a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCForwardProtocolDecl *D) { return true; }
105780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCForwardProtocol; }
1058980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
1059980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
1060a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCCategoryDecl - Represents a category declaration. A category allows
10610c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// you to add methods to an existing class (without subclassing or modifying
10621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// the original class interface or implementation:-). Categories don't allow
10630c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// you to add instance data. The following example adds "myMethod" to all
10640c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// NSView's within a process:
10650c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
10660c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @interface NSView (MyViewMethods)
10670c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - myMethod;
10680c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end
10690c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
107033ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor/// Categories also allow you to split the implementation of a class across
10710c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// several files (a feature more naturally supported in C++).
10720c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
10730c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// Categories were originally inspired by dynamic languages such as Common
10741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Lisp and Smalltalk.  More traditional class-based languages (C++, Java)
10750c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// don't support this level of dynamism, which is both powerful and dangerous.
10760c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
1077e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroffclass ObjCCategoryDecl : public ObjCContainerDecl {
1078980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  /// Interface belonging to this category
1079a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *ClassInterface;
10801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
108168c82cf61228102aba1194efef222fa1478af2a8Chris Lattner  /// referenced protocols in this category.
108218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  ObjCProtocolList ReferencedProtocols;
10831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1084a8ff9f455d94d9609766cfd5186b6e21dc2102f1Chris Lattner  /// Next category belonging to this class.
1085a8ff9f455d94d9609766cfd5186b6e21dc2102f1Chris Lattner  /// FIXME: this should not be a singly-linked list.  Move storage elsewhere.
1086a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCCategoryDecl *NextClassCategory;
10871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1088000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  /// true of class extension has at least one bitfield ivar.
1089000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  bool HasSynthBitfield : 1;
10903db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor
10913db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  /// \brief The location of the category name in this declaration.
10923db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  SourceLocation CategoryNameLoc;
10931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10943db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  ObjCCategoryDecl(DeclContext *DC, SourceLocation AtLoc,
10953db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor                   SourceLocation ClassNameLoc, SourceLocation CategoryNameLoc,
1096955fadbdfecfa24a590febe66a86519096787f2dArgyrios Kyrtzidis                   IdentifierInfo *Id, ObjCInterfaceDecl *IDecl)
10971711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis    : ObjCContainerDecl(ObjCCategory, DC, Id, ClassNameLoc, AtLoc),
1098955fadbdfecfa24a590febe66a86519096787f2dArgyrios Kyrtzidis      ClassInterface(IDecl), NextClassCategory(0), HasSynthBitfield(false),
10991711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis      CategoryNameLoc(CategoryNameLoc) {
1100a906135721c350435319347d2672bbb3bf494f91Chris Lattner  }
110161f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattnerpublic:
11021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1103d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCCategoryDecl *Create(ASTContext &C, DeclContext *DC,
11043db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor                                  SourceLocation AtLoc,
11053db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor                                  SourceLocation ClassNameLoc,
11063db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor                                  SourceLocation CategoryNameLoc,
1107955fadbdfecfa24a590febe66a86519096787f2dArgyrios Kyrtzidis                                  IdentifierInfo *Id,
1108955fadbdfecfa24a590febe66a86519096787f2dArgyrios Kyrtzidis                                  ObjCInterfaceDecl *IDecl);
1109955fadbdfecfa24a590febe66a86519096787f2dArgyrios Kyrtzidis  static ObjCCategoryDecl *Create(ASTContext &C, EmptyShell Empty);
11101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1111e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
1112e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; }
11138a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis
11148a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis  ObjCCategoryImplDecl *getImplementation() const;
11158a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis  void setImplementation(ObjCCategoryImplDecl *ImplD);
11168a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis
111738af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  /// setProtocolList - Set the list of protocols that this interface
1118f7b2c98c16dfb2261ea57d40a1d5bc4738e73175Chris Lattner  /// implements.
111938af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num,
112018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                       const SourceLocation *Locs, ASTContext &C) {
112118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    ReferencedProtocols.set(List, Num, Locs, C);
1122780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  }
11231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
112418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  const ObjCProtocolList &getReferencedProtocols() const {
1125780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner    return ReferencedProtocols;
11268f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian  }
11271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
112818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::iterator protocol_iterator;
1129780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();}
1130780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  protocol_iterator protocol_end() const { return ReferencedProtocols.end(); }
113130833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  unsigned protocol_size() const { return ReferencedProtocols.size(); }
113218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
113318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  protocol_loc_iterator protocol_loc_begin() const {
113418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    return ReferencedProtocols.loc_begin();
113518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
113618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  protocol_loc_iterator protocol_loc_end() const {
113718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    return ReferencedProtocols.loc_end();
113818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
11391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1140a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCCategoryDecl *getNextClassCategory() const { return NextClassCategory; }
11413db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor
114225760611365be23556b32332f8a66ae21ea93ecfFariborz Jahanian  bool IsClassExtension() const { return getIdentifier() == 0; }
114380aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  const ObjCCategoryDecl *getNextClassExtension() const;
114425760611365be23556b32332f8a66ae21ea93ecfFariborz Jahanian
1145000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  bool hasSynthBitfield() const { return HasSynthBitfield; }
1146000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  void setHasSynthBitfield (bool val) { HasSynthBitfield = val; }
1147000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian
11480e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
11490e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  ivar_iterator ivar_begin() const {
11500e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian    return ivar_iterator(decls_begin());
11510e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  }
11520e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  ivar_iterator ivar_end() const {
11530e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian    return ivar_iterator(decls_end());
11540e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  }
11550e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  unsigned ivar_size() const {
11560e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian    return std::distance(ivar_begin(), ivar_end());
11570e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  }
11580e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  bool ivar_empty() const {
11590e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian    return ivar_begin() == ivar_end();
11600e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  }
11613db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor
11623db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  SourceLocation getCategoryNameLoc() const { return CategoryNameLoc; }
11633db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  void setCategoryNameLoc(SourceLocation Loc) { CategoryNameLoc = Loc; }
11643db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor
116580cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1166a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCCategoryDecl *D) { return true; }
116780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCCategory; }
1168955fadbdfecfa24a590febe66a86519096787f2dArgyrios Kyrtzidis
1169955fadbdfecfa24a590febe66a86519096787f2dArgyrios Kyrtzidis  friend class ASTDeclReader;
1170955fadbdfecfa24a590febe66a86519096787f2dArgyrios Kyrtzidis  friend class ASTDeclWriter;
1171980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
11720c6b6243d3efd958c17943130e2a773653511edcSteve Naroff
1173aecae629269fae3bf484baf1d109e9a89d14eeadArgyrios Kyrtzidisclass ObjCImplDecl : public ObjCContainerDecl {
11740d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// Class interface for this class/category implementation
1175a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *ClassInterface;
11761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11773aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattnerprotected:
11781711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis  ObjCImplDecl(Kind DK, DeclContext *DC,
11791711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis               ObjCInterfaceDecl *classInterface,
11801711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis               SourceLocation nameLoc, SourceLocation atStartLoc)
11811711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis    : ObjCContainerDecl(DK, DC,
11821711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                        classInterface? classInterface->getIdentifier() : 0,
11831711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                        nameLoc, atStartLoc),
1184aecae629269fae3bf484baf1d109e9a89d14eeadArgyrios Kyrtzidis      ClassInterface(classInterface) {}
11851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
118675c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattnerpublic:
1187e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; }
1188e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
11898a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis  void setClassInterface(ObjCInterfaceDecl *IFace);
11902c2d43c557beca1b4ba4bd743f33978aecb46a97Douglas Gregor
11911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void addInstanceMethod(ObjCMethodDecl *method) {
11922c2d43c557beca1b4ba4bd743f33978aecb46a97Douglas Gregor    // FIXME: Context should be set correctly before we get here.
1193653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor    method->setLexicalDeclContext(this);
11941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    addDecl(method);
1195e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff  }
11961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void addClassMethod(ObjCMethodDecl *method) {
11972c2d43c557beca1b4ba4bd743f33978aecb46a97Douglas Gregor    // FIXME: Context should be set correctly before we get here.
1198653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor    method->setLexicalDeclContext(this);
11991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    addDecl(method);
120053df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner  }
12011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
120217945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  void addPropertyImplementation(ObjCPropertyImplDecl *property);
12031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
120417945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  ObjCPropertyImplDecl *FindPropertyImplDecl(IdentifierInfo *propertyId) const;
120517945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  ObjCPropertyImplDecl *FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const;
1206653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor
1207653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor  // Iterator access to properties.
1208653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor  typedef specific_decl_iterator<ObjCPropertyImplDecl> propimpl_iterator;
12091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  propimpl_iterator propimpl_begin() const {
121017945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return propimpl_iterator(decls_begin());
1211559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  }
12121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  propimpl_iterator propimpl_end() const {
121317945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return propimpl_iterator(decls_end());
1214559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  }
1215653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor
121680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1217bfb498d0996ef049efe9476f2802976fd145cd60Argyrios Kyrtzidis  static bool classof(const ObjCImplDecl *D) { return true; }
121880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) {
12199a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt    return K >= firstObjCImpl && K <= lastObjCImpl;
122080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  }
12213aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner};
12221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ObjCCategoryImplDecl - An object of this class encapsulates a category
12241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// @implementation declaration. If a category class has declaration of a
12251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// property, its implementation must be specified in the category's
12263aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @implementation declaration. Example:
12273aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @interface I @end
12283aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @interface I(CATEGORY)
12293aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner///    @property int p1, d1;
12303aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @end
12313aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @implementation I(CATEGORY)
12323aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner///  @dynamic p1,d1;
12333aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @end
12343aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner///
12353aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// ObjCCategoryImplDecl
12363aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattnerclass ObjCCategoryImplDecl : public ObjCImplDecl {
12373aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  // Category name
12383aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  IdentifierInfo *Id;
12393aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner
12401711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis  ObjCCategoryImplDecl(DeclContext *DC, IdentifierInfo *Id,
12411711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                       ObjCInterfaceDecl *classInterface,
12421711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                       SourceLocation nameLoc, SourceLocation atStartLoc)
12431711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis    : ObjCImplDecl(ObjCCategoryImpl, DC, classInterface, nameLoc, atStartLoc),
12441711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis      Id(Id) {}
12453aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattnerpublic:
12463aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  static ObjCCategoryImplDecl *Create(ASTContext &C, DeclContext *DC,
12471711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                                      IdentifierInfo *Id,
12481711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                                      ObjCInterfaceDecl *classInterface,
12491711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                                      SourceLocation nameLoc,
12501711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                                      SourceLocation atStartLoc);
12511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12520d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// getIdentifier - Get the identifier that names the category
12533aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  /// interface associated with this implementation.
12540d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// FIXME: This is a bad API, we are overriding the NamedDecl::getIdentifier()
12550d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// to mean something different. For example:
12560d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// ((NamedDecl *)SomeCategoryImplDecl)->getIdentifier()
12570d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// returns the class interface name, whereas
12580d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// ((ObjCCategoryImplDecl *)SomeCategoryImplDecl)->getIdentifier()
12590d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// returns the category name.
12601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  IdentifierInfo *getIdentifier() const {
12611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return Id;
12623aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  }
126310b0e1fa3aabd8877dbbc0df1f2414e04afd5fddDouglas Gregor  void setIdentifier(IdentifierInfo *II) { Id = II; }
12641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12650d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  ObjCCategoryDecl *getCategoryDecl() const;
126610b0e1fa3aabd8877dbbc0df1f2414e04afd5fddDouglas Gregor
1267b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  /// getName - Get the name of identifier for the class interface associated
1268b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  /// with this implementation as a StringRef.
1269b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  //
1270b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  // FIXME: This is a bad API, we are overriding the NamedDecl::getName, to mean
1271b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  // something different.
1272686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getName() const {
1273b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar    return Id ? Id->getNameStart() : "";
1274b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  }
1275b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar
12763aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  /// getNameAsCString - Get the name of identifier for the class
12773aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  /// interface associated with this implementation as a C string
12783aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  /// (const char*).
12797fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar  //
1280b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  // FIXME: Deprecated, move clients to getName().
12813aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  const char *getNameAsCString() const {
12827fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar    return Id ? Id->getNameStart() : "";
12833aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  }
12841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12853aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  /// @brief Get the name of the class associated with this interface.
12867fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar  //
1287b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  // FIXME: Deprecated, move clients to getName().
12883aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  std::string getNameAsString() const {
1289b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar    return getName();
12903aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  }
12911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
129280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1293a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCCategoryImplDecl *D) { return true; }
129480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCCategoryImpl;}
12958f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian};
12968f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian
12978cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattnerraw_ostream &operator<<(raw_ostream &OS,
1298900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer                              const ObjCCategoryImplDecl *CID);
1299900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer
1300a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCImplementationDecl - Represents a class definition - this is where
13010c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// method definitions are specified. For example:
13020c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
130398abf4bd3526a00a0e5cf71a9462c181f97b1c81Fariborz Jahanian/// @code
13040c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @implementation MyClass
13050c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (void)myMethod { /* do something */ }
13060c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end
130798abf4bd3526a00a0e5cf71a9462c181f97b1c81Fariborz Jahanian/// @endcode
13080c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
13091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Typically, instance variables are specified in the class interface,
1310ec0d7a6f4b0699cc9960e6d9fee0f957c64d1cf9Douglas Gregor/// *not* in the implementation. Nevertheless (for legacy reasons), we
131153df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner/// allow instance variables to be specified in the implementation.  When
131253df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner/// specified, they need to be *identical* to the interface.
13130c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
13141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ObjCImplementationDecl : public ObjCImplDecl {
1315980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  /// Implementation Class's super class.
1316a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *SuperClass;
1317e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// Support for ivar initialization.
1318e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// IvarInitializers - The arguments used to initialize the ivars
1319cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt  CXXCtorInitializer **IvarInitializers;
1320e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  unsigned NumIvarInitializers;
1321f85e193739c953358c865005855253af4f68a497John McCall
1322f85e193739c953358c865005855253af4f68a497John McCall  /// true if class has a .cxx_[construct,destruct] method.
1323f85e193739c953358c865005855253af4f68a497John McCall  bool HasCXXStructors : 1;
1324e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian
1325000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  /// true of class extension has at least one bitfield ivar.
1326000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  bool HasSynthBitfield : 1;
1327000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian
13281711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis  ObjCImplementationDecl(DeclContext *DC,
1329a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek                         ObjCInterfaceDecl *classInterface,
13301711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                         ObjCInterfaceDecl *superDecl,
13311711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                         SourceLocation nameLoc, SourceLocation atStartLoc)
13321711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis    : ObjCImplDecl(ObjCImplementation, DC, classInterface, nameLoc, atStartLoc),
1333000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian       SuperClass(superDecl), IvarInitializers(0), NumIvarInitializers(0),
1334f85e193739c953358c865005855253af4f68a497John McCall       HasCXXStructors(false), HasSynthBitfield(false) {}
13351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
13361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static ObjCImplementationDecl *Create(ASTContext &C, DeclContext *DC,
133775c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner                                        ObjCInterfaceDecl *classInterface,
13381711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                                        ObjCInterfaceDecl *superDecl,
13391711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                                        SourceLocation nameLoc,
13401711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                                        SourceLocation atStartLoc);
1341e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian
1342e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// init_iterator - Iterates through the ivar initializer list.
1343cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt  typedef CXXCtorInitializer **init_iterator;
1344e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian
1345e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// init_const_iterator - Iterates through the ivar initializer list.
1346cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt  typedef CXXCtorInitializer * const * init_const_iterator;
1347e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian
1348e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// init_begin() - Retrieve an iterator to the first initializer.
1349e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  init_iterator       init_begin()       { return IvarInitializers; }
1350e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// begin() - Retrieve an iterator to the first initializer.
1351e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  init_const_iterator init_begin() const { return IvarInitializers; }
1352e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian
1353e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// init_end() - Retrieve an iterator past the last initializer.
1354e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  init_iterator       init_end()       {
1355e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian    return IvarInitializers + NumIvarInitializers;
1356e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  }
1357e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// end() - Retrieve an iterator past the last initializer.
1358e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  init_const_iterator init_end() const {
1359e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian    return IvarInitializers + NumIvarInitializers;
1360e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  }
1361e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// getNumArgs - Number of ivars which must be initialized.
1362e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  unsigned getNumIvarInitializers() const {
1363e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian    return NumIvarInitializers;
1364e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  }
1365e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian
1366e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  void setNumIvarInitializers(unsigned numNumIvarInitializers) {
1367e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian    NumIvarInitializers = numNumIvarInitializers;
1368e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  }
1369e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian
1370e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  void setIvarInitializers(ASTContext &C,
1371cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt                           CXXCtorInitializer ** initializers,
1372e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian                           unsigned numInitializers);
1373f85e193739c953358c865005855253af4f68a497John McCall
1374f85e193739c953358c865005855253af4f68a497John McCall  bool hasCXXStructors() const { return HasCXXStructors; }
1375f85e193739c953358c865005855253af4f68a497John McCall  void setHasCXXStructors(bool val) { HasCXXStructors = val; }
1376000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian
1377000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  bool hasSynthBitfield() const { return HasSynthBitfield; }
1378000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  void setHasSynthBitfield (bool val) { HasSynthBitfield = val; }
1379e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian
13804afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  /// getIdentifier - Get the identifier that names the class
13814afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  /// interface associated with this implementation.
13821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  IdentifierInfo *getIdentifier() const {
13831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return getClassInterface()->getIdentifier();
13844afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  }
13854afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor
1386d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  /// getName - Get the name of identifier for the class interface associated
1387d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  /// with this implementation as a StringRef.
1388d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  //
1389d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  // FIXME: This is a bad API, we are overriding the NamedDecl::getName, to mean
1390d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  // something different.
1391686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getName() const {
1392d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar    assert(getIdentifier() && "Name is not a simple identifier");
1393d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar    return getIdentifier()->getName();
1394d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  }
1395d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar
13964afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  /// getNameAsCString - Get the name of identifier for the class
13974afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  /// interface associated with this implementation as a C string
13984afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  /// (const char*).
13997fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar  //
14007fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar  // FIXME: Move to StringRef API.
14014afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  const char *getNameAsCString() const {
1402d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar    return getName().data();
14034afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  }
14044afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor
14054afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  /// @brief Get the name of the class associated with this interface.
14067fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar  //
14077fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar  // FIXME: Move to StringRef API.
14084afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  std::string getNameAsString() const {
1409d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar    return getName();
14104afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  }
14114afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor
1412e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  const ObjCInterfaceDecl *getSuperClass() const { return SuperClass; }
1413e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  ObjCInterfaceDecl *getSuperClass() { return SuperClass; }
14141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1415f3a7af901231535191d14cb524d58f22907ac4d2Chris Lattner  void setSuperClass(ObjCInterfaceDecl * superCls) { SuperClass = superCls; }
14161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14178f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor  typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
14181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ivar_iterator ivar_begin() const {
14191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return ivar_iterator(decls_begin());
14208f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor  }
14211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ivar_iterator ivar_end() const {
142217945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return ivar_iterator(decls_end());
14238f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor  }
14241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  unsigned ivar_size() const {
142517945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return std::distance(ivar_begin(), ivar_end());
14268f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor  }
14271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool ivar_empty() const {
142817945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return ivar_begin() == ivar_end();
14298f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor  }
14301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
143180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1432a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCImplementationDecl *D) { return true; }
143380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCImplementation; }
14349d50c0635fb213b2a1857e3f8488580f0dab2f98Argyrios Kyrtzidis
1435d527cc06d78fe5afa5f20105b51697637eb02c56Sebastian Redl  friend class ASTDeclReader;
14363397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl  friend class ASTDeclWriter;
1437980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
1438243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian
14398cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattnerraw_ostream &operator<<(raw_ostream &OS,
1440900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer                              const ObjCImplementationDecl *ID);
1441900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer
14421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ObjCCompatibleAliasDecl - Represents alias of a class. This alias is
1443243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian/// declared as @compatibility_alias alias class.
14444afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCCompatibleAliasDecl : public NamedDecl {
1445243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian  /// Class that this is an alias of.
1446a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *AliasedClass;
14471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1448d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  ObjCCompatibleAliasDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
1449e8043c39176e7f253fbd92982b077eca6bf2fd59Steve Naroff                          ObjCInterfaceDecl* aliasedClass)
14504afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor    : NamedDecl(ObjCCompatibleAlias, DC, L, Id), AliasedClass(aliasedClass) {}
1451f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattnerpublic:
1452d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCCompatibleAliasDecl *Create(ASTContext &C, DeclContext *DC,
14530ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner                                         SourceLocation L, IdentifierInfo *Id,
1454f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner                                         ObjCInterfaceDecl* aliasedClass);
1455f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner
1456f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner  const ObjCInterfaceDecl *getClassInterface() const { return AliasedClass; }
1457f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner  ObjCInterfaceDecl *getClassInterface() { return AliasedClass; }
145830833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  void setClassInterface(ObjCInterfaceDecl *D) { AliasedClass = D; }
14591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
146080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1461a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCCompatibleAliasDecl *D) { return true; }
146280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCCompatibleAlias; }
14631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1464243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian};
14651de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian
14661de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian/// ObjCPropertyDecl - Represents one property declaration in an interface.
14671de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian/// For example:
14681de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian/// @property (assign, readwrite) int MyProperty;
14691de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian///
14704afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCPropertyDecl : public NamedDecl {
147182a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanianpublic:
1472a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner  enum PropertyAttributeKind {
14731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    OBJC_PR_noattr    = 0x00,
14741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    OBJC_PR_readonly  = 0x01,
1475a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_getter    = 0x02,
14761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    OBJC_PR_assign    = 0x04,
14771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    OBJC_PR_readwrite = 0x08,
1478a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_retain    = 0x10,
14791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    OBJC_PR_copy      = 0x20,
1480a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_nonatomic = 0x40,
148145937ae10a0f70f74508165aab4f2b63e18ea747Fariborz Jahanian    OBJC_PR_setter    = 0x80,
1482f85e193739c953358c865005855253af4f68a497John McCall    OBJC_PR_atomic    = 0x100,
1483f85e193739c953358c865005855253af4f68a497John McCall    OBJC_PR_weak      = 0x200,
1484f85e193739c953358c865005855253af4f68a497John McCall    OBJC_PR_strong    = 0x400,
14859f3480bab8fcb6547978f8ad9e2b8f468e3658eeArgyrios Kyrtzidis    OBJC_PR_unsafe_unretained = 0x800
14869f3480bab8fcb6547978f8ad9e2b8f468e3658eeArgyrios Kyrtzidis    // Adding a property should change NumPropertyAttrsBits
14879f3480bab8fcb6547978f8ad9e2b8f468e3658eeArgyrios Kyrtzidis  };
14880a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis
14899f3480bab8fcb6547978f8ad9e2b8f468e3658eeArgyrios Kyrtzidis  enum {
14900a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis    /// \brief Number of bits fitting all the property attributes.
14919f3480bab8fcb6547978f8ad9e2b8f468e3658eeArgyrios Kyrtzidis    NumPropertyAttrsBits = 12
1492a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner  };
1493af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
14943a02b44e3948f7762dbfba94b7961281ca29d022Fariborz Jahanian  enum SetterKind { Assign, Retain, Copy, Weak };
149546b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  enum PropertyControl { None, Required, Optional };
149682a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanianprivate:
1497d8265b838360578032020757d9a2a84c86457edcFariborz Jahanian  SourceLocation AtLoc;   // location of @property
149883a230c83a54190366138c1a4f4310ef838b88fcJohn McCall  TypeSourceInfo *DeclType;
14999f3480bab8fcb6547978f8ad9e2b8f468e3658eeArgyrios Kyrtzidis  unsigned PropertyAttributes : NumPropertyAttrsBits;
15009f3480bab8fcb6547978f8ad9e2b8f468e3658eeArgyrios Kyrtzidis  unsigned PropertyAttributesAsWritten : NumPropertyAttrsBits;
150146b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  // @required/@optional
150246b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  unsigned PropertyImplementation : 2;
15031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15045251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  Selector GetterName;    // getter name of NULL if no getter
15055251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  Selector SetterName;    // setter name of NULL if no setter
15061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
150733de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  ObjCMethodDecl *GetterMethodDecl; // Declaration of getter instance method
150833de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  ObjCMethodDecl *SetterMethodDecl; // Declaration of setter instance method
1509af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian  ObjCIvarDecl *PropertyIvarDecl;   // Synthesize ivar for this property
151033de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian
15111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ObjCPropertyDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
151283a230c83a54190366138c1a4f4310ef838b88fcJohn McCall                   SourceLocation AtLocation, TypeSourceInfo *T)
1513d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian    : NamedDecl(ObjCProperty, DC, L, Id), AtLoc(AtLocation), DeclType(T),
151480aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian      PropertyAttributes(OBJC_PR_noattr),
151580aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian      PropertyAttributesAsWritten(OBJC_PR_noattr),
151680aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian      PropertyImplementation(None),
15171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      GetterName(Selector()),
151833de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian      SetterName(Selector()),
1519af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian      GetterMethodDecl(0), SetterMethodDecl(0) , PropertyIvarDecl(0) {}
1520f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattnerpublic:
15211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static ObjCPropertyDecl *Create(ASTContext &C, DeclContext *DC,
15221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                  SourceLocation L,
1523d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian                                  IdentifierInfo *Id, SourceLocation AtLocation,
152483a230c83a54190366138c1a4f4310ef838b88fcJohn McCall                                  TypeSourceInfo *T,
152546b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian                                  PropertyControl propControl = None);
1526d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian  SourceLocation getAtLoc() const { return AtLoc; }
1527d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian  void setAtLoc(SourceLocation L) { AtLoc = L; }
1528d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian
152983a230c83a54190366138c1a4f4310ef838b88fcJohn McCall  TypeSourceInfo *getTypeSourceInfo() const { return DeclType; }
153083a230c83a54190366138c1a4f4310ef838b88fcJohn McCall  QualType getType() const { return DeclType->getType(); }
153183a230c83a54190366138c1a4f4310ef838b88fcJohn McCall  void setType(TypeSourceInfo *T) { DeclType = T; }
153270e5a14c6076d63833c62d1d6d628c26309897c1Douglas Gregor
1533a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner  PropertyAttributeKind getPropertyAttributes() const {
1534f4af5154571e0c5eadb19df10e65464766ef6683Chris Lattner    return PropertyAttributeKind(PropertyAttributes);
1535f4af5154571e0c5eadb19df10e65464766ef6683Chris Lattner  }
15361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setPropertyAttributes(PropertyAttributeKind PRVal) {
1537a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    PropertyAttributes |= PRVal;
153882a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian  }
1539394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar
154080aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  PropertyAttributeKind getPropertyAttributesAsWritten() const {
154180aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian    return PropertyAttributeKind(PropertyAttributesAsWritten);
154280aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  }
15430a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis
15440a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis  bool hasWrittenStorageAttribute() const {
15450a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis    return PropertyAttributesAsWritten & (OBJC_PR_assign | OBJC_PR_copy |
15460a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis        OBJC_PR_unsafe_unretained | OBJC_PR_retain | OBJC_PR_strong |
15470a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis        OBJC_PR_weak);
15480a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis  }
154980aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian
155080aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  void setPropertyAttributesAsWritten(PropertyAttributeKind PRVal) {
155180aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian    PropertyAttributesAsWritten = PRVal;
155280aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  }
155380aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian
15548cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian void makeitReadWriteAttribute(void) {
15558cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian    PropertyAttributes &= ~OBJC_PR_readonly;
15568cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian    PropertyAttributes |= OBJC_PR_readwrite;
15571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump }
15588cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian
1559af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  // Helper methods for accessing attributes.
1560af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
1561af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  /// isReadOnly - Return true iff the property has a setter.
1562394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar  bool isReadOnly() const {
1563394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar    return (PropertyAttributes & OBJC_PR_readonly);
1564394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar  }
1565af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
1566265941bc308d65cc270d5c4de5806f37ce405606John McCall  /// isAtomic - Return true if the property is atomic.
1567265941bc308d65cc270d5c4de5806f37ce405606John McCall  bool isAtomic() const {
1568265941bc308d65cc270d5c4de5806f37ce405606John McCall    return (PropertyAttributes & OBJC_PR_atomic);
1569265941bc308d65cc270d5c4de5806f37ce405606John McCall  }
1570265941bc308d65cc270d5c4de5806f37ce405606John McCall
1571265941bc308d65cc270d5c4de5806f37ce405606John McCall  /// isRetaining - Return true if the property retains its value.
1572265941bc308d65cc270d5c4de5806f37ce405606John McCall  bool isRetaining() const {
1573265941bc308d65cc270d5c4de5806f37ce405606John McCall    return (PropertyAttributes &
1574265941bc308d65cc270d5c4de5806f37ce405606John McCall            (OBJC_PR_retain | OBJC_PR_strong | OBJC_PR_copy));
1575265941bc308d65cc270d5c4de5806f37ce405606John McCall  }
1576265941bc308d65cc270d5c4de5806f37ce405606John McCall
1577af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  /// getSetterKind - Return the method used for doing assignment in
1578af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  /// the property setter. This is only valid if the property has been
1579af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  /// defined to have a setter.
1580af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  SetterKind getSetterKind() const {
15816dc6f008994472cf4da321855e8c51c39720f3edJohn McCall    if (PropertyAttributes & OBJC_PR_strong)
15826dc6f008994472cf4da321855e8c51c39720f3edJohn McCall      return getType()->isBlockPointerType() ? Copy : Retain;
15836dc6f008994472cf4da321855e8c51c39720f3edJohn McCall    if (PropertyAttributes & OBJC_PR_retain)
1584af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar      return Retain;
1585af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar    if (PropertyAttributes & OBJC_PR_copy)
1586af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar      return Copy;
15873a02b44e3948f7762dbfba94b7961281ca29d022Fariborz Jahanian    if (PropertyAttributes & OBJC_PR_weak)
15883a02b44e3948f7762dbfba94b7961281ca29d022Fariborz Jahanian      return Weak;
1589af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar    return Assign;
1590af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  }
1591af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
15925251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  Selector getGetterName() const { return GetterName; }
15935251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  void setGetterName(Selector Sel) { GetterName = Sel; }
15941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15955251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  Selector getSetterName() const { return SetterName; }
15965251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  void setSetterName(Selector Sel) { SetterName = Sel; }
15971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
159833de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  ObjCMethodDecl *getGetterMethodDecl() const { return GetterMethodDecl; }
159933de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  void setGetterMethodDecl(ObjCMethodDecl *gDecl) { GetterMethodDecl = gDecl; }
160033de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian
160133de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  ObjCMethodDecl *getSetterMethodDecl() const { return SetterMethodDecl; }
160233de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  void setSetterMethodDecl(ObjCMethodDecl *gDecl) { SetterMethodDecl = gDecl; }
16031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
160446b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  // Related to @optional/@required declared in @protocol
160546b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  void setPropertyImplementation(PropertyControl pc) {
160646b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian    PropertyImplementation = pc;
160746b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  }
160846b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  PropertyControl getPropertyImplementation() const {
160946b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian    return PropertyControl(PropertyImplementation);
16101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
16111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1612af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian  void setPropertyIvarDecl(ObjCIvarDecl *Ivar) {
1613af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian    PropertyIvarDecl = Ivar;
1614af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian  }
1615af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian  ObjCIvarDecl *getPropertyIvarDecl() const {
1616af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian    return PropertyIvarDecl;
1617af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian  }
16181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1619da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor  virtual SourceRange getSourceRange() const {
1620e3c60a7ce9e0f42c7ca2344b33203266aceca1dbDouglas Gregor    return SourceRange(AtLoc, getLocation());
1621e3c60a7ce9e0f42c7ca2344b33203266aceca1dbDouglas Gregor  }
1622e3c60a7ce9e0f42c7ca2344b33203266aceca1dbDouglas Gregor
16239f550ff05d496e6b9480e5619a21d9da0c9e27c1Ted Kremenek  /// Lookup a property by name in the specified DeclContext.
1624de09d0c9694f01a99870a8825266d44a29ebb325Ted Kremenek  static ObjCPropertyDecl *findPropertyDecl(const DeclContext *DC,
16259f550ff05d496e6b9480e5619a21d9da0c9e27c1Ted Kremenek                                            IdentifierInfo *propertyID);
16269f550ff05d496e6b9480e5619a21d9da0c9e27c1Ted Kremenek
162780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1628a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCPropertyDecl *D) { return true; }
162980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCProperty; }
163082a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian};
1631980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
16321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ObjCPropertyImplDecl - Represents implementation declaration of a property
163361d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian/// in a class or category implementation block. For example:
163461d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian/// @synthesize prop1 = ivar1;
163561d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian///
16364afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCPropertyImplDecl : public Decl {
163761d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanianpublic:
16389f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar  enum Kind {
16399f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar    Synthesize,
16409f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar    Dynamic
164161d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  };
164261d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanianprivate:
1643559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  SourceLocation AtLoc;   // location of @synthesize or @dynamic
1644a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor
1645a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  /// \brief For @synthesize, the location of the ivar, if it was written in
1646a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  /// the source code.
1647a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  ///
1648a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  /// \code
1649a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  /// @synthesize int a = b
1650a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  /// \endcode
1651a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  SourceLocation IvarLoc;
1652a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor
165361d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  /// Property declaration being implemented
165461d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  ObjCPropertyDecl *PropertyDecl;
1655be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek
165661d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  /// Null for @dynamic. Required for @synthesize.
165761d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  ObjCIvarDecl *PropertyIvarDecl;
165817cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian
165917cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  /// Null for @dynamic. Non-null if property must be copy-constructed in getter
166017cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  Expr *GetterCXXConstructor;
166117cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian
166217cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  /// Null for @dynamic. Non-null if property has assignment operator to call
166317cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  /// in Setter synthesis.
166417cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  Expr *SetterCXXAssignment;
1665be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek
1666d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  ObjCPropertyImplDecl(DeclContext *DC, SourceLocation atLoc, SourceLocation L,
16671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                       ObjCPropertyDecl *property,
16681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                       Kind PK,
1669a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor                       ObjCIvarDecl *ivarDecl,
1670a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor                       SourceLocation ivarLoc)
16711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : Decl(ObjCPropertyImpl, DC, L), AtLoc(atLoc),
1672a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor      IvarLoc(ivarLoc), PropertyDecl(property), PropertyIvarDecl(ivarDecl),
167317cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian      GetterCXXConstructor(0), SetterCXXAssignment(0) {
16749f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar    assert (PK == Dynamic || PropertyIvarDecl);
16759f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar  }
16761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16779f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbarpublic:
1678d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCPropertyImplDecl *Create(ASTContext &C, DeclContext *DC,
16791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                      SourceLocation atLoc, SourceLocation L,
16801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                      ObjCPropertyDecl *property,
16811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                      Kind PK,
1682a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor                                      ObjCIvarDecl *ivarDecl,
1683a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor                                      SourceLocation ivarLoc);
168461d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian
1685da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor  virtual SourceRange getSourceRange() const;
1686a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor
1687d40910b581b09c937a8c1fdcde9b8ec724398fb9Steve Naroff  SourceLocation getLocStart() const { return AtLoc; }
16888818c4fb69cb2a4eec94b217a90f94f9e075296eDouglas Gregor  void setAtLoc(SourceLocation Loc) { AtLoc = Loc; }
1689d40910b581b09c937a8c1fdcde9b8ec724398fb9Steve Naroff
1690be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek  ObjCPropertyDecl *getPropertyDecl() const {
1691be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek    return PropertyDecl;
1692be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek  }
16938818c4fb69cb2a4eec94b217a90f94f9e075296eDouglas Gregor  void setPropertyDecl(ObjCPropertyDecl *Prop) { PropertyDecl = Prop; }
16948818c4fb69cb2a4eec94b217a90f94f9e075296eDouglas Gregor
16959f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar  Kind getPropertyImplementation() const {
16969f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar    return PropertyIvarDecl ? Synthesize : Dynamic;
1697be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek  }
16981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1699af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  ObjCIvarDecl *getPropertyIvarDecl() const {
1700be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek    return PropertyIvarDecl;
1701be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek  }
1702a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  SourceLocation getPropertyIvarDeclLoc() const { return IvarLoc; }
1703a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor
1704a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  void setPropertyIvarDecl(ObjCIvarDecl *Ivar,
1705a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor                           SourceLocation IvarLoc) {
1706a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor    PropertyIvarDecl = Ivar;
1707a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor    this->IvarLoc = IvarLoc;
1708a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  }
170917cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian
171017cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  Expr *getGetterCXXConstructor() const {
171117cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian    return GetterCXXConstructor;
171217cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  }
171317cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  void setGetterCXXConstructor(Expr *getterCXXConstructor) {
171417cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian    GetterCXXConstructor = getterCXXConstructor;
171517cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  }
17168818c4fb69cb2a4eec94b217a90f94f9e075296eDouglas Gregor
171717cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  Expr *getSetterCXXAssignment() const {
171817cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian    return SetterCXXAssignment;
171917cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  }
172017cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  void setSetterCXXAssignment(Expr *setterCXXAssignment) {
172117cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian    SetterCXXAssignment = setterCXXAssignment;
172217cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  }
172317cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian
172480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
17251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const ObjCPropertyImplDecl *D) { return true; }
172680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Decl::Kind K) { return K == ObjCPropertyImpl; }
1727a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor
1728a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  friend class ASTDeclReader;
172961d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian};
173061d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian
1731980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff}  // end namespace clang
1732980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff#endif
1733