DeclObjC.h revision cbb67480094b3bcb5b715acd827cbad55e2a204c
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;
31cbb67480094b3bcb5b715acd827cbad55e2a204cSean Huntclass CXXCtorInitializer;
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
46226ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
46326ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  /// \brief Indicates that the contents of this Objective-C class will be
46426ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  /// completed by the external AST source when required.
46526ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  mutable bool ExternallyCompleted : 1;
46626ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
467d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff  SourceLocation ClassLoc; // location of the class identifier.
468d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff  SourceLocation SuperClassLoc; // location of the super class identifier.
469f908a87299d278164540f90b5b6e6cab7b14fb41Steve Naroff  SourceLocation EndLoc; // marks the '>', '}', or identifier.
4700e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner
471d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id,
472deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor                    SourceLocation CLoc, bool FD, bool isInternal);
4731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
47426ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  void LoadExternalDefinition() const;
4750e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattnerpublic:
476d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCInterfaceDecl *Create(ASTContext &C, DeclContext *DC,
4770ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner                                   SourceLocation atLoc,
4781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                   IdentifierInfo *Id,
479deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor                                   SourceLocation ClassLoc = SourceLocation(),
4800e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner                                   bool ForwardDecl = false,
4810e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner                                   bool isInternal = false);
48226ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
48326ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  /// \brief Indicate that this Objective-C class is complete, but that
48426ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  /// the external AST source will be responsible for filling in its contents
48526ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  /// when a complete class is required.
48626ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  void setExternallyCompleted();
48726ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
48818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  const ObjCProtocolList &getReferencedProtocols() const {
48926ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor    if (ExternallyCompleted)
49026ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
49126ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
4921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return ReferencedProtocols;
4937ed9e0f97f4645edc5d4670385b985ea4c617ce7Fariborz Jahanian  }
4948a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis
4958a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis  ObjCImplementationDecl *getImplementation() const;
4968a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis  void setImplementation(ObjCImplementationDecl *ImplD);
4978a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis
498559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  ObjCCategoryDecl *FindCategoryDeclaration(IdentifierInfo *CategoryId) const;
4991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5001cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis  // Get the local instance/class method declared in a category.
5011cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis  ObjCMethodDecl *getCategoryInstanceMethod(Selector Sel) const;
5021cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis  ObjCMethodDecl *getCategoryClassMethod(Selector Sel) const;
5031cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis  ObjCMethodDecl *getCategoryMethod(Selector Sel, bool isInstance) const {
5041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return isInstance ? getInstanceMethod(Sel)
5051cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis                      : getClassMethod(Sel);
5061cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis  }
5073db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner
50818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::iterator protocol_iterator;
50953b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
51053b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  protocol_iterator protocol_begin() const {
51126ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor    if (ExternallyCompleted)
51226ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
51326ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
51453b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek    return ReferencedProtocols.begin();
51553b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  }
51653b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  protocol_iterator protocol_end() const {
51726ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor    if (ExternallyCompleted)
51826ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
51926ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
52053b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek    return ReferencedProtocols.end();
52153b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  }
52253b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
52318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
52453b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
52518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  protocol_loc_iterator protocol_loc_begin() const {
52626ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor    if (ExternallyCompleted)
52726ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
52826ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
52918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    return ReferencedProtocols.loc_begin();
53018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
53153b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
53218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  protocol_loc_iterator protocol_loc_end() const {
53326ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor    if (ExternallyCompleted)
53426ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
53526ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
53618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    return ReferencedProtocols.loc_end();
53718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
53853b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
53953b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  typedef ObjCList<ObjCProtocolDecl>::iterator all_protocol_iterator;
54053b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
54153b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  all_protocol_iterator all_referenced_protocol_begin() const {
54226ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor    if (ExternallyCompleted)
54326ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
54426ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
54553b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek    return AllReferencedProtocols.empty() ? protocol_begin()
54653b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek      : AllReferencedProtocols.begin();
54753b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  }
54853b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  all_protocol_iterator all_referenced_protocol_end() const {
54926ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor    if (ExternallyCompleted)
55026ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
55126ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
55253b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek    return AllReferencedProtocols.empty() ? protocol_end()
55353b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek      : AllReferencedProtocols.end();
55453b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  }
555291be393aa33759e6e34b6429c5ffa206ba50115Douglas Gregor
55611062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian  typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
55753b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
55811062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian  ivar_iterator ivar_begin() const { return  ivar_iterator(decls_begin()); }
55911062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian  ivar_iterator ivar_end() const { return ivar_iterator(decls_end()); }
56053b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
56111062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian  unsigned ivar_size() const {
56211062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian    return std::distance(ivar_begin(), ivar_end());
56311062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian  }
56453b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
56511062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian  bool ivar_empty() const { return ivar_begin() == ivar_end(); }
5662c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian
5672c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  ObjCIvarDecl  *all_declared_ivar_begin();
5682c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  void setIvarList(ObjCIvarDecl *ivar) { IvarList = ivar; }
5692c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian
57038af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  /// setProtocolList - Set the list of protocols that this interface
571b752f289026ad8e5f44851b20e009a27ed61eefcChris Lattner  /// implements.
57238af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  void setProtocolList(ObjCProtocolDecl *const* List, unsigned Num,
57318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                       const SourceLocation *Locs, ASTContext &C) {
57418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    ReferencedProtocols.set(List, Num, Locs, C);
5753db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  }
5761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
577339798eae1eb61c50ca68766ed028c0a16d0a284Fariborz Jahanian  /// mergeClassExtensionProtocolList - Merge class extension's protocol list
578339798eae1eb61c50ca68766ed028c0a16d0a284Fariborz Jahanian  /// into the protocol list for this class.
57918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  void mergeClassExtensionProtocolList(ObjCProtocolDecl *const* List,
58018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                                       unsigned Num,
58118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                                       ASTContext &C);
582339798eae1eb61c50ca68766ed028c0a16d0a284Fariborz Jahanian
583768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff  bool isForwardDecl() const { return ForwardDecl; }
584768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff  void setForwardDecl(bool val) { ForwardDecl = val; }
5851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
58626ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  ObjCInterfaceDecl *getSuperClass() const {
58726ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor    if (ExternallyCompleted)
58826ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
58926ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
59026ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor    return SuperClass;
59126ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  }
59226ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
593a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void setSuperClass(ObjCInterfaceDecl * superCls) { SuperClass = superCls; }
5941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
59526ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  ObjCCategoryDecl* getCategoryList() const {
59626ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor    if (ExternallyCompleted)
59726ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor      LoadExternalDefinition();
59826ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
59926ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor    return CategoryList;
60026ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor  }
60126ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor
6021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setCategoryList(ObjCCategoryDecl *category) {
60353efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    CategoryList = category;
604980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  }
60580aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian
60680aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  ObjCCategoryDecl* getFirstClassExtension() const;
60737cafb077ad5b170acae77e566638603011ef4c0Ted Kremenek
60837cafb077ad5b170acae77e566638603011ef4c0Ted Kremenek  ObjCPropertyDecl
60937cafb077ad5b170acae77e566638603011ef4c0Ted Kremenek    *FindPropertyVisibleInPrimaryClass(IdentifierInfo *PropertyId) const;
61037cafb077ad5b170acae77e566638603011ef4c0Ted Kremenek
61153efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner  /// isSuperClassOf - Return true if this class is the specified class or is a
61253efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner  /// super class of the specified interface class.
61353efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner  bool isSuperClassOf(const ObjCInterfaceDecl *I) const {
61453efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    // If RHS is derived from LHS it is OK; else it is not OK.
61553efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    while (I != NULL) {
61653efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner      if (this == I)
61753efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner        return true;
61853efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner      I = I->getSuperClass();
61953efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    }
62053efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    return false;
62153efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner  }
6221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
62317945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName,
62468a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner                                       ObjCInterfaceDecl *&ClassDeclared);
62517945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName) {
62668a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner    ObjCInterfaceDecl *ClassDeclared;
62717945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return lookupInstanceVariable(IVarName, ClassDeclared);
62868a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner  }
62968a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner
63094a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // Lookup a method. First, we search locally. If a method isn't
63194a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // found, we search referenced protocols and class categories.
632aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis  ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance) const;
633aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis  ObjCMethodDecl *lookupInstanceMethod(Selector Sel) const {
634aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis    return lookupMethod(Sel, true/*isInstance*/);
635aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis  }
636aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis  ObjCMethodDecl *lookupClassMethod(Selector Sel) const {
637aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis    return lookupMethod(Sel, false/*isInstance*/);
638aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis  }
639cd1876207f5564beba74e4b2524b664bdba0ba9fFariborz Jahanian  ObjCInterfaceDecl *lookupInheritedClass(const IdentifierInfo *ICName);
640d789d3d985e28c9404e62157af46dcb7331920e0Steve Naroff
641d789d3d985e28c9404e62157af46dcb7331920e0Steve Naroff  // Lookup a method in the classes implementation hierarchy.
64274b2756bc1f1f5f7c189996fe7e4cd3efef70263Fariborz Jahanian  ObjCMethodDecl *lookupPrivateMethod(const Selector &Sel, bool Instance=true);
64360fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff
644ddfd4c9eda34765b08fae4cb31ad5a365face107Argyrios Kyrtzidis  // Location information, modeled after the Stmt API.
64560fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff  SourceLocation getLocStart() const { return getLocation(); } // '@'interface
646f908a87299d278164540f90b5b6e6cab7b14fb41Steve Naroff  SourceLocation getLocEnd() const { return EndLoc; }
6477177dee8aee4b432911c91f1b788963bec0cac9fDaniel Dunbar  void setLocEnd(SourceLocation LE) { EndLoc = LE; }
6481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
64933feeb019a5742b286eededd5446ec0fe87c5a61Steve Naroff  void setClassLoc(SourceLocation Loc) { ClassLoc = Loc; }
650d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff  SourceLocation getClassLoc() const { return ClassLoc; }
651d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff  void setSuperClassLoc(SourceLocation Loc) { SuperClassLoc = Loc; }
652d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff  SourceLocation getSuperClassLoc() const { return SuperClassLoc; }
6531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
65428e71cf851b73a67604735a9a95aef800b144e2eSteve Naroff  /// isImplicitInterfaceDecl - check that this is an implicitly declared
655a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  /// ObjCInterfaceDecl node. This is for legacy objective-c @implementation
6564b6df3fa953267c5d755628c8afd818bb571e579Fariborz Jahanian  /// declaration without an @interface declaration.
65733feeb019a5742b286eededd5446ec0fe87c5a61Steve Naroff  bool isImplicitInterfaceDecl() const { return InternalInterface; }
65833feeb019a5742b286eededd5446ec0fe87c5a61Steve Naroff  void setImplicitInterfaceDecl(bool val) { InternalInterface = val; }
6591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6600fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian  /// ClassImplementsProtocol - Checks that 'lProto' protocol
6610fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian  /// has been implemented in IDecl class, its super class or categories (if
6620fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian  /// lookupCategory is true).
6630fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian  bool ClassImplementsProtocol(ObjCProtocolDecl *lProto,
6640fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian                               bool lookupCategory,
6650fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian                               bool RHSIsQualifiedID = false);
6661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
66733feeb019a5742b286eededd5446ec0fe87c5a61Steve Naroff  // Low-level accessor
66833feeb019a5742b286eededd5446ec0fe87c5a61Steve Naroff  Type *getTypeForDecl() const { return TypeForDecl; }
6693b3a45858c6b2a45114e91902c3bf3c4b7f5f302Daniel Dunbar  void setTypeForDecl(Type *TD) const { TypeForDecl = TD; }
67033feeb019a5742b286eededd5446ec0fe87c5a61Steve Naroff
67180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
672a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCInterfaceDecl *D) { return true; }
67380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCInterface; }
67453b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek
67553b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  friend class ASTDeclReader;
67653b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek  friend class ASTDeclWriter;
677980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
678980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
679a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCIvarDecl - Represents an ObjC instance variable. In general, ObjC
6800c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// instance variables are identical to C. The only exception is Objective-C
6810c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// supports C++ style access control. For example:
6820c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
6830c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @interface IvarExample : NSObject
6840c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   {
685f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek///     id defaultToProtected;
6860c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @public:
6870c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     id canBePublic; // same as C++.
6880c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @protected:
6890c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     id canBeProtected; // same as C++.
6900c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @package:
6910c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     id canBePackage; // framework visibility (not available in C++).
6920c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   }
6930c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
694a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCIvarDecl : public FieldDecl {
6950e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattnerpublic:
696980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  enum AccessControl {
697980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff    None, Private, Protected, Public, Package
698980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  };
6991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
700b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenekprivate:
701a06549226f45d5b72169a3d054415616dd1014a2Daniel Dunbar  ObjCIvarDecl(ObjCContainerDecl *DC, SourceLocation L, IdentifierInfo *Id,
702ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian               QualType T, TypeSourceInfo *TInfo, AccessControl ac, Expr *BW,
703ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian               bool synthesized)
704a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    : FieldDecl(ObjCIvar, DC, L, Id, T, TInfo, BW, /*Mutable=*/false),
7052c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian      NextIvar(0), DeclAccess(ac),  Synthesized(synthesized) {}
7061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
707b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenekpublic:
708a06549226f45d5b72169a3d054415616dd1014a2Daniel Dunbar  static ObjCIvarDecl *Create(ASTContext &C, ObjCContainerDecl *DC,
709a06549226f45d5b72169a3d054415616dd1014a2Daniel Dunbar                              SourceLocation L, IdentifierInfo *Id, QualType T,
710a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall                              TypeSourceInfo *TInfo,
711ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian                              AccessControl ac, Expr *BW = NULL,
712ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian                              bool synthesized=false);
7131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
71427a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar  /// \brief Return the class interface that this ivar is logically contained
71527a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar  /// in; this is either the interface where the ivar was declared, or the
71627a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar  /// interface the ivar is conceptually a part of in the case of synthesized
71727a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar  /// ivars.
71827a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar  const ObjCInterfaceDecl *getContainingInterface() const;
7192c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian
7202c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  ObjCIvarDecl *getNextIvar() { return NextIvar; }
7212c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  void setNextIvar(ObjCIvarDecl *ivar) { NextIvar = ivar; }
72227a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar
723980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  void setAccessControl(AccessControl ac) { DeclAccess = ac; }
724f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek
725ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  AccessControl getAccessControl() const { return AccessControl(DeclAccess); }
726f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek
727f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek  AccessControl getCanonicalAccessControl() const {
728f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek    return DeclAccess == None ? Protected : AccessControl(DeclAccess);
729f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek  }
7301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
731ac0021ba802e193e0f9f8207768c7862c7603bc0Fariborz Jahanian  void setSynthesize(bool synth) { Synthesized = synth; }
732ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian  bool getSynthesize() const { return Synthesized; }
733ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian
734980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  // Implement isa/cast/dyncast/etc.
73580cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
736a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCIvarDecl *D) { return true; }
73780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCIvar; }
738980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffprivate:
7392c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  /// NextIvar - Next Ivar in the list of ivars declared in class; class's
7402c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  /// extensions and class's implementation
7412c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian  ObjCIvarDecl *NextIvar;
7422c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian
743ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  // NOTE: VC++ treats enums as signed, avoid using the AccessControl enum
744ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  unsigned DeclAccess : 3;
745ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian  unsigned Synthesized : 1;
746980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
747980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
7481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
74901e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek/// ObjCAtDefsFieldDecl - Represents a field declaration created by an
75001e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek///  @defs(...).
75101e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenekclass ObjCAtDefsFieldDecl : public FieldDecl {
75201e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenekprivate:
75344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor  ObjCAtDefsFieldDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
75401e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek                      QualType T, Expr *BW)
755a1d5662d96465f0fddf8819d245da4d19b892effArgyrios Kyrtzidis    : FieldDecl(ObjCAtDefsField, DC, L, Id, T,
756a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall                /*TInfo=*/0, // FIXME: Do ObjCAtDefs have declarators ?
757a1d5662d96465f0fddf8819d245da4d19b892effArgyrios Kyrtzidis                BW, /*Mutable=*/false) {}
7581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
75901e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenekpublic:
76044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor  static ObjCAtDefsFieldDecl *Create(ASTContext &C, DeclContext *DC,
76144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor                                     SourceLocation L,
76201e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek                                     IdentifierInfo *Id, QualType T,
76301e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek                                     Expr *BW);
7641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
76501e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek  // Implement isa/cast/dyncast/etc.
76680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
76701e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek  static bool classof(const ObjCAtDefsFieldDecl *D) { return true; }
76880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCAtDefsField; }
76901e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek};
770980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
771a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCProtocolDecl - Represents a protocol declaration. ObjC protocols
7721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// declare a pure abstract type (i.e no instance variables are permitted).
7731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Protocols orginally drew inspiration from C++ pure virtual functions (a C++
7740c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// feature with nice semantics and lousy syntax:-). Here is an example:
7750c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
776eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// @protocol NSDraggingInfo <refproto1, refproto2>
7770c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (NSWindow *)draggingDestinationWindow;
7780c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (NSImage *)draggedImage;
7790c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end
7800c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
781eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// This says that NSDraggingInfo requires two methods and requires everything
782eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// that the two "referenced protocols" 'refproto1' and 'refproto2' require as
783eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// well.
784eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner///
7850c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @interface ImplementsNSDraggingInfo : NSObject <NSDraggingInfo>
7860c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end
7870c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
788a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjC protocols inspired Java interfaces. Unlike Java, ObjC classes and
7890c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// protocols are in distinct namespaces. For example, Cocoa defines both
7901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// an NSObject protocol and class (which isn't allowed in Java). As a result,
7910c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// protocols are referenced using angle brackets as follows:
7920c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
7930c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// id <NSDraggingInfo> anyObjectThatImplementsNSDraggingInfo;
7940c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
795e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroffclass ObjCProtocolDecl : public ObjCContainerDecl {
796780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  /// Referenced protocols
79718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  ObjCProtocolList ReferencedProtocols;
7981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
799980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  bool isForwardProtoDecl; // declared with @protocol.
8001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
801423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff  SourceLocation EndLoc; // marks the '>' or identifier.
8021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
803d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  ObjCProtocolDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id)
8041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : ObjCContainerDecl(ObjCProtocol, DC, L, Id),
805c858105d41602a2dadb2efbc1af80a7b791ebac3Chris Lattner      isForwardProtoDecl(true) {
806cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattner  }
8071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
808cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattnerpublic:
8091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static ObjCProtocolDecl *Create(ASTContext &C, DeclContext *DC,
810d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor                                  SourceLocation L, IdentifierInfo *Id);
811cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattner
81218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  const ObjCProtocolList &getReferencedProtocols() const {
813780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner    return ReferencedProtocols;
814980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  }
81518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::iterator protocol_iterator;
816780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();}
817780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  protocol_iterator protocol_end() const { return ReferencedProtocols.end(); }
81818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
81918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  protocol_loc_iterator protocol_loc_begin() const {
82018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    return ReferencedProtocols.loc_begin();
82118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
82218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  protocol_loc_iterator protocol_loc_end() const {
82318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    return ReferencedProtocols.loc_end();
82418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
82530833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  unsigned protocol_size() const { return ReferencedProtocols.size(); }
8261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
82738af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  /// setProtocolList - Set the list of protocols that this interface
828780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  /// implements.
82938af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num,
83018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                       const SourceLocation *Locs, ASTContext &C) {
83118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    ReferencedProtocols.set(List, Num, Locs, C);
832aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian  }
8331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
83491b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff  ObjCProtocolDecl *lookupProtocolNamed(IdentifierInfo *PName);
8351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
83694a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // Lookup a method. First, we search locally. If a method isn't
83794a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // found, we search referenced protocols and class categories.
838094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis  ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance) const;
839094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis  ObjCMethodDecl *lookupInstanceMethod(Selector Sel) const {
840094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis    return lookupMethod(Sel, true/*isInstance*/);
841094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis  }
842094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis  ObjCMethodDecl *lookupClassMethod(Selector Sel) const {
843094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis    return lookupMethod(Sel, false/*isInstance*/);
844094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis  }
845d789d3d985e28c9404e62157af46dcb7331920e0Steve Naroff
846768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff  bool isForwardDecl() const { return isForwardProtoDecl; }
847768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff  void setForwardDecl(bool val) { isForwardProtoDecl = val; }
848980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
8491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // Location information, modeled after the Stmt API.
850423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff  SourceLocation getLocStart() const { return getLocation(); } // '@'protocol
851423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff  SourceLocation getLocEnd() const { return EndLoc; }
8527177dee8aee4b432911c91f1b788963bec0cac9fDaniel Dunbar  void setLocEnd(SourceLocation LE) { EndLoc = LE; }
8531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
85480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
855a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCProtocolDecl *D) { return true; }
85680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCProtocol; }
857980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
8581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
859a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCClassDecl - Specifies a list of forward class declarations. For example:
86006ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff///
86106ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff/// @class NSCursor, NSImage, NSPasteboard, NSWindow;
8620c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
8634afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCClassDecl : public Decl {
864321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenekpublic:
865321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek  class ObjCClassRef {
866321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek    ObjCInterfaceDecl *ID;
867321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek    SourceLocation L;
868321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek  public:
869321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek    ObjCClassRef(ObjCInterfaceDecl *d, SourceLocation l) : ID(d), L(l) {}
870321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek    SourceLocation getLocation() const { return L; }
871321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek    ObjCInterfaceDecl *getInterface() const { return ID; }
872321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek  };
873321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenekprivate:
874321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek  ObjCClassRef *ForwardDecls;
875321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek  unsigned NumDecls;
8761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ObjCClassDecl(DeclContext *DC, SourceLocation L,
878321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek                ObjCInterfaceDecl *const *Elts, const SourceLocation *Locs,
879321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek                unsigned nElts, ASTContext &C);
88061f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattnerpublic:
881d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCClassDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L,
8821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                               ObjCInterfaceDecl *const *Elts = 0,
883321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek                               const SourceLocation *Locs = 0,
88430833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff                               unsigned nElts = 0);
8852dbdd622d02d1bfbe1e5bcf421b07b74c7a748f1Ted Kremenek
8862dbdd622d02d1bfbe1e5bcf421b07b74c7a748f1Ted Kremenek  virtual SourceRange getSourceRange() const;
8871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
888321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek  typedef const ObjCClassRef* iterator;
889321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek  iterator begin() const { return ForwardDecls; }
890321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek  iterator end() const { return ForwardDecls + NumDecls; }
891321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek  unsigned size() const { return NumDecls; }
89230833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff
89330833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  /// setClassList - Set the list of forward classes.
894321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek  void setClassList(ASTContext &C, ObjCInterfaceDecl*const*List,
895321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek                    const SourceLocation *Locs, unsigned Num);
8961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
89780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
898a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCClassDecl *D) { return true; }
89980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCClass; }
90006ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff};
90106ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff
902a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCForwardProtocolDecl - Specifies a list of forward protocol declarations.
90306ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff/// For example:
9041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
9050c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @protocol NSTextInput, NSChangeSpelling, NSDraggingInfo;
9061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
9074afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCForwardProtocolDecl : public Decl {
90818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  ObjCProtocolList ReferencedProtocols;
9091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
910d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  ObjCForwardProtocolDecl(DeclContext *DC, SourceLocation L,
91138af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner                          ObjCProtocolDecl *const *Elts, unsigned nElts,
91218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                          const SourceLocation *Locs, ASTContext &C);
9131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
91461f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattnerpublic:
915d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCForwardProtocolDecl *Create(ASTContext &C, DeclContext *DC,
9161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                         SourceLocation L,
91718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                                         ObjCProtocolDecl *const *Elts,
91818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                                         unsigned Num,
91918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                                         const SourceLocation *Locs);
92018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor
92118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  static ObjCForwardProtocolDecl *Create(ASTContext &C, DeclContext *DC,
92218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                                         SourceLocation L) {
92318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    return Create(C, DC, L, 0, 0, 0);
92418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
92561f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner
92618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::iterator protocol_iterator;
92730833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();}
92830833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  protocol_iterator protocol_end() const { return ReferencedProtocols.end(); }
92918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
93018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  protocol_loc_iterator protocol_loc_begin() const {
93118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    return ReferencedProtocols.loc_begin();
93218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
93318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  protocol_loc_iterator protocol_loc_end() const {
93418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    return ReferencedProtocols.loc_end();
93518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
93618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor
93730833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  unsigned protocol_size() const { return ReferencedProtocols.size(); }
93830833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff
93930833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  /// setProtocolList - Set the list of forward protocols.
94030833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num,
94118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                       const SourceLocation *Locs, ASTContext &C) {
94218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    ReferencedProtocols.set(List, Num, Locs, C);
94330833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  }
94480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
945a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCForwardProtocolDecl *D) { return true; }
94680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCForwardProtocol; }
947980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
948980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
949a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCCategoryDecl - Represents a category declaration. A category allows
9500c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// you to add methods to an existing class (without subclassing or modifying
9511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// the original class interface or implementation:-). Categories don't allow
9520c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// you to add instance data. The following example adds "myMethod" to all
9530c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// NSView's within a process:
9540c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
9550c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @interface NSView (MyViewMethods)
9560c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - myMethod;
9570c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end
9580c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
95933ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor/// Categories also allow you to split the implementation of a class across
9600c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// several files (a feature more naturally supported in C++).
9610c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
9620c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// Categories were originally inspired by dynamic languages such as Common
9631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Lisp and Smalltalk.  More traditional class-based languages (C++, Java)
9640c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// don't support this level of dynamism, which is both powerful and dangerous.
9650c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
966e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroffclass ObjCCategoryDecl : public ObjCContainerDecl {
967980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  /// Interface belonging to this category
968a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *ClassInterface;
9691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
97068c82cf61228102aba1194efef222fa1478af2a8Chris Lattner  /// referenced protocols in this category.
97118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  ObjCProtocolList ReferencedProtocols;
9721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
973a8ff9f455d94d9609766cfd5186b6e21dc2102f1Chris Lattner  /// Next category belonging to this class.
974a8ff9f455d94d9609766cfd5186b6e21dc2102f1Chris Lattner  /// FIXME: this should not be a singly-linked list.  Move storage elsewhere.
975a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCCategoryDecl *NextClassCategory;
9761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
977000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  /// true of class extension has at least one bitfield ivar.
978000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  bool HasSynthBitfield : 1;
979000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian
9803db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  /// \brief The location of the '@' in '@interface'
9813db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  SourceLocation AtLoc;
9823db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor
9833db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  /// \brief The location of the category name in this declaration.
9843db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  SourceLocation CategoryNameLoc;
9851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9863db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  ObjCCategoryDecl(DeclContext *DC, SourceLocation AtLoc,
9873db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor                   SourceLocation ClassNameLoc, SourceLocation CategoryNameLoc,
9883db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor                   IdentifierInfo *Id)
9893db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor    : ObjCContainerDecl(ObjCCategory, DC, ClassNameLoc, Id),
990000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian      ClassInterface(0), NextClassCategory(0), HasSynthBitfield(false),
991000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian      AtLoc(AtLoc), CategoryNameLoc(CategoryNameLoc) {
992a906135721c350435319347d2672bbb3bf494f91Chris Lattner  }
99361f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattnerpublic:
9941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
995d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCCategoryDecl *Create(ASTContext &C, DeclContext *DC,
9963db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor                                  SourceLocation AtLoc,
9973db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor                                  SourceLocation ClassNameLoc,
9983db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor                                  SourceLocation CategoryNameLoc,
9993db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor                                  IdentifierInfo *Id);
10001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1001e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
1002e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; }
1003a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void setClassInterface(ObjCInterfaceDecl *IDecl) { ClassInterface = IDecl; }
10048a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis
10058a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis  ObjCCategoryImplDecl *getImplementation() const;
10068a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis  void setImplementation(ObjCCategoryImplDecl *ImplD);
10078a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis
100838af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  /// setProtocolList - Set the list of protocols that this interface
1009f7b2c98c16dfb2261ea57d40a1d5bc4738e73175Chris Lattner  /// implements.
101038af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner  void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num,
101118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor                       const SourceLocation *Locs, ASTContext &C) {
101218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    ReferencedProtocols.set(List, Num, Locs, C);
1013780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  }
10141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
101518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  const ObjCProtocolList &getReferencedProtocols() const {
1016780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner    return ReferencedProtocols;
10178f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian  }
10181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
101918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::iterator protocol_iterator;
1020780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();}
1021780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  protocol_iterator protocol_end() const { return ReferencedProtocols.end(); }
102230833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  unsigned protocol_size() const { return ReferencedProtocols.size(); }
102318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
102418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  protocol_loc_iterator protocol_loc_begin() const {
102518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    return ReferencedProtocols.loc_begin();
102618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
102718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  protocol_loc_iterator protocol_loc_end() const {
102818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor    return ReferencedProtocols.loc_end();
102918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor  }
10301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1031a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCCategoryDecl *getNextClassCategory() const { return NextClassCategory; }
103230833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  void setNextClassCategory(ObjCCategoryDecl *Cat) {
103330833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff    NextClassCategory = Cat;
103430833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  }
1035980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  void insertNextClassCategory() {
10363d58138992b9bc7b34aaa680f3ddf3971292eb7dSteve Naroff    NextClassCategory = ClassInterface->getCategoryList();
10373d58138992b9bc7b34aaa680f3ddf3971292eb7dSteve Naroff    ClassInterface->setCategoryList(this);
10385e9888c2786bfffa6879a08ff40f5a11545eec23Douglas Gregor    ClassInterface->setChangedSinceDeserialization(true);
1039980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  }
10403db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor
104125760611365be23556b32332f8a66ae21ea93ecfFariborz Jahanian  bool IsClassExtension() const { return getIdentifier() == 0; }
104280aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  const ObjCCategoryDecl *getNextClassExtension() const;
104325760611365be23556b32332f8a66ae21ea93ecfFariborz Jahanian
1044000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  bool hasSynthBitfield() const { return HasSynthBitfield; }
1045000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  void setHasSynthBitfield (bool val) { HasSynthBitfield = val; }
1046000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian
10470e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
10480e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  ivar_iterator ivar_begin() const {
10490e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian    return ivar_iterator(decls_begin());
10500e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  }
10510e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  ivar_iterator ivar_end() const {
10520e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian    return ivar_iterator(decls_end());
10530e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  }
10540e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  unsigned ivar_size() const {
10550e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian    return std::distance(ivar_begin(), ivar_end());
10560e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  }
10570e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  bool ivar_empty() const {
10580e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian    return ivar_begin() == ivar_end();
10590e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian  }
10600e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian
10613db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  SourceLocation getAtLoc() const { return AtLoc; }
10623db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  void setAtLoc(SourceLocation At) { AtLoc = At; }
10633db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor
10643db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  SourceLocation getCategoryNameLoc() const { return CategoryNameLoc; }
10653db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  void setCategoryNameLoc(SourceLocation Loc) { CategoryNameLoc = Loc; }
10663db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor
10673db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  virtual SourceRange getSourceRange() const {
10683db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor    return SourceRange(AtLoc, getAtEndRange().getEnd());
10693db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor  }
10701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
107180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1072a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCCategoryDecl *D) { return true; }
107380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCCategory; }
1074980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
10750c6b6243d3efd958c17943130e2a773653511edcSteve Naroff
1076aecae629269fae3bf484baf1d109e9a89d14eeadArgyrios Kyrtzidisclass ObjCImplDecl : public ObjCContainerDecl {
10770d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// Class interface for this class/category implementation
1078a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *ClassInterface;
10791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10803aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattnerprotected:
10813aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  ObjCImplDecl(Kind DK, DeclContext *DC, SourceLocation L,
10823aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner               ObjCInterfaceDecl *classInterface)
10831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : ObjCContainerDecl(DK, DC, L,
10841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                        classInterface? classInterface->getIdentifier() : 0),
1085aecae629269fae3bf484baf1d109e9a89d14eeadArgyrios Kyrtzidis      ClassInterface(classInterface) {}
10861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
108775c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattnerpublic:
1088e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; }
1089e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
10908a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis  void setClassInterface(ObjCInterfaceDecl *IFace);
10912c2d43c557beca1b4ba4bd743f33978aecb46a97Douglas Gregor
10921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void addInstanceMethod(ObjCMethodDecl *method) {
10932c2d43c557beca1b4ba4bd743f33978aecb46a97Douglas Gregor    // FIXME: Context should be set correctly before we get here.
1094653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor    method->setLexicalDeclContext(this);
10951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    addDecl(method);
1096e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff  }
10971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void addClassMethod(ObjCMethodDecl *method) {
10982c2d43c557beca1b4ba4bd743f33978aecb46a97Douglas Gregor    // FIXME: Context should be set correctly before we get here.
1099653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor    method->setLexicalDeclContext(this);
11001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    addDecl(method);
110153df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner  }
11021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
110317945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  void addPropertyImplementation(ObjCPropertyImplDecl *property);
11041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
110517945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  ObjCPropertyImplDecl *FindPropertyImplDecl(IdentifierInfo *propertyId) const;
110617945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis  ObjCPropertyImplDecl *FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const;
1107653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor
1108653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor  // Iterator access to properties.
1109653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor  typedef specific_decl_iterator<ObjCPropertyImplDecl> propimpl_iterator;
11101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  propimpl_iterator propimpl_begin() const {
111117945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return propimpl_iterator(decls_begin());
1112559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  }
11131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  propimpl_iterator propimpl_end() const {
111417945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return propimpl_iterator(decls_end());
1115559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  }
1116653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor
111780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1118bfb498d0996ef049efe9476f2802976fd145cd60Argyrios Kyrtzidis  static bool classof(const ObjCImplDecl *D) { return true; }
111980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) {
11209a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt    return K >= firstObjCImpl && K <= lastObjCImpl;
112180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  }
11223aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner};
11231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ObjCCategoryImplDecl - An object of this class encapsulates a category
11251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// @implementation declaration. If a category class has declaration of a
11261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// property, its implementation must be specified in the category's
11273aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @implementation declaration. Example:
11283aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @interface I @end
11293aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @interface I(CATEGORY)
11303aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner///    @property int p1, d1;
11313aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @end
11323aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @implementation I(CATEGORY)
11333aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner///  @dynamic p1,d1;
11343aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @end
11353aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner///
11363aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// ObjCCategoryImplDecl
11373aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattnerclass ObjCCategoryImplDecl : public ObjCImplDecl {
11383aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  // Category name
11393aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  IdentifierInfo *Id;
11403aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner
11413aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  ObjCCategoryImplDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
11423aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner                       ObjCInterfaceDecl *classInterface)
11433aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner    : ObjCImplDecl(ObjCCategoryImpl, DC, L, classInterface), Id(Id) {}
11443aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattnerpublic:
11453aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  static ObjCCategoryImplDecl *Create(ASTContext &C, DeclContext *DC,
11463aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner                                      SourceLocation L, IdentifierInfo *Id,
11473aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner                                      ObjCInterfaceDecl *classInterface);
11481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11490d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// getIdentifier - Get the identifier that names the category
11503aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  /// interface associated with this implementation.
11510d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// FIXME: This is a bad API, we are overriding the NamedDecl::getIdentifier()
11520d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// to mean something different. For example:
11530d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// ((NamedDecl *)SomeCategoryImplDecl)->getIdentifier()
11540d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// returns the class interface name, whereas
11550d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// ((ObjCCategoryImplDecl *)SomeCategoryImplDecl)->getIdentifier()
11560d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  /// returns the category name.
11571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  IdentifierInfo *getIdentifier() const {
11581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return Id;
11593aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  }
116010b0e1fa3aabd8877dbbc0df1f2414e04afd5fddDouglas Gregor  void setIdentifier(IdentifierInfo *II) { Id = II; }
11611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11620d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff  ObjCCategoryDecl *getCategoryDecl() const;
116310b0e1fa3aabd8877dbbc0df1f2414e04afd5fddDouglas Gregor
1164b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  /// getName - Get the name of identifier for the class interface associated
1165b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  /// with this implementation as a StringRef.
1166b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  //
1167b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  // FIXME: This is a bad API, we are overriding the NamedDecl::getName, to mean
1168b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  // something different.
1169b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  llvm::StringRef getName() const {
1170b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar    return Id ? Id->getNameStart() : "";
1171b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  }
1172b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar
11733aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  /// getNameAsCString - Get the name of identifier for the class
11743aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  /// interface associated with this implementation as a C string
11753aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  /// (const char*).
11767fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar  //
1177b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  // FIXME: Deprecated, move clients to getName().
11783aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  const char *getNameAsCString() const {
11797fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar    return Id ? Id->getNameStart() : "";
11803aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  }
11811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11823aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  /// @brief Get the name of the class associated with this interface.
11837fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar  //
1184b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar  // FIXME: Deprecated, move clients to getName().
11853aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  std::string getNameAsString() const {
1186b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar    return getName();
11873aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner  }
11881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
118980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1190a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCCategoryImplDecl *D) { return true; }
119180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCCategoryImpl;}
11928f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian};
11938f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian
1194900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramerllvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
1195900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer                              const ObjCCategoryImplDecl *CID);
1196900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer
1197a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCImplementationDecl - Represents a class definition - this is where
11980c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// method definitions are specified. For example:
11990c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
120098abf4bd3526a00a0e5cf71a9462c181f97b1c81Fariborz Jahanian/// @code
12010c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @implementation MyClass
12020c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (void)myMethod { /* do something */ }
12030c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end
120498abf4bd3526a00a0e5cf71a9462c181f97b1c81Fariborz Jahanian/// @endcode
12050c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
12061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Typically, instance variables are specified in the class interface,
1207ec0d7a6f4b0699cc9960e6d9fee0f957c64d1cf9Douglas Gregor/// *not* in the implementation. Nevertheless (for legacy reasons), we
120853df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner/// allow instance variables to be specified in the implementation.  When
120953df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner/// specified, they need to be *identical* to the interface.
12100c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
12111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ObjCImplementationDecl : public ObjCImplDecl {
1212980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  /// Implementation Class's super class.
1213a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *SuperClass;
1214e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// Support for ivar initialization.
1215e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// IvarInitializers - The arguments used to initialize the ivars
1216cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt  CXXCtorInitializer **IvarInitializers;
1217e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  unsigned NumIvarInitializers;
1218e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian
1219000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  /// true of class extension has at least one bitfield ivar.
1220000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  bool HasSynthBitfield : 1;
1221000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian
12221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ObjCImplementationDecl(DeclContext *DC, SourceLocation L,
1223a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek                         ObjCInterfaceDecl *classInterface,
1224a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek                         ObjCInterfaceDecl *superDecl)
12251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : ObjCImplDecl(ObjCImplementation, DC, L, classInterface),
1226000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian       SuperClass(superDecl), IvarInitializers(0), NumIvarInitializers(0),
1227000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian       HasSynthBitfield(false) {}
12281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
12291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static ObjCImplementationDecl *Create(ASTContext &C, DeclContext *DC,
12301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                        SourceLocation L,
123175c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner                                        ObjCInterfaceDecl *classInterface,
123275c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner                                        ObjCInterfaceDecl *superDecl);
1233e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian
1234e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// init_iterator - Iterates through the ivar initializer list.
1235cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt  typedef CXXCtorInitializer **init_iterator;
1236e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian
1237e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// init_const_iterator - Iterates through the ivar initializer list.
1238cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt  typedef CXXCtorInitializer * const * init_const_iterator;
1239e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian
1240e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// init_begin() - Retrieve an iterator to the first initializer.
1241e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  init_iterator       init_begin()       { return IvarInitializers; }
1242e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// begin() - Retrieve an iterator to the first initializer.
1243e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  init_const_iterator init_begin() const { return IvarInitializers; }
1244e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian
1245e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// init_end() - Retrieve an iterator past the last initializer.
1246e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  init_iterator       init_end()       {
1247e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian    return IvarInitializers + NumIvarInitializers;
1248e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  }
1249e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// end() - Retrieve an iterator past the last initializer.
1250e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  init_const_iterator init_end() const {
1251e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian    return IvarInitializers + NumIvarInitializers;
1252e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  }
1253e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  /// getNumArgs - Number of ivars which must be initialized.
1254e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  unsigned getNumIvarInitializers() const {
1255e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian    return NumIvarInitializers;
1256e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  }
1257e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian
1258e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  void setNumIvarInitializers(unsigned numNumIvarInitializers) {
1259e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian    NumIvarInitializers = numNumIvarInitializers;
1260e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  }
1261e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian
1262e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian  void setIvarInitializers(ASTContext &C,
1263cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt                           CXXCtorInitializer ** initializers,
1264e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian                           unsigned numInitializers);
1265000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian
1266000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  bool hasSynthBitfield() const { return HasSynthBitfield; }
1267000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian  void setHasSynthBitfield (bool val) { HasSynthBitfield = val; }
1268e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian
12694afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  /// getIdentifier - Get the identifier that names the class
12704afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  /// interface associated with this implementation.
12711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  IdentifierInfo *getIdentifier() const {
12721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return getClassInterface()->getIdentifier();
12734afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  }
12744afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor
1275d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  /// getName - Get the name of identifier for the class interface associated
1276d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  /// with this implementation as a StringRef.
1277d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  //
1278d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  // FIXME: This is a bad API, we are overriding the NamedDecl::getName, to mean
1279d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  // something different.
1280d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  llvm::StringRef getName() const {
1281d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar    assert(getIdentifier() && "Name is not a simple identifier");
1282d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar    return getIdentifier()->getName();
1283d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar  }
1284d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar
12854afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  /// getNameAsCString - Get the name of identifier for the class
12864afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  /// interface associated with this implementation as a C string
12874afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  /// (const char*).
12887fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar  //
12897fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar  // FIXME: Move to StringRef API.
12904afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  const char *getNameAsCString() const {
1291d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar    return getName().data();
12924afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  }
12934afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor
12944afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  /// @brief Get the name of the class associated with this interface.
12957fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar  //
12967fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar  // FIXME: Move to StringRef API.
12974afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  std::string getNameAsString() const {
1298d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar    return getName();
12994afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor  }
13004afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor
1301e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  const ObjCInterfaceDecl *getSuperClass() const { return SuperClass; }
1302e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  ObjCInterfaceDecl *getSuperClass() { return SuperClass; }
13031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1304f3a7af901231535191d14cb524d58f22907ac4d2Chris Lattner  void setSuperClass(ObjCInterfaceDecl * superCls) { SuperClass = superCls; }
13051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13068f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor  typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
13071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ivar_iterator ivar_begin() const {
13081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return ivar_iterator(decls_begin());
13098f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor  }
13101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ivar_iterator ivar_end() const {
131117945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return ivar_iterator(decls_end());
13128f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor  }
13131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  unsigned ivar_size() const {
131417945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return std::distance(ivar_begin(), ivar_end());
13158f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor  }
13161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool ivar_empty() const {
131717945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis    return ivar_begin() == ivar_end();
13188f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor  }
13191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
132080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1321a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCImplementationDecl *D) { return true; }
132280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCImplementation; }
13239d50c0635fb213b2a1857e3f8488580f0dab2f98Argyrios Kyrtzidis
1324d527cc06d78fe5afa5f20105b51697637eb02c56Sebastian Redl  friend class ASTDeclReader;
13253397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl  friend class ASTDeclWriter;
1326980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
1327243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian
1328900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramerllvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
1329900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer                              const ObjCImplementationDecl *ID);
1330900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer
13311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ObjCCompatibleAliasDecl - Represents alias of a class. This alias is
1332243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian/// declared as @compatibility_alias alias class.
13334afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCCompatibleAliasDecl : public NamedDecl {
1334243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian  /// Class that this is an alias of.
1335a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *AliasedClass;
13361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1337d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  ObjCCompatibleAliasDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
1338e8043c39176e7f253fbd92982b077eca6bf2fd59Steve Naroff                          ObjCInterfaceDecl* aliasedClass)
13394afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor    : NamedDecl(ObjCCompatibleAlias, DC, L, Id), AliasedClass(aliasedClass) {}
1340f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattnerpublic:
1341d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCCompatibleAliasDecl *Create(ASTContext &C, DeclContext *DC,
13420ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner                                         SourceLocation L, IdentifierInfo *Id,
1343f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner                                         ObjCInterfaceDecl* aliasedClass);
1344f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner
1345f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner  const ObjCInterfaceDecl *getClassInterface() const { return AliasedClass; }
1346f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner  ObjCInterfaceDecl *getClassInterface() { return AliasedClass; }
134730833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff  void setClassInterface(ObjCInterfaceDecl *D) { AliasedClass = D; }
13481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
134980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1350a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCCompatibleAliasDecl *D) { return true; }
135180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCCompatibleAlias; }
13521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1353243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian};
13541de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian
13551de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian/// ObjCPropertyDecl - Represents one property declaration in an interface.
13561de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian/// For example:
13571de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian/// @property (assign, readwrite) int MyProperty;
13581de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian///
13594afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCPropertyDecl : public NamedDecl {
136082a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanianpublic:
1361a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner  enum PropertyAttributeKind {
13621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    OBJC_PR_noattr    = 0x00,
13631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    OBJC_PR_readonly  = 0x01,
1364a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_getter    = 0x02,
13651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    OBJC_PR_assign    = 0x04,
13661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    OBJC_PR_readwrite = 0x08,
1367a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_retain    = 0x10,
13681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    OBJC_PR_copy      = 0x20,
1369a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_nonatomic = 0x40,
1370dd4430e596fac34e9ce44228a249f71e73effd4aFariborz Jahanian    OBJC_PR_setter    = 0x80,
1371dd4430e596fac34e9ce44228a249f71e73effd4aFariborz Jahanian    OBJC_PR_atomic    = 0x100
1372a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner  };
1373af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
1374af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  enum SetterKind { Assign, Retain, Copy };
137546b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  enum PropertyControl { None, Required, Optional };
137682a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanianprivate:
1377d8265b838360578032020757d9a2a84c86457edcFariborz Jahanian  SourceLocation AtLoc;   // location of @property
137883a230c83a54190366138c1a4f4310ef838b88fcJohn McCall  TypeSourceInfo *DeclType;
1379dd4430e596fac34e9ce44228a249f71e73effd4aFariborz Jahanian  unsigned PropertyAttributes : 9;
1380dd4430e596fac34e9ce44228a249f71e73effd4aFariborz Jahanian  unsigned PropertyAttributesAsWritten : 9;
138146b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  // @required/@optional
138246b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  unsigned PropertyImplementation : 2;
13831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13845251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  Selector GetterName;    // getter name of NULL if no getter
13855251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  Selector SetterName;    // setter name of NULL if no setter
13861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
138733de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  ObjCMethodDecl *GetterMethodDecl; // Declaration of getter instance method
138833de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  ObjCMethodDecl *SetterMethodDecl; // Declaration of setter instance method
1389af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian  ObjCIvarDecl *PropertyIvarDecl;   // Synthesize ivar for this property
139033de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian
13911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ObjCPropertyDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
139283a230c83a54190366138c1a4f4310ef838b88fcJohn McCall                   SourceLocation AtLocation, TypeSourceInfo *T)
1393d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian    : NamedDecl(ObjCProperty, DC, L, Id), AtLoc(AtLocation), DeclType(T),
139480aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian      PropertyAttributes(OBJC_PR_noattr),
139580aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian      PropertyAttributesAsWritten(OBJC_PR_noattr),
139680aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian      PropertyImplementation(None),
13971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      GetterName(Selector()),
139833de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian      SetterName(Selector()),
1399af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian      GetterMethodDecl(0), SetterMethodDecl(0) , PropertyIvarDecl(0) {}
1400f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattnerpublic:
14011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static ObjCPropertyDecl *Create(ASTContext &C, DeclContext *DC,
14021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                  SourceLocation L,
1403d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian                                  IdentifierInfo *Id, SourceLocation AtLocation,
140483a230c83a54190366138c1a4f4310ef838b88fcJohn McCall                                  TypeSourceInfo *T,
140546b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian                                  PropertyControl propControl = None);
1406d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian  SourceLocation getAtLoc() const { return AtLoc; }
1407d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian  void setAtLoc(SourceLocation L) { AtLoc = L; }
1408d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian
140983a230c83a54190366138c1a4f4310ef838b88fcJohn McCall  TypeSourceInfo *getTypeSourceInfo() const { return DeclType; }
141083a230c83a54190366138c1a4f4310ef838b88fcJohn McCall  QualType getType() const { return DeclType->getType(); }
141183a230c83a54190366138c1a4f4310ef838b88fcJohn McCall  void setType(TypeSourceInfo *T) { DeclType = T; }
141270e5a14c6076d63833c62d1d6d628c26309897c1Douglas Gregor
1413a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner  PropertyAttributeKind getPropertyAttributes() const {
1414f4af5154571e0c5eadb19df10e65464766ef6683Chris Lattner    return PropertyAttributeKind(PropertyAttributes);
1415f4af5154571e0c5eadb19df10e65464766ef6683Chris Lattner  }
14161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setPropertyAttributes(PropertyAttributeKind PRVal) {
1417a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    PropertyAttributes |= PRVal;
141882a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian  }
1419394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar
142080aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  PropertyAttributeKind getPropertyAttributesAsWritten() const {
142180aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian    return PropertyAttributeKind(PropertyAttributesAsWritten);
142280aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  }
142380aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian
142480aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  void setPropertyAttributesAsWritten(PropertyAttributeKind PRVal) {
142580aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian    PropertyAttributesAsWritten = PRVal;
142680aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian  }
142780aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian
14288cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian void makeitReadWriteAttribute(void) {
14298cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian    PropertyAttributes &= ~OBJC_PR_readonly;
14308cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian    PropertyAttributes |= OBJC_PR_readwrite;
14311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump }
14328cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian
1433af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  // Helper methods for accessing attributes.
1434af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
1435af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  /// isReadOnly - Return true iff the property has a setter.
1436394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar  bool isReadOnly() const {
1437394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar    return (PropertyAttributes & OBJC_PR_readonly);
1438394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar  }
1439af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
1440af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  /// getSetterKind - Return the method used for doing assignment in
1441af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  /// the property setter. This is only valid if the property has been
1442af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  /// defined to have a setter.
1443af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  SetterKind getSetterKind() const {
1444af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar    if (PropertyAttributes & OBJC_PR_retain)
1445af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar      return Retain;
1446af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar    if (PropertyAttributes & OBJC_PR_copy)
1447af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar      return Copy;
1448af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar    return Assign;
1449af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  }
1450af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
14515251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  Selector getGetterName() const { return GetterName; }
14525251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  void setGetterName(Selector Sel) { GetterName = Sel; }
14531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14545251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  Selector getSetterName() const { return SetterName; }
14555251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  void setSetterName(Selector Sel) { SetterName = Sel; }
14561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
145733de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  ObjCMethodDecl *getGetterMethodDecl() const { return GetterMethodDecl; }
145833de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  void setGetterMethodDecl(ObjCMethodDecl *gDecl) { GetterMethodDecl = gDecl; }
145933de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian
146033de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  ObjCMethodDecl *getSetterMethodDecl() const { return SetterMethodDecl; }
146133de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  void setSetterMethodDecl(ObjCMethodDecl *gDecl) { SetterMethodDecl = gDecl; }
14621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
146346b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  // Related to @optional/@required declared in @protocol
146446b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  void setPropertyImplementation(PropertyControl pc) {
146546b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian    PropertyImplementation = pc;
146646b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  }
146746b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  PropertyControl getPropertyImplementation() const {
146846b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian    return PropertyControl(PropertyImplementation);
14691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
14701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1471af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian  void setPropertyIvarDecl(ObjCIvarDecl *Ivar) {
1472af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian    PropertyIvarDecl = Ivar;
1473af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian  }
1474af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian  ObjCIvarDecl *getPropertyIvarDecl() const {
1475af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian    return PropertyIvarDecl;
1476af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian  }
14771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1478e3c60a7ce9e0f42c7ca2344b33203266aceca1dbDouglas Gregor  virtual SourceRange getSourceRange() const {
1479e3c60a7ce9e0f42c7ca2344b33203266aceca1dbDouglas Gregor    return SourceRange(AtLoc, getLocation());
1480e3c60a7ce9e0f42c7ca2344b33203266aceca1dbDouglas Gregor  }
1481e3c60a7ce9e0f42c7ca2344b33203266aceca1dbDouglas Gregor
14829f550ff05d496e6b9480e5619a21d9da0c9e27c1Ted Kremenek  /// Lookup a property by name in the specified DeclContext.
1483de09d0c9694f01a99870a8825266d44a29ebb325Ted Kremenek  static ObjCPropertyDecl *findPropertyDecl(const DeclContext *DC,
14849f550ff05d496e6b9480e5619a21d9da0c9e27c1Ted Kremenek                                            IdentifierInfo *propertyID);
14859f550ff05d496e6b9480e5619a21d9da0c9e27c1Ted Kremenek
148680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1487a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCPropertyDecl *D) { return true; }
148880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Kind K) { return K == ObjCProperty; }
148982a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian};
1490980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
14911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ObjCPropertyImplDecl - Represents implementation declaration of a property
149261d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian/// in a class or category implementation block. For example:
149361d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian/// @synthesize prop1 = ivar1;
149461d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian///
14954afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCPropertyImplDecl : public Decl {
149661d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanianpublic:
14979f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar  enum Kind {
14989f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar    Synthesize,
14999f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar    Dynamic
150061d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  };
150161d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanianprivate:
1502559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  SourceLocation AtLoc;   // location of @synthesize or @dynamic
1503a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor
1504a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  /// \brief For @synthesize, the location of the ivar, if it was written in
1505a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  /// the source code.
1506a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  ///
1507a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  /// \code
1508a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  /// @synthesize int a = b
1509a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  /// \endcode
1510a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  SourceLocation IvarLoc;
1511a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor
151261d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  /// Property declaration being implemented
151361d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  ObjCPropertyDecl *PropertyDecl;
1514be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek
151561d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  /// Null for @dynamic. Required for @synthesize.
151661d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  ObjCIvarDecl *PropertyIvarDecl;
151717cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian
151817cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  /// Null for @dynamic. Non-null if property must be copy-constructed in getter
151917cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  Expr *GetterCXXConstructor;
152017cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian
152117cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  /// Null for @dynamic. Non-null if property has assignment operator to call
152217cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  /// in Setter synthesis.
152317cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  Expr *SetterCXXAssignment;
1524be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek
1525d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  ObjCPropertyImplDecl(DeclContext *DC, SourceLocation atLoc, SourceLocation L,
15261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                       ObjCPropertyDecl *property,
15271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                       Kind PK,
1528a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor                       ObjCIvarDecl *ivarDecl,
1529a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor                       SourceLocation ivarLoc)
15301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : Decl(ObjCPropertyImpl, DC, L), AtLoc(atLoc),
1531a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor      IvarLoc(ivarLoc), PropertyDecl(property), PropertyIvarDecl(ivarDecl),
153217cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian      GetterCXXConstructor(0), SetterCXXAssignment(0) {
15339f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar    assert (PK == Dynamic || PropertyIvarDecl);
15349f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar  }
15351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15369f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbarpublic:
1537d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCPropertyImplDecl *Create(ASTContext &C, DeclContext *DC,
15381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                      SourceLocation atLoc, SourceLocation L,
15391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                      ObjCPropertyDecl *property,
15401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                      Kind PK,
1541a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor                                      ObjCIvarDecl *ivarDecl,
1542a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor                                      SourceLocation ivarLoc);
154361d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian
1544a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  virtual SourceRange getSourceRange() const;
1545a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor
1546d40910b581b09c937a8c1fdcde9b8ec724398fb9Steve Naroff  SourceLocation getLocStart() const { return AtLoc; }
15478818c4fb69cb2a4eec94b217a90f94f9e075296eDouglas Gregor  void setAtLoc(SourceLocation Loc) { AtLoc = Loc; }
1548d40910b581b09c937a8c1fdcde9b8ec724398fb9Steve Naroff
1549be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek  ObjCPropertyDecl *getPropertyDecl() const {
1550be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek    return PropertyDecl;
1551be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek  }
15528818c4fb69cb2a4eec94b217a90f94f9e075296eDouglas Gregor  void setPropertyDecl(ObjCPropertyDecl *Prop) { PropertyDecl = Prop; }
15538818c4fb69cb2a4eec94b217a90f94f9e075296eDouglas Gregor
15549f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar  Kind getPropertyImplementation() const {
15559f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar    return PropertyIvarDecl ? Synthesize : Dynamic;
1556be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek  }
15571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1558af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  ObjCIvarDecl *getPropertyIvarDecl() const {
1559be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek    return PropertyIvarDecl;
1560be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek  }
1561a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  SourceLocation getPropertyIvarDeclLoc() const { return IvarLoc; }
1562a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor
1563a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  void setPropertyIvarDecl(ObjCIvarDecl *Ivar,
1564a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor                           SourceLocation IvarLoc) {
1565a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor    PropertyIvarDecl = Ivar;
1566a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor    this->IvarLoc = IvarLoc;
1567a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  }
156817cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian
156917cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  Expr *getGetterCXXConstructor() const {
157017cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian    return GetterCXXConstructor;
157117cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  }
157217cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  void setGetterCXXConstructor(Expr *getterCXXConstructor) {
157317cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian    GetterCXXConstructor = getterCXXConstructor;
157417cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  }
15758818c4fb69cb2a4eec94b217a90f94f9e075296eDouglas Gregor
157617cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  Expr *getSetterCXXAssignment() const {
157717cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian    return SetterCXXAssignment;
157817cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  }
157917cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  void setSetterCXXAssignment(Expr *setterCXXAssignment) {
158017cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian    SetterCXXAssignment = setterCXXAssignment;
158117cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian  }
158217cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian
158380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
15841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const ObjCPropertyImplDecl *D) { return true; }
158580cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall  static bool classofKind(Decl::Kind K) { return K == ObjCPropertyImpl; }
1586a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor
1587a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor  friend class ASTDeclReader;
158861d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian};
158961d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian
1590980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff}  // end namespace clang
1591980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff#endif
1592