DeclObjC.h revision 53b9441b5a81a24fa1f66f3f6416f1e36baa9c2f
1980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff//===--- DeclObjC.h - Classes for representing declarations -----*- C++ -*-===//
2980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff//
3980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff//                     The LLVM Compiler Infrastructure
4980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff//
50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source
60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details.
7980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff//
8980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff//===----------------------------------------------------------------------===//
9980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff//
10980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff//  This file defines the DeclObjC interface and subclasses.
11980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff//
12980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff//===----------------------------------------------------------------------===//
13980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
14980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff#ifndef LLVM_CLANG_AST_DECLOBJC_H
15980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff#define LLVM_CLANG_AST_DECLOBJC_H
16980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
17980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff#include "clang/AST/Decl.h"
186ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson#include "llvm/ADT/STLExtras.h"
19980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
20980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffnamespace clang {
21980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffclass Expr;
22980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffclass Stmt;
23980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffclass FunctionDecl;
2460f8c868ffb346b78451a3eccaecd0461d2ae498Fariborz Jahanianclass RecordDecl;
25a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCIvarDecl;
26a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCMethodDecl;
27a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCProtocolDecl;
28a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCCategoryDecl;
29a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCPropertyDecl;
30f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanianclass ObjCPropertyImplDecl;
31e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanianclass CXXBaseOrMemberInitializer;
3268835718c4125f2f66740cd04de7088645ec695dChris Lattner
33793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnerclass ObjCListBase {
34793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  void operator=(const ObjCListBase &);     // DO NOT IMPLEMENT
35793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  ObjCListBase(const ObjCListBase&);        // DO NOT IMPLEMENT
36793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnerprotected:
37793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  /// List is an array of pointers to objects that are not owned by this object.
38793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  void **List;
393db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  unsigned NumElts;
40793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner
413db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattnerpublic:
42793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  ObjCListBase() : List(0), NumElts(0) {}
43793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  unsigned size() const { return NumElts; }
44793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  bool empty() const { return NumElts == 0; }
451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
46793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnerprotected:
4738af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  void set(void *const* InList, unsigned Elts, ASTContext &Ctx);
48793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner};
491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
51793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner/// ObjCList - This is a simple template class used to hold various lists of
52793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner/// decls etc, which is heavily used by the ObjC front-end.  This only use case
53793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner/// this supports is setting the list all at once and then reading elements out
54793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner/// of it.
55793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnertemplate <typename T>
56793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnerclass ObjCList : public ObjCListBase {
57793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnerpublic:
5838af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  void set(T* const* InList, unsigned Elts, ASTContext &Ctx) {
5938af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner    ObjCListBase::set(reinterpret_cast<void*const*>(InList), Elts, Ctx);
60793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  }
611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
62793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  typedef T* const * iterator;
63793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  iterator begin() const { return (iterator)List; }
64793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  iterator end() const { return (iterator)List+NumElts; }
651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
66793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner  T* operator[](unsigned Idx) const {
67793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner    assert(Idx < NumElts && "Invalid access");
68793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner    return (T*)List[Idx];
693db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  }
703db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner};
713db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner
7218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor/// \brief A list of Objective-C protocols, along with the source
7318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor/// locations at which they were referenced.
7418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregorclass ObjCProtocolList : public ObjCList<ObjCProtocolDecl> {
7518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  SourceLocation *Locations;
7618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor
7718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  using ObjCList<ObjCProtocolDecl>::set;
7818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor
7918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregorpublic:
8018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  ObjCProtocolList() : ObjCList<ObjCProtocolDecl>(), Locations(0) { }
8118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor
8218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef const SourceLocation *loc_iterator;
8318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  loc_iterator loc_begin() const { return Locations; }
8418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  loc_iterator loc_end() const { return Locations + size(); }
8518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor
8618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  void set(ObjCProtocolDecl* const* InList, unsigned Elts,
8718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor           const SourceLocation *Locs, ASTContext &Ctx);
8818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor};
891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff
91a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCMethodDecl - Represents an instance or class method declaration.
9258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// ObjC methods can be declared within 4 contexts: class interfaces,
9358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// categories, protocols, and class implementations. While C++ member
941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// functions leverage C syntax, Objective-C method syntax is modeled after
951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Smalltalk (using colons to specify argument types/expressions).
9658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Here are some brief examples:
9758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff///
9858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Setter/getter instance methods:
9958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// - (void)setMenu:(NSMenu *)menu;
1001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// - (NSMenu *)menu;
1011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
10258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Instance method that takes 2 NSView arguments:
10358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// - (void)replaceSubview:(NSView *)oldView with:(NSView *)newView;
10458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff///
10558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Getter class method:
10658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// + (NSMenu *)defaultMenu;
10758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff///
10858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// A selector represents a unique name for a method. The selector names for
10958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// the above methods are setMenu:, menu, replaceSubview:with:, and defaultMenu.
11058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff///
1114afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCMethodDecl : public NamedDecl, public DeclContext {
11258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroffpublic:
11358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  enum ImplementationControl { None, Required, Optional };
11458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroffprivate:
11558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  /// Bitfields must be first fields in this class so they pack with those
11658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  /// declared in class Decl.
11758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  /// instance (true) or class (false) method.
11858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  bool IsInstance : 1;
11958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  bool IsVariadic : 1;
1201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1214607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian  // Synthesized declaration method for a property setter/getter
1224607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian  bool IsSynthesized : 1;
1233fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian
1243fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian  // Method has a definition.
1253fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian  bool IsDefined : 1;
1261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
127ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  // NOTE: VC++ treats enums as signed, avoid using ImplementationControl enum
12858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  /// @required/@optional
129ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  unsigned DeclImplementation : 2;
1301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
131ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  // NOTE: VC++ treats enums as signed, avoid using the ObjCDeclQualifier enum
13258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  /// in, inout, etc.
133ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  unsigned objcDeclQualifier : 6;
1341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1357732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian  // Number of args separated by ':' in a method declaration.
1367732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian  unsigned NumSelectorArgs;
1377732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian
1384bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor  // Result type of this method.
13958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  QualType MethodDeclType;
1404bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor
1414bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor  // Type source information for the result type.
1424bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor  TypeSourceInfo *ResultTInfo;
1434bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor
1442073216a1075767b5d25c23d1462b7034686d94dChris Lattner  /// ParamInfo - List of pointers to VarDecls for the formal parameters of this
1452073216a1075767b5d25c23d1462b7034686d94dChris Lattner  /// Method.
1462073216a1075767b5d25c23d1462b7034686d94dChris Lattner  ObjCList<ParmVarDecl> ParamInfo;
1471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  /// List of attributes for this method declaration.
149a2e85ada1dfef36201a31f6646bc4ea3bd76a89aArgyrios Kyrtzidis  SourceLocation EndLoc; // the location of the ';' or '}'.
1501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  // The following are only used for method definitions, null otherwise.
15258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  // FIXME: space savings opportunity, consider a sub-class.
15358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  Stmt *Body;
154451318c08a6342c10b8986060386fd9274418437Daniel Dunbar
155451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// SelfDecl - Decl for the implicit self parameter. This is lazily
156451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// constructed by createImplicitParams.
1574111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  ImplicitParamDecl *SelfDecl;
158451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// CmdDecl - Decl for the implicit _cmd parameter. This is lazily
159451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// constructed by createImplicitParams.
1604111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  ImplicitParamDecl *CmdDecl;
1611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
162a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCMethodDecl(SourceLocation beginLoc, SourceLocation endLoc,
16358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff                 Selector SelInfo, QualType T,
1644bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor                 TypeSourceInfo *ResultTInfo,
1650701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff                 DeclContext *contextDecl,
166f6414927e67e27d9324d8d179c5f7ea620443924Daniel Dunbar                 bool isInstance = true,
16758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff                 bool isVariadic = false,
1684607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian                 bool isSynthesized = false,
1693fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian                 bool isDefined = false,
1707732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian                 ImplementationControl impControl = None,
1717732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian                 unsigned numSelectorArgs = 0)
1724afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  : NamedDecl(ObjCMethod, contextDecl, beginLoc, SelInfo),
173b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner    DeclContext(ObjCMethod),
17458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff    IsInstance(isInstance), IsVariadic(isVariadic),
1754607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian    IsSynthesized(isSynthesized),
1763fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian    IsDefined(isDefined),
17758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff    DeclImplementation(impControl), objcDeclQualifier(OBJC_TQ_None),
1787732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian    NumSelectorArgs(numSelectorArgs), MethodDeclType(T),
1797732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian    ResultTInfo(ResultTInfo),
1804111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner    EndLoc(endLoc), Body(0), SelfDecl(0), CmdDecl(0) {}
1818a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek
18257ea6bee79cc60ba20c7886b453f40f380dce1b1Argyrios Kyrtzidis  /// \brief A definition will return its interface declaration.
18357ea6bee79cc60ba20c7886b453f40f380dce1b1Argyrios Kyrtzidis  /// An interface declaration will return its definition.
18457ea6bee79cc60ba20c7886b453f40f380dce1b1Argyrios Kyrtzidis  /// Otherwise it will return itself.
18557ea6bee79cc60ba20c7886b453f40f380dce1b1Argyrios Kyrtzidis  virtual ObjCMethodDecl *getNextRedeclaration();
18657ea6bee79cc60ba20c7886b453f40f380dce1b1Argyrios Kyrtzidis
1876c4ae5de0c356777446f823b573821fb95560d91Chris Lattnerpublic:
1880ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner  static ObjCMethodDecl *Create(ASTContext &C,
1891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                SourceLocation beginLoc,
1906c4ae5de0c356777446f823b573821fb95560d91Chris Lattner                                SourceLocation endLoc, Selector SelInfo,
1914bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor                                QualType T,
1924bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor                                TypeSourceInfo *ResultTInfo,
1934bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor                                DeclContext *contextDecl,
194f6414927e67e27d9324d8d179c5f7ea620443924Daniel Dunbar                                bool isInstance = true,
1956c4ae5de0c356777446f823b573821fb95560d91Chris Lattner                                bool isVariadic = false,
1964607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian                                bool isSynthesized = false,
1973fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian                                bool isDefined = false,
1987732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian                                ImplementationControl impControl = None,
1997732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian                                unsigned numSelectorArgs = 0);
200e7f9d301a10b4b3223e91d9be4362b44cba0a212Argyrios Kyrtzidis
201e7f9d301a10b4b3223e91d9be4362b44cba0a212Argyrios Kyrtzidis  virtual ObjCMethodDecl *getCanonicalDecl();
20213e635c55eb23f736d38abf9c954801bd6482db4Ted Kremenek  const ObjCMethodDecl *getCanonicalDecl() const {
20313e635c55eb23f736d38abf9c954801bd6482db4Ted Kremenek    return const_cast<ObjCMethodDecl*>(this)->getCanonicalDecl();
20413e635c55eb23f736d38abf9c954801bd6482db4Ted Kremenek  }
205e7f9d301a10b4b3223e91d9be4362b44cba0a212Argyrios Kyrtzidis
206ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  ObjCDeclQualifier getObjCDeclQualifier() const {
207ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek    return ObjCDeclQualifier(objcDeclQualifier);
208ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  }
209a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void setObjCDeclQualifier(ObjCDeclQualifier QV) { objcDeclQualifier = QV; }
2101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2117732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian  unsigned getNumSelectorArgs() const { return NumSelectorArgs; }
2127732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian  void setNumSelectorArgs(unsigned numSelectorArgs) {
2137732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian    NumSelectorArgs = numSelectorArgs;
2147732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian  }
2157732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian
21658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  // Location information, modeled after the Stmt API.
21758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  SourceLocation getLocStart() const { return getLocation(); }
21858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  SourceLocation getLocEnd() const { return EndLoc; }
21953c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setEndLoc(SourceLocation Loc) { EndLoc = Loc; }
2201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual SourceRange getSourceRange() const {
2211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(getLocation(), EndLoc);
2229776ba0d844cf9f6888e871e3fd246ae782f76f4Daniel Dunbar  }
2231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2245619688510185081cbb4621d703daf7ee24cf39aChris Lattner  ObjCInterfaceDecl *getClassInterface();
2255619688510185081cbb4621d703daf7ee24cf39aChris Lattner  const ObjCInterfaceDecl *getClassInterface() const {
2265619688510185081cbb4621d703daf7ee24cf39aChris Lattner    return const_cast<ObjCMethodDecl*>(this)->getClassInterface();
227e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  }
2281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2292e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  Selector getSelector() const { return getDeclName().getObjCSelector(); }
2303a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson
23158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  QualType getResultType() const { return MethodDeclType; }
23253c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setResultType(QualType T) { MethodDeclType = T; }
2331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2345291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// \brief Determine the type of an expression that sends a message to this
2355291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// function.
2365291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  QualType getSendResultType() const {
2376398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor    return getResultType().getNonLValueExprType(getASTContext());
2385291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  }
2395291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor
2404bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor  TypeSourceInfo *getResultTypeSourceInfo() const { return ResultTInfo; }
2414bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor  void setResultTypeSourceInfo(TypeSourceInfo *TInfo) { ResultTInfo = TInfo; }
2424bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor
243d57f635d520e8cb5b93d3d770ff58db06c62de54Chris Lattner  // Iterator access to formal parameters.
2442073216a1075767b5d25c23d1462b7034686d94dChris Lattner  unsigned param_size() const { return ParamInfo.size(); }
2452073216a1075767b5d25c23d1462b7034686d94dChris Lattner  typedef ObjCList<ParmVarDecl>::iterator param_iterator;
2462073216a1075767b5d25c23d1462b7034686d94dChris Lattner  param_iterator param_begin() const { return ParamInfo.begin(); }
2472073216a1075767b5d25c23d1462b7034686d94dChris Lattner  param_iterator param_end() const { return ParamInfo.end(); }
2487732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian  // This method returns and of the parameters which are part of the selector
2497732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian  // name mangling requirements.
2507732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian  param_iterator sel_param_end() const {
2517732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian    return ParamInfo.begin() + NumSelectorArgs;
2527732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian  }
25389951a86b594513c2a013532ed45d197413b1087Chris Lattner
2544ecb25fa94897b2c03510292acace710e5262ba5Fariborz Jahanian  void setMethodParams(ASTContext &C, ParmVarDecl *const *List, unsigned Num,
2554ecb25fa94897b2c03510292acace710e5262ba5Fariborz Jahanian                       unsigned numSelectorArgs) {
25638af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner    ParamInfo.set(List, Num, C);
2574ecb25fa94897b2c03510292acace710e5262ba5Fariborz Jahanian    NumSelectorArgs = numSelectorArgs;
2582073216a1075767b5d25c23d1462b7034686d94dChris Lattner  }
2594111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner
2606ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson  // Iterator access to parameter types.
2616ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson  typedef std::const_mem_fun_t<QualType, ParmVarDecl> deref_fun;
2626ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson  typedef llvm::mapped_iterator<param_iterator, deref_fun> arg_type_iterator;
2636ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson
2646ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson  arg_type_iterator arg_type_begin() const {
2656ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson    return llvm::map_iterator(param_begin(), deref_fun(&ParmVarDecl::getType));
2666ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson  }
2676ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson  arg_type_iterator arg_type_end() const {
2686ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson    return llvm::map_iterator(param_end(), deref_fun(&ParmVarDecl::getType));
2696ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson  }
2701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
271451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// createImplicitParams - Used to lazily create the self and cmd
272451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// implict parameters. This must be called prior to using getSelfDecl()
273451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// or getCmdDecl(). The call is ignored if the implicit paramters
274451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// have already been created.
275fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian  void createImplicitParams(ASTContext &Context, const ObjCInterfaceDecl *ID);
276451318c08a6342c10b8986060386fd9274418437Daniel Dunbar
2774111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  ImplicitParamDecl * getSelfDecl() const { return SelfDecl; }
27853c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setSelfDecl(ImplicitParamDecl *SD) { SelfDecl = SD; }
2794111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  ImplicitParamDecl * getCmdDecl() const { return CmdDecl; }
28053c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setCmdDecl(ImplicitParamDecl *CD) { CmdDecl = CD; }
2811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
282f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor  bool isInstanceMethod() const { return IsInstance; }
28353c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setInstanceMethod(bool isInst) { IsInstance = isInst; }
28458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  bool isVariadic() const { return IsVariadic; }
28553c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setVariadic(bool isVar) { IsVariadic = isVar; }
2861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
287f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor  bool isClassMethod() const { return !IsInstance; }
288f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor
2894607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian  bool isSynthesized() const { return IsSynthesized; }
29053c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff  void setSynthesized(bool isSynth) { IsSynthesized = isSynth; }
2913fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian
2923fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian  bool isDefined() const { return IsDefined; }
2933fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian  void setDefined(bool isDefined) { IsDefined = isDefined; }
2941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
29558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  // Related to protocols declared in  @protocol
2961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setDeclImplementation(ImplementationControl ic) {
2971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    DeclImplementation = ic;
29858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  }
2991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ImplementationControl getImplementationControl() const {
3001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return ImplementationControl(DeclImplementation);
30158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  }
302792481eec23d8c1aa92173be589e2ae9d02514a5Ted Kremenek
3031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual Stmt *getBody() const {
3041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return (Stmt*) Body;
3057297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor  }
3066fb0aee4f9dc261bbec72e1283ad8dc0557a6d96Argyrios Kyrtzidis  CompoundStmt *getCompoundBody() { return (CompoundStmt*)Body; }
307d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl  void setBody(Stmt *B) { Body = B; }
30858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff
30966570b230941651245accbc5680b60e904eb993cArgyrios Kyrtzidis  /// \brief Returns whether this specific method is a definition.
31066570b230941651245accbc5680b60e904eb993cArgyrios Kyrtzidis  bool isThisDeclarationADefinition() const { return Body; }
31166570b230941651245accbc5680b60e904eb993cArgyrios Kyrtzidis
31258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  // Implement isa/cast/dyncast/etc.
31380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
314a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCMethodDecl *D) { return true; }
31580cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCMethod; }
31642220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  static DeclContext *castToDeclContext(const ObjCMethodDecl *D) {
31742220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis    return static_cast<DeclContext *>(const_cast<ObjCMethodDecl*>(D));
31842220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  }
31942220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  static ObjCMethodDecl *castFromDeclContext(const DeclContext *DC) {
32042220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis    return static_cast<ObjCMethodDecl *>(const_cast<DeclContext*>(DC));
32142220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  }
32258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff};
323e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
324e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff/// ObjCContainerDecl - Represents a container for method declarations.
325aecae629269fae3bf484baf1d109e9a89d14eeadArgyrios Kyrtzidis/// Current sub-classes are ObjCInterfaceDecl, ObjCCategoryDecl,
3261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ObjCProtocolDecl, and ObjCImplDecl.
327e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff///
3284afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCContainerDecl : public NamedDecl, public DeclContext {
329782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  // These two locations in the range mark the end of the method container.
330782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  // The first points to the '@' token, and the second to the 'end' token.
331782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  SourceRange AtEnd;
332e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroffpublic:
333e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
3341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ObjCContainerDecl(Kind DK, DeclContext *DC, SourceLocation L,
335d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor                    IdentifierInfo *Id)
3364afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor    : NamedDecl(DK, DC, L, Id), DeclContext(DK) {}
337e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
33893983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff  // Iterator access to properties.
33993983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff  typedef specific_decl_iterator<ObjCPropertyDecl> prop_iterator;
3401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  prop_iterator prop_begin() const {
34117945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return prop_iterator(decls_begin());
34293983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff  }
3431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  prop_iterator prop_end() const {
34417945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return prop_iterator(decls_end());
34509c4719788a5cea09897525e528fa00420f1677bSteve Naroff  }
3461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3470701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  // Iterator access to instance/class methods.
348f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor  typedef specific_decl_iterator<ObjCMethodDecl> method_iterator;
3491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  method_iterator meth_begin() const {
35017945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return method_iterator(decls_begin());
3517ed4faca5162b3ab85be7f7e57aa40e6ec170971Ted Kremenek  }
3521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  method_iterator meth_end() const {
35317945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return method_iterator(decls_end());
3547ed4faca5162b3ab85be7f7e57aa40e6ec170971Ted Kremenek  }
3550701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
3561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  typedef filtered_decl_iterator<ObjCMethodDecl,
3571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                 &ObjCMethodDecl::isInstanceMethod>
358669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor    instmeth_iterator;
35917945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  instmeth_iterator instmeth_begin() const {
36017945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return instmeth_iterator(decls_begin());
361e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff  }
36217945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  instmeth_iterator instmeth_end() const {
36317945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return instmeth_iterator(decls_end());
364e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff  }
365e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
3661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  typedef filtered_decl_iterator<ObjCMethodDecl,
3671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                 &ObjCMethodDecl::isClassMethod>
368669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor    classmeth_iterator;
36917945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  classmeth_iterator classmeth_begin() const {
37017945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return classmeth_iterator(decls_begin());
371e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff  }
37217945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  classmeth_iterator classmeth_end() const {
37317945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return classmeth_iterator(decls_end());
3740701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  }
3750701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
3760701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  // Get the local instance/class method declared in this interface.
377467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis  ObjCMethodDecl *getMethod(Selector Sel, bool isInstance) const;
378467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis  ObjCMethodDecl *getInstanceMethod(Selector Sel) const {
379467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis    return getMethod(Sel, true/*isInstance*/);
38053df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner  }
381467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis  ObjCMethodDecl *getClassMethod(Selector Sel) const {
382467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis    return getMethod(Sel, false/*isInstance*/);
383467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis  }
384467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis  ObjCIvarDecl *getIvarDecl(IdentifierInfo *Id) const;
3851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
38617945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  ObjCPropertyDecl *FindPropertyDeclaration(IdentifierInfo *PropertyId) const;
38793983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff
388e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff  // Marks the end of the container.
389782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  SourceRange getAtEndRange() const {
390782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek    return AtEnd;
391782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  }
392782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  void setAtEndRange(SourceRange atEnd) {
393782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek    AtEnd = atEnd;
394782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  }
395ddfd4c9eda34765b08fae4cb31ad5a365face107Argyrios Kyrtzidis
396ddfd4c9eda34765b08fae4cb31ad5a365face107Argyrios Kyrtzidis  virtual SourceRange getSourceRange() const {
397782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek    return SourceRange(getLocation(), getAtEndRange().getEnd());
398ddfd4c9eda34765b08fae4cb31ad5a365face107Argyrios Kyrtzidis  }
3991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
40009c4719788a5cea09897525e528fa00420f1677bSteve Naroff  // Implement isa/cast/dyncast/etc.
40180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
40209c4719788a5cea09897525e528fa00420f1677bSteve Naroff  static bool classof(const ObjCContainerDecl *D) { return true; }
40380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) {
4049a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt    return K >= firstObjCContainer &&
4059a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt           K <= lastObjCContainer;
40680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  }
40709c4719788a5cea09897525e528fa00420f1677bSteve Naroff
40809c4719788a5cea09897525e528fa00420f1677bSteve Naroff  static DeclContext *castToDeclContext(const ObjCContainerDecl *D) {
40909c4719788a5cea09897525e528fa00420f1677bSteve Naroff    return static_cast<DeclContext *>(const_cast<ObjCContainerDecl*>(D));
41009c4719788a5cea09897525e528fa00420f1677bSteve Naroff  }
41109c4719788a5cea09897525e528fa00420f1677bSteve Naroff  static ObjCContainerDecl *castFromDeclContext(const DeclContext *DC) {
41209c4719788a5cea09897525e528fa00420f1677bSteve Naroff    return static_cast<ObjCContainerDecl *>(const_cast<DeclContext*>(DC));
41309c4719788a5cea09897525e528fa00420f1677bSteve Naroff  }
414e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff};
415e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
416a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCInterfaceDecl - Represents an ObjC class declaration. For example:
4170c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
4180c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   // MostPrimitive declares no super class (not particularly useful).
4191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///   @interface MostPrimitive
4200c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     // no instance variables or methods.
4210c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @end
4220c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
4231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///   // NSResponder inherits from NSObject & implements NSCoding (a protocol).
4240c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @interface NSResponder : NSObject <NSCoding>
425a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek///   { // instance variables are represented by ObjCIvarDecl.
4260c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     id nextResponder; // nextResponder instance variable.
4270c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   }
4280c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   - (NSResponder *)nextResponder; // return a pointer to NSResponder.
4290c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   - (void)mouseMoved:(NSEvent *)theEvent; // return void, takes a pointer
4300c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @end                                    // to an NSEvent.
4310c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
4320c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   Unlike C/C++, forward class declarations are accomplished with @class.
4330c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   Unlike C/C++, @class allows for a list of classes to be forward declared.
4340c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   Unlike C++, ObjC is a single-rooted class model. In Cocoa, classes
4350c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   typically inherit from NSObject (an exception is NSProxy).
4360c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
437deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregorclass ObjCInterfaceDecl : public ObjCContainerDecl {
4383110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff  /// TypeForDecl - This indicates the Type object that represents this
4393110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff  /// TypeDecl.  It is a cache maintained by ASTContext::getObjCInterfaceType
4403b3a45858c6b2a45114e91902c3bf3c4b7f5f302Daniel Dunbar  mutable Type *TypeForDecl;
4413110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff  friend class ASTContext;
4421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
443980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  /// Class's super class.
444a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *SuperClass;
4451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
44653b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  /// Protocols referenced in the @interface  declaration
44718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  ObjCProtocolList ReferencedProtocols;
44853b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
44953b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  /// Protocols reference in both the @interface and class extensions.
45053b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  ObjCList<ObjCProtocolDecl> AllReferencedProtocols;
4511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
452980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  /// List of categories defined for this class.
453a8ff9f455d94d9609766cfd5186b6e21dc2102f1Chris Lattner  /// FIXME: Why is this a linked list??
454a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCCategoryDecl *CategoryList;
4552c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian
4562c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  /// IvarList - List of all ivars defined by this class; including class
4572c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  /// extensions and implementation. This list is built lazily.
4582c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  ObjCIvarDecl *IvarList;
4591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4603a3ca1b35a7121aea0bf465a192dce748465e10fFariborz Jahanian  bool ForwardDecl:1; // declared with @class.
4613a3ca1b35a7121aea0bf465a192dce748465e10fFariborz Jahanian  bool InternalInterface:1; // true - no @interface for @implementation
4621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
463d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff  SourceLocation ClassLoc; // location of the class identifier.
464d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff  SourceLocation SuperClassLoc; // location of the super class identifier.
465f908a87299d278164540f90b5b6e6cab7b14fb41Steve Naroff  SourceLocation EndLoc; // marks the '>', '}', or identifier.
4660e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner
467d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id,
468deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor                    SourceLocation CLoc, bool FD, bool isInternal);
4691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4700e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattnerpublic:
471d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCInterfaceDecl *Create(ASTContext &C, DeclContext *DC,
4720ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner                                   SourceLocation atLoc,
4731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                   IdentifierInfo *Id,
474deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor                                   SourceLocation ClassLoc = SourceLocation(),
4750e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner                                   bool ForwardDecl = false,
4760e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner                                   bool isInternal = false);
47718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  const ObjCProtocolList &getReferencedProtocols() const {
4781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return ReferencedProtocols;
4797ed9e0f97f4645edc5d4670385b985ea4c617ce7Fariborz Jahanian  }
4808a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis
4818a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis  ObjCImplementationDecl *getImplementation() const;
4828a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis  void setImplementation(ObjCImplementationDecl *ImplD);
4838a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis
484559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  ObjCCategoryDecl *FindCategoryDeclaration(IdentifierInfo *CategoryId) const;
4851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4861cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis  // Get the local instance/class method declared in a category.
4871cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis  ObjCMethodDecl *getCategoryInstanceMethod(Selector Sel) const;
4881cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis  ObjCMethodDecl *getCategoryClassMethod(Selector Sel) const;
4891cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis  ObjCMethodDecl *getCategoryMethod(Selector Sel, bool isInstance) const {
4901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return isInstance ? getInstanceMethod(Sel)
4911cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis                      : getClassMethod(Sel);
4921cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis  }
4933db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner
49418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::iterator protocol_iterator;
49553b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
49653b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  protocol_iterator protocol_begin() const {
49753b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek    return ReferencedProtocols.begin();
49853b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  }
49953b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  protocol_iterator protocol_end() const {
50053b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek    return ReferencedProtocols.end();
50153b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  }
50253b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
50318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
50453b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
50518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  protocol_loc_iterator protocol_loc_begin() const {
50618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    return ReferencedProtocols.loc_begin();
50718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
50853b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
50918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  protocol_loc_iterator protocol_loc_end() const {
51018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    return ReferencedProtocols.loc_end();
51118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
51253b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
51353b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  typedef ObjCList<ObjCProtocolDecl>::iterator all_protocol_iterator;
51453b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
51553b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  all_protocol_iterator all_referenced_protocol_begin() const {
51653b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek    return AllReferencedProtocols.empty() ? protocol_begin()
51753b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek      : AllReferencedProtocols.begin();
51853b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  }
51953b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  all_protocol_iterator all_referenced_protocol_end() const {
52053b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek    return AllReferencedProtocols.empty() ? protocol_end()
52153b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek      : AllReferencedProtocols.end();
52253b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  }
523291be393aa33759e6e34b6429c5ffa206ba50115Douglas Gregor
52411062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian  typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
52553b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
52611062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian  ivar_iterator ivar_begin() const { return  ivar_iterator(decls_begin()); }
52711062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian  ivar_iterator ivar_end() const { return ivar_iterator(decls_end()); }
52853b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
52911062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian  unsigned ivar_size() const {
53011062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian    return std::distance(ivar_begin(), ivar_end());
53111062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian  }
53253b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
53311062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian  bool ivar_empty() const { return ivar_begin() == ivar_end(); }
5342c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian
5352c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  ObjCIvarDecl  *all_declared_ivar_begin();
5362c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  void setIvarList(ObjCIvarDecl *ivar) { IvarList = ivar; }
5372c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian
53838af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  /// setProtocolList - Set the list of protocols that this interface
539b752f289026ad8e5f44851b20e009a27ed61eefcChris Lattner  /// implements.
54038af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  void setProtocolList(ObjCProtocolDecl *const* List, unsigned Num,
54118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                       const SourceLocation *Locs, ASTContext &C) {
54218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    ReferencedProtocols.set(List, Num, Locs, C);
5433db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  }
5441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
545339798eae1eb61c50ca68766ed028c0a16d0a284Fariborz Jahanian  /// mergeClassExtensionProtocolList - Merge class extension's protocol list
546339798eae1eb61c50ca68766ed028c0a16d0a284Fariborz Jahanian  /// into the protocol list for this class.
54718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  void mergeClassExtensionProtocolList(ObjCProtocolDecl *const* List,
54818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                                       unsigned Num,
54918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                                       ASTContext &C);
550339798eae1eb61c50ca68766ed028c0a16d0a284Fariborz Jahanian
551768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff  bool isForwardDecl() const { return ForwardDecl; }
552768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff  void setForwardDecl(bool val) { ForwardDecl = val; }
5531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
554a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *getSuperClass() const { return SuperClass; }
555a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void setSuperClass(ObjCInterfaceDecl * superCls) { SuperClass = superCls; }
5561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
557a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCCategoryDecl* getCategoryList() const { return CategoryList; }
5581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setCategoryList(ObjCCategoryDecl *category) {
55953efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    CategoryList = category;
560980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  }
56180aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian
56280aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  ObjCCategoryDecl* getFirstClassExtension() const;
56337cafb077ad5b170acae77e566638603011ef4c0Ted Kremenek
56437cafb077ad5b170acae77e566638603011ef4c0Ted Kremenek  ObjCPropertyDecl
56537cafb077ad5b170acae77e566638603011ef4c0Ted Kremenek    *FindPropertyVisibleInPrimaryClass(IdentifierInfo *PropertyId) const;
56637cafb077ad5b170acae77e566638603011ef4c0Ted Kremenek
56753efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner  /// isSuperClassOf - Return true if this class is the specified class or is a
56853efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner  /// super class of the specified interface class.
56953efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner  bool isSuperClassOf(const ObjCInterfaceDecl *I) const {
57053efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    // If RHS is derived from LHS it is OK; else it is not OK.
57153efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    while (I != NULL) {
57253efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner      if (this == I)
57353efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner        return true;
57453efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner      I = I->getSuperClass();
57553efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    }
57653efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    return false;
57753efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner  }
5781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
57917945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName,
58068a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner                                       ObjCInterfaceDecl *&ClassDeclared);
58117945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName) {
58268a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner    ObjCInterfaceDecl *ClassDeclared;
58317945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return lookupInstanceVariable(IVarName, ClassDeclared);
58468a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner  }
58568a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner
58694a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // Lookup a method. First, we search locally. If a method isn't
58794a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // found, we search referenced protocols and class categories.
588aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis  ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance) const;
589aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis  ObjCMethodDecl *lookupInstanceMethod(Selector Sel) const {
590aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis    return lookupMethod(Sel, true/*isInstance*/);
591aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis  }
592aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis  ObjCMethodDecl *lookupClassMethod(Selector Sel) const {
593aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis    return lookupMethod(Sel, false/*isInstance*/);
594aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis  }
595cd1876207f5564beba74e4b2524b664bdba0ba9fFariborz Jahanian  ObjCInterfaceDecl *lookupInheritedClass(const IdentifierInfo *ICName);
596d789d3d985e28c9404e62157af46dcb7331920e0Steve Naroff
597d789d3d985e28c9404e62157af46dcb7331920e0Steve Naroff  // Lookup a method in the classes implementation hierarchy.
598d789d3d985e28c9404e62157af46dcb7331920e0Steve Naroff  ObjCMethodDecl *lookupPrivateInstanceMethod(const Selector &Sel);
59960fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff
600ddfd4c9eda34765b08fae4cb31ad5a365face107Argyrios Kyrtzidis  // Location information, modeled after the Stmt API.
60160fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff  SourceLocation getLocStart() const { return getLocation(); } // '@'interface
602f908a87299d278164540f90b5b6e6cab7b14fb41Steve Naroff  SourceLocation getLocEnd() const { return EndLoc; }
6037177dee8aee4b432911c91f1b788963bec0cac9fDaniel Dunbar  void setLocEnd(SourceLocation LE) { EndLoc = LE; }
6041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
60533feeb019a5742b286eededd5446ec0fe87c5a61Steve Naroff  void setClassLoc(SourceLocation Loc) { ClassLoc = Loc; }
606d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff  SourceLocation getClassLoc() const { return ClassLoc; }
607d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff  void setSuperClassLoc(SourceLocation Loc) { SuperClassLoc = Loc; }
608d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff  SourceLocation getSuperClassLoc() const { return SuperClassLoc; }
6091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
61028e71cf851b73a67604735a9a95aef800b144e2eSteve Naroff  /// isImplicitInterfaceDecl - check that this is an implicitly declared
611a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  /// ObjCInterfaceDecl node. This is for legacy objective-c @implementation
6124b6df3fa953267c5d755628c8afd818bb571e579Fariborz Jahanian  /// declaration without an @interface declaration.
61333feeb019a5742b286eededd5446ec0fe87c5a61Steve Naroff  bool isImplicitInterfaceDecl() const { return InternalInterface; }
61433feeb019a5742b286eededd5446ec0fe87c5a61Steve Naroff  void setImplicitInterfaceDecl(bool val) { InternalInterface = val; }
6151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6160fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian  /// ClassImplementsProtocol - Checks that 'lProto' protocol
6170fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian  /// has been implemented in IDecl class, its super class or categories (if
6180fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian  /// lookupCategory is true).
6190fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian  bool ClassImplementsProtocol(ObjCProtocolDecl *lProto,
6200fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian                               bool lookupCategory,
6210fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian                               bool RHSIsQualifiedID = false);
6221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
62333feeb019a5742b286eededd5446ec0fe87c5a61Steve Naroff  // Low-level accessor
62433feeb019a5742b286eededd5446ec0fe87c5a61Steve Naroff  Type *getTypeForDecl() const { return TypeForDecl; }
6253b3a45858c6b2a45114e91902c3bf3c4b7f5f302Daniel Dunbar  void setTypeForDecl(Type *TD) const { TypeForDecl = TD; }
62633feeb019a5742b286eededd5446ec0fe87c5a61Steve Naroff
62780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
628a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCInterfaceDecl *D) { return true; }
62980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCInterface; }
63053b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
63153b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  friend class ASTDeclReader;
63253b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  friend class ASTDeclWriter;
633980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
634980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
635a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCIvarDecl - Represents an ObjC instance variable. In general, ObjC
6360c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// instance variables are identical to C. The only exception is Objective-C
6370c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// supports C++ style access control. For example:
6380c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
6390c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @interface IvarExample : NSObject
6400c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   {
641f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek///     id defaultToProtected;
6420c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @public:
6430c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     id canBePublic; // same as C++.
6440c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @protected:
6450c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     id canBeProtected; // same as C++.
6460c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @package:
6470c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     id canBePackage; // framework visibility (not available in C++).
6480c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   }
6490c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
650a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCIvarDecl : public FieldDecl {
6510e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattnerpublic:
652980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  enum AccessControl {
653980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff    None, Private, Protected, Public, Package
654980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  };
6551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
656b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenekprivate:
657a06549226f45d5b72169a3d054415616dd1014a2Daniel Dunbar  ObjCIvarDecl(ObjCContainerDecl *DC, SourceLocation L, IdentifierInfo *Id,
658ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian               QualType T, TypeSourceInfo *TInfo, AccessControl ac, Expr *BW,
659ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian               bool synthesized)
660a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    : FieldDecl(ObjCIvar, DC, L, Id, T, TInfo, BW, /*Mutable=*/false),
6612c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian      NextIvar(0), DeclAccess(ac),  Synthesized(synthesized) {}
6621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
663b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenekpublic:
664a06549226f45d5b72169a3d054415616dd1014a2Daniel Dunbar  static ObjCIvarDecl *Create(ASTContext &C, ObjCContainerDecl *DC,
665a06549226f45d5b72169a3d054415616dd1014a2Daniel Dunbar                              SourceLocation L, IdentifierInfo *Id, QualType T,
666a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall                              TypeSourceInfo *TInfo,
667ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian                              AccessControl ac, Expr *BW = NULL,
668ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian                              bool synthesized=false);
6691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
67027a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar  /// \brief Return the class interface that this ivar is logically contained
67127a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar  /// in; this is either the interface where the ivar was declared, or the
67227a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar  /// interface the ivar is conceptually a part of in the case of synthesized
67327a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar  /// ivars.
67427a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar  const ObjCInterfaceDecl *getContainingInterface() const;
6752c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian
6762c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  ObjCIvarDecl *getNextIvar() { return NextIvar; }
6772c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  void setNextIvar(ObjCIvarDecl *ivar) { NextIvar = ivar; }
67827a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar
679980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  void setAccessControl(AccessControl ac) { DeclAccess = ac; }
680f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek
681ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  AccessControl getAccessControl() const { return AccessControl(DeclAccess); }
682f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek
683f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek  AccessControl getCanonicalAccessControl() const {
684f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek    return DeclAccess == None ? Protected : AccessControl(DeclAccess);
685f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek  }
6861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
687ac0021ba802e193e0f9f8207768c7862c7603bc0Fariborz Jahanian  void setSynthesize(bool synth) { Synthesized = synth; }
688ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian  bool getSynthesize() const { return Synthesized; }
689ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian
690980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  // Implement isa/cast/dyncast/etc.
69180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
692a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCIvarDecl *D) { return true; }
69380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCIvar; }
694980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffprivate:
6952c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  /// NextIvar - Next Ivar in the list of ivars declared in class; class's
6962c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  /// extensions and class's implementation
6972c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  ObjCIvarDecl *NextIvar;
6982c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian
699ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  // NOTE: VC++ treats enums as signed, avoid using the AccessControl enum
700ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  unsigned DeclAccess : 3;
701ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian  unsigned Synthesized : 1;
702980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
703980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
7041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
70501e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek/// ObjCAtDefsFieldDecl - Represents a field declaration created by an
70601e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek///  @defs(...).
70701e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenekclass ObjCAtDefsFieldDecl : public FieldDecl {
70801e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenekprivate:
70944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor  ObjCAtDefsFieldDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
71001e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek                      QualType T, Expr *BW)
711a1d5662d96465f0fddf8819d245da4d19b892effArgyrios Kyrtzidis    : FieldDecl(ObjCAtDefsField, DC, L, Id, T,
712a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall                /*TInfo=*/0, // FIXME: Do ObjCAtDefs have declarators ?
713a1d5662d96465f0fddf8819d245da4d19b892effArgyrios Kyrtzidis                BW, /*Mutable=*/false) {}
7141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
71501e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenekpublic:
71644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor  static ObjCAtDefsFieldDecl *Create(ASTContext &C, DeclContext *DC,
71744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor                                     SourceLocation L,
71801e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek                                     IdentifierInfo *Id, QualType T,
71901e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek                                     Expr *BW);
7201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
72101e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek  // Implement isa/cast/dyncast/etc.
72280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
72301e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek  static bool classof(const ObjCAtDefsFieldDecl *D) { return true; }
72480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCAtDefsField; }
72501e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek};
726980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
727a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCProtocolDecl - Represents a protocol declaration. ObjC protocols
7281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// declare a pure abstract type (i.e no instance variables are permitted).
7291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Protocols orginally drew inspiration from C++ pure virtual functions (a C++
7300c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// feature with nice semantics and lousy syntax:-). Here is an example:
7310c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
732eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// @protocol NSDraggingInfo <refproto1, refproto2>
7330c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (NSWindow *)draggingDestinationWindow;
7340c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (NSImage *)draggedImage;
7350c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end
7360c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
737eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// This says that NSDraggingInfo requires two methods and requires everything
738eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// that the two "referenced protocols" 'refproto1' and 'refproto2' require as
739eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// well.
740eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner///
7410c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @interface ImplementsNSDraggingInfo : NSObject <NSDraggingInfo>
7420c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end
7430c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
744a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjC protocols inspired Java interfaces. Unlike Java, ObjC classes and
7450c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// protocols are in distinct namespaces. For example, Cocoa defines both
7461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// an NSObject protocol and class (which isn't allowed in Java). As a result,
7470c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// protocols are referenced using angle brackets as follows:
7480c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
7490c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// id <NSDraggingInfo> anyObjectThatImplementsNSDraggingInfo;
7500c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
751e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroffclass ObjCProtocolDecl : public ObjCContainerDecl {
752780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  /// Referenced protocols
75318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  ObjCProtocolList ReferencedProtocols;
7541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
755980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  bool isForwardProtoDecl; // declared with @protocol.
7561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
757423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff  SourceLocation EndLoc; // marks the '>' or identifier.
7581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
759d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  ObjCProtocolDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id)
7601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : ObjCContainerDecl(ObjCProtocol, DC, L, Id),
761c858105d41602a2dadb2efbc1af80a7b791ebac3Chris Lattner      isForwardProtoDecl(true) {
762cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattner  }
7631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
764cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattnerpublic:
7651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static ObjCProtocolDecl *Create(ASTContext &C, DeclContext *DC,
766d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor                                  SourceLocation L, IdentifierInfo *Id);
767cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattner
76818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  const ObjCProtocolList &getReferencedProtocols() const {
769780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner    return ReferencedProtocols;
770980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  }
77118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::iterator protocol_iterator;
772780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();}
773780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  protocol_iterator protocol_end() const { return ReferencedProtocols.end(); }
77418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
77518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  protocol_loc_iterator protocol_loc_begin() const {
77618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    return ReferencedProtocols.loc_begin();
77718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
77818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  protocol_loc_iterator protocol_loc_end() const {
77918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    return ReferencedProtocols.loc_end();
78018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
78130833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  unsigned protocol_size() const { return ReferencedProtocols.size(); }
7821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
78338af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  /// setProtocolList - Set the list of protocols that this interface
784780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  /// implements.
78538af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num,
78618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                       const SourceLocation *Locs, ASTContext &C) {
78718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    ReferencedProtocols.set(List, Num, Locs, C);
788aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian  }
7891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
79091b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff  ObjCProtocolDecl *lookupProtocolNamed(IdentifierInfo *PName);
7911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
79294a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // Lookup a method. First, we search locally. If a method isn't
79394a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // found, we search referenced protocols and class categories.
794094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis  ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance) const;
795094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis  ObjCMethodDecl *lookupInstanceMethod(Selector Sel) const {
796094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis    return lookupMethod(Sel, true/*isInstance*/);
797094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis  }
798094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis  ObjCMethodDecl *lookupClassMethod(Selector Sel) const {
799094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis    return lookupMethod(Sel, false/*isInstance*/);
800094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis  }
801d789d3d985e28c9404e62157af46dcb7331920e0Steve Naroff
802768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff  bool isForwardDecl() const { return isForwardProtoDecl; }
803768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff  void setForwardDecl(bool val) { isForwardProtoDecl = val; }
804980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
8051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // Location information, modeled after the Stmt API.
806423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff  SourceLocation getLocStart() const { return getLocation(); } // '@'protocol
807423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff  SourceLocation getLocEnd() const { return EndLoc; }
8087177dee8aee4b432911c91f1b788963bec0cac9fDaniel Dunbar  void setLocEnd(SourceLocation LE) { EndLoc = LE; }
8091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
81080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
811a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCProtocolDecl *D) { return true; }
81280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCProtocol; }
813980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
8141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
815a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCClassDecl - Specifies a list of forward class declarations. For example:
81606ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff///
81706ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff/// @class NSCursor, NSImage, NSPasteboard, NSWindow;
8180c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
8194afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCClassDecl : public Decl {
820321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenekpublic:
821321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek  class ObjCClassRef {
822321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek    ObjCInterfaceDecl *ID;
823321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek    SourceLocation L;
824321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek  public:
825321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek    ObjCClassRef(ObjCInterfaceDecl *d, SourceLocation l) : ID(d), L(l) {}
826321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek    SourceLocation getLocation() const { return L; }
827321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek    ObjCInterfaceDecl *getInterface() const { return ID; }
828321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek  };
829321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenekprivate:
830321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek  ObjCClassRef *ForwardDecls;
831321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek  unsigned NumDecls;
8321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ObjCClassDecl(DeclContext *DC, SourceLocation L,
834321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek                ObjCInterfaceDecl *const *Elts, const SourceLocation *Locs,
835321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek                unsigned nElts, ASTContext &C);
83661f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattnerpublic:
837d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCClassDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L,
8381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                               ObjCInterfaceDecl *const *Elts = 0,
839321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek                               const SourceLocation *Locs = 0,
84030833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff                               unsigned nElts = 0);
8412dbdd622d02d1bfbe1e5bcf421b07b74c7a748f1Ted Kremenek
8422dbdd622d02d1bfbe1e5bcf421b07b74c7a748f1Ted Kremenek  virtual SourceRange getSourceRange() const;
8431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
844321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek  typedef const ObjCClassRef* iterator;
845321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek  iterator begin() const { return ForwardDecls; }
846321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek  iterator end() const { return ForwardDecls + NumDecls; }
847321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek  unsigned size() const { return NumDecls; }
84830833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff
84930833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  /// setClassList - Set the list of forward classes.
850321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek  void setClassList(ASTContext &C, ObjCInterfaceDecl*const*List,
851321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek                    const SourceLocation *Locs, unsigned Num);
8521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
85380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
854a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCClassDecl *D) { return true; }
85580cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCClass; }
85606ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff};
85706ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff
858a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCForwardProtocolDecl - Specifies a list of forward protocol declarations.
85906ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff/// For example:
8601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
8610c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @protocol NSTextInput, NSChangeSpelling, NSDraggingInfo;
8621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
8634afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCForwardProtocolDecl : public Decl {
86418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  ObjCProtocolList ReferencedProtocols;
8651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
866d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  ObjCForwardProtocolDecl(DeclContext *DC, SourceLocation L,
86738af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner                          ObjCProtocolDecl *const *Elts, unsigned nElts,
86818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                          const SourceLocation *Locs, ASTContext &C);
8691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
87061f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattnerpublic:
871d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCForwardProtocolDecl *Create(ASTContext &C, DeclContext *DC,
8721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                         SourceLocation L,
87318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                                         ObjCProtocolDecl *const *Elts,
87418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                                         unsigned Num,
87518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                                         const SourceLocation *Locs);
87618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor
87718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  static ObjCForwardProtocolDecl *Create(ASTContext &C, DeclContext *DC,
87818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                                         SourceLocation L) {
87918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    return Create(C, DC, L, 0, 0, 0);
88018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
88161f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner
88218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::iterator protocol_iterator;
88330833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();}
88430833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  protocol_iterator protocol_end() const { return ReferencedProtocols.end(); }
88518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
88618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  protocol_loc_iterator protocol_loc_begin() const {
88718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    return ReferencedProtocols.loc_begin();
88818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
88918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  protocol_loc_iterator protocol_loc_end() const {
89018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    return ReferencedProtocols.loc_end();
89118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
89218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor
89330833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  unsigned protocol_size() const { return ReferencedProtocols.size(); }
89430833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff
89530833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  /// setProtocolList - Set the list of forward protocols.
89630833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num,
89718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                       const SourceLocation *Locs, ASTContext &C) {
89818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    ReferencedProtocols.set(List, Num, Locs, C);
89930833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  }
90080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
901a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCForwardProtocolDecl *D) { return true; }
90280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCForwardProtocol; }
903980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
904980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
905a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCCategoryDecl - Represents a category declaration. A category allows
9060c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// you to add methods to an existing class (without subclassing or modifying
9071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// the original class interface or implementation:-). Categories don't allow
9080c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// you to add instance data. The following example adds "myMethod" to all
9090c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// NSView's within a process:
9100c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
9110c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @interface NSView (MyViewMethods)
9120c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - myMethod;
9130c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end
9140c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
91533ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor/// Categories also allow you to split the implementation of a class across
9160c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// several files (a feature more naturally supported in C++).
9170c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
9180c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// Categories were originally inspired by dynamic languages such as Common
9191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Lisp and Smalltalk.  More traditional class-based languages (C++, Java)
9200c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// don't support this level of dynamism, which is both powerful and dangerous.
9210c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
922e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroffclass ObjCCategoryDecl : public ObjCContainerDecl {
923980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  /// Interface belonging to this category
924a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *ClassInterface;
9251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
92668c82cf61228102aba1194efef222fa1478af2a8Chris Lattner  /// referenced protocols in this category.
92718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  ObjCProtocolList ReferencedProtocols;
9281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
929a8ff9f455d94d9609766cfd5186b6e21dc2102f1Chris Lattner  /// Next category belonging to this class.
930a8ff9f455d94d9609766cfd5186b6e21dc2102f1Chris Lattner  /// FIXME: this should not be a singly-linked list.  Move storage elsewhere.
931a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCCategoryDecl *NextClassCategory;
9321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
933000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  /// true of class extension has at least one bitfield ivar.
934000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  bool HasSynthBitfield : 1;
935000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian
9363db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  /// \brief The location of the '@' in '@interface'
9373db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  SourceLocation AtLoc;
9383db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor
9393db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  /// \brief The location of the category name in this declaration.
9403db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  SourceLocation CategoryNameLoc;
9411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9423db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  ObjCCategoryDecl(DeclContext *DC, SourceLocation AtLoc,
9433db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor                   SourceLocation ClassNameLoc, SourceLocation CategoryNameLoc,
9443db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor                   IdentifierInfo *Id)
9453db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor    : ObjCContainerDecl(ObjCCategory, DC, ClassNameLoc, Id),
946000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian      ClassInterface(0), NextClassCategory(0), HasSynthBitfield(false),
947000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian      AtLoc(AtLoc), CategoryNameLoc(CategoryNameLoc) {
948a906135721c350435319347d2672bbb3bf494f91Chris Lattner  }
94961f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattnerpublic:
9501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
951d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCCategoryDecl *Create(ASTContext &C, DeclContext *DC,
9523db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor                                  SourceLocation AtLoc,
9533db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor                                  SourceLocation ClassNameLoc,
9543db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor                                  SourceLocation CategoryNameLoc,
9553db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor                                  IdentifierInfo *Id);
9561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
957e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
958e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; }
959a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void setClassInterface(ObjCInterfaceDecl *IDecl) { ClassInterface = IDecl; }
9608a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis
9618a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis  ObjCCategoryImplDecl *getImplementation() const;
9628a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis  void setImplementation(ObjCCategoryImplDecl *ImplD);
9638a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis
96438af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  /// setProtocolList - Set the list of protocols that this interface
965f7b2c98c16dfb2261ea57d40a1d5bc4738e73175Chris Lattner  /// implements.
96638af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num,
96718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                       const SourceLocation *Locs, ASTContext &C) {
96818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    ReferencedProtocols.set(List, Num, Locs, C);
969780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  }
9701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
97118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  const ObjCProtocolList &getReferencedProtocols() const {
972780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner    return ReferencedProtocols;
9738f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian  }
9741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
97518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::iterator protocol_iterator;
976780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();}
977780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  protocol_iterator protocol_end() const { return ReferencedProtocols.end(); }
97830833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  unsigned protocol_size() const { return ReferencedProtocols.size(); }
97918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
98018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  protocol_loc_iterator protocol_loc_begin() const {
98118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    return ReferencedProtocols.loc_begin();
98218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
98318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  protocol_loc_iterator protocol_loc_end() const {
98418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    return ReferencedProtocols.loc_end();
98518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
9861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
987a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCCategoryDecl *getNextClassCategory() const { return NextClassCategory; }
98830833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  void setNextClassCategory(ObjCCategoryDecl *Cat) {
98930833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff    NextClassCategory = Cat;
99030833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  }
991980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  void insertNextClassCategory() {
9923d58138992b9bc7b34aaa680f3ddf3971292eb7dSteve Naroff    NextClassCategory = ClassInterface->getCategoryList();
9933d58138992b9bc7b34aaa680f3ddf3971292eb7dSteve Naroff    ClassInterface->setCategoryList(this);
994980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  }
9953db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor
99625760611365be23556b32332f8a66ae21ea93ecfFariborz Jahanian  bool IsClassExtension() const { return getIdentifier() == 0; }
99780aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  const ObjCCategoryDecl *getNextClassExtension() const;
99825760611365be23556b32332f8a66ae21ea93ecfFariborz Jahanian
999000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  bool hasSynthBitfield() const { return HasSynthBitfield; }
1000000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  void setHasSynthBitfield (bool val) { HasSynthBitfield = val; }
1001000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian
10020e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
10030e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  ivar_iterator ivar_begin() const {
10040e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian    return ivar_iterator(decls_begin());
10050e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  }
10060e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  ivar_iterator ivar_end() const {
10070e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian    return ivar_iterator(decls_end());
10080e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  }
10090e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  unsigned ivar_size() const {
10100e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian    return std::distance(ivar_begin(), ivar_end());
10110e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  }
10120e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  bool ivar_empty() const {
10130e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian    return ivar_begin() == ivar_end();
10140e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  }
10150e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian
10163db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  SourceLocation getAtLoc() const { return AtLoc; }
10173db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  void setAtLoc(SourceLocation At) { AtLoc = At; }
10183db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor
10193db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  SourceLocation getCategoryNameLoc() const { return CategoryNameLoc; }
10203db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  void setCategoryNameLoc(SourceLocation Loc) { CategoryNameLoc = Loc; }
10213db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor
10223db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  virtual SourceRange getSourceRange() const {
10233db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor    return SourceRange(AtLoc, getAtEndRange().getEnd());
10243db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  }
10251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
102680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1027a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCCategoryDecl *D) { return true; }
102880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCCategory; }
1029980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
10300c6b6243d3efd958c17943130e2a773653511edcSteve Naroff
1031aecae629269fae3bf484baf1d109e9a89d14eeadArgyrios Kyrtzidisclass ObjCImplDecl : public ObjCContainerDecl {
10320d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// Class interface for this class/category implementation
1033a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *ClassInterface;
10341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10353aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattnerprotected:
10363aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  ObjCImplDecl(Kind DK, DeclContext *DC, SourceLocation L,
10373aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner               ObjCInterfaceDecl *classInterface)
10381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : ObjCContainerDecl(DK, DC, L,
10391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                        classInterface? classInterface->getIdentifier() : 0),
1040aecae629269fae3bf484baf1d109e9a89d14eeadArgyrios Kyrtzidis      ClassInterface(classInterface) {}
10411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
104275c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattnerpublic:
1043e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; }
1044e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
10458a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis  void setClassInterface(ObjCInterfaceDecl *IFace);
10462c2d43c557beca1b4ba4bd743f33978aecb46a97Douglas Gregor
10471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void addInstanceMethod(ObjCMethodDecl *method) {
10482c2d43c557beca1b4ba4bd743f33978aecb46a97Douglas Gregor    // FIXME: Context should be set correctly before we get here.
1049653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor    method->setLexicalDeclContext(this);
10501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    addDecl(method);
1051e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff  }
10521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void addClassMethod(ObjCMethodDecl *method) {
10532c2d43c557beca1b4ba4bd743f33978aecb46a97Douglas Gregor    // FIXME: Context should be set correctly before we get here.
1054653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor    method->setLexicalDeclContext(this);
10551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    addDecl(method);
105653df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner  }
10571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
105817945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  void addPropertyImplementation(ObjCPropertyImplDecl *property);
10591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
106017945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  ObjCPropertyImplDecl *FindPropertyImplDecl(IdentifierInfo *propertyId) const;
106117945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  ObjCPropertyImplDecl *FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const;
1062653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor
1063653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor  // Iterator access to properties.
1064653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor  typedef specific_decl_iterator<ObjCPropertyImplDecl> propimpl_iterator;
10651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  propimpl_iterator propimpl_begin() const {
106617945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return propimpl_iterator(decls_begin());
1067559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  }
10681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  propimpl_iterator propimpl_end() const {
106917945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return propimpl_iterator(decls_end());
1070559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  }
1071653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor
107280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1073bfb498d0996ef049efe9476f2802976fd145cd60Argyrios Kyrtzidis  static bool classof(const ObjCImplDecl *D) { return true; }
107480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) {
10759a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt    return K >= firstObjCImpl && K <= lastObjCImpl;
107680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  }
10773aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner};
10781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ObjCCategoryImplDecl - An object of this class encapsulates a category
10801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// @implementation declaration. If a category class has declaration of a
10811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// property, its implementation must be specified in the category's
10823aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @implementation declaration. Example:
10833aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @interface I @end
10843aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @interface I(CATEGORY)
10853aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner///    @property int p1, d1;
10863aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @end
10873aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @implementation I(CATEGORY)
10883aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner///  @dynamic p1,d1;
10893aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @end
10903aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner///
10913aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// ObjCCategoryImplDecl
10923aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattnerclass ObjCCategoryImplDecl : public ObjCImplDecl {
10933aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  // Category name
10943aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  IdentifierInfo *Id;
10953aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner
10963aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  ObjCCategoryImplDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
10973aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner                       ObjCInterfaceDecl *classInterface)
10983aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner    : ObjCImplDecl(ObjCCategoryImpl, DC, L, classInterface), Id(Id) {}
10993aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattnerpublic:
11003aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  static ObjCCategoryImplDecl *Create(ASTContext &C, DeclContext *DC,
11013aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner                                      SourceLocation L, IdentifierInfo *Id,
11023aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner                                      ObjCInterfaceDecl *classInterface);
11031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11040d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// getIdentifier - Get the identifier that names the category
11053aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  /// interface associated with this implementation.
11060d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// FIXME: This is a bad API, we are overriding the NamedDecl::getIdentifier()
11070d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// to mean something different. For example:
11080d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// ((NamedDecl *)SomeCategoryImplDecl)->getIdentifier()
11090d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// returns the class interface name, whereas
11100d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// ((ObjCCategoryImplDecl *)SomeCategoryImplDecl)->getIdentifier()
11110d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// returns the category name.
11121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  IdentifierInfo *getIdentifier() const {
11131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return Id;
11143aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  }
111510b0e1fa3aabd8877dbbc0df1f2414e04afd5fddDouglas Gregor  void setIdentifier(IdentifierInfo *II) { Id = II; }
11161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11170d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  ObjCCategoryDecl *getCategoryDecl() const;
111810b0e1fa3aabd8877dbbc0df1f2414e04afd5fddDouglas Gregor
1119b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  /// getName - Get the name of identifier for the class interface associated
1120b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  /// with this implementation as a StringRef.
1121b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  //
1122b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  // FIXME: This is a bad API, we are overriding the NamedDecl::getName, to mean
1123b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  // something different.
1124b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  llvm::StringRef getName() const {
1125b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar    return Id ? Id->getNameStart() : "";
1126b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  }
1127b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar
11283aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  /// getNameAsCString - Get the name of identifier for the class
11293aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  /// interface associated with this implementation as a C string
11303aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  /// (const char*).
11317fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar  //
1132b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  // FIXME: Deprecated, move clients to getName().
11333aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  const char *getNameAsCString() const {
11347fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar    return Id ? Id->getNameStart() : "";
11353aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  }
11361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11373aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  /// @brief Get the name of the class associated with this interface.
11387fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar  //
1139b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  // FIXME: Deprecated, move clients to getName().
11403aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  std::string getNameAsString() const {
1141b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar    return getName();
11423aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  }
11431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
114480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1145a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCCategoryImplDecl *D) { return true; }
114680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCCategoryImpl;}
11478f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian};
11488f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian
1149900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramerllvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
1150900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer                              const ObjCCategoryImplDecl *CID);
1151900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer
1152a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCImplementationDecl - Represents a class definition - this is where
11530c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// method definitions are specified. For example:
11540c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
115598abf4bd3526a00a0e5cf71a9462c181f97b1c81Fariborz Jahanian/// @code
11560c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @implementation MyClass
11570c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (void)myMethod { /* do something */ }
11580c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end
115998abf4bd3526a00a0e5cf71a9462c181f97b1c81Fariborz Jahanian/// @endcode
11600c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
11611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Typically, instance variables are specified in the class interface,
1162ec0d7a6f4b0699cc9960e6d9fee0f957c64d1cf9Douglas Gregor/// *not* in the implementation. Nevertheless (for legacy reasons), we
116353df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner/// allow instance variables to be specified in the implementation.  When
116453df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner/// specified, they need to be *identical* to the interface.
11650c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
11661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ObjCImplementationDecl : public ObjCImplDecl {
1167980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  /// Implementation Class's super class.
1168a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *SuperClass;
1169e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// Support for ivar initialization.
1170e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// IvarInitializers - The arguments used to initialize the ivars
1171e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  CXXBaseOrMemberInitializer **IvarInitializers;
1172e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  unsigned NumIvarInitializers;
1173e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian
1174000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  /// true of class extension has at least one bitfield ivar.
1175000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  bool HasSynthBitfield : 1;
1176000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian
11771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ObjCImplementationDecl(DeclContext *DC, SourceLocation L,
1178a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek                         ObjCInterfaceDecl *classInterface,
1179a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek                         ObjCInterfaceDecl *superDecl)
11801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : ObjCImplDecl(ObjCImplementation, DC, L, classInterface),
1181000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian       SuperClass(superDecl), IvarInitializers(0), NumIvarInitializers(0),
1182000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian       HasSynthBitfield(false) {}
11831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
11841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static ObjCImplementationDecl *Create(ASTContext &C, DeclContext *DC,
11851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                        SourceLocation L,
118675c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner                                        ObjCInterfaceDecl *classInterface,
118775c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner                                        ObjCInterfaceDecl *superDecl);
1188e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian
1189e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// init_iterator - Iterates through the ivar initializer list.
1190e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  typedef CXXBaseOrMemberInitializer **init_iterator;
1191e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian
1192e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// init_const_iterator - Iterates through the ivar initializer list.
1193e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  typedef CXXBaseOrMemberInitializer * const * init_const_iterator;
1194e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian
1195e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// init_begin() - Retrieve an iterator to the first initializer.
1196e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  init_iterator       init_begin()       { return IvarInitializers; }
1197e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// begin() - Retrieve an iterator to the first initializer.
1198e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  init_const_iterator init_begin() const { return IvarInitializers; }
1199e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian
1200e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// init_end() - Retrieve an iterator past the last initializer.
1201e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  init_iterator       init_end()       {
1202e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian    return IvarInitializers + NumIvarInitializers;
1203e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  }
1204e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// end() - Retrieve an iterator past the last initializer.
1205e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  init_const_iterator init_end() const {
1206e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian    return IvarInitializers + NumIvarInitializers;
1207e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  }
1208e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// getNumArgs - Number of ivars which must be initialized.
1209e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  unsigned getNumIvarInitializers() const {
1210e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian    return NumIvarInitializers;
1211e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  }
1212e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian
1213e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  void setNumIvarInitializers(unsigned numNumIvarInitializers) {
1214e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian    NumIvarInitializers = numNumIvarInitializers;
1215e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  }
1216e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian
1217e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  void setIvarInitializers(ASTContext &C,
1218e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian                           CXXBaseOrMemberInitializer ** initializers,
1219e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian                           unsigned numInitializers);
1220000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian
1221000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  bool hasSynthBitfield() const { return HasSynthBitfield; }
1222000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  void setHasSynthBitfield (bool val) { HasSynthBitfield = val; }
1223e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian
12244afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  /// getIdentifier - Get the identifier that names the class
12254afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  /// interface associated with this implementation.
12261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  IdentifierInfo *getIdentifier() const {
12271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return getClassInterface()->getIdentifier();
12284afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  }
12294afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor
1230d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  /// getName - Get the name of identifier for the class interface associated
1231d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  /// with this implementation as a StringRef.
1232d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  //
1233d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  // FIXME: This is a bad API, we are overriding the NamedDecl::getName, to mean
1234d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  // something different.
1235d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  llvm::StringRef getName() const {
1236d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar    assert(getIdentifier() && "Name is not a simple identifier");
1237d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar    return getIdentifier()->getName();
1238d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  }
1239d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar
12404afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  /// getNameAsCString - Get the name of identifier for the class
12414afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  /// interface associated with this implementation as a C string
12424afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  /// (const char*).
12437fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar  //
12447fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar  // FIXME: Move to StringRef API.
12454afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  const char *getNameAsCString() const {
1246d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar    return getName().data();
12474afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  }
12484afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor
12494afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  /// @brief Get the name of the class associated with this interface.
12507fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar  //
12517fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar  // FIXME: Move to StringRef API.
12524afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  std::string getNameAsString() const {
1253d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar    return getName();
12544afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  }
12554afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor
1256e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  const ObjCInterfaceDecl *getSuperClass() const { return SuperClass; }
1257e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  ObjCInterfaceDecl *getSuperClass() { return SuperClass; }
12581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1259f3a7af901231535191d14cb524d58f22907ac4d2Chris Lattner  void setSuperClass(ObjCInterfaceDecl * superCls) { SuperClass = superCls; }
12601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12618f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor  typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
12621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ivar_iterator ivar_begin() const {
12631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return ivar_iterator(decls_begin());
12648f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor  }
12651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ivar_iterator ivar_end() const {
126617945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return ivar_iterator(decls_end());
12678f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor  }
12681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  unsigned ivar_size() const {
126917945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return std::distance(ivar_begin(), ivar_end());
12708f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor  }
12711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool ivar_empty() const {
127217945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return ivar_begin() == ivar_end();
12738f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor  }
12741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
127580cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1276a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCImplementationDecl *D) { return true; }
127780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCImplementation; }
12789d50c0635fb213b2a1857e3f8488580f0dab2f98Argyrios Kyrtzidis
1279d527cc06d78fe5afa5f20105b51697637eb02c56Sebastian Redl  friend class ASTDeclReader;
12803397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl  friend class ASTDeclWriter;
1281980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
1282243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian
1283900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramerllvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
1284900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer                              const ObjCImplementationDecl *ID);
1285900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer
12861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ObjCCompatibleAliasDecl - Represents alias of a class. This alias is
1287243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian/// declared as @compatibility_alias alias class.
12884afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCCompatibleAliasDecl : public NamedDecl {
1289243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian  /// Class that this is an alias of.
1290a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *AliasedClass;
12911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1292d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  ObjCCompatibleAliasDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
1293e8043c39176e7f253fbd92982b077eca6bf2fd59Steve Naroff                          ObjCInterfaceDecl* aliasedClass)
12944afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor    : NamedDecl(ObjCCompatibleAlias, DC, L, Id), AliasedClass(aliasedClass) {}
1295f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattnerpublic:
1296d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCCompatibleAliasDecl *Create(ASTContext &C, DeclContext *DC,
12970ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner                                         SourceLocation L, IdentifierInfo *Id,
1298f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner                                         ObjCInterfaceDecl* aliasedClass);
1299f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner
1300f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner  const ObjCInterfaceDecl *getClassInterface() const { return AliasedClass; }
1301f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner  ObjCInterfaceDecl *getClassInterface() { return AliasedClass; }
130230833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  void setClassInterface(ObjCInterfaceDecl *D) { AliasedClass = D; }
13031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
130480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1305a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCCompatibleAliasDecl *D) { return true; }
130680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCCompatibleAlias; }
13071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1308243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian};
13091de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian
13101de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian/// ObjCPropertyDecl - Represents one property declaration in an interface.
13111de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian/// For example:
13121de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian/// @property (assign, readwrite) int MyProperty;
13131de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian///
13144afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCPropertyDecl : public NamedDecl {
131582a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanianpublic:
1316a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner  enum PropertyAttributeKind {
13171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    OBJC_PR_noattr    = 0x00,
13181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    OBJC_PR_readonly  = 0x01,
1319a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_getter    = 0x02,
13201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    OBJC_PR_assign    = 0x04,
13211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    OBJC_PR_readwrite = 0x08,
1322a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_retain    = 0x10,
13231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    OBJC_PR_copy      = 0x20,
1324a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_nonatomic = 0x40,
1325a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_setter    = 0x80
1326a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner  };
1327af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
1328af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  enum SetterKind { Assign, Retain, Copy };
132946b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  enum PropertyControl { None, Required, Optional };
133082a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanianprivate:
1331d8265b838360578032020757d9a2a84c86457edcFariborz Jahanian  SourceLocation AtLoc;   // location of @property
133283a230c83a54190366138c1a4f4310ef838b88fcJohn McCall  TypeSourceInfo *DeclType;
1333ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  unsigned PropertyAttributes : 8;
133480aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  unsigned PropertyAttributesAsWritten : 8;
133546b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  // @required/@optional
133646b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  unsigned PropertyImplementation : 2;
13371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13385251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  Selector GetterName;    // getter name of NULL if no getter
13395251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  Selector SetterName;    // setter name of NULL if no setter
13401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
134133de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  ObjCMethodDecl *GetterMethodDecl; // Declaration of getter instance method
134233de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  ObjCMethodDecl *SetterMethodDecl; // Declaration of setter instance method
1343af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian  ObjCIvarDecl *PropertyIvarDecl;   // Synthesize ivar for this property
134433de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian
13451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ObjCPropertyDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
134683a230c83a54190366138c1a4f4310ef838b88fcJohn McCall                   SourceLocation AtLocation, TypeSourceInfo *T)
1347d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian    : NamedDecl(ObjCProperty, DC, L, Id), AtLoc(AtLocation), DeclType(T),
134880aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian      PropertyAttributes(OBJC_PR_noattr),
134980aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian      PropertyAttributesAsWritten(OBJC_PR_noattr),
135080aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian      PropertyImplementation(None),
13511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      GetterName(Selector()),
135233de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian      SetterName(Selector()),
1353af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian      GetterMethodDecl(0), SetterMethodDecl(0) , PropertyIvarDecl(0) {}
1354f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattnerpublic:
13551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static ObjCPropertyDecl *Create(ASTContext &C, DeclContext *DC,
13561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                  SourceLocation L,
1357d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian                                  IdentifierInfo *Id, SourceLocation AtLocation,
135883a230c83a54190366138c1a4f4310ef838b88fcJohn McCall                                  TypeSourceInfo *T,
135946b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian                                  PropertyControl propControl = None);
1360d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian  SourceLocation getAtLoc() const { return AtLoc; }
1361d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian  void setAtLoc(SourceLocation L) { AtLoc = L; }
1362d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian
136383a230c83a54190366138c1a4f4310ef838b88fcJohn McCall  TypeSourceInfo *getTypeSourceInfo() const { return DeclType; }
136483a230c83a54190366138c1a4f4310ef838b88fcJohn McCall  QualType getType() const { return DeclType->getType(); }
136583a230c83a54190366138c1a4f4310ef838b88fcJohn McCall  void setType(TypeSourceInfo *T) { DeclType = T; }
136670e5a14c6076d63833c62d1d6d628c26309897c1Douglas Gregor
1367a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner  PropertyAttributeKind getPropertyAttributes() const {
1368f4af5154571e0c5eadb19df10e65464766ef6683Chris Lattner    return PropertyAttributeKind(PropertyAttributes);
1369f4af5154571e0c5eadb19df10e65464766ef6683Chris Lattner  }
13701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setPropertyAttributes(PropertyAttributeKind PRVal) {
1371a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    PropertyAttributes |= PRVal;
137282a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian  }
1373394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar
137480aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  PropertyAttributeKind getPropertyAttributesAsWritten() const {
137580aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian    return PropertyAttributeKind(PropertyAttributesAsWritten);
137680aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  }
137780aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian
137880aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  void setPropertyAttributesAsWritten(PropertyAttributeKind PRVal) {
137980aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian    PropertyAttributesAsWritten = PRVal;
138080aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  }
138180aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian
13828cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian void makeitReadWriteAttribute(void) {
13838cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian    PropertyAttributes &= ~OBJC_PR_readonly;
13848cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian    PropertyAttributes |= OBJC_PR_readwrite;
13851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump }
13868cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian
1387af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  // Helper methods for accessing attributes.
1388af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
1389af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  /// isReadOnly - Return true iff the property has a setter.
1390394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar  bool isReadOnly() const {
1391394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar    return (PropertyAttributes & OBJC_PR_readonly);
1392394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar  }
1393af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
1394af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  /// getSetterKind - Return the method used for doing assignment in
1395af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  /// the property setter. This is only valid if the property has been
1396af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  /// defined to have a setter.
1397af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  SetterKind getSetterKind() const {
1398af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar    if (PropertyAttributes & OBJC_PR_retain)
1399af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar      return Retain;
1400af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar    if (PropertyAttributes & OBJC_PR_copy)
1401af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar      return Copy;
1402af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar    return Assign;
1403af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  }
1404af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
14055251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  Selector getGetterName() const { return GetterName; }
14065251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  void setGetterName(Selector Sel) { GetterName = Sel; }
14071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14085251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  Selector getSetterName() const { return SetterName; }
14095251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  void setSetterName(Selector Sel) { SetterName = Sel; }
14101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
141133de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  ObjCMethodDecl *getGetterMethodDecl() const { return GetterMethodDecl; }
141233de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  void setGetterMethodDecl(ObjCMethodDecl *gDecl) { GetterMethodDecl = gDecl; }
141333de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian
141433de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  ObjCMethodDecl *getSetterMethodDecl() const { return SetterMethodDecl; }
141533de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  void setSetterMethodDecl(ObjCMethodDecl *gDecl) { SetterMethodDecl = gDecl; }
14161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
141746b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  // Related to @optional/@required declared in @protocol
141846b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  void setPropertyImplementation(PropertyControl pc) {
141946b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian    PropertyImplementation = pc;
142046b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  }
142146b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  PropertyControl getPropertyImplementation() const {
142246b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian    return PropertyControl(PropertyImplementation);
14231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
14241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1425af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian  void setPropertyIvarDecl(ObjCIvarDecl *Ivar) {
1426af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian    PropertyIvarDecl = Ivar;
1427af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian  }
1428af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian  ObjCIvarDecl *getPropertyIvarDecl() const {
1429af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian    return PropertyIvarDecl;
1430af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian  }
14311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14329f550ff05d496e6b9480e5619a21d9da0c9e27c1Ted Kremenek  /// Lookup a property by name in the specified DeclContext.
1433de09d0c9694f01a99870a8825266d44a29ebb325Ted Kremenek  static ObjCPropertyDecl *findPropertyDecl(const DeclContext *DC,
14349f550ff05d496e6b9480e5619a21d9da0c9e27c1Ted Kremenek                                            IdentifierInfo *propertyID);
14359f550ff05d496e6b9480e5619a21d9da0c9e27c1Ted Kremenek
143680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1437a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCPropertyDecl *D) { return true; }
143880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCProperty; }
143982a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian};
1440980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
14411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ObjCPropertyImplDecl - Represents implementation declaration of a property
144261d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian/// in a class or category implementation block. For example:
144361d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian/// @synthesize prop1 = ivar1;
144461d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian///
14454afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCPropertyImplDecl : public Decl {
144661d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanianpublic:
14479f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar  enum Kind {
14489f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar    Synthesize,
14499f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar    Dynamic
145061d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  };
145161d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanianprivate:
1452559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  SourceLocation AtLoc;   // location of @synthesize or @dynamic
145361d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  /// Property declaration being implemented
145461d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  ObjCPropertyDecl *PropertyDecl;
1455be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek
145661d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  /// Null for @dynamic. Required for @synthesize.
145761d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  ObjCIvarDecl *PropertyIvarDecl;
145817cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian
145917cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  /// Null for @dynamic. Non-null if property must be copy-constructed in getter
146017cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  Expr *GetterCXXConstructor;
146117cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian
146217cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  /// Null for @dynamic. Non-null if property has assignment operator to call
146317cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  /// in Setter synthesis.
146417cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  Expr *SetterCXXAssignment;
1465be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek
1466d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  ObjCPropertyImplDecl(DeclContext *DC, SourceLocation atLoc, SourceLocation L,
14671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                       ObjCPropertyDecl *property,
14681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                       Kind PK,
1469628b96f34e93b643b6e15e75eabb8d96079a7e27Fariborz Jahanian                       ObjCIvarDecl *ivarDecl)
14701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : Decl(ObjCPropertyImpl, DC, L), AtLoc(atLoc),
147117cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian      PropertyDecl(property), PropertyIvarDecl(ivarDecl),
147217cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian      GetterCXXConstructor(0), SetterCXXAssignment(0) {
14739f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar    assert (PK == Dynamic || PropertyIvarDecl);
14749f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar  }
14751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14769f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbarpublic:
1477d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCPropertyImplDecl *Create(ASTContext &C, DeclContext *DC,
14781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                      SourceLocation atLoc, SourceLocation L,
14791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                      ObjCPropertyDecl *property,
14801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                      Kind PK,
1481628b96f34e93b643b6e15e75eabb8d96079a7e27Fariborz Jahanian                                      ObjCIvarDecl *ivarDecl);
148261d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian
14831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual SourceRange getSourceRange() const {
14841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(AtLoc, getLocation());
1485ddfd4c9eda34765b08fae4cb31ad5a365face107Argyrios Kyrtzidis  }
1486d40910b581b09c937a8c1fdcde9b8ec724398fb9Steve Naroff  SourceLocation getLocStart() const { return AtLoc; }
14878818c4fb69cb2a4eec94b217a90f94f9e075296eDouglas Gregor  void setAtLoc(SourceLocation Loc) { AtLoc = Loc; }
1488d40910b581b09c937a8c1fdcde9b8ec724398fb9Steve Naroff
1489be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek  ObjCPropertyDecl *getPropertyDecl() const {
1490be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek    return PropertyDecl;
1491be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek  }
14928818c4fb69cb2a4eec94b217a90f94f9e075296eDouglas Gregor  void setPropertyDecl(ObjCPropertyDecl *Prop) { PropertyDecl = Prop; }
14938818c4fb69cb2a4eec94b217a90f94f9e075296eDouglas Gregor
14949f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar  Kind getPropertyImplementation() const {
14959f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar    return PropertyIvarDecl ? Synthesize : Dynamic;
1496be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek  }
14971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1498af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  ObjCIvarDecl *getPropertyIvarDecl() const {
1499be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek    return PropertyIvarDecl;
1500be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek  }
15018818c4fb69cb2a4eec94b217a90f94f9e075296eDouglas Gregor  void setPropertyIvarDecl(ObjCIvarDecl *Ivar) { PropertyIvarDecl = Ivar; }
150217cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian
150317cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  Expr *getGetterCXXConstructor() const {
150417cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian    return GetterCXXConstructor;
150517cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  }
150617cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  void setGetterCXXConstructor(Expr *getterCXXConstructor) {
150717cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian    GetterCXXConstructor = getterCXXConstructor;
150817cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  }
15098818c4fb69cb2a4eec94b217a90f94f9e075296eDouglas Gregor
151017cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  Expr *getSetterCXXAssignment() const {
151117cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian    return SetterCXXAssignment;
151217cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  }
151317cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  void setSetterCXXAssignment(Expr *setterCXXAssignment) {
151417cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian    SetterCXXAssignment = setterCXXAssignment;
151517cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  }
151617cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian
151780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
15181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const ObjCPropertyImplDecl *D) { return true; }
151980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Decl::Kind K) { return K == ObjCPropertyImpl; }
152061d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian};
152161d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian
1522980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff}  // end namespace clang
1523980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff#endif
1524