DeclObjC.h revision 0982205bade2fb4fc984c27b2ab401e683963b10
1980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff//===--- DeclObjC.h - Classes for representing declarations -----*- C++ -*-===//
2980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff//
3980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff//                     The LLVM Compiler Infrastructure
4980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff//
50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source
60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details.
7980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff//
8980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff//===----------------------------------------------------------------------===//
9980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff//
10980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff//  This file defines the DeclObjC interface and subclasses.
11980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff//
12980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff//===----------------------------------------------------------------------===//
13980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
14980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff#ifndef LLVM_CLANG_AST_DECLOBJC_H
15980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff#define LLVM_CLANG_AST_DECLOBJC_H
16980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
17980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff#include "clang/AST/Decl.h"
18491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis#include "clang/AST/SelectorLocationsKind.h"
196ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson#include "llvm/ADT/STLExtras.h"
20aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar#include "llvm/Support/Compiler.h"
21980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
22980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffnamespace clang {
23980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffclass Expr;
24980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffclass Stmt;
25980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffclass FunctionDecl;
2660f8c868ffb346b78451a3eccaecd0461d2ae498Fariborz Jahanianclass RecordDecl;
27a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCIvarDecl;
28a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCMethodDecl;
29a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCProtocolDecl;
30a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCCategoryDecl;
31a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCPropertyDecl;
32f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanianclass ObjCPropertyImplDecl;
33cbb67480094b3bcb5b715acd827cbad55e2a204cSean Huntclass CXXCtorInitializer;
3468835718c4125f2f66740cd04de7088645ec695dChris Lattner
35793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnerclass ObjCListBase {
36793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  void operator=(const ObjCListBase &);     // DO NOT IMPLEMENT
37793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  ObjCListBase(const ObjCListBase&);        // DO NOT IMPLEMENT
38793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnerprotected:
39793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  /// List is an array of pointers to objects that are not owned by this object.
40793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  void **List;
413db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  unsigned NumElts;
42793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner
433db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattnerpublic:
44793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  ObjCListBase() : List(0), NumElts(0) {}
45793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  unsigned size() const { return NumElts; }
46793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  bool empty() const { return NumElts == 0; }
471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
48793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnerprotected:
4938af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  void set(void *const* InList, unsigned Elts, ASTContext &Ctx);
50793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner};
511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
53793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner/// ObjCList - This is a simple template class used to hold various lists of
54793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner/// decls etc, which is heavily used by the ObjC front-end.  This only use case
55793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner/// this supports is setting the list all at once and then reading elements out
56793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner/// of it.
57793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnertemplate <typename T>
58793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnerclass ObjCList : public ObjCListBase {
59793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnerpublic:
6038af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  void set(T* const* InList, unsigned Elts, ASTContext &Ctx) {
6138af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner    ObjCListBase::set(reinterpret_cast<void*const*>(InList), Elts, Ctx);
62793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  }
631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
64793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  typedef T* const * iterator;
65793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  iterator begin() const { return (iterator)List; }
66793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  iterator end() const { return (iterator)List+NumElts; }
671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
68793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  T* operator[](unsigned Idx) const {
69793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner    assert(Idx < NumElts && "Invalid access");
70793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner    return (T*)List[Idx];
713db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  }
723db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner};
733db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner
7418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor/// \brief A list of Objective-C protocols, along with the source
7518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor/// locations at which they were referenced.
7618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregorclass ObjCProtocolList : public ObjCList<ObjCProtocolDecl> {
7718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  SourceLocation *Locations;
7818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor
7918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  using ObjCList<ObjCProtocolDecl>::set;
8018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor
8118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregorpublic:
8218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  ObjCProtocolList() : ObjCList<ObjCProtocolDecl>(), Locations(0) { }
8318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor
8418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef const SourceLocation *loc_iterator;
8518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  loc_iterator loc_begin() const { return Locations; }
8618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  loc_iterator loc_end() const { return Locations + size(); }
8718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor
88ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  void set(ObjCProtocolDecl* const* InList, unsigned Elts,
8918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor           const SourceLocation *Locs, ASTContext &Ctx);
9018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor};
911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff
93a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCMethodDecl - Represents an instance or class method declaration.
9458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// ObjC methods can be declared within 4 contexts: class interfaces,
9558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// categories, protocols, and class implementations. While C++ member
961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// functions leverage C syntax, Objective-C method syntax is modeled after
971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Smalltalk (using colons to specify argument types/expressions).
9858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Here are some brief examples:
9958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff///
10058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Setter/getter instance methods:
10158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// - (void)setMenu:(NSMenu *)menu;
1021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// - (NSMenu *)menu;
1031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
10458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Instance method that takes 2 NSView arguments:
10558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// - (void)replaceSubview:(NSView *)oldView with:(NSView *)newView;
10658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff///
10758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Getter class method:
10858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// + (NSMenu *)defaultMenu;
10958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff///
11058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// A selector represents a unique name for a method. The selector names for
11158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// the above methods are setMenu:, menu, replaceSubview:with:, and defaultMenu.
11258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff///
1134afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCMethodDecl : public NamedDecl, public DeclContext {
11458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroffpublic:
11558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  enum ImplementationControl { None, Required, Optional };
11658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroffprivate:
11785f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  // The conventional meaning of this method; an ObjCMethodFamily.
11885f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  // This is not serialized; instead, it is computed on demand and
11985f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  // cached.
12085f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  mutable unsigned Family : ObjCMethodFamilyBitWidth;
12185f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall
12258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  /// instance (true) or class (false) method.
12385f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  unsigned IsInstance : 1;
12485f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  unsigned IsVariadic : 1;
1251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1264607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian  // Synthesized declaration method for a property setter/getter
12785f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  unsigned IsSynthesized : 1;
128ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1293fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian  // Method has a definition.
13085f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  unsigned IsDefined : 1;
1311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13272b2625aa67c8213acaf4bf6209b67859d60e2cfArgyrios Kyrtzidis  /// \brief Method redeclaration in the same interface.
1333a919e7110407ae7609bb6edc57aac16a5990661Argyrios Kyrtzidis  unsigned IsRedeclaration : 1;
1343a919e7110407ae7609bb6edc57aac16a5990661Argyrios Kyrtzidis
13572b2625aa67c8213acaf4bf6209b67859d60e2cfArgyrios Kyrtzidis  /// \brief Is redeclared in the same interface.
13672b2625aa67c8213acaf4bf6209b67859d60e2cfArgyrios Kyrtzidis  mutable unsigned HasRedeclaration : 1;
13772b2625aa67c8213acaf4bf6209b67859d60e2cfArgyrios Kyrtzidis
138ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  // NOTE: VC++ treats enums as signed, avoid using ImplementationControl enum
13941c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  /// \@required/\@optional
140ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  unsigned DeclImplementation : 2;
1411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
142ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  // NOTE: VC++ treats enums as signed, avoid using the ObjCDeclQualifier enum
14358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  /// in, inout, etc.
144ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  unsigned objcDeclQualifier : 6;
1451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
146926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor  /// \brief Indicates whether this method has a related result type.
147926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor  unsigned RelatedResultType : 1;
148ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
149491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// \brief Whether the locations of the selector identifiers are in a
150491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// "standard" position, a enum SelectorLocationsKind.
151491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  unsigned SelLocsKind : 2;
1527732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian
153e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis  /// \brief Whether this method overrides any other in the class hierarchy.
154e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis  ///
155e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis  /// A method is said to override any method in the class's
156e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis  /// base classes, its protocols, or its categories' protocols, that has
157e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis  /// the same selector and is of the same kind (class or instance).
158e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis  /// A method in an implementation is not considered as overriding the same
159e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis  /// method in the interface or its categories.
160e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis  unsigned IsOverriding : 1;
161e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis
1624bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor  // Result type of this method.
16358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  QualType MethodDeclType;
164ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1654bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor  // Type source information for the result type.
1664bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor  TypeSourceInfo *ResultTInfo;
1674bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor
168491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// \brief Array of ParmVarDecls for the formal parameters of this method
169491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// and optionally followed by selector locations.
170491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  void *ParamsAndSelLocs;
171491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  unsigned NumParams;
1721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  /// List of attributes for this method declaration.
174a2e85ada1dfef36201a31f6646bc4ea3bd76a89aArgyrios Kyrtzidis  SourceLocation EndLoc; // the location of the ';' or '}'.
1751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  // The following are only used for method definitions, null otherwise.
17758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  // FIXME: space savings opportunity, consider a sub-class.
17858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  Stmt *Body;
179451318c08a6342c10b8986060386fd9274418437Daniel Dunbar
180451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// SelfDecl - Decl for the implicit self parameter. This is lazily
181451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// constructed by createImplicitParams.
1824111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  ImplicitParamDecl *SelfDecl;
183451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// CmdDecl - Decl for the implicit _cmd parameter. This is lazily
184451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// constructed by createImplicitParams.
1854111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  ImplicitParamDecl *CmdDecl;
1861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
187491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  SelectorLocationsKind getSelLocsKind() const {
188491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    return (SelectorLocationsKind)SelLocsKind;
189491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  }
190491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  bool hasStandardSelLocs() const {
191491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    return getSelLocsKind() != SelLoc_NonStandard;
192491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  }
193491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis
194491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// \brief Get a pointer to the stored selector identifiers locations array.
195491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// No locations will be stored if HasStandardSelLocs is true.
196491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  SourceLocation *getStoredSelLocs() {
197491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    return reinterpret_cast<SourceLocation*>(getParams() + NumParams);
198491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  }
199491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  const SourceLocation *getStoredSelLocs() const {
200491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    return reinterpret_cast<const SourceLocation*>(getParams() + NumParams);
201491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  }
202491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis
203491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// \brief Get a pointer to the stored selector identifiers locations array.
204491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// No locations will be stored if HasStandardSelLocs is true.
205491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  ParmVarDecl **getParams() {
206491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    return reinterpret_cast<ParmVarDecl **>(ParamsAndSelLocs);
207491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  }
208491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  const ParmVarDecl *const *getParams() const {
209491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    return reinterpret_cast<const ParmVarDecl *const *>(ParamsAndSelLocs);
210491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  }
211491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis
212491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// \brief Get the number of stored selector identifiers locations.
213491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  /// No locations will be stored if HasStandardSelLocs is true.
214491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  unsigned getNumStoredSelLocs() const {
215491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    if (hasStandardSelLocs())
216491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis      return 0;
217491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    return getNumSelectorLocs();
218491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  }
219491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis
220491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  void setParamsAndSelLocs(ASTContext &C,
221491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis                           ArrayRef<ParmVarDecl*> Params,
222491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis                           ArrayRef<SourceLocation> SelLocs);
223491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis
224a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCMethodDecl(SourceLocation beginLoc, SourceLocation endLoc,
22558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff                 Selector SelInfo, QualType T,
2264bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor                 TypeSourceInfo *ResultTInfo,
2270701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff                 DeclContext *contextDecl,
228f6414927e67e27d9324d8d179c5f7ea620443924Daniel Dunbar                 bool isInstance = true,
22958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff                 bool isVariadic = false,
2304607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian                 bool isSynthesized = false,
23175cf3e86d33ce810c12084126385371b335c30baArgyrios Kyrtzidis                 bool isImplicitlyDeclared = false,
2323fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian                 bool isDefined = false,
2337732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian                 ImplementationControl impControl = None,
234da92a7f91cf88f49e02050919676f7fb8e3bdff8Argyrios Kyrtzidis                 bool HasRelatedResultType = false)
2354afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  : NamedDecl(ObjCMethod, contextDecl, beginLoc, SelInfo),
23685f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall    DeclContext(ObjCMethod), Family(InvalidObjCMethodFamily),
23758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff    IsInstance(isInstance), IsVariadic(isVariadic),
2384607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian    IsSynthesized(isSynthesized),
23972b2625aa67c8213acaf4bf6209b67859d60e2cfArgyrios Kyrtzidis    IsDefined(isDefined), IsRedeclaration(0), HasRedeclaration(0),
24058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff    DeclImplementation(impControl), objcDeclQualifier(OBJC_TQ_None),
241da92a7f91cf88f49e02050919676f7fb8e3bdff8Argyrios Kyrtzidis    RelatedResultType(HasRelatedResultType),
242e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis    SelLocsKind(SelLoc_StandardNoSpace), IsOverriding(0),
243926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor    MethodDeclType(T), ResultTInfo(ResultTInfo),
244491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    ParamsAndSelLocs(0), NumParams(0),
24575cf3e86d33ce810c12084126385371b335c30baArgyrios Kyrtzidis    EndLoc(endLoc), Body(0), SelfDecl(0), CmdDecl(0) {
24675cf3e86d33ce810c12084126385371b335c30baArgyrios Kyrtzidis    setImplicit(isImplicitlyDeclared);
24775cf3e86d33ce810c12084126385371b335c30baArgyrios Kyrtzidis  }
2488a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek
24957ea6bee79cc60ba20c7886b453f40f380dce1b1Argyrios Kyrtzidis  /// \brief A definition will return its interface declaration.
25057ea6bee79cc60ba20c7886b453f40f380dce1b1Argyrios Kyrtzidis  /// An interface declaration will return its definition.
25157ea6bee79cc60ba20c7886b453f40f380dce1b1Argyrios Kyrtzidis  /// Otherwise it will return itself.
252da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor  virtual ObjCMethodDecl *getNextRedeclaration();
253da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor
2546c4ae5de0c356777446f823b573821fb95560d91Chris Lattnerpublic:
2550ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner  static ObjCMethodDecl *Create(ASTContext &C,
2561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                SourceLocation beginLoc,
25711d77169555480ee0a04c6e5bc390d8fde41175dArgyrios Kyrtzidis                                SourceLocation endLoc,
25811d77169555480ee0a04c6e5bc390d8fde41175dArgyrios Kyrtzidis                                Selector SelInfo,
259ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                QualType T,
2604bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor                                TypeSourceInfo *ResultTInfo,
2614bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor                                DeclContext *contextDecl,
262f6414927e67e27d9324d8d179c5f7ea620443924Daniel Dunbar                                bool isInstance = true,
2636c4ae5de0c356777446f823b573821fb95560d91Chris Lattner                                bool isVariadic = false,
2644607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian                                bool isSynthesized = false,
26575cf3e86d33ce810c12084126385371b335c30baArgyrios Kyrtzidis                                bool isImplicitlyDeclared = false,
2663fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian                                bool isDefined = false,
2677732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian                                ImplementationControl impControl = None,
268da92a7f91cf88f49e02050919676f7fb8e3bdff8Argyrios Kyrtzidis                                bool HasRelatedResultType = false);
269e7f9d301a10b4b3223e91d9be4362b44cba0a212Argyrios Kyrtzidis
2701e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor  static ObjCMethodDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2711e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor
272da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor  virtual ObjCMethodDecl *getCanonicalDecl();
27313e635c55eb23f736d38abf9c954801bd6482db4Ted Kremenek  const ObjCMethodDecl *getCanonicalDecl() const {
27413e635c55eb23f736d38abf9c954801bd6482db4Ted Kremenek    return const_cast<ObjCMethodDecl*>(this)->getCanonicalDecl();
27513e635c55eb23f736d38abf9c954801bd6482db4Ted Kremenek  }
276e7f9d301a10b4b3223e91d9be4362b44cba0a212Argyrios Kyrtzidis
277ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  ObjCDeclQualifier getObjCDeclQualifier() const {
278ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek    return ObjCDeclQualifier(objcDeclQualifier);
279ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  }
280a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void setObjCDeclQualifier(ObjCDeclQualifier QV) { objcDeclQualifier = QV; }
2811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
282926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor  /// \brief Determine whether this method has a result type that is related
283926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor  /// to the message receiver's type.
284926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor  bool hasRelatedResultType() const { return RelatedResultType; }
285ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
286926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor  /// \brief Note whether this method has a related result type.
287926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor  void SetRelatedResultType(bool RRT = true) { RelatedResultType = RRT; }
2883a919e7110407ae7609bb6edc57aac16a5990661Argyrios Kyrtzidis
2893a919e7110407ae7609bb6edc57aac16a5990661Argyrios Kyrtzidis  /// \brief True if this is a method redeclaration in the same interface.
2903a919e7110407ae7609bb6edc57aac16a5990661Argyrios Kyrtzidis  bool isRedeclaration() const { return IsRedeclaration; }
2913a919e7110407ae7609bb6edc57aac16a5990661Argyrios Kyrtzidis  void setAsRedeclaration(const ObjCMethodDecl *PrevMethod);
292ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
29358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  // Location information, modeled after the Stmt API.
294aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceLocation getLocStart() const LLVM_READONLY { return getLocation(); }
295aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceLocation getLocEnd() const LLVM_READONLY { return EndLoc; }
29653c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setEndLoc(SourceLocation Loc) { EndLoc = Loc; }
297aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  virtual SourceRange getSourceRange() const LLVM_READONLY {
2981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(getLocation(), EndLoc);
2999776ba0d844cf9f6888e871e3fd246ae782f76f4Daniel Dunbar  }
3001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
301746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis  SourceLocation getSelectorStartLoc() const {
302746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis    if (isImplicit())
303746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis      return getLocStart();
304746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis    return getSelectorLoc(0);
305746f5bcbfde5b25269169c63c66492311673b67dArgyrios Kyrtzidis  }
306491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  SourceLocation getSelectorLoc(unsigned Index) const {
307491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    assert(Index < getNumSelectorLocs() && "Index out of range!");
308491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    if (hasStandardSelLocs())
309491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis      return getStandardSelectorLoc(Index, getSelector(),
310491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis                                   getSelLocsKind() == SelLoc_StandardWithSpace,
311491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis                      llvm::makeArrayRef(const_cast<ParmVarDecl**>(getParams()),
312491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis                                         NumParams),
313491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis                                   EndLoc);
314491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    return getStoredSelLocs()[Index];
315491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  }
316491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis
317491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  void getSelectorLocs(SmallVectorImpl<SourceLocation> &SelLocs) const;
318491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis
319491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  unsigned getNumSelectorLocs() const {
320491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    if (isImplicit())
321491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis      return 0;
322491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    Selector Sel = getSelector();
323491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    if (Sel.isUnarySelector())
324491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis      return 1;
325491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis    return Sel.getNumArgs();
326491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  }
327491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis
3285619688510185081cbb4621d703daf7ee24cf39aChris Lattner  ObjCInterfaceDecl *getClassInterface();
3295619688510185081cbb4621d703daf7ee24cf39aChris Lattner  const ObjCInterfaceDecl *getClassInterface() const {
3305619688510185081cbb4621d703daf7ee24cf39aChris Lattner    return const_cast<ObjCMethodDecl*>(this)->getClassInterface();
331e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  }
3321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3332e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  Selector getSelector() const { return getDeclName().getObjCSelector(); }
3343a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson
33558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  QualType getResultType() const { return MethodDeclType; }
33653c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setResultType(QualType T) { MethodDeclType = T; }
3371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
338ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Determine the type of an expression that sends a message to this
3395291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// function.
3405291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  QualType getSendResultType() const {
3416398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor    return getResultType().getNonLValueExprType(getASTContext());
3425291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  }
343ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3444bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor  TypeSourceInfo *getResultTypeSourceInfo() const { return ResultTInfo; }
3454bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor  void setResultTypeSourceInfo(TypeSourceInfo *TInfo) { ResultTInfo = TInfo; }
3464bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor
347d57f635d520e8cb5b93d3d770ff58db06c62de54Chris Lattner  // Iterator access to formal parameters.
348491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  unsigned param_size() const { return NumParams; }
349491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  typedef const ParmVarDecl *const *param_const_iterator;
350491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  typedef ParmVarDecl *const *param_iterator;
351491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  param_const_iterator param_begin() const { return getParams(); }
352491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  param_const_iterator param_end() const { return getParams() + NumParams; }
353491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  param_iterator param_begin() { return getParams(); }
354491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  param_iterator param_end() { return getParams() + NumParams; }
3557732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian  // This method returns and of the parameters which are part of the selector
3567732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian  // name mangling requirements.
357ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  param_const_iterator sel_param_end() const {
358ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return param_begin() + getSelector().getNumArgs();
3597732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian  }
36089951a86b594513c2a013532ed45d197413b1087Chris Lattner
3619dd0065e61ea4b48b19eee550704ce964e64e946Argyrios Kyrtzidis  /// \brief Sets the method's parameters and selector source locations.
3629dd0065e61ea4b48b19eee550704ce964e64e946Argyrios Kyrtzidis  /// If the method is implicit (not coming from source) \arg SelLocs is
3639dd0065e61ea4b48b19eee550704ce964e64e946Argyrios Kyrtzidis  /// ignored.
364491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  void setMethodParams(ASTContext &C,
365491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis                       ArrayRef<ParmVarDecl*> Params,
3669dd0065e61ea4b48b19eee550704ce964e64e946Argyrios Kyrtzidis                       ArrayRef<SourceLocation> SelLocs =
3679dd0065e61ea4b48b19eee550704ce964e64e946Argyrios Kyrtzidis                           ArrayRef<SourceLocation>());
3684111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner
3696ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson  // Iterator access to parameter types.
3706ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson  typedef std::const_mem_fun_t<QualType, ParmVarDecl> deref_fun;
371491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  typedef llvm::mapped_iterator<param_const_iterator, deref_fun>
372491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis      arg_type_iterator;
3736ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson
3746ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson  arg_type_iterator arg_type_begin() const {
3756ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson    return llvm::map_iterator(param_begin(), deref_fun(&ParmVarDecl::getType));
3766ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson  }
3776ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson  arg_type_iterator arg_type_end() const {
3786ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson    return llvm::map_iterator(param_end(), deref_fun(&ParmVarDecl::getType));
3796ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson  }
3801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
381451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// createImplicitParams - Used to lazily create the self and cmd
382451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// implict parameters. This must be called prior to using getSelfDecl()
383451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// or getCmdDecl(). The call is ignored if the implicit paramters
384451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// have already been created.
385fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian  void createImplicitParams(ASTContext &Context, const ObjCInterfaceDecl *ID);
386451318c08a6342c10b8986060386fd9274418437Daniel Dunbar
3874111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  ImplicitParamDecl * getSelfDecl() const { return SelfDecl; }
38853c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setSelfDecl(ImplicitParamDecl *SD) { SelfDecl = SD; }
3894111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  ImplicitParamDecl * getCmdDecl() const { return CmdDecl; }
39053c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setCmdDecl(ImplicitParamDecl *CD) { CmdDecl = CD; }
3911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
39285f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  /// Determines the family of this method.
39385f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall  ObjCMethodFamily getMethodFamily() const;
39485f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall
395f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor  bool isInstanceMethod() const { return IsInstance; }
39653c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setInstanceMethod(bool isInst) { IsInstance = isInst; }
39758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  bool isVariadic() const { return IsVariadic; }
39853c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setVariadic(bool isVar) { IsVariadic = isVar; }
3991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
400f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor  bool isClassMethod() const { return !IsInstance; }
401f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor
4024607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian  bool isSynthesized() const { return IsSynthesized; }
40353c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setSynthesized(bool isSynth) { IsSynthesized = isSynth; }
404ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
4053fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian  bool isDefined() const { return IsDefined; }
4063fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian  void setDefined(bool isDefined) { IsDefined = isDefined; }
4071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
408e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis  /// \brief Whether this method overrides any other in the class hierarchy.
409e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis  ///
410e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis  /// A method is said to override any method in the class's
411e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis  /// base classes, its protocols, or its categories' protocols, that has
412e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis  /// the same selector and is of the same kind (class or instance).
413e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis  /// A method in an implementation is not considered as overriding the same
414e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis  /// method in the interface or its categories.
415e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis  bool isOverriding() const { return IsOverriding; }
416e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis  void setOverriding(bool isOverriding) { IsOverriding = isOverriding; }
417e15db6f0d226a3bc88d244512d1004c7c1c07391Argyrios Kyrtzidis
41841c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  // Related to protocols declared in  \@protocol
4191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setDeclImplementation(ImplementationControl ic) {
4201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    DeclImplementation = ic;
42158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  }
4221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ImplementationControl getImplementationControl() const {
4231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return ImplementationControl(DeclImplementation);
42458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  }
425792481eec23d8c1aa92173be589e2ae9d02514a5Ted Kremenek
426da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor  virtual Stmt *getBody() const {
4271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return (Stmt*) Body;
4287297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor  }
4296fb0aee4f9dc261bbec72e1283ad8dc0557a6d96Argyrios Kyrtzidis  CompoundStmt *getCompoundBody() { return (CompoundStmt*)Body; }
430d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl  void setBody(Stmt *B) { Body = B; }
43158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff
43266570b230941651245accbc5680b60e904eb993cArgyrios Kyrtzidis  /// \brief Returns whether this specific method is a definition.
43366570b230941651245accbc5680b60e904eb993cArgyrios Kyrtzidis  bool isThisDeclarationADefinition() const { return Body; }
43466570b230941651245accbc5680b60e904eb993cArgyrios Kyrtzidis
43558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  // Implement isa/cast/dyncast/etc.
43680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
437a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCMethodDecl *D) { return true; }
43880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCMethod; }
43942220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  static DeclContext *castToDeclContext(const ObjCMethodDecl *D) {
44042220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis    return static_cast<DeclContext *>(const_cast<ObjCMethodDecl*>(D));
44142220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  }
44242220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  static ObjCMethodDecl *castFromDeclContext(const DeclContext *DC) {
44342220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis    return static_cast<ObjCMethodDecl *>(const_cast<DeclContext*>(DC));
44442220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  }
445491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis
446491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  friend class ASTDeclReader;
447491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis  friend class ASTDeclWriter;
44858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff};
449e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
450e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff/// ObjCContainerDecl - Represents a container for method declarations.
451aecae629269fae3bf484baf1d109e9a89d14eeadArgyrios Kyrtzidis/// Current sub-classes are ObjCInterfaceDecl, ObjCCategoryDecl,
4521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ObjCProtocolDecl, and ObjCImplDecl.
453e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff///
4544afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCContainerDecl : public NamedDecl, public DeclContext {
45599ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
45699ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie
4571711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis  SourceLocation AtStart;
4581711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis
459782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  // These two locations in the range mark the end of the method container.
460782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  // The first points to the '@' token, and the second to the 'end' token.
461782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  SourceRange AtEnd;
462e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroffpublic:
463e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
4641711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis  ObjCContainerDecl(Kind DK, DeclContext *DC,
4651711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                    IdentifierInfo *Id, SourceLocation nameLoc,
4661711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                    SourceLocation atStartLoc)
4671711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis    : NamedDecl(DK, DC, nameLoc, Id), DeclContext(DK), AtStart(atStartLoc) {}
468e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
46993983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff  // Iterator access to properties.
47093983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff  typedef specific_decl_iterator<ObjCPropertyDecl> prop_iterator;
4711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  prop_iterator prop_begin() const {
47217945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return prop_iterator(decls_begin());
47393983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff  }
4741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  prop_iterator prop_end() const {
47517945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return prop_iterator(decls_end());
47609c4719788a5cea09897525e528fa00420f1677bSteve Naroff  }
4771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4780701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  // Iterator access to instance/class methods.
479f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor  typedef specific_decl_iterator<ObjCMethodDecl> method_iterator;
4801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  method_iterator meth_begin() const {
48117945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return method_iterator(decls_begin());
4827ed4faca5162b3ab85be7f7e57aa40e6ec170971Ted Kremenek  }
4831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  method_iterator meth_end() const {
48417945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return method_iterator(decls_end());
4857ed4faca5162b3ab85be7f7e57aa40e6ec170971Ted Kremenek  }
4860701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
4871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  typedef filtered_decl_iterator<ObjCMethodDecl,
4881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                 &ObjCMethodDecl::isInstanceMethod>
489669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor    instmeth_iterator;
49017945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  instmeth_iterator instmeth_begin() const {
49117945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return instmeth_iterator(decls_begin());
492e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff  }
49317945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  instmeth_iterator instmeth_end() const {
49417945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return instmeth_iterator(decls_end());
495e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff  }
496e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
4971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  typedef filtered_decl_iterator<ObjCMethodDecl,
4981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                 &ObjCMethodDecl::isClassMethod>
499669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor    classmeth_iterator;
50017945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  classmeth_iterator classmeth_begin() const {
50117945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return classmeth_iterator(decls_begin());
502e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff  }
50317945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  classmeth_iterator classmeth_end() const {
50417945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return classmeth_iterator(decls_end());
5050701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  }
5060701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
5070701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  // Get the local instance/class method declared in this interface.
508467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis  ObjCMethodDecl *getMethod(Selector Sel, bool isInstance) const;
509467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis  ObjCMethodDecl *getInstanceMethod(Selector Sel) const {
510467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis    return getMethod(Sel, true/*isInstance*/);
51153df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner  }
512467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis  ObjCMethodDecl *getClassMethod(Selector Sel) const {
513467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis    return getMethod(Sel, false/*isInstance*/);
514467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis  }
515467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis  ObjCIvarDecl *getIvarDecl(IdentifierInfo *Id) const;
5161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
51717945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  ObjCPropertyDecl *FindPropertyDeclaration(IdentifierInfo *PropertyId) const;
51893983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff
5191711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis  SourceLocation getAtStartLoc() const { return AtStart; }
5201711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis  void setAtStartLoc(SourceLocation Loc) { AtStart = Loc; }
5211711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis
522e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff  // Marks the end of the container.
523782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  SourceRange getAtEndRange() const {
524782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek    return AtEnd;
525782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  }
526782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  void setAtEndRange(SourceRange atEnd) {
527782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek    AtEnd = atEnd;
528782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  }
529ddfd4c9eda34765b08fae4cb31ad5a365face107Argyrios Kyrtzidis
530aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  virtual SourceRange getSourceRange() const LLVM_READONLY {
5311711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis    return SourceRange(AtStart, getAtEndRange().getEnd());
532ddfd4c9eda34765b08fae4cb31ad5a365face107Argyrios Kyrtzidis  }
5331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
53409c4719788a5cea09897525e528fa00420f1677bSteve Naroff  // Implement isa/cast/dyncast/etc.
53580cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
53609c4719788a5cea09897525e528fa00420f1677bSteve Naroff  static bool classof(const ObjCContainerDecl *D) { return true; }
53780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) {
5389a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt    return K >= firstObjCContainer &&
5399a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt           K <= lastObjCContainer;
54080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  }
54109c4719788a5cea09897525e528fa00420f1677bSteve Naroff
54209c4719788a5cea09897525e528fa00420f1677bSteve Naroff  static DeclContext *castToDeclContext(const ObjCContainerDecl *D) {
54309c4719788a5cea09897525e528fa00420f1677bSteve Naroff    return static_cast<DeclContext *>(const_cast<ObjCContainerDecl*>(D));
54409c4719788a5cea09897525e528fa00420f1677bSteve Naroff  }
54509c4719788a5cea09897525e528fa00420f1677bSteve Naroff  static ObjCContainerDecl *castFromDeclContext(const DeclContext *DC) {
54609c4719788a5cea09897525e528fa00420f1677bSteve Naroff    return static_cast<ObjCContainerDecl *>(const_cast<DeclContext*>(DC));
54709c4719788a5cea09897525e528fa00420f1677bSteve Naroff  }
548e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff};
549e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
5500982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief Represents an ObjC class declaration.
5510c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
5520982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// For example:
5530982205bade2fb4fc984c27b2ab401e683963b10James Dennett///
5540982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \code
5550c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   // MostPrimitive declares no super class (not particularly useful).
55641c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth///   \@interface MostPrimitive
5570c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     // no instance variables or methods.
55841c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth///   \@end
5590c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
5601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///   // NSResponder inherits from NSObject & implements NSCoding (a protocol).
5610982205bade2fb4fc984c27b2ab401e683963b10James Dennett///   \@interface NSResponder : NSObject \<NSCoding>
562a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek///   { // instance variables are represented by ObjCIvarDecl.
5630c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     id nextResponder; // nextResponder instance variable.
5640c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   }
5650c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   - (NSResponder *)nextResponder; // return a pointer to NSResponder.
5660c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   - (void)mouseMoved:(NSEvent *)theEvent; // return void, takes a pointer
56741c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth///   \@end                                    // to an NSEvent.
5680982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \endcode
5690c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
57041c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth///   Unlike C/C++, forward class declarations are accomplished with \@class.
57141c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth///   Unlike C/C++, \@class allows for a list of classes to be forward declared.
5720c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   Unlike C++, ObjC is a single-rooted class model. In Cocoa, classes
5730c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   typically inherit from NSObject (an exception is NSProxy).
5740c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
57553df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregorclass ObjCInterfaceDecl : public ObjCContainerDecl
57653df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor                        , public Redeclarable<ObjCInterfaceDecl> {
57799ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
57899ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie
5793110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff  /// TypeForDecl - This indicates the Type object that represents this
5803110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff  /// TypeDecl.  It is a cache maintained by ASTContext::getObjCInterfaceType
581f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  mutable const Type *TypeForDecl;
5823110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff  friend class ASTContext;
5832e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
5842e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  struct DefinitionData {
58526fec63b14565e9e2d8c9935b276b99be950444aDouglas Gregor    /// \brief The definition of this class, for quick access from any
58626fec63b14565e9e2d8c9935b276b99be950444aDouglas Gregor    /// declaration.
58726fec63b14565e9e2d8c9935b276b99be950444aDouglas Gregor    ObjCInterfaceDecl *Definition;
58826fec63b14565e9e2d8c9935b276b99be950444aDouglas Gregor
5892e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    /// Class's super class.
5902e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    ObjCInterfaceDecl *SuperClass;
5911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
59241c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth    /// Protocols referenced in the \@interface  declaration
5932e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    ObjCProtocolList ReferencedProtocols;
5941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
59541c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth    /// Protocols reference in both the \@interface and class extensions.
5962e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    ObjCList<ObjCProtocolDecl> AllReferencedProtocols;
597ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
5982e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    /// \brief List of categories and class extensions defined for this class.
5992e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    ///
6002e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    /// Categories are stored as a linked list in the AST, since the categories
6012e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    /// and class extensions come long after the initial interface declaration,
6022e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    /// and we avoid dynamically-resized arrays in the AST wherever possible.
6032e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    ObjCCategoryDecl *CategoryList;
6041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6052e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    /// IvarList - List of all ivars defined by this class; including class
6062e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    /// extensions and implementation. This list is built lazily.
6072e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    ObjCIvarDecl *IvarList;
608ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
6092e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    /// \brief Indicates that the contents of this Objective-C class will be
6102e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    /// completed by the external AST source when required.
6112e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    mutable bool ExternallyCompleted : 1;
6122e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
61305c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor    /// \brief The location of the superclass, if any.
61405c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor    SourceLocation SuperClassLoc;
615161794732195881c33305f701f6e58721998541fDouglas Gregor
61605c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor    /// \brief The location of the last location in this declaration, before
61705c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor    /// the properties/methods. For example, this will be the '>', '}', or
61805c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor    /// identifier,
61905c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor    SourceLocation EndLoc;
62005c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor
62126fec63b14565e9e2d8c9935b276b99be950444aDouglas Gregor    DefinitionData() : Definition(), SuperClass(), CategoryList(), IvarList(),
622161794732195881c33305f701f6e58721998541fDouglas Gregor                       ExternallyCompleted() { }
6232e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  };
6242e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
6252e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id,
62637f953f021c67e3b97f1ef38e1ef3cb08bd9d146Douglas Gregor                    SourceLocation CLoc, ObjCInterfaceDecl *PrevDecl,
62737f953f021c67e3b97f1ef38e1ef3cb08bd9d146Douglas Gregor                    bool isInternal);
6282e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
6292e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  void LoadExternalDefinition() const;
6302e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
6312e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  /// \brief Contains a pointer to the data associated with this class,
6322e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  /// which will be NULL if this class has not yet been defined.
63326fec63b14565e9e2d8c9935b276b99be950444aDouglas Gregor  DefinitionData *Data;
6342e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
6352e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  DefinitionData &data() const {
63626fec63b14565e9e2d8c9935b276b99be950444aDouglas Gregor    assert(Data != 0 && "Declaration has no definition!");
63726fec63b14565e9e2d8c9935b276b99be950444aDouglas Gregor    return *Data;
6382e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  }
6391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6402e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  /// \brief Allocate the definition data for this class.
6412e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  void allocateDefinitionData();
6422e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
64353df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor  typedef Redeclarable<ObjCInterfaceDecl> redeclarable_base;
64453df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor  virtual ObjCInterfaceDecl *getNextRedeclaration() {
64553df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor    return RedeclLink.getNext();
64653df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor  }
647ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor  virtual ObjCInterfaceDecl *getPreviousDeclImpl() {
648ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor    return getPreviousDecl();
649ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor  }
650ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor  virtual ObjCInterfaceDecl *getMostRecentDeclImpl() {
651ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor    return getMostRecentDecl();
652ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor  }
65353df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor
6540e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattnerpublic:
655a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor  static ObjCInterfaceDecl *Create(const ASTContext &C, DeclContext *DC,
6560ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner                                   SourceLocation atLoc,
6571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                   IdentifierInfo *Id,
6580af550115df1f57f17a4f125ff0e8b34820c65d1Douglas Gregor                                   ObjCInterfaceDecl *PrevDecl,
659deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor                                   SourceLocation ClassLoc = SourceLocation(),
6600e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner                                   bool isInternal = false);
661d1cf3ff6c7e34fce764293cd2900fce99a60ed69Argyrios Kyrtzidis
6621e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor  static ObjCInterfaceDecl *CreateDeserialized(ASTContext &C, unsigned ID);
6630af550115df1f57f17a4f125ff0e8b34820c65d1Douglas Gregor
664aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  virtual SourceRange getSourceRange() const LLVM_READONLY {
6657723fec9b45b7258c0eddf4cbfd0d335348f5edcDouglas Gregor    if (isThisDeclarationADefinition())
6667723fec9b45b7258c0eddf4cbfd0d335348f5edcDouglas Gregor      return ObjCContainerDecl::getSourceRange();
6677723fec9b45b7258c0eddf4cbfd0d335348f5edcDouglas Gregor
6687723fec9b45b7258c0eddf4cbfd0d335348f5edcDouglas Gregor    return SourceRange(getAtStartLoc(), getLocation());
669d1cf3ff6c7e34fce764293cd2900fce99a60ed69Argyrios Kyrtzidis  }
670ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
67126ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  /// \brief Indicate that this Objective-C class is complete, but that
67226ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  /// the external AST source will be responsible for filling in its contents
67326ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  /// when a complete class is required.
67426ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  void setExternallyCompleted();
675ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
67618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  const ObjCProtocolList &getReferencedProtocols() const {
677a5f4441de7890953460d95f4e88b9fa432b48dc2Argyrios Kyrtzidis    assert(hasDefinition() && "Caller did not check for forward reference!");
6782e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (data().ExternallyCompleted)
67926ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
680ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
6812e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    return data().ReferencedProtocols;
6827ed9e0f97f4645edc5d4670385b985ea4c617ce7Fariborz Jahanian  }
6838a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis
6848a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis  ObjCImplementationDecl *getImplementation() const;
6858a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis  void setImplementation(ObjCImplementationDecl *ImplD);
6868a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis
687559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  ObjCCategoryDecl *FindCategoryDeclaration(IdentifierInfo *CategoryId) const;
6881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6891cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis  // Get the local instance/class method declared in a category.
6901cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis  ObjCMethodDecl *getCategoryInstanceMethod(Selector Sel) const;
6911cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis  ObjCMethodDecl *getCategoryClassMethod(Selector Sel) const;
6921cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis  ObjCMethodDecl *getCategoryMethod(Selector Sel, bool isInstance) const {
6931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return isInstance ? getInstanceMethod(Sel)
6941cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis                      : getClassMethod(Sel);
6951cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis  }
6963db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner
69718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::iterator protocol_iterator;
698ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
69953b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  protocol_iterator protocol_begin() const {
7002e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    // FIXME: Should make sure no callers ever do this.
7012e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (!hasDefinition())
7022e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor      return protocol_iterator();
7032e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
7042e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (data().ExternallyCompleted)
70526ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
70626ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
7072e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    return data().ReferencedProtocols.begin();
70853b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  }
70953b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  protocol_iterator protocol_end() const {
7102e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    // FIXME: Should make sure no callers ever do this.
7112e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (!hasDefinition())
7122e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor      return protocol_iterator();
7132e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
7142e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (data().ExternallyCompleted)
71526ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
71626ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
7172e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    return data().ReferencedProtocols.end();
71853b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  }
71953b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
72018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
72153b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
722ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  protocol_loc_iterator protocol_loc_begin() const {
7232e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    // FIXME: Should make sure no callers ever do this.
7242e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (!hasDefinition())
7252e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor      return protocol_loc_iterator();
7262e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
7272e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (data().ExternallyCompleted)
72826ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
72926ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
7302e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    return data().ReferencedProtocols.loc_begin();
73118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
73253b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
733ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  protocol_loc_iterator protocol_loc_end() const {
7342e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    // FIXME: Should make sure no callers ever do this.
7352e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (!hasDefinition())
7362e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor      return protocol_loc_iterator();
7372e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
7382e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (data().ExternallyCompleted)
73926ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
74026ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
7412e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    return data().ReferencedProtocols.loc_end();
74218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
743ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
74453b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  typedef ObjCList<ObjCProtocolDecl>::iterator all_protocol_iterator;
745ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
74653b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  all_protocol_iterator all_referenced_protocol_begin() const {
7472e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    // FIXME: Should make sure no callers ever do this.
7482e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (!hasDefinition())
7492e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor      return all_protocol_iterator();
7502e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
7512e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (data().ExternallyCompleted)
75226ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
75326ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
7542e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    return data().AllReferencedProtocols.empty()
7552e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor             ? protocol_begin()
7562e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor             : data().AllReferencedProtocols.begin();
75753b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  }
75853b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  all_protocol_iterator all_referenced_protocol_end() const {
7592e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    // FIXME: Should make sure no callers ever do this.
7602e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (!hasDefinition())
7612e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor      return all_protocol_iterator();
7622e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
7632e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (data().ExternallyCompleted)
76426ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
76526ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
7662e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    return data().AllReferencedProtocols.empty()
7672e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor             ? protocol_end()
7682e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor             : data().AllReferencedProtocols.end();
76953b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  }
770291be393aa33759e6e34b6429c5ffa206ba50115Douglas Gregor
77111062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian  typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
77253b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
7732e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  ivar_iterator ivar_begin() const {
7742e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (const ObjCInterfaceDecl *Def = getDefinition())
7752e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor      return ivar_iterator(Def->decls_begin());
7762e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
7772e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    // FIXME: Should make sure no callers ever do this.
7782e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    return ivar_iterator();
7792e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  }
7802e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  ivar_iterator ivar_end() const {
7812e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (const ObjCInterfaceDecl *Def = getDefinition())
7822e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor      return ivar_iterator(Def->decls_end());
7832e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
7842e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    // FIXME: Should make sure no callers ever do this.
7852e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    return ivar_iterator();
7862e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  }
78753b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
78811062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian  unsigned ivar_size() const {
78911062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian    return std::distance(ivar_begin(), ivar_end());
79011062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian  }
791ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
79211062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian  bool ivar_empty() const { return ivar_begin() == ivar_end(); }
793ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
794db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose  ObjCIvarDecl *all_declared_ivar_begin();
795db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose  const ObjCIvarDecl *all_declared_ivar_begin() const {
796db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose    // Even though this modifies IvarList, it's conceptually const:
797db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose    // the ivar chain is essentially a cached property of ObjCInterfaceDecl.
798db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose    return const_cast<ObjCInterfaceDecl *>(this)->all_declared_ivar_begin();
799db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose  }
8002e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  void setIvarList(ObjCIvarDecl *ivar) { data().IvarList = ivar; }
801ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
80238af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  /// setProtocolList - Set the list of protocols that this interface
803b752f289026ad8e5f44851b20e009a27ed61eefcChris Lattner  /// implements.
80438af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  void setProtocolList(ObjCProtocolDecl *const* List, unsigned Num,
80518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                       const SourceLocation *Locs, ASTContext &C) {
8062e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    data().ReferencedProtocols.set(List, Num, Locs, C);
8073db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  }
8081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
809339798eae1eb61c50ca68766ed028c0a16d0a284Fariborz Jahanian  /// mergeClassExtensionProtocolList - Merge class extension's protocol list
810339798eae1eb61c50ca68766ed028c0a16d0a284Fariborz Jahanian  /// into the protocol list for this class.
811ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  void mergeClassExtensionProtocolList(ObjCProtocolDecl *const* List,
81218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                                       unsigned Num,
81318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                                       ASTContext &C);
814339798eae1eb61c50ca68766ed028c0a16d0a284Fariborz Jahanian
81553df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor  /// \brief Determine whether this particular declaration of this class is
81653df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor  /// actually also a definition.
81726fec63b14565e9e2d8c9935b276b99be950444aDouglas Gregor  bool isThisDeclarationADefinition() const {
8187723fec9b45b7258c0eddf4cbfd0d335348f5edcDouglas Gregor    return Data && Data->Definition == this;
81926fec63b14565e9e2d8c9935b276b99be950444aDouglas Gregor  }
82053df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor
8212e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  /// \brief Determine whether this class has been defined.
82226fec63b14565e9e2d8c9935b276b99be950444aDouglas Gregor  bool hasDefinition() const { return Data; }
82353df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor
8242e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  /// \brief Retrieve the definition of this class, or NULL if this class
82541c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  /// has been forward-declared (with \@class) but not yet defined (with
82641c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  /// \@interface).
8272e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  ObjCInterfaceDecl *getDefinition() {
82826fec63b14565e9e2d8c9935b276b99be950444aDouglas Gregor    return hasDefinition()? Data->Definition : 0;
8292e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  }
830ad834d534e9a5db3d3baa09593775f83ceaff1f2Argyrios Kyrtzidis
8312e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  /// \brief Retrieve the definition of this class, or NULL if this class
83241c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  /// has been forward-declared (with \@class) but not yet defined (with
83341c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  /// \@interface).
8342e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  const ObjCInterfaceDecl *getDefinition() const {
83526fec63b14565e9e2d8c9935b276b99be950444aDouglas Gregor    return hasDefinition()? Data->Definition : 0;
8362e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  }
8371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8382e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  /// \brief Starts the definition of this Objective-C class, taking it from
83941c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  /// a forward declaration (\@class) to a definition (\@interface).
8402e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  void startDefinition();
8412e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
842ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  ObjCInterfaceDecl *getSuperClass() const {
8432e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    // FIXME: Should make sure no callers ever do this.
8442e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (!hasDefinition())
8452e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor      return 0;
8462e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
8472e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (data().ExternallyCompleted)
84826ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
84926ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
8502e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    return data().SuperClass;
85126ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  }
852ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
8532e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  void setSuperClass(ObjCInterfaceDecl * superCls) {
854712ef874534ee1bef41d1aa4664ae36148ec8b12Fariborz Jahanian    data().SuperClass =
855712ef874534ee1bef41d1aa4664ae36148ec8b12Fariborz Jahanian      (superCls && superCls->hasDefinition()) ? superCls->getDefinition()
856712ef874534ee1bef41d1aa4664ae36148ec8b12Fariborz Jahanian                                              : superCls;
8572e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  }
8581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
859ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  ObjCCategoryDecl* getCategoryList() const {
8602e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    // FIXME: Should make sure no callers ever do this.
8612e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (!hasDefinition())
8622e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor      return 0;
8632e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
8642e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    if (data().ExternallyCompleted)
86526ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
86626ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
8672e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    return data().CategoryList;
86826ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  }
869ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
8701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setCategoryList(ObjCCategoryDecl *category) {
8712e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor    data().CategoryList = category;
872980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  }
873ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
87480aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  ObjCCategoryDecl* getFirstClassExtension() const;
87537cafb077ad5b170acae77e566638603011ef4c0Ted Kremenek
87637cafb077ad5b170acae77e566638603011ef4c0Ted Kremenek  ObjCPropertyDecl
87737cafb077ad5b170acae77e566638603011ef4c0Ted Kremenek    *FindPropertyVisibleInPrimaryClass(IdentifierInfo *PropertyId) const;
87837cafb077ad5b170acae77e566638603011ef4c0Ted Kremenek
87953efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner  /// isSuperClassOf - Return true if this class is the specified class or is a
88053efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner  /// super class of the specified interface class.
88153efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner  bool isSuperClassOf(const ObjCInterfaceDecl *I) const {
88253efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    // If RHS is derived from LHS it is OK; else it is not OK.
88353efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    while (I != NULL) {
88460ef308e51c71b760d7f598c1b763ceb7b768148Douglas Gregor      if (declaresSameEntity(this, I))
88553efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner        return true;
8862e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
88753efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner      I = I->getSuperClass();
88853efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    }
88953efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    return false;
89053efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner  }
8911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8927263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian  /// isArcWeakrefUnavailable - Checks for a class or one of its super classes
8937263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian  /// to be incompatible with __weak references. Returns true if it is.
8947263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian  bool isArcWeakrefUnavailable() const {
8957263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian    const ObjCInterfaceDecl *Class = this;
8967263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian    while (Class) {
8977263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian      if (Class->hasAttr<ArcWeakrefUnavailableAttr>())
8987263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian        return true;
8997263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian      Class = Class->getSuperClass();
9007263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian   }
901ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie   return false;
9027263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian  }
9037263feeb367ab55af7e9a6fd701148b1b8264dbaFariborz Jahanian
90471207fc0470e1eee40a2951cd5cc3ff47725b755Ted Kremenek  /// isObjCRequiresPropertyDefs - Checks that a class or one of its super
90541c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  /// classes must not be auto-synthesized. Returns class decl. if it must not
90641c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  /// be; 0, otherwise.
90771207fc0470e1eee40a2951cd5cc3ff47725b755Ted Kremenek  const ObjCInterfaceDecl *isObjCRequiresPropertyDefs() const {
908e23dcf3524fe01208cc79e707412f0a5dd8eed7bFariborz Jahanian    const ObjCInterfaceDecl *Class = this;
909e23dcf3524fe01208cc79e707412f0a5dd8eed7bFariborz Jahanian    while (Class) {
91071207fc0470e1eee40a2951cd5cc3ff47725b755Ted Kremenek      if (Class->hasAttr<ObjCRequiresPropertyDefsAttr>())
911da611a74c408af0f9526acc690b85214bf180852Fariborz Jahanian        return Class;
912e23dcf3524fe01208cc79e707412f0a5dd8eed7bFariborz Jahanian      Class = Class->getSuperClass();
913e23dcf3524fe01208cc79e707412f0a5dd8eed7bFariborz Jahanian   }
914da611a74c408af0f9526acc690b85214bf180852Fariborz Jahanian   return 0;
915e23dcf3524fe01208cc79e707412f0a5dd8eed7bFariborz Jahanian  }
916e23dcf3524fe01208cc79e707412f0a5dd8eed7bFariborz Jahanian
91717945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName,
91868a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner                                       ObjCInterfaceDecl *&ClassDeclared);
91917945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName) {
92068a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner    ObjCInterfaceDecl *ClassDeclared;
92117945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return lookupInstanceVariable(IVarName, ClassDeclared);
92268a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner  }
92368a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner
92494a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // Lookup a method. First, we search locally. If a method isn't
92594a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // found, we search referenced protocols and class categories.
926bb3d14e55d267bf5228699c7bf0c8ccdb71c8f46Fariborz Jahanian  ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance,
927bf393be8a0b8b573ceb23ed19ac953832a2a69e4Fariborz Jahanian                               bool shallowCategoryLookup= false) const;
928bb3d14e55d267bf5228699c7bf0c8ccdb71c8f46Fariborz Jahanian  ObjCMethodDecl *lookupInstanceMethod(Selector Sel,
929bf393be8a0b8b573ceb23ed19ac953832a2a69e4Fariborz Jahanian                            bool shallowCategoryLookup = false) const {
930bf393be8a0b8b573ceb23ed19ac953832a2a69e4Fariborz Jahanian    return lookupMethod(Sel, true/*isInstance*/, shallowCategoryLookup);
931bb3d14e55d267bf5228699c7bf0c8ccdb71c8f46Fariborz Jahanian  }
932bb3d14e55d267bf5228699c7bf0c8ccdb71c8f46Fariborz Jahanian  ObjCMethodDecl *lookupClassMethod(Selector Sel,
933bf393be8a0b8b573ceb23ed19ac953832a2a69e4Fariborz Jahanian                     bool shallowCategoryLookup = false) const {
934bf393be8a0b8b573ceb23ed19ac953832a2a69e4Fariborz Jahanian    return lookupMethod(Sel, false/*isInstance*/, shallowCategoryLookup);
935aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis  }
936cd1876207f5564beba74e4b2524b664bdba0ba9fFariborz Jahanian  ObjCInterfaceDecl *lookupInheritedClass(const IdentifierInfo *ICName);
937ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
938d789d3d985e28c9404e62157af46dcb7331920e0Steve Naroff  // Lookup a method in the classes implementation hierarchy.
93974b2756bc1f1f5f7c189996fe7e4cd3efef70263Fariborz Jahanian  ObjCMethodDecl *lookupPrivateMethod(const Selector &Sel, bool Instance=true);
94060fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff
94105c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor  SourceLocation getEndOfDefinitionLoc() const {
94205c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor    if (!hasDefinition())
94305c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor      return getLocation();
94405c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor
94505c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor    return data().EndLoc;
94605c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor  }
94705c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor
94805c272fed899b8d3142cf080e86a235fc6168862Douglas Gregor  void setEndOfDefinitionLoc(SourceLocation LE) { data().EndLoc = LE; }
9491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9502e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  void setSuperClassLoc(SourceLocation Loc) { data().SuperClassLoc = Loc; }
9512e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  SourceLocation getSuperClassLoc() const { return data().SuperClassLoc; }
9521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
95328e71cf851b73a67604735a9a95aef800b144e2eSteve Naroff  /// isImplicitInterfaceDecl - check that this is an implicitly declared
95441c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  /// ObjCInterfaceDecl node. This is for legacy objective-c \@implementation
95541c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  /// declaration without an \@interface declaration.
95697bbab2df74cbfe221fb20454738d607a41f3ca4Fariborz Jahanian  bool isImplicitInterfaceDecl() const {
95797bbab2df74cbfe221fb20454738d607a41f3ca4Fariborz Jahanian    return hasDefinition() ? Data->Definition->isImplicit() : isImplicit();
95897bbab2df74cbfe221fb20454738d607a41f3ca4Fariborz Jahanian  }
9591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9600fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian  /// ClassImplementsProtocol - Checks that 'lProto' protocol
9610fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian  /// has been implemented in IDecl class, its super class or categories (if
9620fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian  /// lookupCategory is true).
9630fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian  bool ClassImplementsProtocol(ObjCProtocolDecl *lProto,
9640fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian                               bool lookupCategory,
9650fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian                               bool RHSIsQualifiedID = false);
9661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
967a54fbf2499c7cc999e22abb9be484ce976ed9689Douglas Gregor  typedef redeclarable_base::redecl_iterator redecl_iterator;
968ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor  using redeclarable_base::redecls_begin;
969ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor  using redeclarable_base::redecls_end;
970ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor  using redeclarable_base::getPreviousDecl;
971ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor  using redeclarable_base::getMostRecentDecl;
972f785a7d611404cf4747287a2bbc59b4d0e6a5a8cDouglas Gregor
97353df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor  /// Retrieves the canonical declaration of this Objective-C class.
97453df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor  ObjCInterfaceDecl *getCanonicalDecl() {
97553df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor    return getFirstDeclaration();
97653df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor  }
97753df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor  const ObjCInterfaceDecl *getCanonicalDecl() const {
97853df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor    return getFirstDeclaration();
97953df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor  }
98053df7a1d34f21d8f2309311d1067d463e9064c60Douglas Gregor
98133feeb019a5742b286eededd5446ec0fe87c5a61Steve Naroff  // Low-level accessor
982f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const Type *getTypeForDecl() const { return TypeForDecl; }
983f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  void setTypeForDecl(const Type *TD) const { TypeForDecl = TD; }
98433feeb019a5742b286eededd5446ec0fe87c5a61Steve Naroff
98580cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
986a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCInterfaceDecl *D) { return true; }
98780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCInterface; }
98853b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
989fc529f7fcafe7da0b8a32621e13685891e8ce52aDouglas Gregor  friend class ASTReader;
99053b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  friend class ASTDeclReader;
99153b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  friend class ASTDeclWriter;
992980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
993980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
994a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCIvarDecl - Represents an ObjC instance variable. In general, ObjC
9950c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// instance variables are identical to C. The only exception is Objective-C
9960c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// supports C++ style access control. For example:
9970c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
99841c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth///   \@interface IvarExample : NSObject
9990c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   {
1000f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek///     id defaultToProtected;
100141c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth///   \@public:
10020c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     id canBePublic; // same as C++.
100341c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth///   \@protected:
10040c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     id canBeProtected; // same as C++.
100541c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth///   \@package:
10060c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     id canBePackage; // framework visibility (not available in C++).
10070c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   }
10080c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
1009a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCIvarDecl : public FieldDecl {
101099ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
101199ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie
10120e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattnerpublic:
1013980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  enum AccessControl {
1014980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff    None, Private, Protected, Public, Package
1015980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  };
10161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1017b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenekprivate:
1018ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara  ObjCIvarDecl(ObjCContainerDecl *DC, SourceLocation StartLoc,
1019ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara               SourceLocation IdLoc, IdentifierInfo *Id,
1020ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian               QualType T, TypeSourceInfo *TInfo, AccessControl ac, Expr *BW,
1021ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian               bool synthesized)
1022ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara    : FieldDecl(ObjCIvar, DC, StartLoc, IdLoc, Id, T, TInfo, BW,
1023ca5233044ef679840d1ad1c46a36b16e2ee8a6e1Richard Smith                /*Mutable=*/false, /*HasInit=*/ICIS_NoInit),
1024ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara      NextIvar(0), DeclAccess(ac), Synthesized(synthesized) {}
10251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1026b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenekpublic:
1027a06549226f45d5b72169a3d054415616dd1014a2Daniel Dunbar  static ObjCIvarDecl *Create(ASTContext &C, ObjCContainerDecl *DC,
1028ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                              SourceLocation StartLoc, SourceLocation IdLoc,
1029ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                              IdentifierInfo *Id, QualType T,
1030a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall                              TypeSourceInfo *TInfo,
1031ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian                              AccessControl ac, Expr *BW = NULL,
1032ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian                              bool synthesized=false);
10331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10341e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor  static ObjCIvarDecl *CreateDeserialized(ASTContext &C, unsigned ID);
10351e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor
103627a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar  /// \brief Return the class interface that this ivar is logically contained
103727a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar  /// in; this is either the interface where the ivar was declared, or the
103827a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar  /// interface the ivar is conceptually a part of in the case of synthesized
103927a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar  /// ivars.
104027a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar  const ObjCInterfaceDecl *getContainingInterface() const;
1041ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
10422c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  ObjCIvarDecl *getNextIvar() { return NextIvar; }
1043db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose  const ObjCIvarDecl *getNextIvar() const { return NextIvar; }
10442c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  void setNextIvar(ObjCIvarDecl *ivar) { NextIvar = ivar; }
104527a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar
1046980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  void setAccessControl(AccessControl ac) { DeclAccess = ac; }
1047f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek
1048ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  AccessControl getAccessControl() const { return AccessControl(DeclAccess); }
1049f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek
1050f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek  AccessControl getCanonicalAccessControl() const {
1051f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek    return DeclAccess == None ? Protected : AccessControl(DeclAccess);
1052f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek  }
10531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1054ac0021ba802e193e0f9f8207768c7862c7603bc0Fariborz Jahanian  void setSynthesize(bool synth) { Synthesized = synth; }
1055ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian  bool getSynthesize() const { return Synthesized; }
1056ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1057980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  // Implement isa/cast/dyncast/etc.
105880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1059a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCIvarDecl *D) { return true; }
106080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCIvar; }
1061980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffprivate:
1062ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// NextIvar - Next Ivar in the list of ivars declared in class; class's
10632c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  /// extensions and class's implementation
10642c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  ObjCIvarDecl *NextIvar;
1065ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1066ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  // NOTE: VC++ treats enums as signed, avoid using the AccessControl enum
1067ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  unsigned DeclAccess : 3;
1068ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian  unsigned Synthesized : 1;
1069980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
1070980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
10711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10720982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief Represents a field declaration created by an \@defs(...).
107301e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenekclass ObjCAtDefsFieldDecl : public FieldDecl {
107499ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
1075ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara  ObjCAtDefsFieldDecl(DeclContext *DC, SourceLocation StartLoc,
1076ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                      SourceLocation IdLoc, IdentifierInfo *Id,
107701e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek                      QualType T, Expr *BW)
1078ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara    : FieldDecl(ObjCAtDefsField, DC, StartLoc, IdLoc, Id, T,
1079a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall                /*TInfo=*/0, // FIXME: Do ObjCAtDefs have declarators ?
1080ca5233044ef679840d1ad1c46a36b16e2ee8a6e1Richard Smith                BW, /*Mutable=*/false, /*HasInit=*/ICIS_NoInit) {}
10811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
108201e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenekpublic:
108344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor  static ObjCAtDefsFieldDecl *Create(ASTContext &C, DeclContext *DC,
1084ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                     SourceLocation StartLoc,
1085ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                     SourceLocation IdLoc, IdentifierInfo *Id,
1086ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                     QualType T, Expr *BW);
10871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10881e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor  static ObjCAtDefsFieldDecl *CreateDeserialized(ASTContext &C, unsigned ID);
10891e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor
109001e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek  // Implement isa/cast/dyncast/etc.
109180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
109201e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek  static bool classof(const ObjCAtDefsFieldDecl *D) { return true; }
109380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCAtDefsField; }
109401e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek};
1095980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
10960982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief Represents an Objective-C protocol declaration.
10970982205bade2fb4fc984c27b2ab401e683963b10James Dennett///
10980982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// Objective-C protocols declare a pure abstract type (i.e., no instance
10990982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// variables are permitted).  Protocols originally drew inspiration from
11000982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// C++ pure virtual functions (a C++ feature with nice semantics and lousy
11010982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// syntax:-). Here is an example:
11020c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
11030982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \code
110441c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth/// \@protocol NSDraggingInfo <refproto1, refproto2>
11050c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (NSWindow *)draggingDestinationWindow;
11060c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (NSImage *)draggedImage;
110741c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth/// \@end
11080982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \endcode
11090c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
1110eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// This says that NSDraggingInfo requires two methods and requires everything
1111eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// that the two "referenced protocols" 'refproto1' and 'refproto2' require as
1112eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// well.
1113eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner///
11140982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \code
11150982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \@interface ImplementsNSDraggingInfo : NSObject \<NSDraggingInfo>
111641c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth/// \@end
11170982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \endcode
11180c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
1119a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjC protocols inspired Java interfaces. Unlike Java, ObjC classes and
11200c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// protocols are in distinct namespaces. For example, Cocoa defines both
11211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// an NSObject protocol and class (which isn't allowed in Java). As a result,
11220c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// protocols are referenced using angle brackets as follows:
11230c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
11240982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// id \<NSDraggingInfo> anyObjectThatImplementsNSDraggingInfo;
11250c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
11261d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregorclass ObjCProtocolDecl : public ObjCContainerDecl,
11271d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor                         public Redeclarable<ObjCProtocolDecl> {
112899ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
112999ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie
11305e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  struct DefinitionData {
11311d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor    // \brief The declaration that defines this protocol.
11321d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor    ObjCProtocolDecl *Definition;
11331d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor
1134ec1a58b201b3276966aaade8ac3ac4705aba96c2Douglas Gregor    /// \brief Referenced protocols
11355e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    ObjCProtocolList ReferencedProtocols;
11365e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  };
11375e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor
11385e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  DefinitionData *Data;
11391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11405e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  DefinitionData &data() const {
11415e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    assert(Data && "Objective-C protocol has no definition!");
11425e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    return *Data;
11435e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  }
11445e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor
11451711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis  ObjCProtocolDecl(DeclContext *DC, IdentifierInfo *Id,
1146b05d7b20171bbd2feb14b059f39332cbe1bf1014Argyrios Kyrtzidis                   SourceLocation nameLoc, SourceLocation atStartLoc,
1147c9d3c7edb513e9b8a6ab65b04133653e71d7a72bDouglas Gregor                   ObjCProtocolDecl *PrevDecl);
11481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11495e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  void allocateDefinitionData();
11501d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor
11511d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor  typedef Redeclarable<ObjCProtocolDecl> redeclarable_base;
11521d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor  virtual ObjCProtocolDecl *getNextRedeclaration() {
11531d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor    return RedeclLink.getNext();
11541d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor  }
1155ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor  virtual ObjCProtocolDecl *getPreviousDeclImpl() {
1156ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor    return getPreviousDecl();
1157ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor  }
1158ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor  virtual ObjCProtocolDecl *getMostRecentDeclImpl() {
1159ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor    return getMostRecentDecl();
1160ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor  }
11611d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor
1162cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattnerpublic:
11631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static ObjCProtocolDecl *Create(ASTContext &C, DeclContext *DC,
11641711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                                  IdentifierInfo *Id,
11651711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                                  SourceLocation nameLoc,
1166b05d7b20171bbd2feb14b059f39332cbe1bf1014Argyrios Kyrtzidis                                  SourceLocation atStartLoc,
1167c9d3c7edb513e9b8a6ab65b04133653e71d7a72bDouglas Gregor                                  ObjCProtocolDecl *PrevDecl);
1168cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattner
11691e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor  static ObjCProtocolDecl *CreateDeserialized(ASTContext &C, unsigned ID);
11701e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor
117118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  const ObjCProtocolList &getReferencedProtocols() const {
11725e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    assert(hasDefinition() && "No definition available!");
11735e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    return data().ReferencedProtocols;
1174980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  }
117518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::iterator protocol_iterator;
11765e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  protocol_iterator protocol_begin() const {
11775e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    if (!hasDefinition())
11785e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor      return protocol_iterator();
11795e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor
11805e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    return data().ReferencedProtocols.begin();
11815e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  }
11825e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  protocol_iterator protocol_end() const {
11835e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    if (!hasDefinition())
11845e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor      return protocol_iterator();
11855e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor
11865e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    return data().ReferencedProtocols.end();
11875e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  }
118818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
1189ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  protocol_loc_iterator protocol_loc_begin() const {
11905e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    if (!hasDefinition())
11915e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor      return protocol_loc_iterator();
11925e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor
11935e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    return data().ReferencedProtocols.loc_begin();
119418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
1195ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  protocol_loc_iterator protocol_loc_end() const {
11965e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    if (!hasDefinition())
11975e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor      return protocol_loc_iterator();
11985e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor
11995e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    return data().ReferencedProtocols.loc_end();
12005e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  }
12015e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  unsigned protocol_size() const {
12025e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    if (!hasDefinition())
12035e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor      return 0;
12045e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor
12055e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    return data().ReferencedProtocols.size();
120618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
12071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
120838af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  /// setProtocolList - Set the list of protocols that this interface
1209780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  /// implements.
121038af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num,
121118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                       const SourceLocation *Locs, ASTContext &C) {
12125e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    assert(Data && "Protocol is not defined");
12135e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    data().ReferencedProtocols.set(List, Num, Locs, C);
1214aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian  }
12151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
121691b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff  ObjCProtocolDecl *lookupProtocolNamed(IdentifierInfo *PName);
12171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
121894a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // Lookup a method. First, we search locally. If a method isn't
121994a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // found, we search referenced protocols and class categories.
1220094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis  ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance) const;
1221094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis  ObjCMethodDecl *lookupInstanceMethod(Selector Sel) const {
1222094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis    return lookupMethod(Sel, true/*isInstance*/);
1223094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis  }
1224094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis  ObjCMethodDecl *lookupClassMethod(Selector Sel) const {
1225094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis    return lookupMethod(Sel, false/*isInstance*/);
1226094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis  }
1227b05d7b20171bbd2feb14b059f39332cbe1bf1014Argyrios Kyrtzidis
12285e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  /// \brief Determine whether this protocol has a definition.
12295e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  bool hasDefinition() const { return Data != 0; }
12305e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor
12315e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  /// \brief Retrieve the definition of this protocol, if any.
12325e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  ObjCProtocolDecl *getDefinition() {
12331d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor    return Data? Data->Definition : 0;
12345e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  }
12355e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor
12365e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  /// \brief Retrieve the definition of this protocol, if any.
12375e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  const ObjCProtocolDecl *getDefinition() const {
12381d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor    return Data? Data->Definition : 0;
12395e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  }
12405e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor
12415e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  /// \brief Determine whether this particular declaration is also the
12425e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  /// definition.
12435e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  bool isThisDeclarationADefinition() const {
12445e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor    return getDefinition() == this;
12455e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  }
12465e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor
12475e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  /// \brief Starts the definition of this Objective-C protocol.
12485e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  void startDefinition();
12495e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor
1250aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  virtual SourceRange getSourceRange() const LLVM_READONLY {
1251ec1a58b201b3276966aaade8ac3ac4705aba96c2Douglas Gregor    if (isThisDeclarationADefinition())
1252ec1a58b201b3276966aaade8ac3ac4705aba96c2Douglas Gregor      return ObjCContainerDecl::getSourceRange();
1253ec1a58b201b3276966aaade8ac3ac4705aba96c2Douglas Gregor
1254ec1a58b201b3276966aaade8ac3ac4705aba96c2Douglas Gregor    return SourceRange(getAtStartLoc(), getLocation());
1255ec1a58b201b3276966aaade8ac3ac4705aba96c2Douglas Gregor  }
1256f785a7d611404cf4747287a2bbc59b4d0e6a5a8cDouglas Gregor
1257a54fbf2499c7cc999e22abb9be484ce976ed9689Douglas Gregor  typedef redeclarable_base::redecl_iterator redecl_iterator;
1258ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor  using redeclarable_base::redecls_begin;
1259ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor  using redeclarable_base::redecls_end;
1260ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor  using redeclarable_base::getPreviousDecl;
1261ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor  using redeclarable_base::getMostRecentDecl;
1262f785a7d611404cf4747287a2bbc59b4d0e6a5a8cDouglas Gregor
12633fc73ee0c613715ebce78e30b4d050ea715a007dDouglas Gregor  /// Retrieves the canonical declaration of this Objective-C protocol.
12643fc73ee0c613715ebce78e30b4d050ea715a007dDouglas Gregor  ObjCProtocolDecl *getCanonicalDecl() {
12651d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor    return getFirstDeclaration();
12663fc73ee0c613715ebce78e30b4d050ea715a007dDouglas Gregor  }
12673fc73ee0c613715ebce78e30b4d050ea715a007dDouglas Gregor  const ObjCProtocolDecl *getCanonicalDecl() const {
12681d784b277cdfd4eba03680715d2a082b3f28d295Douglas Gregor    return getFirstDeclaration();
12693fc73ee0c613715ebce78e30b4d050ea715a007dDouglas Gregor  }
12703fc73ee0c613715ebce78e30b4d050ea715a007dDouglas Gregor
127180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1272a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCProtocolDecl *D) { return true; }
127380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCProtocol; }
1274b05d7b20171bbd2feb14b059f39332cbe1bf1014Argyrios Kyrtzidis
12755e2a1ff9f28d2eab256d2553e76a9c9d54693875Douglas Gregor  friend class ASTReader;
1276b05d7b20171bbd2feb14b059f39332cbe1bf1014Argyrios Kyrtzidis  friend class ASTDeclReader;
1277b05d7b20171bbd2feb14b059f39332cbe1bf1014Argyrios Kyrtzidis  friend class ASTDeclWriter;
1278980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
12791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1280a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCCategoryDecl - Represents a category declaration. A category allows
12810c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// you to add methods to an existing class (without subclassing or modifying
12821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// the original class interface or implementation:-). Categories don't allow
12830c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// you to add instance data. The following example adds "myMethod" to all
12840c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// NSView's within a process:
12850c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
128641c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth/// \@interface NSView (MyViewMethods)
12870c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - myMethod;
128841c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth/// \@end
12890c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
129033ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor/// Categories also allow you to split the implementation of a class across
12910c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// several files (a feature more naturally supported in C++).
12920c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
12930c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// Categories were originally inspired by dynamic languages such as Common
12941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Lisp and Smalltalk.  More traditional class-based languages (C++, Java)
12950c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// don't support this level of dynamism, which is both powerful and dangerous.
12960c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
1297e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroffclass ObjCCategoryDecl : public ObjCContainerDecl {
129899ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
129999ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie
1300980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  /// Interface belonging to this category
1301a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *ClassInterface;
13021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
130368c82cf61228102aba1194efef222fa1478af2a8Chris Lattner  /// referenced protocols in this category.
130418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  ObjCProtocolList ReferencedProtocols;
13051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1306a8ff9f455d94d9609766cfd5186b6e21dc2102f1Chris Lattner  /// Next category belonging to this class.
1307a8ff9f455d94d9609766cfd5186b6e21dc2102f1Chris Lattner  /// FIXME: this should not be a singly-linked list.  Move storage elsewhere.
1308a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCCategoryDecl *NextClassCategory;
13091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1310000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  /// true of class extension has at least one bitfield ivar.
1311000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  bool HasSynthBitfield : 1;
13123db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor
13133db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  /// \brief The location of the category name in this declaration.
13143db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  SourceLocation CategoryNameLoc;
13151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1316af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian  /// class extension may have private ivars.
1317af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian  SourceLocation IvarLBraceLoc;
1318af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian  SourceLocation IvarRBraceLoc;
1319af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian
1320ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  ObjCCategoryDecl(DeclContext *DC, SourceLocation AtLoc,
13213db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor                   SourceLocation ClassNameLoc, SourceLocation CategoryNameLoc,
1322af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian                   IdentifierInfo *Id, ObjCInterfaceDecl *IDecl,
1323af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian                   SourceLocation IvarLBraceLoc=SourceLocation(),
1324af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian                   SourceLocation IvarRBraceLoc=SourceLocation())
13251711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis    : ObjCContainerDecl(ObjCCategory, DC, Id, ClassNameLoc, AtLoc),
1326955fadbdfecfa24a590febe66a86519096787f2dArgyrios Kyrtzidis      ClassInterface(IDecl), NextClassCategory(0), HasSynthBitfield(false),
1327af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian      CategoryNameLoc(CategoryNameLoc),
1328af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian      IvarLBraceLoc(IvarLBraceLoc), IvarRBraceLoc(IvarRBraceLoc) {
1329a906135721c350435319347d2672bbb3bf494f91Chris Lattner  }
133061f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattnerpublic:
13311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1332d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCCategoryDecl *Create(ASTContext &C, DeclContext *DC,
1333ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                  SourceLocation AtLoc,
13343db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor                                  SourceLocation ClassNameLoc,
13353db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor                                  SourceLocation CategoryNameLoc,
1336955fadbdfecfa24a590febe66a86519096787f2dArgyrios Kyrtzidis                                  IdentifierInfo *Id,
1337af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian                                  ObjCInterfaceDecl *IDecl,
1338af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian                                  SourceLocation IvarLBraceLoc=SourceLocation(),
1339af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian                                  SourceLocation IvarRBraceLoc=SourceLocation());
13401e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor  static ObjCCategoryDecl *CreateDeserialized(ASTContext &C, unsigned ID);
13411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1342e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
1343e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; }
13448a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis
13458a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis  ObjCCategoryImplDecl *getImplementation() const;
13468a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis  void setImplementation(ObjCCategoryImplDecl *ImplD);
13478a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis
134838af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  /// setProtocolList - Set the list of protocols that this interface
1349f7b2c98c16dfb2261ea57d40a1d5bc4738e73175Chris Lattner  /// implements.
135038af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num,
135118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                       const SourceLocation *Locs, ASTContext &C) {
135218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    ReferencedProtocols.set(List, Num, Locs, C);
1353780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  }
13541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
135518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  const ObjCProtocolList &getReferencedProtocols() const {
1356780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner    return ReferencedProtocols;
13578f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian  }
13581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
135918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::iterator protocol_iterator;
1360780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();}
1361780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  protocol_iterator protocol_end() const { return ReferencedProtocols.end(); }
136230833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  unsigned protocol_size() const { return ReferencedProtocols.size(); }
136318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
1364ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  protocol_loc_iterator protocol_loc_begin() const {
1365ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return ReferencedProtocols.loc_begin();
136618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
1367ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  protocol_loc_iterator protocol_loc_end() const {
1368ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return ReferencedProtocols.loc_end();
136918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
13701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1371a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCCategoryDecl *getNextClassCategory() const { return NextClassCategory; }
13723db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor
137325760611365be23556b32332f8a66ae21ea93ecfFariborz Jahanian  bool IsClassExtension() const { return getIdentifier() == 0; }
137480aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  const ObjCCategoryDecl *getNextClassExtension() const;
1375ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1376000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  bool hasSynthBitfield() const { return HasSynthBitfield; }
1377000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  void setHasSynthBitfield (bool val) { HasSynthBitfield = val; }
1378ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
13790e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
13800e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  ivar_iterator ivar_begin() const {
13810e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian    return ivar_iterator(decls_begin());
13820e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  }
13830e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  ivar_iterator ivar_end() const {
13840e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian    return ivar_iterator(decls_end());
13850e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  }
13860e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  unsigned ivar_size() const {
13870e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian    return std::distance(ivar_begin(), ivar_end());
13880e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  }
13890e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  bool ivar_empty() const {
13900e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian    return ivar_begin() == ivar_end();
13910e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  }
13923db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor
13933db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  SourceLocation getCategoryNameLoc() const { return CategoryNameLoc; }
13943db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  void setCategoryNameLoc(SourceLocation Loc) { CategoryNameLoc = Loc; }
1395af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian
1396af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian  void setIvarLBraceLoc(SourceLocation Loc) { IvarLBraceLoc = Loc; }
1397af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian  SourceLocation getIvarLBraceLoc() const { return IvarLBraceLoc; }
1398af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian  void setIvarRBraceLoc(SourceLocation Loc) { IvarRBraceLoc = Loc; }
1399af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian  SourceLocation getIvarRBraceLoc() const { return IvarRBraceLoc; }
14003db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor
140180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1402a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCCategoryDecl *D) { return true; }
140380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCCategory; }
1404955fadbdfecfa24a590febe66a86519096787f2dArgyrios Kyrtzidis
1405955fadbdfecfa24a590febe66a86519096787f2dArgyrios Kyrtzidis  friend class ASTDeclReader;
1406955fadbdfecfa24a590febe66a86519096787f2dArgyrios Kyrtzidis  friend class ASTDeclWriter;
1407980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
14080c6b6243d3efd958c17943130e2a773653511edcSteve Naroff
1409aecae629269fae3bf484baf1d109e9a89d14eeadArgyrios Kyrtzidisclass ObjCImplDecl : public ObjCContainerDecl {
141099ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
141199ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie
14120d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// Class interface for this class/category implementation
1413a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *ClassInterface;
14141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14153aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattnerprotected:
14161711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis  ObjCImplDecl(Kind DK, DeclContext *DC,
14171711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis               ObjCInterfaceDecl *classInterface,
14181711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis               SourceLocation nameLoc, SourceLocation atStartLoc)
14191711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis    : ObjCContainerDecl(DK, DC,
14201711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                        classInterface? classInterface->getIdentifier() : 0,
14211711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                        nameLoc, atStartLoc),
1422aecae629269fae3bf484baf1d109e9a89d14eeadArgyrios Kyrtzidis      ClassInterface(classInterface) {}
14231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
142475c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattnerpublic:
1425e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; }
1426e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
14278a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis  void setClassInterface(ObjCInterfaceDecl *IFace);
14282c2d43c557beca1b4ba4bd743f33978aecb46a97Douglas Gregor
14291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void addInstanceMethod(ObjCMethodDecl *method) {
14302c2d43c557beca1b4ba4bd743f33978aecb46a97Douglas Gregor    // FIXME: Context should be set correctly before we get here.
1431653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor    method->setLexicalDeclContext(this);
14321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    addDecl(method);
1433e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff  }
14341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void addClassMethod(ObjCMethodDecl *method) {
14352c2d43c557beca1b4ba4bd743f33978aecb46a97Douglas Gregor    // FIXME: Context should be set correctly before we get here.
1436653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor    method->setLexicalDeclContext(this);
14371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    addDecl(method);
143853df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner  }
14391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
144017945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  void addPropertyImplementation(ObjCPropertyImplDecl *property);
14411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
144217945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  ObjCPropertyImplDecl *FindPropertyImplDecl(IdentifierInfo *propertyId) const;
144317945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  ObjCPropertyImplDecl *FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const;
1444653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor
1445653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor  // Iterator access to properties.
1446653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor  typedef specific_decl_iterator<ObjCPropertyImplDecl> propimpl_iterator;
14471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  propimpl_iterator propimpl_begin() const {
144817945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return propimpl_iterator(decls_begin());
1449559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  }
14501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  propimpl_iterator propimpl_end() const {
145117945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return propimpl_iterator(decls_end());
1452559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  }
1453653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor
145480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1455bfb498d0996ef049efe9476f2802976fd145cd60Argyrios Kyrtzidis  static bool classof(const ObjCImplDecl *D) { return true; }
145680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) {
14579a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt    return K >= firstObjCImpl && K <= lastObjCImpl;
145880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  }
14593aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner};
14601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ObjCCategoryImplDecl - An object of this class encapsulates a category
146241c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth/// \@implementation declaration. If a category class has declaration of a
14631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// property, its implementation must be specified in the category's
146441c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth/// \@implementation declaration. Example:
146541c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth/// \@interface I \@end
146641c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth/// \@interface I(CATEGORY)
146741c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth///    \@property int p1, d1;
146841c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth/// \@end
146941c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth/// \@implementation I(CATEGORY)
147041c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth///  \@dynamic p1,d1;
147141c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth/// \@end
14723aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner///
14733aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// ObjCCategoryImplDecl
14743aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattnerclass ObjCCategoryImplDecl : public ObjCImplDecl {
147599ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
147699ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie
14773aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  // Category name
14783aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  IdentifierInfo *Id;
14793aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner
1480c6994005dc9f677c831b8e90bdab483cc2197c29Argyrios Kyrtzidis  // Category name location
1481c6994005dc9f677c831b8e90bdab483cc2197c29Argyrios Kyrtzidis  SourceLocation CategoryNameLoc;
1482c6994005dc9f677c831b8e90bdab483cc2197c29Argyrios Kyrtzidis
14831711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis  ObjCCategoryImplDecl(DeclContext *DC, IdentifierInfo *Id,
14841711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                       ObjCInterfaceDecl *classInterface,
1485c6994005dc9f677c831b8e90bdab483cc2197c29Argyrios Kyrtzidis                       SourceLocation nameLoc, SourceLocation atStartLoc,
1486c6994005dc9f677c831b8e90bdab483cc2197c29Argyrios Kyrtzidis                       SourceLocation CategoryNameLoc)
14871711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis    : ObjCImplDecl(ObjCCategoryImpl, DC, classInterface, nameLoc, atStartLoc),
1488c6994005dc9f677c831b8e90bdab483cc2197c29Argyrios Kyrtzidis      Id(Id), CategoryNameLoc(CategoryNameLoc) {}
14893aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattnerpublic:
14903aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  static ObjCCategoryImplDecl *Create(ASTContext &C, DeclContext *DC,
14911711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                                      IdentifierInfo *Id,
14921711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                                      ObjCInterfaceDecl *classInterface,
14931711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                                      SourceLocation nameLoc,
1494c6994005dc9f677c831b8e90bdab483cc2197c29Argyrios Kyrtzidis                                      SourceLocation atStartLoc,
1495c6994005dc9f677c831b8e90bdab483cc2197c29Argyrios Kyrtzidis                                      SourceLocation CategoryNameLoc);
14961e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor  static ObjCCategoryImplDecl *CreateDeserialized(ASTContext &C, unsigned ID);
14971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14980d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// getIdentifier - Get the identifier that names the category
14993aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  /// interface associated with this implementation.
15000d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// FIXME: This is a bad API, we are overriding the NamedDecl::getIdentifier()
15010d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// to mean something different. For example:
1502ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// ((NamedDecl *)SomeCategoryImplDecl)->getIdentifier()
1503ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// returns the class interface name, whereas
1504ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// ((ObjCCategoryImplDecl *)SomeCategoryImplDecl)->getIdentifier()
15050d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// returns the category name.
15061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  IdentifierInfo *getIdentifier() const {
15071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return Id;
15083aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  }
150910b0e1fa3aabd8877dbbc0df1f2414e04afd5fddDouglas Gregor  void setIdentifier(IdentifierInfo *II) { Id = II; }
15101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15110d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  ObjCCategoryDecl *getCategoryDecl() const;
151210b0e1fa3aabd8877dbbc0df1f2414e04afd5fddDouglas Gregor
1513c6994005dc9f677c831b8e90bdab483cc2197c29Argyrios Kyrtzidis  SourceLocation getCategoryNameLoc() const { return CategoryNameLoc; }
1514c6994005dc9f677c831b8e90bdab483cc2197c29Argyrios Kyrtzidis
1515b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  /// getName - Get the name of identifier for the class interface associated
1516b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  /// with this implementation as a StringRef.
1517b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  //
1518b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  // FIXME: This is a bad API, we are overriding the NamedDecl::getName, to mean
1519b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  // something different.
1520686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getName() const {
1521b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar    return Id ? Id->getNameStart() : "";
1522b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  }
1523b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar
15243aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  /// getNameAsCString - Get the name of identifier for the class
15253aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  /// interface associated with this implementation as a C string
15263aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  /// (const char*).
15277fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar  //
1528b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  // FIXME: Deprecated, move clients to getName().
15293aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  const char *getNameAsCString() const {
15307fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar    return Id ? Id->getNameStart() : "";
15313aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  }
15321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15333aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  /// @brief Get the name of the class associated with this interface.
15347fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar  //
1535b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  // FIXME: Deprecated, move clients to getName().
15363aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  std::string getNameAsString() const {
1537b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar    return getName();
15383aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  }
15391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
154080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1541a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCCategoryImplDecl *D) { return true; }
154280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCCategoryImpl;}
1543c6994005dc9f677c831b8e90bdab483cc2197c29Argyrios Kyrtzidis
1544c6994005dc9f677c831b8e90bdab483cc2197c29Argyrios Kyrtzidis  friend class ASTDeclReader;
1545c6994005dc9f677c831b8e90bdab483cc2197c29Argyrios Kyrtzidis  friend class ASTDeclWriter;
15468f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian};
15478f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian
1548f978059b82db8c0d849c5f992036210b5ca53200Benjamin Kramerraw_ostream &operator<<(raw_ostream &OS, const ObjCCategoryImplDecl &CID);
1549900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer
1550a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCImplementationDecl - Represents a class definition - this is where
15510c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// method definitions are specified. For example:
15520c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
155398abf4bd3526a00a0e5cf71a9462c181f97b1c81Fariborz Jahanian/// @code
155441c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth/// \@implementation MyClass
15550c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (void)myMethod { /* do something */ }
155641c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth/// \@end
155798abf4bd3526a00a0e5cf71a9462c181f97b1c81Fariborz Jahanian/// @endcode
15580c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
15591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Typically, instance variables are specified in the class interface,
1560ec0d7a6f4b0699cc9960e6d9fee0f957c64d1cf9Douglas Gregor/// *not* in the implementation. Nevertheless (for legacy reasons), we
156153df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner/// allow instance variables to be specified in the implementation.  When
156253df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner/// specified, they need to be *identical* to the interface.
15630c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
15641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ObjCImplementationDecl : public ObjCImplDecl {
156599ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
1566980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  /// Implementation Class's super class.
1567a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *SuperClass;
156841c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  /// \@implementation may have private ivars.
1569af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian  SourceLocation IvarLBraceLoc;
1570af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian  SourceLocation IvarRBraceLoc;
1571af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian
1572e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// Support for ivar initialization.
1573e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// IvarInitializers - The arguments used to initialize the ivars
1574cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt  CXXCtorInitializer **IvarInitializers;
1575e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  unsigned NumIvarInitializers;
1576f85e193739c953358c865005855253af4f68a497John McCall
1577f85e193739c953358c865005855253af4f68a497John McCall  /// true if class has a .cxx_[construct,destruct] method.
1578f85e193739c953358c865005855253af4f68a497John McCall  bool HasCXXStructors : 1;
1579ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
15800982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// true if class extension has at least one bitfield ivar.
1581000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  bool HasSynthBitfield : 1;
1582ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
15831711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis  ObjCImplementationDecl(DeclContext *DC,
1584a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek                         ObjCInterfaceDecl *classInterface,
15851711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                         ObjCInterfaceDecl *superDecl,
1586af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian                         SourceLocation nameLoc, SourceLocation atStartLoc,
1587af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian                         SourceLocation IvarLBraceLoc=SourceLocation(),
1588af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian                         SourceLocation IvarRBraceLoc=SourceLocation())
15891711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis    : ObjCImplDecl(ObjCImplementation, DC, classInterface, nameLoc, atStartLoc),
1590af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian       SuperClass(superDecl), IvarLBraceLoc(IvarLBraceLoc),
1591af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian       IvarRBraceLoc(IvarRBraceLoc),
1592af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian       IvarInitializers(0), NumIvarInitializers(0),
1593af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian       HasCXXStructors(false), HasSynthBitfield(false){}
15941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
15951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static ObjCImplementationDecl *Create(ASTContext &C, DeclContext *DC,
159675c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner                                        ObjCInterfaceDecl *classInterface,
15971711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                                        ObjCInterfaceDecl *superDecl,
15981711fc91efb36d131f7ba771f73f0154dc1abd1fArgyrios Kyrtzidis                                        SourceLocation nameLoc,
1599af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian                                        SourceLocation atStartLoc,
1600af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian                                        SourceLocation IvarLBraceLoc=SourceLocation(),
1601af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian                                        SourceLocation IvarRBraceLoc=SourceLocation());
1602ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
16031e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor  static ObjCImplementationDecl *CreateDeserialized(ASTContext &C, unsigned ID);
16041e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor
1605e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// init_iterator - Iterates through the ivar initializer list.
1606cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt  typedef CXXCtorInitializer **init_iterator;
1607ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1608e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// init_const_iterator - Iterates through the ivar initializer list.
1609cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt  typedef CXXCtorInitializer * const * init_const_iterator;
1610ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1611e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// init_begin() - Retrieve an iterator to the first initializer.
1612e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  init_iterator       init_begin()       { return IvarInitializers; }
1613e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// begin() - Retrieve an iterator to the first initializer.
1614e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  init_const_iterator init_begin() const { return IvarInitializers; }
1615ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1616e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// init_end() - Retrieve an iterator past the last initializer.
1617e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  init_iterator       init_end()       {
1618e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian    return IvarInitializers + NumIvarInitializers;
1619e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  }
1620e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// end() - Retrieve an iterator past the last initializer.
1621e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  init_const_iterator init_end() const {
1622e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian    return IvarInitializers + NumIvarInitializers;
1623e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  }
1624e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// getNumArgs - Number of ivars which must be initialized.
1625e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  unsigned getNumIvarInitializers() const {
1626e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian    return NumIvarInitializers;
1627e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  }
1628ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1629e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  void setNumIvarInitializers(unsigned numNumIvarInitializers) {
1630e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian    NumIvarInitializers = numNumIvarInitializers;
1631e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  }
1632ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1633e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  void setIvarInitializers(ASTContext &C,
1634cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt                           CXXCtorInitializer ** initializers,
1635e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian                           unsigned numInitializers);
1636f85e193739c953358c865005855253af4f68a497John McCall
1637f85e193739c953358c865005855253af4f68a497John McCall  bool hasCXXStructors() const { return HasCXXStructors; }
1638f85e193739c953358c865005855253af4f68a497John McCall  void setHasCXXStructors(bool val) { HasCXXStructors = val; }
1639ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1640000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  bool hasSynthBitfield() const { return HasSynthBitfield; }
1641000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  void setHasSynthBitfield (bool val) { HasSynthBitfield = val; }
1642ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
16434afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  /// getIdentifier - Get the identifier that names the class
16444afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  /// interface associated with this implementation.
16451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  IdentifierInfo *getIdentifier() const {
16461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return getClassInterface()->getIdentifier();
16474afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  }
16484afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor
1649d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  /// getName - Get the name of identifier for the class interface associated
1650d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  /// with this implementation as a StringRef.
1651d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  //
1652d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  // FIXME: This is a bad API, we are overriding the NamedDecl::getName, to mean
1653d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  // something different.
1654686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getName() const {
1655d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar    assert(getIdentifier() && "Name is not a simple identifier");
1656d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar    return getIdentifier()->getName();
1657d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  }
1658d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar
16594afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  /// getNameAsCString - Get the name of identifier for the class
16604afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  /// interface associated with this implementation as a C string
16614afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  /// (const char*).
16627fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar  //
16637fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar  // FIXME: Move to StringRef API.
16644afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  const char *getNameAsCString() const {
1665d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar    return getName().data();
16664afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  }
16674afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor
16684afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  /// @brief Get the name of the class associated with this interface.
16697fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar  //
16707fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar  // FIXME: Move to StringRef API.
16714afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  std::string getNameAsString() const {
1672d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar    return getName();
16734afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  }
16744afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor
1675e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  const ObjCInterfaceDecl *getSuperClass() const { return SuperClass; }
1676e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  ObjCInterfaceDecl *getSuperClass() { return SuperClass; }
16771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1678f3a7af901231535191d14cb524d58f22907ac4d2Chris Lattner  void setSuperClass(ObjCInterfaceDecl * superCls) { SuperClass = superCls; }
16791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1680af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian  void setIvarLBraceLoc(SourceLocation Loc) { IvarLBraceLoc = Loc; }
1681af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian  SourceLocation getIvarLBraceLoc() const { return IvarLBraceLoc; }
1682af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian  void setIvarRBraceLoc(SourceLocation Loc) { IvarRBraceLoc = Loc; }
1683af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian  SourceLocation getIvarRBraceLoc() const { return IvarRBraceLoc; }
1684af300298ab86752fa64e339ba34195888a830756Fariborz Jahanian
16858f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor  typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
16861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ivar_iterator ivar_begin() const {
16871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return ivar_iterator(decls_begin());
16888f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor  }
16891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ivar_iterator ivar_end() const {
169017945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return ivar_iterator(decls_end());
16918f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor  }
16921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  unsigned ivar_size() const {
169317945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return std::distance(ivar_begin(), ivar_end());
16948f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor  }
16951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool ivar_empty() const {
169617945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return ivar_begin() == ivar_end();
16978f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor  }
16981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
169980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1700a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCImplementationDecl *D) { return true; }
170180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCImplementation; }
17029d50c0635fb213b2a1857e3f8488580f0dab2f98Argyrios Kyrtzidis
1703d527cc06d78fe5afa5f20105b51697637eb02c56Sebastian Redl  friend class ASTDeclReader;
17043397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl  friend class ASTDeclWriter;
1705980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
1706243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian
1707f978059b82db8c0d849c5f992036210b5ca53200Benjamin Kramerraw_ostream &operator<<(raw_ostream &OS, const ObjCImplementationDecl &ID);
1708900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer
17091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ObjCCompatibleAliasDecl - Represents alias of a class. This alias is
171041c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth/// declared as \@compatibility_alias alias class.
17114afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCCompatibleAliasDecl : public NamedDecl {
171299ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
1713243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian  /// Class that this is an alias of.
1714a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *AliasedClass;
17151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1716d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  ObjCCompatibleAliasDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
1717e8043c39176e7f253fbd92982b077eca6bf2fd59Steve Naroff                          ObjCInterfaceDecl* aliasedClass)
17184afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor    : NamedDecl(ObjCCompatibleAlias, DC, L, Id), AliasedClass(aliasedClass) {}
1719f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattnerpublic:
1720d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCCompatibleAliasDecl *Create(ASTContext &C, DeclContext *DC,
17210ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner                                         SourceLocation L, IdentifierInfo *Id,
1722f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner                                         ObjCInterfaceDecl* aliasedClass);
1723f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner
17241e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor  static ObjCCompatibleAliasDecl *CreateDeserialized(ASTContext &C,
17251e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor                                                     unsigned ID);
17261e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor
1727f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner  const ObjCInterfaceDecl *getClassInterface() const { return AliasedClass; }
1728f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner  ObjCInterfaceDecl *getClassInterface() { return AliasedClass; }
172930833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  void setClassInterface(ObjCInterfaceDecl *D) { AliasedClass = D; }
17301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
173180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1732a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCCompatibleAliasDecl *D) { return true; }
173380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCCompatibleAlias; }
17341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1735243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian};
17361de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian
17370982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief Represents one property declaration in an Objective-C interface.
17380982205bade2fb4fc984c27b2ab401e683963b10James Dennett///
17391de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian/// For example:
17400982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \code{.mm}
174141c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth/// \@property (assign, readwrite) int MyProperty;
17420982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \endcode
17434afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCPropertyDecl : public NamedDecl {
174499ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
174582a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanianpublic:
1746a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner  enum PropertyAttributeKind {
17471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    OBJC_PR_noattr    = 0x00,
17481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    OBJC_PR_readonly  = 0x01,
1749a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_getter    = 0x02,
17501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    OBJC_PR_assign    = 0x04,
17511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    OBJC_PR_readwrite = 0x08,
1752a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_retain    = 0x10,
17531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    OBJC_PR_copy      = 0x20,
1754a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_nonatomic = 0x40,
175545937ae10a0f70f74508165aab4f2b63e18ea747Fariborz Jahanian    OBJC_PR_setter    = 0x80,
1756f85e193739c953358c865005855253af4f68a497John McCall    OBJC_PR_atomic    = 0x100,
1757f85e193739c953358c865005855253af4f68a497John McCall    OBJC_PR_weak      = 0x200,
1758f85e193739c953358c865005855253af4f68a497John McCall    OBJC_PR_strong    = 0x400,
17599f3480bab8fcb6547978f8ad9e2b8f468e3658eeArgyrios Kyrtzidis    OBJC_PR_unsafe_unretained = 0x800
17609f3480bab8fcb6547978f8ad9e2b8f468e3658eeArgyrios Kyrtzidis    // Adding a property should change NumPropertyAttrsBits
17619f3480bab8fcb6547978f8ad9e2b8f468e3658eeArgyrios Kyrtzidis  };
17620a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis
17639f3480bab8fcb6547978f8ad9e2b8f468e3658eeArgyrios Kyrtzidis  enum {
17640a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis    /// \brief Number of bits fitting all the property attributes.
17659f3480bab8fcb6547978f8ad9e2b8f468e3658eeArgyrios Kyrtzidis    NumPropertyAttrsBits = 12
1766a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner  };
1767af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
17683a02b44e3948f7762dbfba94b7961281ca29d022Fariborz Jahanian  enum SetterKind { Assign, Retain, Copy, Weak };
176946b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  enum PropertyControl { None, Required, Optional };
177082a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanianprivate:
177141c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  SourceLocation AtLoc;   // location of \@property
177277bfb8b43ec3f7dee3a71f6e854b03ad29dab84fFariborz Jahanian  SourceLocation LParenLoc; // location of '(' starting attribute list or null.
177383a230c83a54190366138c1a4f4310ef838b88fcJohn McCall  TypeSourceInfo *DeclType;
17749f3480bab8fcb6547978f8ad9e2b8f468e3658eeArgyrios Kyrtzidis  unsigned PropertyAttributes : NumPropertyAttrsBits;
17759f3480bab8fcb6547978f8ad9e2b8f468e3658eeArgyrios Kyrtzidis  unsigned PropertyAttributesAsWritten : NumPropertyAttrsBits;
177641c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  // \@required/\@optional
177746b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  unsigned PropertyImplementation : 2;
17781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17795251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  Selector GetterName;    // getter name of NULL if no getter
17805251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  Selector SetterName;    // setter name of NULL if no setter
17811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
178233de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  ObjCMethodDecl *GetterMethodDecl; // Declaration of getter instance method
178333de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  ObjCMethodDecl *SetterMethodDecl; // Declaration of setter instance method
1784af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian  ObjCIvarDecl *PropertyIvarDecl;   // Synthesize ivar for this property
178533de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian
17861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ObjCPropertyDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
178777bfb8b43ec3f7dee3a71f6e854b03ad29dab84fFariborz Jahanian                   SourceLocation AtLocation,  SourceLocation LParenLocation,
178877bfb8b43ec3f7dee3a71f6e854b03ad29dab84fFariborz Jahanian                   TypeSourceInfo *T)
178977bfb8b43ec3f7dee3a71f6e854b03ad29dab84fFariborz Jahanian    : NamedDecl(ObjCProperty, DC, L, Id), AtLoc(AtLocation),
179077bfb8b43ec3f7dee3a71f6e854b03ad29dab84fFariborz Jahanian      LParenLoc(LParenLocation), DeclType(T),
1791ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie      PropertyAttributes(OBJC_PR_noattr),
179280aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian      PropertyAttributesAsWritten(OBJC_PR_noattr),
179380aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian      PropertyImplementation(None),
17941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      GetterName(Selector()),
179533de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian      SetterName(Selector()),
1796af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian      GetterMethodDecl(0), SetterMethodDecl(0) , PropertyIvarDecl(0) {}
1797f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattnerpublic:
17981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static ObjCPropertyDecl *Create(ASTContext &C, DeclContext *DC,
17991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                  SourceLocation L,
1800d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian                                  IdentifierInfo *Id, SourceLocation AtLocation,
180177bfb8b43ec3f7dee3a71f6e854b03ad29dab84fFariborz Jahanian                                  SourceLocation LParenLocation,
180283a230c83a54190366138c1a4f4310ef838b88fcJohn McCall                                  TypeSourceInfo *T,
180346b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian                                  PropertyControl propControl = None);
18041e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor
18051e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor  static ObjCPropertyDecl *CreateDeserialized(ASTContext &C, unsigned ID);
18061e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor
1807d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian  SourceLocation getAtLoc() const { return AtLoc; }
1808d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian  void setAtLoc(SourceLocation L) { AtLoc = L; }
180977bfb8b43ec3f7dee3a71f6e854b03ad29dab84fFariborz Jahanian
181077bfb8b43ec3f7dee3a71f6e854b03ad29dab84fFariborz Jahanian  SourceLocation getLParenLoc() const { return LParenLoc; }
181177bfb8b43ec3f7dee3a71f6e854b03ad29dab84fFariborz Jahanian  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1812ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
181383a230c83a54190366138c1a4f4310ef838b88fcJohn McCall  TypeSourceInfo *getTypeSourceInfo() const { return DeclType; }
181483a230c83a54190366138c1a4f4310ef838b88fcJohn McCall  QualType getType() const { return DeclType->getType(); }
181583a230c83a54190366138c1a4f4310ef838b88fcJohn McCall  void setType(TypeSourceInfo *T) { DeclType = T; }
181670e5a14c6076d63833c62d1d6d628c26309897c1Douglas Gregor
1817a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner  PropertyAttributeKind getPropertyAttributes() const {
1818f4af5154571e0c5eadb19df10e65464766ef6683Chris Lattner    return PropertyAttributeKind(PropertyAttributes);
1819f4af5154571e0c5eadb19df10e65464766ef6683Chris Lattner  }
18201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setPropertyAttributes(PropertyAttributeKind PRVal) {
1821a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    PropertyAttributes |= PRVal;
182282a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian  }
1823394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar
182480aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  PropertyAttributeKind getPropertyAttributesAsWritten() const {
182580aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian    return PropertyAttributeKind(PropertyAttributesAsWritten);
182680aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  }
18270a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis
18280a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis  bool hasWrittenStorageAttribute() const {
18290a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis    return PropertyAttributesAsWritten & (OBJC_PR_assign | OBJC_PR_copy |
18300a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis        OBJC_PR_unsafe_unretained | OBJC_PR_retain | OBJC_PR_strong |
18310a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis        OBJC_PR_weak);
18320a68dc7f04be1542ce249ff4adb169453698ad91Argyrios Kyrtzidis  }
1833ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
183480aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  void setPropertyAttributesAsWritten(PropertyAttributeKind PRVal) {
183580aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian    PropertyAttributesAsWritten = PRVal;
183680aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  }
1837ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
18388cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian void makeitReadWriteAttribute(void) {
18398cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian    PropertyAttributes &= ~OBJC_PR_readonly;
18408cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian    PropertyAttributes |= OBJC_PR_readwrite;
18411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump }
18428cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian
1843af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  // Helper methods for accessing attributes.
1844af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
1845af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  /// isReadOnly - Return true iff the property has a setter.
1846394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar  bool isReadOnly() const {
1847394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar    return (PropertyAttributes & OBJC_PR_readonly);
1848394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar  }
1849af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
1850265941bc308d65cc270d5c4de5806f37ce405606John McCall  /// isAtomic - Return true if the property is atomic.
1851265941bc308d65cc270d5c4de5806f37ce405606John McCall  bool isAtomic() const {
1852265941bc308d65cc270d5c4de5806f37ce405606John McCall    return (PropertyAttributes & OBJC_PR_atomic);
1853265941bc308d65cc270d5c4de5806f37ce405606John McCall  }
1854265941bc308d65cc270d5c4de5806f37ce405606John McCall
1855265941bc308d65cc270d5c4de5806f37ce405606John McCall  /// isRetaining - Return true if the property retains its value.
1856265941bc308d65cc270d5c4de5806f37ce405606John McCall  bool isRetaining() const {
1857265941bc308d65cc270d5c4de5806f37ce405606John McCall    return (PropertyAttributes &
1858265941bc308d65cc270d5c4de5806f37ce405606John McCall            (OBJC_PR_retain | OBJC_PR_strong | OBJC_PR_copy));
1859265941bc308d65cc270d5c4de5806f37ce405606John McCall  }
1860265941bc308d65cc270d5c4de5806f37ce405606John McCall
1861af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  /// getSetterKind - Return the method used for doing assignment in
1862af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  /// the property setter. This is only valid if the property has been
1863af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  /// defined to have a setter.
1864af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  SetterKind getSetterKind() const {
18656dc6f008994472cf4da321855e8c51c39720f3edJohn McCall    if (PropertyAttributes & OBJC_PR_strong)
18666dc6f008994472cf4da321855e8c51c39720f3edJohn McCall      return getType()->isBlockPointerType() ? Copy : Retain;
18676dc6f008994472cf4da321855e8c51c39720f3edJohn McCall    if (PropertyAttributes & OBJC_PR_retain)
1868af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar      return Retain;
1869af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar    if (PropertyAttributes & OBJC_PR_copy)
1870af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar      return Copy;
18713a02b44e3948f7762dbfba94b7961281ca29d022Fariborz Jahanian    if (PropertyAttributes & OBJC_PR_weak)
18723a02b44e3948f7762dbfba94b7961281ca29d022Fariborz Jahanian      return Weak;
1873af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar    return Assign;
1874af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  }
1875af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
18765251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  Selector getGetterName() const { return GetterName; }
18775251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  void setGetterName(Selector Sel) { GetterName = Sel; }
18781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18795251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  Selector getSetterName() const { return SetterName; }
18805251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  void setSetterName(Selector Sel) { SetterName = Sel; }
18811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
188233de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  ObjCMethodDecl *getGetterMethodDecl() const { return GetterMethodDecl; }
188333de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  void setGetterMethodDecl(ObjCMethodDecl *gDecl) { GetterMethodDecl = gDecl; }
188433de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian
188533de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  ObjCMethodDecl *getSetterMethodDecl() const { return SetterMethodDecl; }
188633de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  void setSetterMethodDecl(ObjCMethodDecl *gDecl) { SetterMethodDecl = gDecl; }
18871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
188841c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  // Related to \@optional/\@required declared in \@protocol
188946b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  void setPropertyImplementation(PropertyControl pc) {
189046b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian    PropertyImplementation = pc;
189146b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  }
189246b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  PropertyControl getPropertyImplementation() const {
189346b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian    return PropertyControl(PropertyImplementation);
18941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
18951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1896af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian  void setPropertyIvarDecl(ObjCIvarDecl *Ivar) {
1897af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian    PropertyIvarDecl = Ivar;
1898af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian  }
1899af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian  ObjCIvarDecl *getPropertyIvarDecl() const {
1900af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian    return PropertyIvarDecl;
1901af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian  }
19021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1903aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  virtual SourceRange getSourceRange() const LLVM_READONLY {
1904e3c60a7ce9e0f42c7ca2344b33203266aceca1dbDouglas Gregor    return SourceRange(AtLoc, getLocation());
1905e3c60a7ce9e0f42c7ca2344b33203266aceca1dbDouglas Gregor  }
1906e3c60a7ce9e0f42c7ca2344b33203266aceca1dbDouglas Gregor
19079f550ff05d496e6b9480e5619a21d9da0c9e27c1Ted Kremenek  /// Lookup a property by name in the specified DeclContext.
1908de09d0c9694f01a99870a8825266d44a29ebb325Ted Kremenek  static ObjCPropertyDecl *findPropertyDecl(const DeclContext *DC,
19099f550ff05d496e6b9480e5619a21d9da0c9e27c1Ted Kremenek                                            IdentifierInfo *propertyID);
19109f550ff05d496e6b9480e5619a21d9da0c9e27c1Ted Kremenek
191180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1912a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCPropertyDecl *D) { return true; }
191380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCProperty; }
191482a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian};
1915980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
19161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ObjCPropertyImplDecl - Represents implementation declaration of a property
191761d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian/// in a class or category implementation block. For example:
191841c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth/// \@synthesize prop1 = ivar1;
191961d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian///
19204afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCPropertyImplDecl : public Decl {
192161d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanianpublic:
19229f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar  enum Kind {
19239f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar    Synthesize,
19249f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar    Dynamic
192561d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  };
192661d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanianprivate:
192741c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  SourceLocation AtLoc;   // location of \@synthesize or \@dynamic
1928ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
192941c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  /// \brief For \@synthesize, the location of the ivar, if it was written in
1930a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  /// the source code.
1931a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  ///
1932a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  /// \code
193341c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  /// \@synthesize int a = b
1934a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  /// \endcode
1935a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  SourceLocation IvarLoc;
1936ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
193761d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  /// Property declaration being implemented
193861d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  ObjCPropertyDecl *PropertyDecl;
1939be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek
194041c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  /// Null for \@dynamic. Required for \@synthesize.
194161d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  ObjCIvarDecl *PropertyIvarDecl;
1942ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
194341c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  /// Null for \@dynamic. Non-null if property must be copy-constructed in
194441c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  /// getter.
194517cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  Expr *GetterCXXConstructor;
1946ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
194741c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  /// Null for \@dynamic. Non-null if property has assignment operator to call
194817cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  /// in Setter synthesis.
194917cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  Expr *SetterCXXAssignment;
1950be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek
1951d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  ObjCPropertyImplDecl(DeclContext *DC, SourceLocation atLoc, SourceLocation L,
19521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                       ObjCPropertyDecl *property,
19531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                       Kind PK,
1954a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor                       ObjCIvarDecl *ivarDecl,
1955a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor                       SourceLocation ivarLoc)
19561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : Decl(ObjCPropertyImpl, DC, L), AtLoc(atLoc),
1957ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie      IvarLoc(ivarLoc), PropertyDecl(property), PropertyIvarDecl(ivarDecl),
195817cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian      GetterCXXConstructor(0), SetterCXXAssignment(0) {
19599f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar    assert (PK == Dynamic || PropertyIvarDecl);
19609f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar  }
19611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19629f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbarpublic:
1963d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCPropertyImplDecl *Create(ASTContext &C, DeclContext *DC,
19641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                      SourceLocation atLoc, SourceLocation L,
19651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                      ObjCPropertyDecl *property,
19661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                      Kind PK,
1967a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor                                      ObjCIvarDecl *ivarDecl,
1968a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor                                      SourceLocation ivarLoc);
196961d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian
19701e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor  static ObjCPropertyImplDecl *CreateDeserialized(ASTContext &C, unsigned ID);
19711e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor
1972aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  virtual SourceRange getSourceRange() const LLVM_READONLY;
1973ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1974aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceLocation getLocStart() const LLVM_READONLY { return AtLoc; }
19758818c4fb69cb2a4eec94b217a90f94f9e075296eDouglas Gregor  void setAtLoc(SourceLocation Loc) { AtLoc = Loc; }
1976d40910b581b09c937a8c1fdcde9b8ec724398fb9Steve Naroff
1977be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek  ObjCPropertyDecl *getPropertyDecl() const {
1978be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek    return PropertyDecl;
1979be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek  }
19808818c4fb69cb2a4eec94b217a90f94f9e075296eDouglas Gregor  void setPropertyDecl(ObjCPropertyDecl *Prop) { PropertyDecl = Prop; }
19818818c4fb69cb2a4eec94b217a90f94f9e075296eDouglas Gregor
19829f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar  Kind getPropertyImplementation() const {
19839f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar    return PropertyIvarDecl ? Synthesize : Dynamic;
1984be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek  }
19851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1986af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  ObjCIvarDecl *getPropertyIvarDecl() const {
1987be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek    return PropertyIvarDecl;
1988be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek  }
1989a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  SourceLocation getPropertyIvarDeclLoc() const { return IvarLoc; }
1990ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1991a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  void setPropertyIvarDecl(ObjCIvarDecl *Ivar,
1992ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                           SourceLocation IvarLoc) {
1993ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    PropertyIvarDecl = Ivar;
1994a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor    this->IvarLoc = IvarLoc;
1995a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  }
1996ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1997135bf8ee69e2ae2daea4f713381995028c41e264Argyrios Kyrtzidis  /// \brief For \@synthesize, returns true if an ivar name was explicitly
1998135bf8ee69e2ae2daea4f713381995028c41e264Argyrios Kyrtzidis  /// specified.
1999135bf8ee69e2ae2daea4f713381995028c41e264Argyrios Kyrtzidis  ///
2000135bf8ee69e2ae2daea4f713381995028c41e264Argyrios Kyrtzidis  /// \code
2001135bf8ee69e2ae2daea4f713381995028c41e264Argyrios Kyrtzidis  /// \@synthesize int a = b; // true
2002135bf8ee69e2ae2daea4f713381995028c41e264Argyrios Kyrtzidis  /// \@synthesize int a; // false
2003135bf8ee69e2ae2daea4f713381995028c41e264Argyrios Kyrtzidis  /// \endcode
2004135bf8ee69e2ae2daea4f713381995028c41e264Argyrios Kyrtzidis  bool isIvarNameSpecified() const {
2005135bf8ee69e2ae2daea4f713381995028c41e264Argyrios Kyrtzidis    return IvarLoc.isValid() && IvarLoc != getLocation();
2006135bf8ee69e2ae2daea4f713381995028c41e264Argyrios Kyrtzidis  }
2007135bf8ee69e2ae2daea4f713381995028c41e264Argyrios Kyrtzidis
200817cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  Expr *getGetterCXXConstructor() const {
200917cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian    return GetterCXXConstructor;
201017cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  }
201117cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  void setGetterCXXConstructor(Expr *getterCXXConstructor) {
201217cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian    GetterCXXConstructor = getterCXXConstructor;
201317cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  }
20148818c4fb69cb2a4eec94b217a90f94f9e075296eDouglas Gregor
201517cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  Expr *getSetterCXXAssignment() const {
201617cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian    return SetterCXXAssignment;
201717cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  }
201817cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  void setSetterCXXAssignment(Expr *setterCXXAssignment) {
201917cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian    SetterCXXAssignment = setterCXXAssignment;
202017cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  }
2021ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
202280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
20231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const ObjCPropertyImplDecl *D) { return true; }
202480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Decl::Kind K) { return K == ObjCPropertyImpl; }
2025ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2026a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  friend class ASTDeclReader;
202761d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian};
202861d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian
2029980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff}  // end namespace clang
2030980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff#endif
2031