DeclObjC.h revision f8d49f64ef6ab7e632717a31631fc289aab69428
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"
18c7229c338c21ef26b01ef3ecf9eec4fd373fa9ecChris Lattner#include "clang/Basic/IdentifierTable.h"
19b85cce6498c8c1c20f701571d85a3b2fe53338ebFariborz Jahanian#include "llvm/ADT/DenseMap.h"
20980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
21980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffnamespace clang {
22980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffclass Expr;
23980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffclass Stmt;
24980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffclass FunctionDecl;
25980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffclass AttributeList;
2660f8c868ffb346b78451a3eccaecd0461d2ae498Fariborz Jahanianclass RecordDecl;
27a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCIvarDecl;
28a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCMethodDecl;
29a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCProtocolDecl;
30a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCCategoryDecl;
31a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCPropertyDecl;
32f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanianclass ObjCPropertyImplDecl;
333db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner
343db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner
353db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner/// ObjCList - This is a simple template class used to hold various lists of
363db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner/// decls etc, which is heavily used by the ObjC front-end.  This only use case
373db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner/// this supports is setting the list all at once and then reading elements out
383db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner/// of it.
393db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattnertemplate <typename T>
403db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattnerclass ObjCList {
413db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  /// List is a new[]'d array of pointers to objects that are not owned by this
423db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  /// list.
433db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  T **List;
443db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  unsigned NumElts;
453db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner
463db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  void operator=(const ObjCList &); // DO NOT IMPLEMENT
473db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  ObjCList(const ObjCList&);        // DO NOT IMPLEMENT
483db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattnerpublic:
493db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  ObjCList() : List(0), NumElts(0) {}
503db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  ~ObjCList() {
513db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner    delete[] List;
523db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  }
533db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner
543db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  void set(T* const* InList, unsigned Elts) {
553db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner    assert(List == 0 && "Elements already set!");
563db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner    List = new T*[Elts];
573db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner    NumElts = Elts;
583db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner    memcpy(List, InList, sizeof(T*)*Elts);
593db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  }
603db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner
613db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  typedef T* const * iterator;
623db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  iterator begin() const { return List; }
633db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  iterator end() const { return List+NumElts; }
643db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner
653db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  unsigned size() const { return NumElts; }
663db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  bool empty() const { return NumElts == 0; }
673db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner
68780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  T* operator[](unsigned idx) const {
693db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner    assert(idx < NumElts && "Invalid access");
703db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner    return List[idx];
713db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  }
723db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner};
733db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner
743db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner
7558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff
76a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCMethodDecl - Represents an instance or class method declaration.
7758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// ObjC methods can be declared within 4 contexts: class interfaces,
7858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// categories, protocols, and class implementations. While C++ member
7958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// functions leverage C syntax, Objective-C method syntax is modeled after
8058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Smalltalk (using colons to specify argument types/expressions).
8158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Here are some brief examples:
8258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff///
8358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Setter/getter instance methods:
8458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// - (void)setMenu:(NSMenu *)menu;
8558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// - (NSMenu *)menu;
8658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff///
8758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Instance method that takes 2 NSView arguments:
8858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// - (void)replaceSubview:(NSView *)oldView with:(NSView *)newView;
8958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff///
9058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Getter class method:
9158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// + (NSMenu *)defaultMenu;
9258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff///
9358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// A selector represents a unique name for a method. The selector names for
9458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// the above methods are setMenu:, menu, replaceSubview:with:, and defaultMenu.
9558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff///
960701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroffclass ObjCMethodDecl : public ScopedDecl, public DeclContext {
9758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroffpublic:
9858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  enum ImplementationControl { None, Required, Optional };
9958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroffprivate:
10058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  /// Bitfields must be first fields in this class so they pack with those
10158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  /// declared in class Decl.
10258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  /// instance (true) or class (false) method.
10358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  bool IsInstance : 1;
10458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  bool IsVariadic : 1;
10558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff
1064607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian  // Synthesized declaration method for a property setter/getter
1074607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian  bool IsSynthesized : 1;
1084607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian
109ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  // NOTE: VC++ treats enums as signed, avoid using ImplementationControl enum
11058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  /// @required/@optional
111ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  unsigned DeclImplementation : 2;
11258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff
113ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  // NOTE: VC++ treats enums as signed, avoid using the ObjCDeclQualifier enum
11458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  /// in, inout, etc.
115ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  unsigned objcDeclQualifier : 6;
11658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff
11758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  // Type of this method.
11858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  QualType MethodDeclType;
11958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  /// ParamInfo - new[]'d array of pointers to VarDecls for the formal
12058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  /// parameters of this Method.  This is null if there are no formals.
12158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  ParmVarDecl **ParamInfo;
12258cce3b0dcbdcc95b7e713795834b4cb2c8a008aChris Lattner  unsigned NumMethodParams;
12358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff
12458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  /// List of attributes for this method declaration.
12558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  SourceLocation EndLoc; // the location of the ';' or '{'.
12658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff
12758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  // The following are only used for method definitions, null otherwise.
12858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  // FIXME: space savings opportunity, consider a sub-class.
12958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  Stmt *Body;
130451318c08a6342c10b8986060386fd9274418437Daniel Dunbar
131451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// SelfDecl - Decl for the implicit self parameter. This is lazily
132451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// constructed by createImplicitParams.
1334111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  ImplicitParamDecl *SelfDecl;
134451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// CmdDecl - Decl for the implicit _cmd parameter. This is lazily
135451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// constructed by createImplicitParams.
1364111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  ImplicitParamDecl *CmdDecl;
1376c4ae5de0c356777446f823b573821fb95560d91Chris Lattner
138a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCMethodDecl(SourceLocation beginLoc, SourceLocation endLoc,
13958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff                 Selector SelInfo, QualType T,
1400701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff                 DeclContext *contextDecl,
141f6414927e67e27d9324d8d179c5f7ea620443924Daniel Dunbar                 bool isInstance = true,
14258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff                 bool isVariadic = false,
1434607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian                 bool isSynthesized = false,
14458cce3b0dcbdcc95b7e713795834b4cb2c8a008aChris Lattner                 ImplementationControl impControl = None)
1450701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  : ScopedDecl(ObjCMethod, contextDecl, beginLoc, SelInfo, 0),
146b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner    DeclContext(ObjCMethod),
14758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff    IsInstance(isInstance), IsVariadic(isVariadic),
1484607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian    IsSynthesized(isSynthesized),
14958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff    DeclImplementation(impControl), objcDeclQualifier(OBJC_TQ_None),
1502e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor    MethodDeclType(T),
151f6414927e67e27d9324d8d179c5f7ea620443924Daniel Dunbar    ParamInfo(0), NumMethodParams(0),
1524111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner    EndLoc(endLoc), Body(0), SelfDecl(0), CmdDecl(0) {}
1538a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek
1541c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek  virtual ~ObjCMethodDecl();
1551c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek
1566c4ae5de0c356777446f823b573821fb95560d91Chris Lattnerpublic:
1578a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek
1588a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek  /// Destroy - Call destructors and release memory.
1598a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek  virtual void Destroy(ASTContext& C);
1606c4ae5de0c356777446f823b573821fb95560d91Chris Lattner
1610ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner  static ObjCMethodDecl *Create(ASTContext &C,
1620ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner                                SourceLocation beginLoc,
1636c4ae5de0c356777446f823b573821fb95560d91Chris Lattner                                SourceLocation endLoc, Selector SelInfo,
1640701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff                                QualType T, DeclContext *contextDecl,
165f6414927e67e27d9324d8d179c5f7ea620443924Daniel Dunbar                                bool isInstance = true,
1666c4ae5de0c356777446f823b573821fb95560d91Chris Lattner                                bool isVariadic = false,
1674607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian                                bool isSynthesized = false,
168b06fa3b86951b9f179c99c3768331536c32e902dChris Lattner                                ImplementationControl impControl = None);
16958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff
170ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  ObjCDeclQualifier getObjCDeclQualifier() const {
171ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek    return ObjCDeclQualifier(objcDeclQualifier);
172ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  }
173a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void setObjCDeclQualifier(ObjCDeclQualifier QV) { objcDeclQualifier = QV; }
17458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff
17558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  // Location information, modeled after the Stmt API.
17658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  SourceLocation getLocStart() const { return getLocation(); }
17758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  SourceLocation getLocEnd() const { return EndLoc; }
1789776ba0d844cf9f6888e871e3fd246ae782f76f4Daniel Dunbar  SourceRange getSourceRange() const {
1799776ba0d844cf9f6888e871e3fd246ae782f76f4Daniel Dunbar    return SourceRange(getLocation(), EndLoc);
1809776ba0d844cf9f6888e871e3fd246ae782f76f4Daniel Dunbar  }
1813e0a540b6d846178857289ec0eb8470a278d11a3Steve Naroff
1825619688510185081cbb4621d703daf7ee24cf39aChris Lattner  ObjCInterfaceDecl *getClassInterface();
1835619688510185081cbb4621d703daf7ee24cf39aChris Lattner  const ObjCInterfaceDecl *getClassInterface() const {
1845619688510185081cbb4621d703daf7ee24cf39aChris Lattner    return const_cast<ObjCMethodDecl*>(this)->getClassInterface();
185e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  }
18658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff
1872e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  Selector getSelector() const { return getDeclName().getObjCSelector(); }
188faf5e779d16bb4590f2a97e1c7ded255eddd90f3Fariborz Jahanian  unsigned getSynthesizedMethodSize() const;
18958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  QualType getResultType() const { return MethodDeclType; }
19058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff
191d57f635d520e8cb5b93d3d770ff58db06c62de54Chris Lattner  // Iterator access to formal parameters.
19258cce3b0dcbdcc95b7e713795834b4cb2c8a008aChris Lattner  unsigned param_size() const { return NumMethodParams; }
193d57f635d520e8cb5b93d3d770ff58db06c62de54Chris Lattner  typedef ParmVarDecl **param_iterator;
194d57f635d520e8cb5b93d3d770ff58db06c62de54Chris Lattner  typedef ParmVarDecl * const *param_const_iterator;
195d57f635d520e8cb5b93d3d770ff58db06c62de54Chris Lattner  param_iterator param_begin() { return ParamInfo; }
196d57f635d520e8cb5b93d3d770ff58db06c62de54Chris Lattner  param_iterator param_end() { return ParamInfo+param_size(); }
197d57f635d520e8cb5b93d3d770ff58db06c62de54Chris Lattner  param_const_iterator param_begin() const { return ParamInfo; }
198d57f635d520e8cb5b93d3d770ff58db06c62de54Chris Lattner  param_const_iterator param_end() const { return ParamInfo+param_size(); }
199d57f635d520e8cb5b93d3d770ff58db06c62de54Chris Lattner
20058cce3b0dcbdcc95b7e713795834b4cb2c8a008aChris Lattner  unsigned getNumParams() const { return NumMethodParams; }
20158cce3b0dcbdcc95b7e713795834b4cb2c8a008aChris Lattner  ParmVarDecl *getParamDecl(unsigned i) const {
20258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff    assert(i < getNumParams() && "Illegal param #");
20358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff    return ParamInfo[i];
20458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  }
2052338d58a905191c4205d4f73affd0bdaa13493b4Fariborz Jahanian  void setParamDecl(int i, ParmVarDecl *pDecl) {
2062338d58a905191c4205d4f73affd0bdaa13493b4Fariborz Jahanian    ParamInfo[i] = pDecl;
2072338d58a905191c4205d4f73affd0bdaa13493b4Fariborz Jahanian  }
20858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  void setMethodParams(ParmVarDecl **NewParamInfo, unsigned NumParams);
2094111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner
210451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// createImplicitParams - Used to lazily create the self and cmd
211451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// implict parameters. This must be called prior to using getSelfDecl()
212451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// or getCmdDecl(). The call is ignored if the implicit paramters
213451318c08a6342c10b8986060386fd9274418437Daniel Dunbar  /// have already been created.
214fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian  void createImplicitParams(ASTContext &Context, const ObjCInterfaceDecl *ID);
215451318c08a6342c10b8986060386fd9274418437Daniel Dunbar
2164111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  ImplicitParamDecl * getSelfDecl() const { return SelfDecl; }
2174111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  ImplicitParamDecl * getCmdDecl() const { return CmdDecl; }
21858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff
219f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor  bool isInstanceMethod() const { return IsInstance; }
22058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  bool isVariadic() const { return IsVariadic; }
22158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff
222f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor  bool isClassMethod() const { return !IsInstance; }
223f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor
2244607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian  bool isSynthesized() const { return IsSynthesized; }
22591b51a92f2e9fc8025b6a9df88442840eb62823aFariborz Jahanian  void setIsSynthesized() { IsSynthesized = true; }
2264607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian
22758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  // Related to protocols declared in  @protocol
22858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  void setDeclImplementation(ImplementationControl ic) {
22958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff    DeclImplementation = ic;
23058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  }
23158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  ImplementationControl getImplementationControl() const {
232ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek    return ImplementationControl(DeclImplementation);
23358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  }
234792481eec23d8c1aa92173be589e2ae9d02514a5Ted Kremenek
23569c8f0aab655257e9e532d9d53756acf4f7a2d78Ted Kremenek  virtual Stmt *getBody() const { return Body; }
23658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  void setBody(Stmt *B) { Body = B; }
23758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff
23858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  // Implement isa/cast/dyncast/etc.
239a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const Decl *D) { return D->getKind() == ObjCMethod; }
240a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCMethodDecl *D) { return true; }
24142220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  static DeclContext *castToDeclContext(const ObjCMethodDecl *D) {
24242220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis    return static_cast<DeclContext *>(const_cast<ObjCMethodDecl*>(D));
24342220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  }
24442220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  static ObjCMethodDecl *castFromDeclContext(const DeclContext *DC) {
24542220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis    return static_cast<ObjCMethodDecl *>(const_cast<DeclContext*>(DC));
24642220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  }
24758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff};
248e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
249e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff/// ObjCContainerDecl - Represents a container for method declarations.
250e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff/// Current sub-classes are ObjCInterfaceDecl, ObjCCategoryDecl, and
2510701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff/// ObjCProtocolDecl.
2520701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff/// FIXME: Use for ObjC implementation decls.
25309c4719788a5cea09897525e528fa00420f1677bSteve Naroff/// FIXME: Convert property implementation to DeclContext::addDecl(). Holding
25409c4719788a5cea09897525e528fa00420f1677bSteve Naroff/// off until we have an iterator adaptor that plays with DeclContext.
255e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff///
256d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregorclass ObjCContainerDecl : public ScopedDecl, public DeclContext {
25709c4719788a5cea09897525e528fa00420f1677bSteve Naroff  /// class properties
25809c4719788a5cea09897525e528fa00420f1677bSteve Naroff  ObjCPropertyDecl **PropertyDecl;  // Null if no property
25909c4719788a5cea09897525e528fa00420f1677bSteve Naroff  unsigned NumPropertyDecl;  // 0 if none.
26009c4719788a5cea09897525e528fa00420f1677bSteve Naroff
261e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff  SourceLocation AtEndLoc; // marks the end of the method container.
262e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroffpublic:
263e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
264d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  ObjCContainerDecl(Kind DK, DeclContext *DC, SourceLocation L,
265d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor                    IdentifierInfo *Id)
26609c4719788a5cea09897525e528fa00420f1677bSteve Naroff    : ScopedDecl(DK, DC, L, Id), DeclContext(DK),
26709c4719788a5cea09897525e528fa00420f1677bSteve Naroff      PropertyDecl(0), NumPropertyDecl(0) {}
268e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
269e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff  virtual ~ObjCContainerDecl();
27009c4719788a5cea09897525e528fa00420f1677bSteve Naroff
27109c4719788a5cea09897525e528fa00420f1677bSteve Naroff  void addProperties(ObjCPropertyDecl **Properties, unsigned NumProperties);
27209c4719788a5cea09897525e528fa00420f1677bSteve Naroff
27309c4719788a5cea09897525e528fa00420f1677bSteve Naroff  // FIXME: Replace with appropriate lookup. Currently used by interfaces and
27409c4719788a5cea09897525e528fa00420f1677bSteve Naroff  // categories.
27509c4719788a5cea09897525e528fa00420f1677bSteve Naroff  void mergeProperties(ObjCPropertyDecl **Properties, unsigned NumProperties);
27609c4719788a5cea09897525e528fa00420f1677bSteve Naroff
27709c4719788a5cea09897525e528fa00420f1677bSteve Naroff  typedef ObjCPropertyDecl * const * prop_iterator;
27809c4719788a5cea09897525e528fa00420f1677bSteve Naroff  prop_iterator prop_begin() const { return PropertyDecl; }
27909c4719788a5cea09897525e528fa00420f1677bSteve Naroff  prop_iterator prop_end() const {
28009c4719788a5cea09897525e528fa00420f1677bSteve Naroff    return PropertyDecl+NumPropertyDecl;
28109c4719788a5cea09897525e528fa00420f1677bSteve Naroff  }
28209c4719788a5cea09897525e528fa00420f1677bSteve Naroff
28309c4719788a5cea09897525e528fa00420f1677bSteve Naroff  ObjCPropertyDecl * const * getPropertyDecl() const { return PropertyDecl; }
28409c4719788a5cea09897525e528fa00420f1677bSteve Naroff  ObjCPropertyDecl **getPropertyDecl() { return PropertyDecl; }
28509c4719788a5cea09897525e528fa00420f1677bSteve Naroff  unsigned getNumPropertyDecl() const { return NumPropertyDecl; }
286e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
28709c4719788a5cea09897525e528fa00420f1677bSteve Naroff  ObjCPropertyDecl *FindPropertyDeclaration(IdentifierInfo *PropertyId) const;
28809c4719788a5cea09897525e528fa00420f1677bSteve Naroff
2890701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  // Iterator access to instance/class methods.
290f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor  typedef specific_decl_iterator<ObjCMethodDecl> method_iterator;
291f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor  method_iterator meth_begin() const {
292f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor    return method_iterator(decls_begin(), decls_end());
2937ed4faca5162b3ab85be7f7e57aa40e6ec170971Ted Kremenek  }
294f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor  method_iterator meth_end() const {
295f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor    return method_iterator(decls_end(), decls_end());
2967ed4faca5162b3ab85be7f7e57aa40e6ec170971Ted Kremenek  }
2970701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
298f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor  typedef method_iterator instmeth_iterator;
2990701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  instmeth_iterator instmeth_begin() const {
300f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor    return instmeth_iterator(decls_begin(), decls_end(),
301f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor                             &ObjCMethodDecl::isInstanceMethod);
302e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff  }
3030701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  instmeth_iterator instmeth_end() const {
304f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor    return instmeth_iterator(decls_end(), decls_end(),
305f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor                             &ObjCMethodDecl::isInstanceMethod);
306e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff  }
307e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
308f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor  typedef method_iterator classmeth_iterator;
3090701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  classmeth_iterator classmeth_begin() const {
310f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor    return classmeth_iterator(decls_begin(), decls_end(),
311f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor                              &ObjCMethodDecl::isClassMethod);
312e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff  }
3130701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  classmeth_iterator classmeth_end() const {
314f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor    return classmeth_iterator(decls_end(), decls_end(),
315f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor                              &ObjCMethodDecl::isClassMethod);
3160701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  }
3170701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
3180701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  // Get the local instance/class method declared in this interface.
3190701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  ObjCMethodDecl *getInstanceMethod(Selector Sel) const;
3200701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  ObjCMethodDecl *getClassMethod(Selector Sel) const;
321e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
32209c4719788a5cea09897525e528fa00420f1677bSteve Naroff  // Get the number of instance/class methods. These methods are slow, O(n).
3230701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  unsigned getNumInstanceMethods() const;
3240701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  unsigned getNumClassMethods() const;
325b245a33e6f562377946dc9cb5694a2d3cb8a98a3Fariborz Jahanian
326e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff  // Marks the end of the container.
327e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff  SourceLocation getAtEndLoc() const { return AtEndLoc; }
3280701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  void setAtEndLoc(SourceLocation L) { AtEndLoc = L; }
32909c4719788a5cea09897525e528fa00420f1677bSteve Naroff
33009c4719788a5cea09897525e528fa00420f1677bSteve Naroff  // Implement isa/cast/dyncast/etc.
33109c4719788a5cea09897525e528fa00420f1677bSteve Naroff  static bool classof(const Decl *D) {
33209c4719788a5cea09897525e528fa00420f1677bSteve Naroff    return D->getKind() >= ObjCContainerFirst &&
33309c4719788a5cea09897525e528fa00420f1677bSteve Naroff           D->getKind() <= ObjCContainerLast;
33409c4719788a5cea09897525e528fa00420f1677bSteve Naroff  }
33509c4719788a5cea09897525e528fa00420f1677bSteve Naroff  static bool classof(const ObjCContainerDecl *D) { return true; }
33609c4719788a5cea09897525e528fa00420f1677bSteve Naroff
33709c4719788a5cea09897525e528fa00420f1677bSteve Naroff  static DeclContext *castToDeclContext(const ObjCContainerDecl *D) {
33809c4719788a5cea09897525e528fa00420f1677bSteve Naroff    return static_cast<DeclContext *>(const_cast<ObjCContainerDecl*>(D));
33909c4719788a5cea09897525e528fa00420f1677bSteve Naroff  }
34009c4719788a5cea09897525e528fa00420f1677bSteve Naroff  static ObjCContainerDecl *castFromDeclContext(const DeclContext *DC) {
34109c4719788a5cea09897525e528fa00420f1677bSteve Naroff    return static_cast<ObjCContainerDecl *>(const_cast<DeclContext*>(DC));
34209c4719788a5cea09897525e528fa00420f1677bSteve Naroff  }
343e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff};
344e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
345a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCInterfaceDecl - Represents an ObjC class declaration. For example:
3460c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
3470c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   // MostPrimitive declares no super class (not particularly useful).
3480c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @interface MostPrimitive
3490c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     // no instance variables or methods.
3500c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @end
3510c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
352fd5de471478a507dd2495c4ea9bcab801ea5fa65Chris Lattner///   // NSResponder inherits from NSObject & implements NSCoding (a protocol).
3530c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @interface NSResponder : NSObject <NSCoding>
354a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek///   { // instance variables are represented by ObjCIvarDecl.
3550c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     id nextResponder; // nextResponder instance variable.
3560c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   }
3570c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   - (NSResponder *)nextResponder; // return a pointer to NSResponder.
3580c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   - (void)mouseMoved:(NSEvent *)theEvent; // return void, takes a pointer
3590c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @end                                    // to an NSEvent.
3600c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
3610c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   Unlike C/C++, forward class declarations are accomplished with @class.
3620c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   Unlike C/C++, @class allows for a list of classes to be forward declared.
3630c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   Unlike C++, ObjC is a single-rooted class model. In Cocoa, classes
3640c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   typically inherit from NSObject (an exception is NSProxy).
3650c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
3660701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroffclass ObjCInterfaceDecl : public ObjCContainerDecl {
3673110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff  /// TypeForDecl - This indicates the Type object that represents this
3683110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff  /// TypeDecl.  It is a cache maintained by ASTContext::getObjCInterfaceType
3693110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff  Type *TypeForDecl;
3703110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff  friend class ASTContext;
371980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
372980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  /// Class's super class.
373a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *SuperClass;
374980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
375980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  /// Protocols referenced in interface header declaration
3763db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  ObjCList<ObjCProtocolDecl> ReferencedProtocols;
377980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
378980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  /// Ivars/NumIvars - This is a new[]'d array of pointers to Decls.
379a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCIvarDecl **Ivars;   // Null if not defined.
380f3a7af901231535191d14cb524d58f22907ac4d2Chris Lattner  unsigned NumIvars;      // 0 if none.
381980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
382980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  /// List of categories defined for this class.
383a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCCategoryDecl *CategoryList;
38482a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian
3853a3ca1b35a7121aea0bf465a192dce748465e10fFariborz Jahanian  bool ForwardDecl:1; // declared with @class.
3863a3ca1b35a7121aea0bf465a192dce748465e10fFariborz Jahanian  bool InternalInterface:1; // true - no @interface for @implementation
38760fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff
388d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff  SourceLocation ClassLoc; // location of the class identifier.
389d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff  SourceLocation SuperClassLoc; // location of the super class identifier.
390f908a87299d278164540f90b5b6e6cab7b14fb41Steve Naroff  SourceLocation EndLoc; // marks the '>', '}', or identifier.
3910e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner
392d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id,
393b752f289026ad8e5f44851b20e009a27ed61eefcChris Lattner                    SourceLocation CLoc, bool FD, bool isInternal)
394d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor    : ObjCContainerDecl(ObjCInterface, DC, atLoc, Id),
395a769c004a2874504c17ea8afccbc4ad35fc33c9fFariborz Jahanian      TypeForDecl(0), SuperClass(0),
3963db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner      Ivars(0), NumIvars(0),
39709c4719788a5cea09897525e528fa00420f1677bSteve Naroff      CategoryList(0),
398d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff      ForwardDecl(FD), InternalInterface(isInternal),
399d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff      ClassLoc(CLoc) {
400980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff      }
4018a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek
4021c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek  virtual ~ObjCInterfaceDecl();
4038a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek
4040e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattnerpublic:
4050e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner
4068a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek  /// Destroy - Call destructors and release memory.
4078a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek  virtual void Destroy(ASTContext& C);
4088a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek
409d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCInterfaceDecl *Create(ASTContext &C, DeclContext *DC,
4100ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner                                   SourceLocation atLoc,
411d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff                                   IdentifierInfo *Id,
412d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff                                   SourceLocation ClassLoc = SourceLocation(),
4130e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner                                   bool ForwardDecl = false,
4140e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner                                   bool isInternal = false);
4153db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  const ObjCList<ObjCProtocolDecl> &getReferencedProtocols() const {
4167ed9e0f97f4645edc5d4670385b985ea4c617ce7Fariborz Jahanian    return ReferencedProtocols;
4177ed9e0f97f4645edc5d4670385b985ea4c617ce7Fariborz Jahanian  }
418980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
419559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  ObjCCategoryDecl *FindCategoryDeclaration(IdentifierInfo *CategoryId) const;
420559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  ObjCIvarDecl *FindIvarDeclaration(IdentifierInfo *IvarId) const;
42131afbf02a381ae9c77d225aa54f972d152838b3aFariborz Jahanian  bool isPropertyReadonly(ObjCPropertyDecl *PropertyDecl) const;
4223db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner
4233db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  typedef ObjCList<ObjCProtocolDecl>::iterator protocol_iterator;
4243db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();}
4253db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  protocol_iterator protocol_end() const { return ReferencedProtocols.end(); }
426aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian
427a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  typedef ObjCIvarDecl * const *ivar_iterator;
428be6df088d69bca0e99c7845a6cd8c1ca85034f31Chris Lattner  ivar_iterator ivar_begin() const { return Ivars; }
4295564e07af5e62875f3b83fc2e5a8823588b5adeaChris Lattner  ivar_iterator ivar_end() const { return Ivars + ivar_size();}
430f3a7af901231535191d14cb524d58f22907ac4d2Chris Lattner  unsigned ivar_size() const { return NumIvars; }
431a0fb5861dec7aa1da0d21d5759678d76b00464f4Ted Kremenek  bool ivar_empty() const { return NumIvars == 0; }
432e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
433b752f289026ad8e5f44851b20e009a27ed61eefcChris Lattner  /// addReferencedProtocols - Set the list of protocols that this interface
434b752f289026ad8e5f44851b20e009a27ed61eefcChris Lattner  /// implements.
435780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  void addReferencedProtocols(ObjCProtocolDecl *const*List, unsigned NumRPs) {
436780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner    ReferencedProtocols.set(List, NumRPs);
4373db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  }
438b752f289026ad8e5f44851b20e009a27ed61eefcChris Lattner
439a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void addInstanceVariablesToClass(ObjCIvarDecl **ivars, unsigned numIvars,
44060fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff                                   SourceLocation RBracLoc);
441fd64bb635dc221baa19f81d5d2a084f7eb269f7fFariborz Jahanian  FieldDecl *lookupFieldDeclForIvar(ASTContext &Context,
442fd64bb635dc221baa19f81d5d2a084f7eb269f7fFariborz Jahanian                                    const ObjCIvarDecl *ivar);
443980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
444768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff  bool isForwardDecl() const { return ForwardDecl; }
445768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff  void setForwardDecl(bool val) { ForwardDecl = val; }
446980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
447a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *getSuperClass() const { return SuperClass; }
448a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void setSuperClass(ObjCInterfaceDecl * superCls) { SuperClass = superCls; }
449980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
450a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCCategoryDecl* getCategoryList() const { return CategoryList; }
451a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void setCategoryList(ObjCCategoryDecl *category) {
45253efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    CategoryList = category;
453980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  }
45453efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner
45553efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner  /// isSuperClassOf - Return true if this class is the specified class or is a
45653efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner  /// super class of the specified interface class.
45753efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner  bool isSuperClassOf(const ObjCInterfaceDecl *I) const {
45853efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    // If RHS is derived from LHS it is OK; else it is not OK.
45953efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    while (I != NULL) {
46053efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner      if (this == I)
46153efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner        return true;
46253efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner      I = I->getSuperClass();
46353efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    }
46453efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    return false;
46553efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner  }
46653efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner
46768a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner  ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName,
46868a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner                                       ObjCInterfaceDecl *&ClassDeclared);
46968a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner  ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName) {
47068a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner    ObjCInterfaceDecl *ClassDeclared;
47168a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner    return lookupInstanceVariable(IVarName, ClassDeclared);
47268a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner  }
47368a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner
47494a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // Lookup a method. First, we search locally. If a method isn't
47594a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // found, we search referenced protocols and class categories.
476a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCMethodDecl *lookupInstanceMethod(Selector Sel);
477a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCMethodDecl *lookupClassMethod(Selector Sel);
47860fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff
479f908a87299d278164540f90b5b6e6cab7b14fb41Steve Naroff  // Location information, modeled after the Stmt API.
48060fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff  SourceLocation getLocStart() const { return getLocation(); } // '@'interface
481f908a87299d278164540f90b5b6e6cab7b14fb41Steve Naroff  SourceLocation getLocEnd() const { return EndLoc; }
482f908a87299d278164540f90b5b6e6cab7b14fb41Steve Naroff  void setLocEnd(SourceLocation LE) { EndLoc = LE; };
48360fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff
484d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff  SourceLocation getClassLoc() const { return ClassLoc; }
485d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff  void setSuperClassLoc(SourceLocation Loc) { SuperClassLoc = Loc; }
486d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff  SourceLocation getSuperClassLoc() const { return SuperClassLoc; }
487e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
4884b6df3fa953267c5d755628c8afd818bb571e579Fariborz Jahanian  /// ImplicitInterfaceDecl - check that this is an implicitely declared
489a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  /// ObjCInterfaceDecl node. This is for legacy objective-c @implementation
4904b6df3fa953267c5d755628c8afd818bb571e579Fariborz Jahanian  /// declaration without an @interface declaration.
4913a3ca1b35a7121aea0bf465a192dce748465e10fFariborz Jahanian  bool ImplicitInterfaceDecl() const { return InternalInterface; }
4924b6df3fa953267c5d755628c8afd818bb571e579Fariborz Jahanian
493a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const Decl *D) { return D->getKind() == ObjCInterface; }
494a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCInterfaceDecl *D) { return true; }
49542220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  static DeclContext *castToDeclContext(const ObjCInterfaceDecl *D) {
49642220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis    return static_cast<DeclContext *>(const_cast<ObjCInterfaceDecl*>(D));
49742220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  }
49842220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  static ObjCInterfaceDecl *castFromDeclContext(const DeclContext *DC) {
49942220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis    return static_cast<ObjCInterfaceDecl *>(const_cast<DeclContext*>(DC));
50042220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  }
501980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
502980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
503a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCIvarDecl - Represents an ObjC instance variable. In general, ObjC
5040c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// instance variables are identical to C. The only exception is Objective-C
5050c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// supports C++ style access control. For example:
5060c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
5070c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @interface IvarExample : NSObject
5080c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   {
509f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek///     id defaultToProtected;
5100c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @public:
5110c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     id canBePublic; // same as C++.
5120c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @protected:
5130c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     id canBeProtected; // same as C++.
5140c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @package:
5150c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     id canBePackage; // framework visibility (not available in C++).
5160c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   }
5170c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
518a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCIvarDecl : public FieldDecl {
5190e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattnerpublic:
520980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  enum AccessControl {
521980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff    None, Private, Protected, Public, Package
522980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  };
523f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek
524b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenekprivate:
525b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenek  ObjCIvarDecl(SourceLocation L, IdentifierInfo *Id, QualType T,
526b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenek               AccessControl ac, Expr *BW)
52744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor    : FieldDecl(ObjCIvar, 0, L, Id, T, BW, /*Mutable=*/false, 0),
52844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor      DeclAccess(ac) {}
529b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenek
530b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenekpublic:
531b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenek  static ObjCIvarDecl *Create(ASTContext &C, SourceLocation L,
532b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenek                              IdentifierInfo *Id, QualType T,
533b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenek                              AccessControl ac, Expr *BW = NULL);
534b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenek
535980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  void setAccessControl(AccessControl ac) { DeclAccess = ac; }
536f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek
537ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  AccessControl getAccessControl() const { return AccessControl(DeclAccess); }
538f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek
539f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek  AccessControl getCanonicalAccessControl() const {
540f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek    return DeclAccess == None ? Protected : AccessControl(DeclAccess);
541f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek  }
542980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
543980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  // Implement isa/cast/dyncast/etc.
544a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const Decl *D) { return D->getKind() == ObjCIvar; }
545a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCIvarDecl *D) { return true; }
546980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffprivate:
547ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  // NOTE: VC++ treats enums as signed, avoid using the AccessControl enum
548ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  unsigned DeclAccess : 3;
549980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
550980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
55101e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek
55201e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek/// ObjCAtDefsFieldDecl - Represents a field declaration created by an
55301e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek///  @defs(...).
55401e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenekclass ObjCAtDefsFieldDecl : public FieldDecl {
55501e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenekprivate:
55644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor  ObjCAtDefsFieldDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
55701e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek                      QualType T, Expr *BW)
55844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor    : FieldDecl(ObjCAtDefsField, DC, L, Id, T, BW, /*Mutable=*/false, 0) {}
55901e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek
56001e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenekpublic:
56144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor  static ObjCAtDefsFieldDecl *Create(ASTContext &C, DeclContext *DC,
56244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor                                     SourceLocation L,
56301e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek                                     IdentifierInfo *Id, QualType T,
56401e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek                                     Expr *BW);
56501e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek
56601e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek  virtual void Destroy(ASTContext& C);
56701e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek
56801e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek  // Implement isa/cast/dyncast/etc.
56901e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek  static bool classof(const Decl *D) { return D->getKind() == ObjCAtDefsField; }
57001e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek  static bool classof(const ObjCAtDefsFieldDecl *D) { return true; }
57101e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek};
572980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
573a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCProtocolDecl - Represents a protocol declaration. ObjC protocols
5740c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// declare a pure abstract type (i.e no instance variables are permitted).
5750c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// Protocols orginally drew inspiration from C++ pure virtual functions (a C++
5760c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// feature with nice semantics and lousy syntax:-). Here is an example:
5770c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
578eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// @protocol NSDraggingInfo <refproto1, refproto2>
5790c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (NSWindow *)draggingDestinationWindow;
5800c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (NSImage *)draggedImage;
5810c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end
5820c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
583eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// This says that NSDraggingInfo requires two methods and requires everything
584eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// that the two "referenced protocols" 'refproto1' and 'refproto2' require as
585eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// well.
586eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner///
5870c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @interface ImplementsNSDraggingInfo : NSObject <NSDraggingInfo>
5880c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end
5890c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
590a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjC protocols inspired Java interfaces. Unlike Java, ObjC classes and
5910c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// protocols are in distinct namespaces. For example, Cocoa defines both
5920c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// an NSObject protocol and class (which isn't allowed in Java). As a result,
5930c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// protocols are referenced using angle brackets as follows:
5940c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
5950c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// id <NSDraggingInfo> anyObjectThatImplementsNSDraggingInfo;
5960c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
597e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroffclass ObjCProtocolDecl : public ObjCContainerDecl {
598780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  /// Referenced protocols
599780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  ObjCList<ObjCProtocolDecl> ReferencedProtocols;
600980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
6013dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian  /// protocol properties
6023dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian  ObjCPropertyDecl **PropertyDecl;  // Null if no property
6033dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian  unsigned NumPropertyDecl;  // 0 if none
6043dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian
605980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  bool isForwardProtoDecl; // declared with @protocol.
606423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff
607423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff  SourceLocation EndLoc; // marks the '>' or identifier.
608423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff  SourceLocation AtEndLoc; // marks the end of the entire interface.
609cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattner
610d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  ObjCProtocolDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id)
611d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor    : ObjCContainerDecl(ObjCProtocol, DC, L, Id),
6123dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian      PropertyDecl(0), NumPropertyDecl(0),
613c858105d41602a2dadb2efbc1af80a7b791ebac3Chris Lattner      isForwardProtoDecl(true) {
614cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattner  }
6151c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek
6161c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek  virtual ~ObjCProtocolDecl();
6171c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek
618cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattnerpublic:
6191c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek
6201c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek  /// Destroy - Call destructors and release memory.
6211c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek  virtual void Destroy(ASTContext& C);
6221c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek
623d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCProtocolDecl *Create(ASTContext &C, DeclContext *DC,
624d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor                                  SourceLocation L, IdentifierInfo *Id);
625cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattner
626780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  const ObjCList<ObjCProtocolDecl> &getReferencedProtocols() const {
627780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner    return ReferencedProtocols;
628980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  }
629dbc933701d20918add13b6a3c9d47ff8c75419cfDaniel Dunbar  typedef ObjCList<ObjCProtocolDecl>::iterator protocol_iterator;
630780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();}
631780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  protocol_iterator protocol_end() const { return ReferencedProtocols.end(); }
632780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner
633780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  /// addReferencedProtocols - Set the list of protocols that this interface
634780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  /// implements.
635780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  void addReferencedProtocols(ObjCProtocolDecl *const*List, unsigned NumRPs) {
636780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner    ReferencedProtocols.set(List, NumRPs);
637aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian  }
638aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian
63994a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // Lookup a method. First, we search locally. If a method isn't
64094a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // found, we search referenced protocols and class categories.
641a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCMethodDecl *lookupInstanceMethod(Selector Sel);
642a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCMethodDecl *lookupClassMethod(Selector Sel);
6437dd82836dca87cf828ce994f161b53a34f6cdb7eFariborz Jahanian
644768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff  bool isForwardDecl() const { return isForwardProtoDecl; }
645768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff  void setForwardDecl(bool val) { isForwardProtoDecl = val; }
646980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
647423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff  // Location information, modeled after the Stmt API.
648423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff  SourceLocation getLocStart() const { return getLocation(); } // '@'protocol
649423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff  SourceLocation getLocEnd() const { return EndLoc; }
650423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff  void setLocEnd(SourceLocation LE) { EndLoc = LE; };
651423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff
652a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const Decl *D) { return D->getKind() == ObjCProtocol; }
653a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCProtocolDecl *D) { return true; }
654b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff  static DeclContext *castToDeclContext(const ObjCProtocolDecl *D) {
655b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff    return static_cast<DeclContext *>(const_cast<ObjCProtocolDecl*>(D));
656b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff  }
657b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff  static ObjCProtocolDecl *castFromDeclContext(const DeclContext *DC) {
658b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff    return static_cast<ObjCProtocolDecl *>(const_cast<DeclContext*>(DC));
659b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff  }
660980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
661980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
662a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCClassDecl - Specifies a list of forward class declarations. For example:
66306ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff///
66406ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff/// @class NSCursor, NSImage, NSPasteboard, NSWindow;
6650c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
666d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor/// FIXME: This could be a transparent DeclContext (!)
667d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregorclass ObjCClassDecl : public ScopedDecl {
668a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl **ForwardDecls;
6697e620729fcb5a0042107f999dcf524f7357ce819Chris Lattner  unsigned NumForwardDecls;
67061f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner
671d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  ObjCClassDecl(DeclContext *DC, SourceLocation L,
672d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor                ObjCInterfaceDecl **Elts, unsigned nElts)
673d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor    : ScopedDecl(ObjCClass, DC, L, DeclarationName()) {
67406ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff    if (nElts) {
675a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      ForwardDecls = new ObjCInterfaceDecl*[nElts];
676a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      memcpy(ForwardDecls, Elts, nElts*sizeof(ObjCInterfaceDecl*));
6777e620729fcb5a0042107f999dcf524f7357ce819Chris Lattner    } else {
6787e620729fcb5a0042107f999dcf524f7357ce819Chris Lattner      ForwardDecls = 0;
67906ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff    }
68006ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff    NumForwardDecls = nElts;
68106ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff  }
682400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek
683400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek  virtual ~ObjCClassDecl();
684400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek
68561f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattnerpublic:
686400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek
687400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek  /// Destroy - Call destructors and release memory.
688400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek  virtual void Destroy(ASTContext& C);
689400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek
690d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCClassDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L,
69161f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner                               ObjCInterfaceDecl **Elts, unsigned nElts);
69261f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner
693a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void setInterfaceDecl(unsigned idx, ObjCInterfaceDecl *OID) {
6947e620729fcb5a0042107f999dcf524f7357ce819Chris Lattner    assert(idx < NumForwardDecls && "index out of range");
69506ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff    ForwardDecls[idx] = OID;
69606ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff  }
697a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl** getForwardDecls() const { return ForwardDecls; }
6987e15891fc89256fc013bd1003676ad3197b85c25Steve Naroff  int getNumForwardDecls() const { return NumForwardDecls; }
6997e15891fc89256fc013bd1003676ad3197b85c25Steve Naroff
700400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek  typedef ObjCInterfaceDecl * const * iterator;
701400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek  iterator begin() const { return ForwardDecls; }
702400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek  iterator end() const { return ForwardDecls+NumForwardDecls; }
703400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek
704a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const Decl *D) { return D->getKind() == ObjCClass; }
705a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCClassDecl *D) { return true; }
70606ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff};
70706ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff
708a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCForwardProtocolDecl - Specifies a list of forward protocol declarations.
70906ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff/// For example:
71006ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff///
7110c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @protocol NSTextInput, NSChangeSpelling, NSDraggingInfo;
7120c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
713d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor/// FIXME: Should this be a transparent DeclContext?
714d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregorclass ObjCForwardProtocolDecl : public ScopedDecl {
715a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCProtocolDecl **ReferencedProtocols;
7169fa5e65d08aee1875c5f2a841c8b0b4069bd00e5Chris Lattner  unsigned NumReferencedProtocols;
71761f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner
718d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  ObjCForwardProtocolDecl(DeclContext *DC, SourceLocation L,
719a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek                          ObjCProtocolDecl **Elts, unsigned nElts)
720d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor    : ScopedDecl(ObjCForwardProtocol, DC, L, DeclarationName()) {
721b97de3eddf0a0f7ff97204e7def6b7e0aa8953f2Chris Lattner    NumReferencedProtocols = nElts;
72206ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff    if (nElts) {
723a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      ReferencedProtocols = new ObjCProtocolDecl*[nElts];
724a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      memcpy(ReferencedProtocols, Elts, nElts*sizeof(ObjCProtocolDecl*));
7259fa5e65d08aee1875c5f2a841c8b0b4069bd00e5Chris Lattner    } else {
7269fa5e65d08aee1875c5f2a841c8b0b4069bd00e5Chris Lattner      ReferencedProtocols = 0;
727980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff    }
72806ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff  }
72905ac3ef08f9d06e0a4439073c9edabf7f912f946Ted Kremenek
73005ac3ef08f9d06e0a4439073c9edabf7f912f946Ted Kremenek  virtual ~ObjCForwardProtocolDecl();
73105ac3ef08f9d06e0a4439073c9edabf7f912f946Ted Kremenek
73261f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattnerpublic:
733d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCForwardProtocolDecl *Create(ASTContext &C, DeclContext *DC,
734d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor                                         SourceLocation L,
73561f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner                                         ObjCProtocolDecl **Elts, unsigned Num);
73661f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner
73761f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner
738a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void setForwardProtocolDecl(unsigned idx, ObjCProtocolDecl *OID) {
7399fa5e65d08aee1875c5f2a841c8b0b4069bd00e5Chris Lattner    assert(idx < NumReferencedProtocols && "index out of range");
7407ed9e0f97f4645edc5d4670385b985ea4c617ce7Fariborz Jahanian    ReferencedProtocols[idx] = OID;
74106ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff  }
7429fa5e65d08aee1875c5f2a841c8b0b4069bd00e5Chris Lattner
7439fa5e65d08aee1875c5f2a841c8b0b4069bd00e5Chris Lattner  unsigned getNumForwardDecls() const { return NumReferencedProtocols; }
7449fa5e65d08aee1875c5f2a841c8b0b4069bd00e5Chris Lattner
745a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCProtocolDecl *getForwardProtocolDecl(unsigned idx) {
7469fa5e65d08aee1875c5f2a841c8b0b4069bd00e5Chris Lattner    assert(idx < NumReferencedProtocols && "index out of range");
7479fa5e65d08aee1875c5f2a841c8b0b4069bd00e5Chris Lattner    return ReferencedProtocols[idx];
7489fa5e65d08aee1875c5f2a841c8b0b4069bd00e5Chris Lattner  }
749a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  const ObjCProtocolDecl *getForwardProtocolDecl(unsigned idx) const {
7509fa5e65d08aee1875c5f2a841c8b0b4069bd00e5Chris Lattner    assert(idx < NumReferencedProtocols && "index out of range");
7519fa5e65d08aee1875c5f2a841c8b0b4069bd00e5Chris Lattner    return ReferencedProtocols[idx];
7529fa5e65d08aee1875c5f2a841c8b0b4069bd00e5Chris Lattner  }
7539fa5e65d08aee1875c5f2a841c8b0b4069bd00e5Chris Lattner
75405ac3ef08f9d06e0a4439073c9edabf7f912f946Ted Kremenek  typedef ObjCProtocolDecl * const * iterator;
75505ac3ef08f9d06e0a4439073c9edabf7f912f946Ted Kremenek  iterator begin() const { return ReferencedProtocols; }
75605ac3ef08f9d06e0a4439073c9edabf7f912f946Ted Kremenek  iterator end() const { return ReferencedProtocols+NumReferencedProtocols; }
75705ac3ef08f9d06e0a4439073c9edabf7f912f946Ted Kremenek
75806ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff  static bool classof(const Decl *D) {
759a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek    return D->getKind() == ObjCForwardProtocol;
76006ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff  }
761a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCForwardProtocolDecl *D) { return true; }
762980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
763980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
764a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCCategoryDecl - Represents a category declaration. A category allows
7650c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// you to add methods to an existing class (without subclassing or modifying
7660c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// the original class interface or implementation:-). Categories don't allow
7670c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// you to add instance data. The following example adds "myMethod" to all
7680c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// NSView's within a process:
7690c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
7700c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @interface NSView (MyViewMethods)
7710c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - myMethod;
7720c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end
7730c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
7740c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// Cateogries also allow you to split the implementation of a class across
7750c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// several files (a feature more naturally supported in C++).
7760c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
7770c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// Categories were originally inspired by dynamic languages such as Common
77868c82cf61228102aba1194efef222fa1478af2a8Chris Lattner/// Lisp and Smalltalk.  More traditional class-based languages (C++, Java)
7790c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// don't support this level of dynamism, which is both powerful and dangerous.
7800c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
781e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroffclass ObjCCategoryDecl : public ObjCContainerDecl {
782980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  /// Interface belonging to this category
783a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *ClassInterface;
784980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
78568c82cf61228102aba1194efef222fa1478af2a8Chris Lattner  /// referenced protocols in this category.
786780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  ObjCList<ObjCProtocolDecl> ReferencedProtocols;
787980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
788980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  /// Next category belonging to this class
789a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCCategoryDecl *NextClassCategory;
790ca3adf7e8cac8c9fbaf592b1e5c2be6f082de7baFariborz Jahanian
7917e7e3872b584bc5e7de7a34c8b9c092032303b72Fariborz Jahanian  /// category properties
7927e7e3872b584bc5e7de7a34c8b9c092032303b72Fariborz Jahanian  ObjCPropertyDecl **PropertyDecl;  // Null if no property
7937e7e3872b584bc5e7de7a34c8b9c092032303b72Fariborz Jahanian  unsigned NumPropertyDecl;  // 0 if none
7947e7e3872b584bc5e7de7a34c8b9c092032303b72Fariborz Jahanian
795423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff  SourceLocation EndLoc; // marks the '>' or identifier.
79661f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner
797d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  ObjCCategoryDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id)
798d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor    : ObjCContainerDecl(ObjCCategory, DC, L, Id),
799780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner      ClassInterface(0),
8007e7e3872b584bc5e7de7a34c8b9c092032303b72Fariborz Jahanian      NextClassCategory(0), PropertyDecl(0),  NumPropertyDecl(0) {
801a906135721c350435319347d2672bbb3bf494f91Chris Lattner  }
80261f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattnerpublic:
80361f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner
804d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCCategoryDecl *Create(ASTContext &C, DeclContext *DC,
8050ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner                                  SourceLocation L, IdentifierInfo *Id);
80661f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner
807e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
808e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; }
809a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void setClassInterface(ObjCInterfaceDecl *IDecl) { ClassInterface = IDecl; }
810980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
811f7b2c98c16dfb2261ea57d40a1d5bc4738e73175Chris Lattner  /// addReferencedProtocols - Set the list of protocols that this interface
812f7b2c98c16dfb2261ea57d40a1d5bc4738e73175Chris Lattner  /// implements.
813780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  void addReferencedProtocols(ObjCProtocolDecl *const*List, unsigned NumRPs) {
814780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner    ReferencedProtocols.set(List, NumRPs);
815780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  }
816980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
817780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  const ObjCList<ObjCProtocolDecl> &getReferencedProtocols() const {
818780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner    return ReferencedProtocols;
8198f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian  }
820780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner
821780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  typedef ObjCProtocolDecl * const * protocol_iterator;
822780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();}
823780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  protocol_iterator protocol_end() const { return ReferencedProtocols.end(); }
824780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner
825a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCCategoryDecl *getNextClassCategory() const { return NextClassCategory; }
826980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  void insertNextClassCategory() {
8273d58138992b9bc7b34aaa680f3ddf3971292eb7dSteve Naroff    NextClassCategory = ClassInterface->getCategoryList();
8283d58138992b9bc7b34aaa680f3ddf3971292eb7dSteve Naroff    ClassInterface->setCategoryList(this);
829980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  }
830423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff  // Location information, modeled after the Stmt API.
831423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff  SourceLocation getLocStart() const { return getLocation(); } // '@'interface
832423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff  SourceLocation getLocEnd() const { return EndLoc; }
833423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff  void setLocEnd(SourceLocation LE) { EndLoc = LE; };
834423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff
835a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const Decl *D) { return D->getKind() == ObjCCategory; }
836a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCCategoryDecl *D) { return true; }
837b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff  static DeclContext *castToDeclContext(const ObjCCategoryDecl *D) {
838b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff    return static_cast<DeclContext *>(const_cast<ObjCCategoryDecl*>(D));
839b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff  }
840b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff  static ObjCCategoryDecl *castFromDeclContext(const DeclContext *DC) {
841b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff    return static_cast<ObjCCategoryDecl *>(const_cast<DeclContext*>(DC));
842b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff  }
843980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
8440c6b6243d3efd958c17943130e2a773653511edcSteve Naroff
845a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCCategoryImplDecl - An object of this class encapsulates a category
846559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// @implementation declaration. If a category class has declaration of a
847559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// property, its implementation must be specified in the category's
848559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// @implementation declaration. Example:
849559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// @interface I @end
850559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// @interface I(CATEGORY)
851559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian///    @property int p1, d1;
852559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// @end
853559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// @implementation I(CATEGORY)
854559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian///  @dynamic p1,d1;
855559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// @end
856559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian///
857d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregorclass ObjCCategoryImplDecl : public ScopedDecl, public DeclContext {
8588f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian  /// Class interface for this category implementation
859a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *ClassInterface;
8608f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian
861e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff  /// implemented instance methods
862a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  llvm::SmallVector<ObjCMethodDecl*, 32> InstanceMethods;
8638f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian
864e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff  /// implemented class methods
865a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  llvm::SmallVector<ObjCMethodDecl*, 32> ClassMethods;
866f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian
867559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  /// Property Implementations in this category
868f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian  llvm::SmallVector<ObjCPropertyImplDecl*, 8> PropertyImplementations;
869e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff
870e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff  SourceLocation EndLoc;
87175c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner
872d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  ObjCCategoryImplDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
873a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek                       ObjCInterfaceDecl *classInterface)
874d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor    : ScopedDecl(ObjCCategoryImpl, DC, L, Id), DeclContext(ObjCCategoryImpl),
8750701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff      ClassInterface(classInterface) {}
87675c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattnerpublic:
877d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCCategoryImplDecl *Create(ASTContext &C, DeclContext *DC,
8780ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner                                      SourceLocation L, IdentifierInfo *Id,
87975c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner                                      ObjCInterfaceDecl *classInterface);
8808f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian
881e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; }
882e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
8838f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian
884ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner  unsigned getNumInstanceMethods() const { return InstanceMethods.size(); }
885ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner  unsigned getNumClassMethods() const { return ClassMethods.size(); }
886e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff
887a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void addInstanceMethod(ObjCMethodDecl *method) {
888e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff    InstanceMethods.push_back(method);
889e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff  }
890a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void addClassMethod(ObjCMethodDecl *method) {
891e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff    ClassMethods.push_back(method);
892f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian  }
89394a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // Get the instance method definition for this implementation.
8943216dcdebb8ae0f2993ac5f5249caa217444bacfDaniel Dunbar  ObjCMethodDecl *getInstanceMethod(Selector Sel) const;
89594a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff
89694a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // Get the class method definition for this implementation.
8973216dcdebb8ae0f2993ac5f5249caa217444bacfDaniel Dunbar  ObjCMethodDecl *getClassMethod(Selector Sel) const;
898f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian
899f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian  void addPropertyImplementation(ObjCPropertyImplDecl *property) {
900f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian    PropertyImplementations.push_back(property);
901f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian  }
902e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff
903ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian  ObjCPropertyImplDecl *FindPropertyImplDecl(IdentifierInfo *propertyId) const;
904ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian  ObjCPropertyImplDecl *FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const;
905ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian
906f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian  unsigned getNumPropertyImplementations() const
907f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian  { return PropertyImplementations.size(); }
908f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian
909559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian
910559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  typedef llvm::SmallVector<ObjCPropertyImplDecl*, 8>::const_iterator
911559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian    propimpl_iterator;
912559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  propimpl_iterator propimpl_begin() const {
913559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian    return PropertyImplementations.begin();
914559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  }
915559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  propimpl_iterator propimpl_end() const {
916559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian    return PropertyImplementations.end();
917559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  }
918559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian
919a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  typedef llvm::SmallVector<ObjCMethodDecl*, 32>::const_iterator
920ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner    instmeth_iterator;
921ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner  instmeth_iterator instmeth_begin() const { return InstanceMethods.begin(); }
922ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner  instmeth_iterator instmeth_end() const { return InstanceMethods.end(); }
923ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner
924a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  typedef llvm::SmallVector<ObjCMethodDecl*, 32>::const_iterator
925ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner    classmeth_iterator;
926ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner  classmeth_iterator classmeth_begin() const { return ClassMethods.begin(); }
927ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner  classmeth_iterator classmeth_end() const { return ClassMethods.end(); }
928ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner
929ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner
930e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff  // Location information, modeled after the Stmt API.
931e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff  SourceLocation getLocStart() const { return getLocation(); }
932e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff  SourceLocation getLocEnd() const { return EndLoc; }
933e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff  void setLocEnd(SourceLocation LE) { EndLoc = LE; };
934e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff
935a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const Decl *D) { return D->getKind() == ObjCCategoryImpl;}
936a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCCategoryImplDecl *D) { return true; }
937b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff  static DeclContext *castToDeclContext(const ObjCCategoryImplDecl *D) {
938b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff    return static_cast<DeclContext *>(const_cast<ObjCCategoryImplDecl*>(D));
939b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff  }
940b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff  static ObjCCategoryImplDecl *castFromDeclContext(const DeclContext *DC) {
941b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff    return static_cast<ObjCCategoryImplDecl *>(const_cast<DeclContext*>(DC));
942b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff  }
9438f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian};
9448f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian
945a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCImplementationDecl - Represents a class definition - this is where
9460c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// method definitions are specified. For example:
9470c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
9480c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @implementation MyClass
9490c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (void)myMethod { /* do something */ }
9500c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end
9510c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
9520c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// Typically, instance variables are specified in the class interface,
9530c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// *not* in the implemenentation. Nevertheless (for legacy reasons), we
9540c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// allow instance variables to be specified in the implementation. When
9550c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// specified, they need to be *identical* to the interface. Now that we
9560c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// have support for non-fragile ivars in ObjC 2.0, we can consider removing
9570c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// the legacy semantics and allow developers to move private ivar declarations
9580c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// from the class interface to the class implementation (but I digress:-)
9590c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
960d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregorclass ObjCImplementationDecl : public ScopedDecl, public DeclContext {
961dae1a1a2aa4f245b1958dc8db6089f24c575ef13Fariborz Jahanian  /// Class interface for this implementation
962a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *ClassInterface;
963f4d331dd922f92478ebf30e808c0ca97ce49418bFariborz Jahanian
964980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  /// Implementation Class's super class.
965a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *SuperClass;
966980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
967980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  /// Optional Ivars/NumIvars - This is a new[]'d array of pointers to Decls.
968a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCIvarDecl **Ivars;   // Null if not specified
969f3a7af901231535191d14cb524d58f22907ac4d2Chris Lattner  unsigned NumIvars;      // 0 if none.
9700416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff
971980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  /// implemented instance methods
972a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  llvm::SmallVector<ObjCMethodDecl*, 32> InstanceMethods;
9730416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff
974980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  /// implemented class methods
975a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  llvm::SmallVector<ObjCMethodDecl*, 32> ClassMethods;
9760416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff
977f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian  /// Propertys' being implemented
978f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian  llvm::SmallVector<ObjCPropertyImplDecl*, 8> PropertyImplementations;
979f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian
9800416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff  SourceLocation EndLoc;
98175c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner
982d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  ObjCImplementationDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
983a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek                         ObjCInterfaceDecl *classInterface,
984a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek                         ObjCInterfaceDecl *superDecl)
985d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor    : ScopedDecl(ObjCImplementation, DC, L, Id), DeclContext(ObjCImplementation),
9860416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff      ClassInterface(classInterface), SuperClass(superDecl),
987f3a7af901231535191d14cb524d58f22907ac4d2Chris Lattner      Ivars(0), NumIvars(0) {}
98875c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattnerpublic:
989d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCImplementationDecl *Create(ASTContext &C, DeclContext *DC,
9900ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner                                        SourceLocation L, IdentifierInfo *Id,
99175c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner                                        ObjCInterfaceDecl *classInterface,
99275c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner                                        ObjCInterfaceDecl *superDecl);
99375c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner
994980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
995a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void ObjCAddInstanceVariablesToClassImpl(ObjCIvarDecl **ivars,
996980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff                                           unsigned numIvars);
997980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
998a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void addInstanceMethod(ObjCMethodDecl *method) {
9990416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff    InstanceMethods.push_back(method);
10000416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff  }
1001a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void addClassMethod(ObjCMethodDecl *method) {
10020416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff    ClassMethods.push_back(method);
10030416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff  }
1004f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian
1005f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian  void addPropertyImplementation(ObjCPropertyImplDecl *property) {
1006f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian    PropertyImplementations.push_back(property);
1007f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian  }
1008ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian
1009ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian  ObjCPropertyImplDecl *FindPropertyImplDecl(IdentifierInfo *propertyId) const;
1010ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian  ObjCPropertyImplDecl *FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const;
1011ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian
1012559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  typedef llvm::SmallVector<ObjCPropertyImplDecl*, 8>::const_iterator
1013559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  propimpl_iterator;
1014559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  propimpl_iterator propimpl_begin() const {
1015559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian    return PropertyImplementations.begin();
1016559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  }
1017559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  propimpl_iterator propimpl_end() const {
1018559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian    return PropertyImplementations.end();
1019559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  }
1020f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian
10210416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff  // Location information, modeled after the Stmt API.
10220416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff  SourceLocation getLocStart() const { return getLocation(); }
10230416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff  SourceLocation getLocEnd() const { return EndLoc; }
10240416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff  void setLocEnd(SourceLocation LE) { EndLoc = LE; };
10250416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff
1026e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; }
1027e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
1028e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  const ObjCInterfaceDecl *getSuperClass() const { return SuperClass; }
1029e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  ObjCInterfaceDecl *getSuperClass() { return SuperClass; }
1030980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
1031f3a7af901231535191d14cb524d58f22907ac4d2Chris Lattner  void setSuperClass(ObjCInterfaceDecl * superCls) { SuperClass = superCls; }
1032980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
1033b5feb35360526da42ad7e3fa7ef3d44a5992b83cChris Lattner  unsigned getNumInstanceMethods() const { return InstanceMethods.size(); }
103462db2f4214c1589082960f12c9cb8924fe0cf8c5Chris Lattner  unsigned getNumClassMethods() const { return ClassMethods.size(); }
1035f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian
1036f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian  unsigned getNumPropertyImplementations() const
1037f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian    { return PropertyImplementations.size(); }
1038c43d868355374d48296ad3be2c9c536698a5e9a8Steve Naroff
1039a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  typedef llvm::SmallVector<ObjCMethodDecl*, 32>::const_iterator
10400157c5144513438bb74aebf50d18f95df4104acbChris Lattner       instmeth_iterator;
10410157c5144513438bb74aebf50d18f95df4104acbChris Lattner  instmeth_iterator instmeth_begin() const { return InstanceMethods.begin(); }
10420157c5144513438bb74aebf50d18f95df4104acbChris Lattner  instmeth_iterator instmeth_end() const { return InstanceMethods.end(); }
10430157c5144513438bb74aebf50d18f95df4104acbChris Lattner
1044a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  typedef llvm::SmallVector<ObjCMethodDecl*, 32>::const_iterator
10450157c5144513438bb74aebf50d18f95df4104acbChris Lattner    classmeth_iterator;
10460157c5144513438bb74aebf50d18f95df4104acbChris Lattner  classmeth_iterator classmeth_begin() const { return ClassMethods.begin(); }
10470157c5144513438bb74aebf50d18f95df4104acbChris Lattner  classmeth_iterator classmeth_end() const { return ClassMethods.end(); }
10480157c5144513438bb74aebf50d18f95df4104acbChris Lattner
104994a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // Get the instance method definition for this implementation.
10503216dcdebb8ae0f2993ac5f5249caa217444bacfDaniel Dunbar  ObjCMethodDecl *getInstanceMethod(Selector Sel) const;
10510157c5144513438bb74aebf50d18f95df4104acbChris Lattner
105294a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // Get the class method definition for this implementation.
10533216dcdebb8ae0f2993ac5f5249caa217444bacfDaniel Dunbar  ObjCMethodDecl *getClassMethod(Selector Sel) const;
10540157c5144513438bb74aebf50d18f95df4104acbChris Lattner
1055a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  typedef ObjCIvarDecl * const *ivar_iterator;
10560157c5144513438bb74aebf50d18f95df4104acbChris Lattner  ivar_iterator ivar_begin() const { return Ivars; }
1057f3a7af901231535191d14cb524d58f22907ac4d2Chris Lattner  ivar_iterator ivar_end() const { return Ivars+NumIvars; }
1058f3a7af901231535191d14cb524d58f22907ac4d2Chris Lattner  unsigned ivar_size() const { return NumIvars; }
1059f3a7af901231535191d14cb524d58f22907ac4d2Chris Lattner  bool ivar_empty() const { return NumIvars == 0; }
10600157c5144513438bb74aebf50d18f95df4104acbChris Lattner
1061980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  static bool classof(const Decl *D) {
1062a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek    return D->getKind() == ObjCImplementation;
1063980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  }
1064a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCImplementationDecl *D) { return true; }
1065b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff  static DeclContext *castToDeclContext(const ObjCImplementationDecl *D) {
1066b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff    return static_cast<DeclContext *>(const_cast<ObjCImplementationDecl*>(D));
1067b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff  }
1068b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff  static ObjCImplementationDecl *castFromDeclContext(const DeclContext *DC) {
1069b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff    return static_cast<ObjCImplementationDecl *>(const_cast<DeclContext*>(DC));
1070b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff  }
1071980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
1072243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian
1073a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCCompatibleAliasDecl - Represents alias of a class. This alias is
1074243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian/// declared as @compatibility_alias alias class.
1075d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregorclass ObjCCompatibleAliasDecl : public ScopedDecl {
1076243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian  /// Class that this is an alias of.
1077a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *AliasedClass;
1078243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian
1079d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  ObjCCompatibleAliasDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
1080e8043c39176e7f253fbd92982b077eca6bf2fd59Steve Naroff                          ObjCInterfaceDecl* aliasedClass)
1081d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor    : ScopedDecl(ObjCCompatibleAlias, DC, L, Id), AliasedClass(aliasedClass) {}
1082f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattnerpublic:
1083d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCCompatibleAliasDecl *Create(ASTContext &C, DeclContext *DC,
10840ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner                                         SourceLocation L, IdentifierInfo *Id,
1085f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner                                         ObjCInterfaceDecl* aliasedClass);
1086f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner
1087f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner  const ObjCInterfaceDecl *getClassInterface() const { return AliasedClass; }
1088f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner  ObjCInterfaceDecl *getClassInterface() { return AliasedClass; }
1089980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
1090243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian  static bool classof(const Decl *D) {
10918a934233d1582b5bde9d270bc0705aa81e471a79Chris Lattner    return D->getKind() == ObjCCompatibleAlias;
1092243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian  }
1093a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCCompatibleAliasDecl *D) { return true; }
1094243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian
1095243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian};
10961de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian
10971de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian/// ObjCPropertyDecl - Represents one property declaration in an interface.
10981de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian/// For example:
10991de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian/// @property (assign, readwrite) int MyProperty;
11001de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian///
1101d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregorclass ObjCPropertyDecl : public ScopedDecl {
110282a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanianpublic:
1103a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner  enum PropertyAttributeKind {
1104a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_noattr    = 0x00,
1105a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_readonly  = 0x01,
1106a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_getter    = 0x02,
1107a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_assign    = 0x04,
1108a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_readwrite = 0x08,
1109a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_retain    = 0x10,
1110a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_copy      = 0x20,
1111a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_nonatomic = 0x40,
1112a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_setter    = 0x80
1113a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner  };
1114af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
1115af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  enum SetterKind { Assign, Retain, Copy };
111646b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  enum PropertyControl { None, Required, Optional };
111782a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanianprivate:
1118dae1a1a2aa4f245b1958dc8db6089f24c575ef13Fariborz Jahanian  QualType DeclType;
1119ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  unsigned PropertyAttributes : 8;
112082a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian
112146b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  // @required/@optional
112246b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  unsigned PropertyImplementation : 2;
112346b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian
11245251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  Selector GetterName;    // getter name of NULL if no getter
11255251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  Selector SetterName;    // setter name of NULL if no setter
112682a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian
112733de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  ObjCMethodDecl *GetterMethodDecl; // Declaration of getter instance method
112833de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  ObjCMethodDecl *SetterMethodDecl; // Declaration of setter instance method
112933de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian
1130d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  ObjCPropertyDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
1131d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor                   QualType T)
1132d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor    : ScopedDecl(ObjCProperty, DC, L, Id), DeclType(T),
113333de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian      PropertyAttributes(OBJC_PR_noattr), PropertyImplementation(None),
113433de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian      GetterName(Selector()),
113533de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian      SetterName(Selector()),
113633de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian      GetterMethodDecl(0), SetterMethodDecl(0) {}
1137f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattnerpublic:
1138d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCPropertyDecl *Create(ASTContext &C, DeclContext *DC,
1139d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor                                  SourceLocation L,
114046b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian                                  IdentifierInfo *Id, QualType T,
114146b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian                                  PropertyControl propControl = None);
1142dae1a1a2aa4f245b1958dc8db6089f24c575ef13Fariborz Jahanian  QualType getType() const { return DeclType; }
1143c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian
1144a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner  PropertyAttributeKind getPropertyAttributes() const {
1145f4af5154571e0c5eadb19df10e65464766ef6683Chris Lattner    return PropertyAttributeKind(PropertyAttributes);
1146f4af5154571e0c5eadb19df10e65464766ef6683Chris Lattner  }
1147564576b225386cbff375351597dd5e2a92872d38Fariborz Jahanian  void setPropertyAttributes(PropertyAttributeKind PRVal) {
1148a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    PropertyAttributes |= PRVal;
114982a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian  }
1150394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar
11518cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian void makeitReadWriteAttribute(void) {
11528cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian    PropertyAttributes &= ~OBJC_PR_readonly;
11538cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian    PropertyAttributes |= OBJC_PR_readwrite;
11548cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian }
11558cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian
1156af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  // Helper methods for accessing attributes.
1157af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
1158af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  /// isReadOnly - Return true iff the property has a setter.
1159394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar  bool isReadOnly() const {
1160394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar    return (PropertyAttributes & OBJC_PR_readonly);
1161394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar  }
1162af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
1163af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  /// getSetterKind - Return the method used for doing assignment in
1164af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  /// the property setter. This is only valid if the property has been
1165af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  /// defined to have a setter.
1166af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  SetterKind getSetterKind() const {
1167af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar    if (PropertyAttributes & OBJC_PR_retain)
1168af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar      return Retain;
1169af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar    if (PropertyAttributes & OBJC_PR_copy)
1170af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar      return Copy;
1171af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar    return Assign;
1172af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  }
1173af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
11745251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  Selector getGetterName() const { return GetterName; }
11755251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  void setGetterName(Selector Sel) { GetterName = Sel; }
117682a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian
11775251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  Selector getSetterName() const { return SetterName; }
11785251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  void setSetterName(Selector Sel) { SetterName = Sel; }
117982a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian
118033de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  ObjCMethodDecl *getGetterMethodDecl() const { return GetterMethodDecl; }
118133de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  void setGetterMethodDecl(ObjCMethodDecl *gDecl) { GetterMethodDecl = gDecl; }
118233de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian
118333de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  ObjCMethodDecl *getSetterMethodDecl() const { return SetterMethodDecl; }
118433de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  void setSetterMethodDecl(ObjCMethodDecl *gDecl) { SetterMethodDecl = gDecl; }
118533de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian
118646b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  // Related to @optional/@required declared in @protocol
118746b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  void setPropertyImplementation(PropertyControl pc) {
118846b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian    PropertyImplementation = pc;
118946b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  }
119046b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  PropertyControl getPropertyImplementation() const {
119146b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian    return PropertyControl(PropertyImplementation);
119246b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  }
119346b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian
119482a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian  static bool classof(const Decl *D) {
1195670aa9d7639278f507930e95dc89c12032ab7c7eSam Bishop    return D->getKind() == ObjCProperty;
119682a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian  }
1197a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCPropertyDecl *D) { return true; }
119882a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian};
1199980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
120061d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian/// ObjCPropertyImplDecl - Represents implementation declaration of a property
120161d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian/// in a class or category implementation block. For example:
120261d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian/// @synthesize prop1 = ivar1;
120361d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian///
1204d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregorclass ObjCPropertyImplDecl : public ScopedDecl {
120561d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanianpublic:
12069f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar  enum Kind {
12079f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar    Synthesize,
12089f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar    Dynamic
120961d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  };
121061d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanianprivate:
1211559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  SourceLocation AtLoc;   // location of @synthesize or @dynamic
121261d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  /// Property declaration being implemented
121361d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  ObjCPropertyDecl *PropertyDecl;
1214be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek
121561d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  /// Null for @dynamic. Required for @synthesize.
121661d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  ObjCIvarDecl *PropertyIvarDecl;
1217be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek
1218d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  ObjCPropertyImplDecl(DeclContext *DC, SourceLocation atLoc, SourceLocation L,
1219628b96f34e93b643b6e15e75eabb8d96079a7e27Fariborz Jahanian                       ObjCPropertyDecl *property,
12209f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar                       Kind PK,
1221628b96f34e93b643b6e15e75eabb8d96079a7e27Fariborz Jahanian                       ObjCIvarDecl *ivarDecl)
1222d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor    : ScopedDecl(ObjCPropertyImpl, DC, L, DeclarationName()), AtLoc(atLoc),
1223d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor      PropertyDecl(property), PropertyIvarDecl(ivarDecl) {
12249f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar    assert (PK == Dynamic || PropertyIvarDecl);
12259f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar  }
1226628b96f34e93b643b6e15e75eabb8d96079a7e27Fariborz Jahanian
12279f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbarpublic:
1228d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor  static ObjCPropertyImplDecl *Create(ASTContext &C, DeclContext *DC,
1229d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor                                      SourceLocation atLoc, SourceLocation L,
1230628b96f34e93b643b6e15e75eabb8d96079a7e27Fariborz Jahanian                                      ObjCPropertyDecl *property,
12319f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar                                      Kind PK,
1232628b96f34e93b643b6e15e75eabb8d96079a7e27Fariborz Jahanian                                      ObjCIvarDecl *ivarDecl);
123361d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian
1234d40910b581b09c937a8c1fdcde9b8ec724398fb9Steve Naroff  SourceLocation getLocStart() const { return AtLoc; }
1235d40910b581b09c937a8c1fdcde9b8ec724398fb9Steve Naroff
1236be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek  ObjCPropertyDecl *getPropertyDecl() const {
1237be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek    return PropertyDecl;
1238be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek  }
123961d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian
12409f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar  Kind getPropertyImplementation() const {
12419f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar    return PropertyIvarDecl ? Synthesize : Dynamic;
1242be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek  }
124361d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian
1244af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  ObjCIvarDecl *getPropertyIvarDecl() const {
1245be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek    return PropertyIvarDecl;
1246be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek  }
124761d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian
124861d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  static bool classof(const Decl *D) {
124961d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian    return D->getKind() == ObjCPropertyImpl;
125061d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  }
125161d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  static bool classof(const ObjCPropertyImplDecl *D) { return true; }
125261d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian};
125361d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian
1254980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff}  // end namespace clang
1255980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff#endif
1256