DeclObjC.h revision b718b407db1f921c5a2dc0164a23582c322f8ce0
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
21958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  bool isInstance() const { return IsInstance; }
22058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  bool isVariadic() const { return IsVariadic; }
22158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff
2224607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian  bool isSynthesized() const { return IsSynthesized; }
22391b51a92f2e9fc8025b6a9df88442840eb62823aFariborz Jahanian  void setIsSynthesized() { IsSynthesized = true; }
2244607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian
22558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  // Related to protocols declared in  @protocol
22658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  void setDeclImplementation(ImplementationControl ic) {
22758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff    DeclImplementation = ic;
22858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  }
22958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  ImplementationControl getImplementationControl() const {
230ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek    return ImplementationControl(DeclImplementation);
23158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  }
232792481eec23d8c1aa92173be589e2ae9d02514a5Ted Kremenek
23369c8f0aab655257e9e532d9d53756acf4f7a2d78Ted Kremenek  virtual Stmt *getBody() const { return Body; }
23458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  void setBody(Stmt *B) { Body = B; }
23558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff
23658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff  // Implement isa/cast/dyncast/etc.
237a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const Decl *D) { return D->getKind() == ObjCMethod; }
238a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCMethodDecl *D) { return true; }
23942220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  static DeclContext *castToDeclContext(const ObjCMethodDecl *D) {
24042220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis    return static_cast<DeclContext *>(const_cast<ObjCMethodDecl*>(D));
24142220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  }
24242220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  static ObjCMethodDecl *castFromDeclContext(const DeclContext *DC) {
24342220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis    return static_cast<ObjCMethodDecl *>(const_cast<DeclContext*>(DC));
24442220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  }
24558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff};
246e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
247e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff/// ObjCContainerDecl - Represents a container for method declarations.
248e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff/// Current sub-classes are ObjCInterfaceDecl, ObjCCategoryDecl, and
2490701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff/// ObjCProtocolDecl.
2500701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff/// FIXME: Use for ObjC implementation decls.
2510701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff/// FIXME: Consider properties.
2520701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff/// FIXME: It would be nice to reduce amount of "boilerplate" iterator code
2530701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff/// below. For now, the iterators are modeled after RecordDecl::field_iterator().
2540701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff/// If DeclContext ends up providing some support for creating more strongly
2550701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff/// typed iterators, the code below should be reduced considerably.
256e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff///
2570701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroffclass ObjCContainerDecl : public NamedDecl, public DeclContext {
258e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff  SourceLocation AtEndLoc; // marks the end of the method container.
259e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroffpublic:
260e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
261e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff  ObjCContainerDecl(Kind DK, SourceLocation L, IdentifierInfo *Id)
2620701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    : NamedDecl(DK, L, Id), DeclContext(DK) {}
263e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
264e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff  virtual ~ObjCContainerDecl();
265e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
2660701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  // Iterator access to instance/class methods.
2670701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  class method_iterator {
2680701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  protected:
2690701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    /// Current - Current position within the sequence of declarations
2700701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    /// in this record.
2710701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    DeclContext::decl_iterator Current;
2720701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
2730701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    /// End - Last position in the sequence of declarations in this
2740701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    /// record.
2750701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    DeclContext::decl_iterator End;
2760701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
2770701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    /// IsInstance - If true, we are iterating through instance methods.
2780701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    /// If false, we are iteratring through class methods.
2790701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    bool IsInstance;
2800701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
2810701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    /// SkipToNextMethod - Advances the current position up to the next
2820701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    /// ObjCMethodDecl.
2830701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    void SkipToNextMethod() {
2840701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff      while (Current != End) {
2850701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff        ObjCMethodDecl *M = dyn_cast<ObjCMethodDecl>(*Current);
2860701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff        if (M &&
2870701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff            (IsInstance && M->isInstance() || !IsInstance && !M->isInstance()))
2880701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff          return;
2890701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff        ++Current;
2900701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff      }
2910701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    }
2920701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
2930701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  public:
2940701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    typedef ObjCMethodDecl const *    value_type;
2950701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    typedef ObjCMethodDecl const *    reference;
2960701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    typedef ObjCMethodDecl const *    pointer;
2970701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    typedef std::ptrdiff_t            difference_type;
2980701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    typedef std::forward_iterator_tag iterator_category;
2990701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
3000701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    method_iterator() : Current(), End(), IsInstance(true) { }
3010701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
3020701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    method_iterator(DeclContext::decl_iterator C,
3030701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff                    DeclContext::decl_iterator E, bool I)
3040701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff      : Current(C), End(E), IsInstance(I) {
3050701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff      SkipToNextMethod();
3060701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    }
3070701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
3080701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    reference operator*() const { return cast<ObjCMethodDecl>(*Current); }
3090701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
3100701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    pointer operator->() const { return cast<ObjCMethodDecl>(*Current); }
3110701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
3120701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    method_iterator& operator++() {
3130701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff      ++Current;
3140701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff      SkipToNextMethod();
3150701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff      return *this;
3160701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    }
3170701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
3180701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    method_iterator operator++(int) {
3190701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff      method_iterator tmp(*this);
3200701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff      ++(*this);
3210701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff      return tmp;
3220701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    }
3230701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
3240701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    friend bool
3250701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    operator==(const method_iterator& x, const method_iterator& y) {
3260701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff      return x.Current == y.Current;
3270701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    }
3280701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
3290701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    friend bool
3300701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    operator!=(const method_iterator& x, const method_iterator& y) {
3310701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff      return x.Current != y.Current;
3320701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    }
3330701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  };
3340701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
3350701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  class instmeth_iterator : public method_iterator {
3360701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  public:
3370701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    typedef ObjCMethodDecl*           value_type;
3380701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    typedef ObjCMethodDecl*           reference;
3390701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    typedef ObjCMethodDecl*           pointer;
3400701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
3410701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    instmeth_iterator() : method_iterator() { }
3420701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
3430701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    instmeth_iterator(DeclContext::decl_iterator C, DeclContext::decl_iterator E)
3440701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff      : method_iterator(C, E, true) { }
3450701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
3460701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    reference operator*() const { return cast<ObjCMethodDecl>(*Current); }
3470701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
3480701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    pointer operator->() const { return cast<ObjCMethodDecl>(*Current); }
3490701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
3500701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    instmeth_iterator& operator++() {
3510701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff      ++Current;
3520701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff      SkipToNextMethod();
3530701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff      return *this;
3540701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    }
3550701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
3560701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    instmeth_iterator operator++(int) {
3570701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff      instmeth_iterator tmp(*this);
3580701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff      ++(*this);
3590701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff      return tmp;
3600701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    }
3610701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  };
3620701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
3630701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  instmeth_iterator instmeth_begin() const {
3640701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    return instmeth_iterator(decls_begin(), decls_end());
365e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff  }
3660701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  instmeth_iterator instmeth_end() const {
3670701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    return instmeth_iterator(decls_end(), decls_end());
368e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff  }
369e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
3700701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  class classmeth_iterator : public method_iterator {
3710701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  public:
3720701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    typedef ObjCMethodDecl*           value_type;
3730701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    typedef ObjCMethodDecl*           reference;
3740701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    typedef ObjCMethodDecl*           pointer;
3750701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
3760701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    classmeth_iterator() : method_iterator() { }
3770701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
3780701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    classmeth_iterator(DeclContext::decl_iterator C, DeclContext::decl_iterator E)
3790701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff      : method_iterator(C, E, false) { }
3800701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
3810701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    reference operator*() const { return cast<ObjCMethodDecl>(*Current); }
3820701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
3830701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    pointer operator->() const { return cast<ObjCMethodDecl>(*Current); }
3840701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
3850701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    classmeth_iterator& operator++() {
3860701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff      ++Current;
3870701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff      SkipToNextMethod();
3880701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff      return *this;
389e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff    }
3900701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
3910701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    classmeth_iterator operator++(int) {
3920701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff      classmeth_iterator tmp(*this);
3930701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff      ++(*this);
3940701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff      return tmp;
395e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff    }
3960701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  };
3970701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  classmeth_iterator classmeth_begin() const {
3980701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    return classmeth_iterator(decls_begin(), decls_end());
399e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff  }
4000701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  classmeth_iterator classmeth_end() const {
4010701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    return classmeth_iterator(decls_end(), decls_end());
4020701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  }
4030701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff
4040701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  // Get the local instance/class method declared in this interface.
4050701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  ObjCMethodDecl *getInstanceMethod(Selector Sel) const;
4060701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  ObjCMethodDecl *getClassMethod(Selector Sel) const;
407e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
4080701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  // Get the number of instance/class methods.
4090701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  unsigned getNumInstanceMethods() const;
4100701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  unsigned getNumClassMethods() const;
411b245a33e6f562377946dc9cb5694a2d3cb8a98a3Fariborz Jahanian
412e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff  // Marks the end of the container.
413e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff  SourceLocation getAtEndLoc() const { return AtEndLoc; }
4140701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff  void setAtEndLoc(SourceLocation L) { AtEndLoc = L; }
415e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff};
416e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
417a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCInterfaceDecl - Represents an ObjC class declaration. For example:
4180c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
4190c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   // MostPrimitive declares no super class (not particularly useful).
4200c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @interface MostPrimitive
4210c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     // no instance variables or methods.
4220c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @end
4230c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
424fd5de471478a507dd2495c4ea9bcab801ea5fa65Chris Lattner///   // NSResponder inherits from NSObject & implements NSCoding (a protocol).
4250c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @interface NSResponder : NSObject <NSCoding>
426a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek///   { // instance variables are represented by ObjCIvarDecl.
4270c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     id nextResponder; // nextResponder instance variable.
4280c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   }
4290c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   - (NSResponder *)nextResponder; // return a pointer to NSResponder.
4300c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   - (void)mouseMoved:(NSEvent *)theEvent; // return void, takes a pointer
4310c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @end                                    // to an NSEvent.
4320c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
4330c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   Unlike C/C++, forward class declarations are accomplished with @class.
4340c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   Unlike C/C++, @class allows for a list of classes to be forward declared.
4350c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   Unlike C++, ObjC is a single-rooted class model. In Cocoa, classes
4360c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   typically inherit from NSObject (an exception is NSProxy).
4370c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
4380701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroffclass ObjCInterfaceDecl : public ObjCContainerDecl {
4393110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff  /// TypeForDecl - This indicates the Type object that represents this
4403110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff  /// TypeDecl.  It is a cache maintained by ASTContext::getObjCInterfaceType
4413110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff  Type *TypeForDecl;
4423110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff  friend class ASTContext;
443980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
444980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  /// Class's super class.
445a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *SuperClass;
446980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
447980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  /// Protocols referenced in interface header declaration
4483db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  ObjCList<ObjCProtocolDecl> ReferencedProtocols;
449980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
450980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  /// Ivars/NumIvars - This is a new[]'d array of pointers to Decls.
451a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCIvarDecl **Ivars;   // Null if not defined.
452f3a7af901231535191d14cb524d58f22907ac4d2Chris Lattner  unsigned NumIvars;      // 0 if none.
453980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
454980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  /// List of categories defined for this class.
455a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCCategoryDecl *CategoryList;
45682a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian
45782a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian  /// class properties
458a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCPropertyDecl **PropertyDecl;  // Null if no property
45955d13b4d5530a14d5baa72adab32ae78ba256cafChris Lattner  unsigned NumPropertyDecl;  // 0 if none.
460980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
4613a3ca1b35a7121aea0bf465a192dce748465e10fFariborz Jahanian  bool ForwardDecl:1; // declared with @class.
4623a3ca1b35a7121aea0bf465a192dce748465e10fFariborz Jahanian  bool InternalInterface:1; // true - no @interface for @implementation
46360fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff
464d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff  SourceLocation ClassLoc; // location of the class identifier.
465d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff  SourceLocation SuperClassLoc; // location of the super class identifier.
466f908a87299d278164540f90b5b6e6cab7b14fb41Steve Naroff  SourceLocation EndLoc; // marks the '>', '}', or identifier.
4670e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner
468b752f289026ad8e5f44851b20e009a27ed61eefcChris Lattner  ObjCInterfaceDecl(SourceLocation atLoc, IdentifierInfo *Id,
469b752f289026ad8e5f44851b20e009a27ed61eefcChris Lattner                    SourceLocation CLoc, bool FD, bool isInternal)
4700701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    : ObjCContainerDecl(ObjCInterface, atLoc, Id),
471a769c004a2874504c17ea8afccbc4ad35fc33c9fFariborz Jahanian      TypeForDecl(0), SuperClass(0),
4723db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner      Ivars(0), NumIvars(0),
473f4af5154571e0c5eadb19df10e65464766ef6683Chris Lattner      CategoryList(0), PropertyDecl(0), NumPropertyDecl(0),
474d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff      ForwardDecl(FD), InternalInterface(isInternal),
475d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff      ClassLoc(CLoc) {
476980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff      }
4778a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek
4781c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek  virtual ~ObjCInterfaceDecl();
4798a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek
4800e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattnerpublic:
4810e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner
4828a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek  /// Destroy - Call destructors and release memory.
4838a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek  virtual void Destroy(ASTContext& C);
4848a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek
4850ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner  static ObjCInterfaceDecl *Create(ASTContext &C,
4860ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner                                   SourceLocation atLoc,
487d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff                                   IdentifierInfo *Id,
488d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff                                   SourceLocation ClassLoc = SourceLocation(),
4890e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner                                   bool ForwardDecl = false,
4900e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner                                   bool isInternal = false);
4913db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  const ObjCList<ObjCProtocolDecl> &getReferencedProtocols() const {
4927ed9e0f97f4645edc5d4670385b985ea4c617ce7Fariborz Jahanian    return ReferencedProtocols;
4937ed9e0f97f4645edc5d4670385b985ea4c617ce7Fariborz Jahanian  }
494980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
495559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  ObjCPropertyDecl *FindPropertyDeclaration(IdentifierInfo *PropertyId) const;
496559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  ObjCCategoryDecl *FindCategoryDeclaration(IdentifierInfo *CategoryId) const;
497559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  ObjCIvarDecl *FindIvarDeclaration(IdentifierInfo *IvarId) const;
49831afbf02a381ae9c77d225aa54f972d152838b3aFariborz Jahanian  bool isPropertyReadonly(ObjCPropertyDecl *PropertyDecl) const;
4993db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner
5003db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  typedef ObjCList<ObjCProtocolDecl>::iterator protocol_iterator;
5013db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();}
5023db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  protocol_iterator protocol_end() const { return ReferencedProtocols.end(); }
503aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian
504a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  typedef ObjCIvarDecl * const *ivar_iterator;
505be6df088d69bca0e99c7845a6cd8c1ca85034f31Chris Lattner  ivar_iterator ivar_begin() const { return Ivars; }
5065564e07af5e62875f3b83fc2e5a8823588b5adeaChris Lattner  ivar_iterator ivar_end() const { return Ivars + ivar_size();}
507f3a7af901231535191d14cb524d58f22907ac4d2Chris Lattner  unsigned ivar_size() const { return NumIvars; }
508a0fb5861dec7aa1da0d21d5759678d76b00464f4Ted Kremenek  bool ivar_empty() const { return NumIvars == 0; }
509e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
510b752f289026ad8e5f44851b20e009a27ed61eefcChris Lattner  /// addReferencedProtocols - Set the list of protocols that this interface
511b752f289026ad8e5f44851b20e009a27ed61eefcChris Lattner  /// implements.
512780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  void addReferencedProtocols(ObjCProtocolDecl *const*List, unsigned NumRPs) {
513780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner    ReferencedProtocols.set(List, NumRPs);
5143db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner  }
515b752f289026ad8e5f44851b20e009a27ed61eefcChris Lattner
516a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void addInstanceVariablesToClass(ObjCIvarDecl **ivars, unsigned numIvars,
51760fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff                                   SourceLocation RBracLoc);
518fd64bb635dc221baa19f81d5d2a084f7eb269f7fFariborz Jahanian  FieldDecl *lookupFieldDeclForIvar(ASTContext &Context,
519fd64bb635dc221baa19f81d5d2a084f7eb269f7fFariborz Jahanian                                    const ObjCIvarDecl *ivar);
520980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
52155d13b4d5530a14d5baa72adab32ae78ba256cafChris Lattner  void addProperties(ObjCPropertyDecl **Properties, unsigned NumProperties);
52255d13b4d5530a14d5baa72adab32ae78ba256cafChris Lattner
523aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian  void mergeProperties(ObjCPropertyDecl **Properties, unsigned NumProperties);
524aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian
5253dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian  typedef ObjCPropertyDecl * const * classprop_iterator;
5263dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian  classprop_iterator classprop_begin() const { return PropertyDecl; }
5273dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian  classprop_iterator classprop_end() const {
5283dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian    return PropertyDecl+NumPropertyDecl;
5293dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian  }
53055d13b4d5530a14d5baa72adab32ae78ba256cafChris Lattner
531768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff  bool isForwardDecl() const { return ForwardDecl; }
532768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff  void setForwardDecl(bool val) { ForwardDecl = val; }
533980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
534a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *getSuperClass() const { return SuperClass; }
535a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void setSuperClass(ObjCInterfaceDecl * superCls) { SuperClass = superCls; }
536980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
537a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCCategoryDecl* getCategoryList() const { return CategoryList; }
538a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void setCategoryList(ObjCCategoryDecl *category) {
53953efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    CategoryList = category;
540980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  }
54153efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner
54253efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner  /// isSuperClassOf - Return true if this class is the specified class or is a
54353efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner  /// super class of the specified interface class.
54453efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner  bool isSuperClassOf(const ObjCInterfaceDecl *I) const {
54553efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    // If RHS is derived from LHS it is OK; else it is not OK.
54653efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    while (I != NULL) {
54753efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner      if (this == I)
54853efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner        return true;
54953efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner      I = I->getSuperClass();
55053efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    }
55153efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner    return false;
55253efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner  }
55353efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner
55468a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner  ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName,
55568a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner                                       ObjCInterfaceDecl *&ClassDeclared);
55668a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner  ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName) {
55768a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner    ObjCInterfaceDecl *ClassDeclared;
55868a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner    return lookupInstanceVariable(IVarName, ClassDeclared);
55968a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner  }
56068a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner
56194a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // Lookup a method. First, we search locally. If a method isn't
56294a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // found, we search referenced protocols and class categories.
563a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCMethodDecl *lookupInstanceMethod(Selector Sel);
564a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCMethodDecl *lookupClassMethod(Selector Sel);
56560fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff
566f908a87299d278164540f90b5b6e6cab7b14fb41Steve Naroff  // Location information, modeled after the Stmt API.
56760fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff  SourceLocation getLocStart() const { return getLocation(); } // '@'interface
568f908a87299d278164540f90b5b6e6cab7b14fb41Steve Naroff  SourceLocation getLocEnd() const { return EndLoc; }
569f908a87299d278164540f90b5b6e6cab7b14fb41Steve Naroff  void setLocEnd(SourceLocation LE) { EndLoc = LE; };
57060fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff
571d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff  SourceLocation getClassLoc() const { return ClassLoc; }
572d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff  void setSuperClassLoc(SourceLocation Loc) { SuperClassLoc = Loc; }
573d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff  SourceLocation getSuperClassLoc() const { return SuperClassLoc; }
574e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
575f4af5154571e0c5eadb19df10e65464766ef6683Chris Lattner  unsigned getNumPropertyDecl() const { return NumPropertyDecl; }
57682a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian
57755d13b4d5530a14d5baa72adab32ae78ba256cafChris Lattner  ObjCPropertyDecl * const * getPropertyDecl() const { return PropertyDecl; }
578a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCPropertyDecl **getPropertyDecl() { return PropertyDecl; }
579f908a87299d278164540f90b5b6e6cab7b14fb41Steve Naroff
5804b6df3fa953267c5d755628c8afd818bb571e579Fariborz Jahanian  /// ImplicitInterfaceDecl - check that this is an implicitely declared
581a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  /// ObjCInterfaceDecl node. This is for legacy objective-c @implementation
5824b6df3fa953267c5d755628c8afd818bb571e579Fariborz Jahanian  /// declaration without an @interface declaration.
5833a3ca1b35a7121aea0bf465a192dce748465e10fFariborz Jahanian  bool ImplicitInterfaceDecl() const { return InternalInterface; }
5844b6df3fa953267c5d755628c8afd818bb571e579Fariborz Jahanian
585a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const Decl *D) { return D->getKind() == ObjCInterface; }
586a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCInterfaceDecl *D) { return true; }
58742220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  static DeclContext *castToDeclContext(const ObjCInterfaceDecl *D) {
58842220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis    return static_cast<DeclContext *>(const_cast<ObjCInterfaceDecl*>(D));
58942220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  }
59042220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  static ObjCInterfaceDecl *castFromDeclContext(const DeclContext *DC) {
59142220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis    return static_cast<ObjCInterfaceDecl *>(const_cast<DeclContext*>(DC));
59242220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis  }
593980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
594980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
595a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCIvarDecl - Represents an ObjC instance variable. In general, ObjC
5960c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// instance variables are identical to C. The only exception is Objective-C
5970c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// supports C++ style access control. For example:
5980c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
5990c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @interface IvarExample : NSObject
6000c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   {
601f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek///     id defaultToProtected;
6020c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @public:
6030c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     id canBePublic; // same as C++.
6040c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @protected:
6050c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     id canBeProtected; // same as C++.
6060c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   @package:
6070c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///     id canBePackage; // framework visibility (not available in C++).
6080c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///   }
6090c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
610a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCIvarDecl : public FieldDecl {
6110e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattnerpublic:
612980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  enum AccessControl {
613980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff    None, Private, Protected, Public, Package
614980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  };
615f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek
616b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenekprivate:
617b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenek  ObjCIvarDecl(SourceLocation L, IdentifierInfo *Id, QualType T,
618b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenek               AccessControl ac, Expr *BW)
61944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor    : FieldDecl(ObjCIvar, 0, L, Id, T, BW, /*Mutable=*/false, 0),
62044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor      DeclAccess(ac) {}
621b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenek
622b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenekpublic:
623b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenek  static ObjCIvarDecl *Create(ASTContext &C, SourceLocation L,
624b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenek                              IdentifierInfo *Id, QualType T,
625b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenek                              AccessControl ac, Expr *BW = NULL);
626b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenek
627980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  void setAccessControl(AccessControl ac) { DeclAccess = ac; }
628f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek
629ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  AccessControl getAccessControl() const { return AccessControl(DeclAccess); }
630f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek
631f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek  AccessControl getCanonicalAccessControl() const {
632f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek    return DeclAccess == None ? Protected : AccessControl(DeclAccess);
633f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek  }
634980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
635980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  // Implement isa/cast/dyncast/etc.
636a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const Decl *D) { return D->getKind() == ObjCIvar; }
637a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCIvarDecl *D) { return true; }
638980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffprivate:
639ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  // NOTE: VC++ treats enums as signed, avoid using the AccessControl enum
640ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  unsigned DeclAccess : 3;
641980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
642980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
64301e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek
64401e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek/// ObjCAtDefsFieldDecl - Represents a field declaration created by an
64501e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek///  @defs(...).
64601e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenekclass ObjCAtDefsFieldDecl : public FieldDecl {
64701e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenekprivate:
64844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor  ObjCAtDefsFieldDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
64901e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek                      QualType T, Expr *BW)
65044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor    : FieldDecl(ObjCAtDefsField, DC, L, Id, T, BW, /*Mutable=*/false, 0) {}
65101e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek
65201e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenekpublic:
65344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor  static ObjCAtDefsFieldDecl *Create(ASTContext &C, DeclContext *DC,
65444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor                                     SourceLocation L,
65501e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek                                     IdentifierInfo *Id, QualType T,
65601e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek                                     Expr *BW);
65701e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek
65801e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek  virtual void Destroy(ASTContext& C);
65901e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek
66001e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek  // Implement isa/cast/dyncast/etc.
66101e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek  static bool classof(const Decl *D) { return D->getKind() == ObjCAtDefsField; }
66201e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek  static bool classof(const ObjCAtDefsFieldDecl *D) { return true; }
66301e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek};
664980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
665a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCProtocolDecl - Represents a protocol declaration. ObjC protocols
6660c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// declare a pure abstract type (i.e no instance variables are permitted).
6670c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// Protocols orginally drew inspiration from C++ pure virtual functions (a C++
6680c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// feature with nice semantics and lousy syntax:-). Here is an example:
6690c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
670eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// @protocol NSDraggingInfo <refproto1, refproto2>
6710c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (NSWindow *)draggingDestinationWindow;
6720c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (NSImage *)draggedImage;
6730c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end
6740c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
675eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// This says that NSDraggingInfo requires two methods and requires everything
676eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// that the two "referenced protocols" 'refproto1' and 'refproto2' require as
677eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// well.
678eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner///
6790c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @interface ImplementsNSDraggingInfo : NSObject <NSDraggingInfo>
6800c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end
6810c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
682a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjC protocols inspired Java interfaces. Unlike Java, ObjC classes and
6830c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// protocols are in distinct namespaces. For example, Cocoa defines both
6840c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// an NSObject protocol and class (which isn't allowed in Java). As a result,
6850c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// protocols are referenced using angle brackets as follows:
6860c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
6870c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// id <NSDraggingInfo> anyObjectThatImplementsNSDraggingInfo;
6880c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
689e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroffclass ObjCProtocolDecl : public ObjCContainerDecl {
690780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  /// Referenced protocols
691780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  ObjCList<ObjCProtocolDecl> ReferencedProtocols;
692980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
6933dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian  /// protocol properties
6943dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian  ObjCPropertyDecl **PropertyDecl;  // Null if no property
6953dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian  unsigned NumPropertyDecl;  // 0 if none
6963dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian
697980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  bool isForwardProtoDecl; // declared with @protocol.
698423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff
699423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff  SourceLocation EndLoc; // marks the '>' or identifier.
700423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff  SourceLocation AtEndLoc; // marks the end of the entire interface.
701cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattner
702780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  ObjCProtocolDecl(SourceLocation L, IdentifierInfo *Id)
703e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff    : ObjCContainerDecl(ObjCProtocol, L, Id),
7043dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian      PropertyDecl(0), NumPropertyDecl(0),
705c858105d41602a2dadb2efbc1af80a7b791ebac3Chris Lattner      isForwardProtoDecl(true) {
706cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattner  }
7071c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek
7081c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek  virtual ~ObjCProtocolDecl();
7091c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek
710cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattnerpublic:
7111c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek
7121c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek  /// Destroy - Call destructors and release memory.
7131c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek  virtual void Destroy(ASTContext& C);
7141c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek
715cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattner  static ObjCProtocolDecl *Create(ASTContext &C, SourceLocation L,
716780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner                                  IdentifierInfo *Id);
717cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattner
718780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  const ObjCList<ObjCProtocolDecl> &getReferencedProtocols() const {
719780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner    return ReferencedProtocols;
720980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  }
721dbc933701d20918add13b6a3c9d47ff8c75419cfDaniel Dunbar  typedef ObjCList<ObjCProtocolDecl>::iterator protocol_iterator;
722780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();}
723780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  protocol_iterator protocol_end() const { return ReferencedProtocols.end(); }
724780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner
725780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  /// addReferencedProtocols - Set the list of protocols that this interface
726780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  /// implements.
727780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  void addReferencedProtocols(ObjCProtocolDecl *const*List, unsigned NumRPs) {
728780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner    ReferencedProtocols.set(List, NumRPs);
729aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian  }
730aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian
7313d2c22b1d334fa74d26a5f21841cb55df5dfdd1aSteve Naroff  ObjCPropertyDecl *FindPropertyDeclaration(IdentifierInfo *PropertyId) const;
7323dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian
7333dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian  unsigned getNumPropertyDecl() const { return NumPropertyDecl; }
7343dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian
7353dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian  ObjCPropertyDecl * const * getPropertyDecl() const { return PropertyDecl; }
7363dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian  ObjCPropertyDecl **getPropertyDecl() { return PropertyDecl; }
7373dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian
7383dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian  void addProperties(ObjCPropertyDecl **Properties, unsigned NumProperties);
7397b4732296b5c7e1a53021a8dbb97f39dedbd961fDaniel Dunbar
7403dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian  typedef ObjCPropertyDecl * const * classprop_iterator;
7413dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian  classprop_iterator classprop_begin() const { return PropertyDecl; }
7423dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian  classprop_iterator classprop_end() const {
7433dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian    return PropertyDecl+NumPropertyDecl;
7443dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian  }
74558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff
74694a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // Lookup a method. First, we search locally. If a method isn't
74794a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // found, we search referenced protocols and class categories.
748a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCMethodDecl *lookupInstanceMethod(Selector Sel);
749a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCMethodDecl *lookupClassMethod(Selector Sel);
7507dd82836dca87cf828ce994f161b53a34f6cdb7eFariborz Jahanian
751768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff  bool isForwardDecl() const { return isForwardProtoDecl; }
752768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff  void setForwardDecl(bool val) { isForwardProtoDecl = val; }
753980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
754423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff  // Location information, modeled after the Stmt API.
755423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff  SourceLocation getLocStart() const { return getLocation(); } // '@'protocol
756423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff  SourceLocation getLocEnd() const { return EndLoc; }
757423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff  void setLocEnd(SourceLocation LE) { EndLoc = LE; };
758423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff
759a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const Decl *D) { return D->getKind() == ObjCProtocol; }
760a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCProtocolDecl *D) { return true; }
761b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff  static DeclContext *castToDeclContext(const ObjCProtocolDecl *D) {
762b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff    return static_cast<DeclContext *>(const_cast<ObjCProtocolDecl*>(D));
763b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff  }
764b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff  static ObjCProtocolDecl *castFromDeclContext(const DeclContext *DC) {
765b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff    return static_cast<ObjCProtocolDecl *>(const_cast<DeclContext*>(DC));
766b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff  }
767980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
768980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
769a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCClassDecl - Specifies a list of forward class declarations. For example:
77006ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff///
77106ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff/// @class NSCursor, NSImage, NSPasteboard, NSWindow;
7720c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
773a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCClassDecl : public Decl {
774a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl **ForwardDecls;
7757e620729fcb5a0042107f999dcf524f7357ce819Chris Lattner  unsigned NumForwardDecls;
77661f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner
777a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCClassDecl(SourceLocation L, ObjCInterfaceDecl **Elts, unsigned nElts)
778a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek    : Decl(ObjCClass, L) {
77906ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff    if (nElts) {
780a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      ForwardDecls = new ObjCInterfaceDecl*[nElts];
781a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      memcpy(ForwardDecls, Elts, nElts*sizeof(ObjCInterfaceDecl*));
7827e620729fcb5a0042107f999dcf524f7357ce819Chris Lattner    } else {
7837e620729fcb5a0042107f999dcf524f7357ce819Chris Lattner      ForwardDecls = 0;
78406ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff    }
78506ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff    NumForwardDecls = nElts;
78606ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff  }
787400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek
788400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek  virtual ~ObjCClassDecl();
789400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek
79061f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattnerpublic:
791400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek
792400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek  /// Destroy - Call destructors and release memory.
793400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek  virtual void Destroy(ASTContext& C);
794400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek
79561f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner  static ObjCClassDecl *Create(ASTContext &C, SourceLocation L,
79661f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner                               ObjCInterfaceDecl **Elts, unsigned nElts);
79761f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner
798a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void setInterfaceDecl(unsigned idx, ObjCInterfaceDecl *OID) {
7997e620729fcb5a0042107f999dcf524f7357ce819Chris Lattner    assert(idx < NumForwardDecls && "index out of range");
80006ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff    ForwardDecls[idx] = OID;
80106ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff  }
802a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl** getForwardDecls() const { return ForwardDecls; }
8037e15891fc89256fc013bd1003676ad3197b85c25Steve Naroff  int getNumForwardDecls() const { return NumForwardDecls; }
8047e15891fc89256fc013bd1003676ad3197b85c25Steve Naroff
805400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek  typedef ObjCInterfaceDecl * const * iterator;
806400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek  iterator begin() const { return ForwardDecls; }
807400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek  iterator end() const { return ForwardDecls+NumForwardDecls; }
808400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek
809a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const Decl *D) { return D->getKind() == ObjCClass; }
810a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCClassDecl *D) { return true; }
81106ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff};
81206ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff
813a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCForwardProtocolDecl - Specifies a list of forward protocol declarations.
81406ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff/// For example:
81506ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff///
8160c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @protocol NSTextInput, NSChangeSpelling, NSDraggingInfo;
8170c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
818a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCForwardProtocolDecl : public Decl {
819a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCProtocolDecl **ReferencedProtocols;
8209fa5e65d08aee1875c5f2a841c8b0b4069bd00e5Chris Lattner  unsigned NumReferencedProtocols;
82161f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner
8220ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner  ObjCForwardProtocolDecl(SourceLocation L,
823a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek                          ObjCProtocolDecl **Elts, unsigned nElts)
824a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  : Decl(ObjCForwardProtocol, L) {
825b97de3eddf0a0f7ff97204e7def6b7e0aa8953f2Chris Lattner    NumReferencedProtocols = nElts;
82606ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff    if (nElts) {
827a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      ReferencedProtocols = new ObjCProtocolDecl*[nElts];
828a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek      memcpy(ReferencedProtocols, Elts, nElts*sizeof(ObjCProtocolDecl*));
8299fa5e65d08aee1875c5f2a841c8b0b4069bd00e5Chris Lattner    } else {
8309fa5e65d08aee1875c5f2a841c8b0b4069bd00e5Chris Lattner      ReferencedProtocols = 0;
831980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff    }
83206ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff  }
83305ac3ef08f9d06e0a4439073c9edabf7f912f946Ted Kremenek
83405ac3ef08f9d06e0a4439073c9edabf7f912f946Ted Kremenek  virtual ~ObjCForwardProtocolDecl();
83505ac3ef08f9d06e0a4439073c9edabf7f912f946Ted Kremenek
83661f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattnerpublic:
83761f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner  static ObjCForwardProtocolDecl *Create(ASTContext &C, SourceLocation L,
83861f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner                                         ObjCProtocolDecl **Elts, unsigned Num);
83961f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner
84061f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner
841a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void setForwardProtocolDecl(unsigned idx, ObjCProtocolDecl *OID) {
8429fa5e65d08aee1875c5f2a841c8b0b4069bd00e5Chris Lattner    assert(idx < NumReferencedProtocols && "index out of range");
8437ed9e0f97f4645edc5d4670385b985ea4c617ce7Fariborz Jahanian    ReferencedProtocols[idx] = OID;
84406ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff  }
8459fa5e65d08aee1875c5f2a841c8b0b4069bd00e5Chris Lattner
8469fa5e65d08aee1875c5f2a841c8b0b4069bd00e5Chris Lattner  unsigned getNumForwardDecls() const { return NumReferencedProtocols; }
8479fa5e65d08aee1875c5f2a841c8b0b4069bd00e5Chris Lattner
848a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCProtocolDecl *getForwardProtocolDecl(unsigned idx) {
8499fa5e65d08aee1875c5f2a841c8b0b4069bd00e5Chris Lattner    assert(idx < NumReferencedProtocols && "index out of range");
8509fa5e65d08aee1875c5f2a841c8b0b4069bd00e5Chris Lattner    return ReferencedProtocols[idx];
8519fa5e65d08aee1875c5f2a841c8b0b4069bd00e5Chris Lattner  }
852a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  const ObjCProtocolDecl *getForwardProtocolDecl(unsigned idx) const {
8539fa5e65d08aee1875c5f2a841c8b0b4069bd00e5Chris Lattner    assert(idx < NumReferencedProtocols && "index out of range");
8549fa5e65d08aee1875c5f2a841c8b0b4069bd00e5Chris Lattner    return ReferencedProtocols[idx];
8559fa5e65d08aee1875c5f2a841c8b0b4069bd00e5Chris Lattner  }
8569fa5e65d08aee1875c5f2a841c8b0b4069bd00e5Chris Lattner
85705ac3ef08f9d06e0a4439073c9edabf7f912f946Ted Kremenek  typedef ObjCProtocolDecl * const * iterator;
85805ac3ef08f9d06e0a4439073c9edabf7f912f946Ted Kremenek  iterator begin() const { return ReferencedProtocols; }
85905ac3ef08f9d06e0a4439073c9edabf7f912f946Ted Kremenek  iterator end() const { return ReferencedProtocols+NumReferencedProtocols; }
86005ac3ef08f9d06e0a4439073c9edabf7f912f946Ted Kremenek
86106ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff  static bool classof(const Decl *D) {
862a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek    return D->getKind() == ObjCForwardProtocol;
86306ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff  }
864a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCForwardProtocolDecl *D) { return true; }
865980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
866980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
867a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCCategoryDecl - Represents a category declaration. A category allows
8680c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// you to add methods to an existing class (without subclassing or modifying
8690c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// the original class interface or implementation:-). Categories don't allow
8700c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// you to add instance data. The following example adds "myMethod" to all
8710c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// NSView's within a process:
8720c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
8730c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @interface NSView (MyViewMethods)
8740c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - myMethod;
8750c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end
8760c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
8770c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// Cateogries also allow you to split the implementation of a class across
8780c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// several files (a feature more naturally supported in C++).
8790c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
8800c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// Categories were originally inspired by dynamic languages such as Common
88168c82cf61228102aba1194efef222fa1478af2a8Chris Lattner/// Lisp and Smalltalk.  More traditional class-based languages (C++, Java)
8820c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// don't support this level of dynamism, which is both powerful and dangerous.
8830c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
884e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroffclass ObjCCategoryDecl : public ObjCContainerDecl {
885980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  /// Interface belonging to this category
886a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *ClassInterface;
887980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
88868c82cf61228102aba1194efef222fa1478af2a8Chris Lattner  /// referenced protocols in this category.
889780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  ObjCList<ObjCProtocolDecl> ReferencedProtocols;
890980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
891980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  /// Next category belonging to this class
892a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCCategoryDecl *NextClassCategory;
893ca3adf7e8cac8c9fbaf592b1e5c2be6f082de7baFariborz Jahanian
8947e7e3872b584bc5e7de7a34c8b9c092032303b72Fariborz Jahanian  /// category properties
8957e7e3872b584bc5e7de7a34c8b9c092032303b72Fariborz Jahanian  ObjCPropertyDecl **PropertyDecl;  // Null if no property
8967e7e3872b584bc5e7de7a34c8b9c092032303b72Fariborz Jahanian  unsigned NumPropertyDecl;  // 0 if none
8977e7e3872b584bc5e7de7a34c8b9c092032303b72Fariborz Jahanian
898423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff  SourceLocation EndLoc; // marks the '>' or identifier.
89961f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner
90068c82cf61228102aba1194efef222fa1478af2a8Chris Lattner  ObjCCategoryDecl(SourceLocation L, IdentifierInfo *Id)
901e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff    : ObjCContainerDecl(ObjCCategory, L, Id),
902780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner      ClassInterface(0),
9037e7e3872b584bc5e7de7a34c8b9c092032303b72Fariborz Jahanian      NextClassCategory(0), PropertyDecl(0),  NumPropertyDecl(0) {
904a906135721c350435319347d2672bbb3bf494f91Chris Lattner  }
90561f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattnerpublic:
90661f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner
9070ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner  static ObjCCategoryDecl *Create(ASTContext &C,
9080ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner                                  SourceLocation L, IdentifierInfo *Id);
90961f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner
910e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
911e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; }
912a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void setClassInterface(ObjCInterfaceDecl *IDecl) { ClassInterface = IDecl; }
913980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
914f7b2c98c16dfb2261ea57d40a1d5bc4738e73175Chris Lattner  /// addReferencedProtocols - Set the list of protocols that this interface
915f7b2c98c16dfb2261ea57d40a1d5bc4738e73175Chris Lattner  /// implements.
916780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  void addReferencedProtocols(ObjCProtocolDecl *const*List, unsigned NumRPs) {
917780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner    ReferencedProtocols.set(List, NumRPs);
918780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  }
919980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
920780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  const ObjCList<ObjCProtocolDecl> &getReferencedProtocols() const {
921780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner    return ReferencedProtocols;
9228f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian  }
923780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner
924780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  typedef ObjCProtocolDecl * const * protocol_iterator;
925780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();}
926780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner  protocol_iterator protocol_end() const { return ReferencedProtocols.end(); }
927780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner
9287e7e3872b584bc5e7de7a34c8b9c092032303b72Fariborz Jahanian  unsigned getNumPropertyDecl() const { return NumPropertyDecl; }
9297e7e3872b584bc5e7de7a34c8b9c092032303b72Fariborz Jahanian
9307e7e3872b584bc5e7de7a34c8b9c092032303b72Fariborz Jahanian  ObjCPropertyDecl * const * getPropertyDecl() const { return PropertyDecl; }
9317e7e3872b584bc5e7de7a34c8b9c092032303b72Fariborz Jahanian
9323dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian  void addProperties(ObjCPropertyDecl **Properties, unsigned NumProperties);
9337b4732296b5c7e1a53021a8dbb97f39dedbd961fDaniel Dunbar
9341ac2bc44781ec8451f880dcf586768a71824d3a6Fariborz Jahanian  void mergeProperties(ObjCPropertyDecl **Properties, unsigned NumProperties);
9351ac2bc44781ec8451f880dcf586768a71824d3a6Fariborz Jahanian
936559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  ObjCPropertyDecl *FindPropertyDeclaration(IdentifierInfo *PropertyId) const;
937559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian
9383dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian  typedef ObjCPropertyDecl * const * classprop_iterator;
9393dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian  classprop_iterator classprop_begin() const { return PropertyDecl; }
9403dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian  classprop_iterator classprop_end() const {
9413dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian    return PropertyDecl+NumPropertyDecl;
9423dd4ba4068e953125b95ce85c723322cdd0a3cb5Fariborz Jahanian  }
943e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff
944a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCCategoryDecl *getNextClassCategory() const { return NextClassCategory; }
945980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  void insertNextClassCategory() {
9463d58138992b9bc7b34aaa680f3ddf3971292eb7dSteve Naroff    NextClassCategory = ClassInterface->getCategoryList();
9473d58138992b9bc7b34aaa680f3ddf3971292eb7dSteve Naroff    ClassInterface->setCategoryList(this);
948980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  }
949423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff  // Location information, modeled after the Stmt API.
950423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff  SourceLocation getLocStart() const { return getLocation(); } // '@'interface
951423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff  SourceLocation getLocEnd() const { return EndLoc; }
952423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff  void setLocEnd(SourceLocation LE) { EndLoc = LE; };
953423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff
954a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const Decl *D) { return D->getKind() == ObjCCategory; }
955a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCCategoryDecl *D) { return true; }
956b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff  static DeclContext *castToDeclContext(const ObjCCategoryDecl *D) {
957b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff    return static_cast<DeclContext *>(const_cast<ObjCCategoryDecl*>(D));
958b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff  }
959b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff  static ObjCCategoryDecl *castFromDeclContext(const DeclContext *DC) {
960b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff    return static_cast<ObjCCategoryDecl *>(const_cast<DeclContext*>(DC));
961b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff  }
962980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
9630c6b6243d3efd958c17943130e2a773653511edcSteve Naroff
964a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCCategoryImplDecl - An object of this class encapsulates a category
965559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// @implementation declaration. If a category class has declaration of a
966559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// property, its implementation must be specified in the category's
967559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// @implementation declaration. Example:
968559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// @interface I @end
969559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// @interface I(CATEGORY)
970559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian///    @property int p1, d1;
971559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// @end
972559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// @implementation I(CATEGORY)
973559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian///  @dynamic p1,d1;
974559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// @end
975559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian///
9760701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroffclass ObjCCategoryImplDecl : public NamedDecl, public DeclContext {
9778f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian  /// Class interface for this category implementation
978a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *ClassInterface;
9798f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian
980e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff  /// implemented instance methods
981a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  llvm::SmallVector<ObjCMethodDecl*, 32> InstanceMethods;
9828f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian
983e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff  /// implemented class methods
984a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  llvm::SmallVector<ObjCMethodDecl*, 32> ClassMethods;
985f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian
986559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  /// Property Implementations in this category
987f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian  llvm::SmallVector<ObjCPropertyImplDecl*, 8> PropertyImplementations;
988e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff
989e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff  SourceLocation EndLoc;
99075c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner
991a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCCategoryImplDecl(SourceLocation L, IdentifierInfo *Id,
992a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek                       ObjCInterfaceDecl *classInterface)
9930701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    : NamedDecl(ObjCCategoryImpl, L, Id), DeclContext(ObjCCategoryImpl),
9940701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff      ClassInterface(classInterface) {}
99575c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattnerpublic:
9960ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner  static ObjCCategoryImplDecl *Create(ASTContext &C,
9970ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner                                      SourceLocation L, IdentifierInfo *Id,
99875c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner                                      ObjCInterfaceDecl *classInterface);
9998f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian
1000e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; }
1001e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
10028f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian
1003ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner  unsigned getNumInstanceMethods() const { return InstanceMethods.size(); }
1004ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner  unsigned getNumClassMethods() const { return ClassMethods.size(); }
1005e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff
1006a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void addInstanceMethod(ObjCMethodDecl *method) {
1007e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff    InstanceMethods.push_back(method);
1008e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff  }
1009a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void addClassMethod(ObjCMethodDecl *method) {
1010e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff    ClassMethods.push_back(method);
1011f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian  }
101294a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // Get the instance method definition for this implementation.
10133216dcdebb8ae0f2993ac5f5249caa217444bacfDaniel Dunbar  ObjCMethodDecl *getInstanceMethod(Selector Sel) const;
101494a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff
101594a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // Get the class method definition for this implementation.
10163216dcdebb8ae0f2993ac5f5249caa217444bacfDaniel Dunbar  ObjCMethodDecl *getClassMethod(Selector Sel) const;
1017f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian
1018f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian  void addPropertyImplementation(ObjCPropertyImplDecl *property) {
1019f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian    PropertyImplementations.push_back(property);
1020f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian  }
1021e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff
1022ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian  ObjCPropertyImplDecl *FindPropertyImplDecl(IdentifierInfo *propertyId) const;
1023ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian  ObjCPropertyImplDecl *FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const;
1024ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian
1025f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian  unsigned getNumPropertyImplementations() const
1026f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian  { return PropertyImplementations.size(); }
1027f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian
1028559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian
1029559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  typedef llvm::SmallVector<ObjCPropertyImplDecl*, 8>::const_iterator
1030559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian    propimpl_iterator;
1031559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  propimpl_iterator propimpl_begin() const {
1032559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian    return PropertyImplementations.begin();
1033559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  }
1034559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  propimpl_iterator propimpl_end() const {
1035559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian    return PropertyImplementations.end();
1036559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  }
1037559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian
1038a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  typedef llvm::SmallVector<ObjCMethodDecl*, 32>::const_iterator
1039ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner    instmeth_iterator;
1040ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner  instmeth_iterator instmeth_begin() const { return InstanceMethods.begin(); }
1041ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner  instmeth_iterator instmeth_end() const { return InstanceMethods.end(); }
1042ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner
1043a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  typedef llvm::SmallVector<ObjCMethodDecl*, 32>::const_iterator
1044ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner    classmeth_iterator;
1045ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner  classmeth_iterator classmeth_begin() const { return ClassMethods.begin(); }
1046ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner  classmeth_iterator classmeth_end() const { return ClassMethods.end(); }
1047ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner
1048ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner
1049e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff  // Location information, modeled after the Stmt API.
1050e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff  SourceLocation getLocStart() const { return getLocation(); }
1051e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff  SourceLocation getLocEnd() const { return EndLoc; }
1052e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff  void setLocEnd(SourceLocation LE) { EndLoc = LE; };
1053e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff
1054a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const Decl *D) { return D->getKind() == ObjCCategoryImpl;}
1055a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCCategoryImplDecl *D) { return true; }
1056b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff  static DeclContext *castToDeclContext(const ObjCCategoryImplDecl *D) {
1057b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff    return static_cast<DeclContext *>(const_cast<ObjCCategoryImplDecl*>(D));
1058b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff  }
1059b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff  static ObjCCategoryImplDecl *castFromDeclContext(const DeclContext *DC) {
1060b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff    return static_cast<ObjCCategoryImplDecl *>(const_cast<DeclContext*>(DC));
1061b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff  }
10628f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian};
10638f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian
1064a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCImplementationDecl - Represents a class definition - this is where
10650c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// method definitions are specified. For example:
10660c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
10670c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @implementation MyClass
10680c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (void)myMethod { /* do something */ }
10690c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end
10700c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
10710c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// Typically, instance variables are specified in the class interface,
10720c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// *not* in the implemenentation. Nevertheless (for legacy reasons), we
10730c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// allow instance variables to be specified in the implementation. When
10740c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// specified, they need to be *identical* to the interface. Now that we
10750c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// have support for non-fragile ivars in ObjC 2.0, we can consider removing
10760c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// the legacy semantics and allow developers to move private ivar declarations
10770c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// from the class interface to the class implementation (but I digress:-)
10780c6b6243d3efd958c17943130e2a773653511edcSteve Naroff///
10790701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroffclass ObjCImplementationDecl : public NamedDecl, public DeclContext {
1080dae1a1a2aa4f245b1958dc8db6089f24c575ef13Fariborz Jahanian  /// Class interface for this implementation
1081a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *ClassInterface;
1082f4d331dd922f92478ebf30e808c0ca97ce49418bFariborz Jahanian
1083980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  /// Implementation Class's super class.
1084a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *SuperClass;
1085980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
1086980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  /// Optional Ivars/NumIvars - This is a new[]'d array of pointers to Decls.
1087a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCIvarDecl **Ivars;   // Null if not specified
1088f3a7af901231535191d14cb524d58f22907ac4d2Chris Lattner  unsigned NumIvars;      // 0 if none.
10890416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff
1090980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  /// implemented instance methods
1091a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  llvm::SmallVector<ObjCMethodDecl*, 32> InstanceMethods;
10920416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff
1093980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  /// implemented class methods
1094a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  llvm::SmallVector<ObjCMethodDecl*, 32> ClassMethods;
10950416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff
1096f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian  /// Propertys' being implemented
1097f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian  llvm::SmallVector<ObjCPropertyImplDecl*, 8> PropertyImplementations;
1098f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian
10990416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff  SourceLocation EndLoc;
110075c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner
1101a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCImplementationDecl(SourceLocation L, IdentifierInfo *Id,
1102a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek                         ObjCInterfaceDecl *classInterface,
1103a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek                         ObjCInterfaceDecl *superDecl)
11040701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff    : NamedDecl(ObjCImplementation, L, Id), DeclContext(ObjCImplementation),
11050416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff      ClassInterface(classInterface), SuperClass(superDecl),
1106f3a7af901231535191d14cb524d58f22907ac4d2Chris Lattner      Ivars(0), NumIvars(0) {}
110775c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattnerpublic:
11080ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner  static ObjCImplementationDecl *Create(ASTContext &C,
11090ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner                                        SourceLocation L, IdentifierInfo *Id,
111075c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner                                        ObjCInterfaceDecl *classInterface,
111175c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner                                        ObjCInterfaceDecl *superDecl);
111275c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner
1113980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
1114a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void ObjCAddInstanceVariablesToClassImpl(ObjCIvarDecl **ivars,
1115980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff                                           unsigned numIvars);
1116980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
1117a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void addInstanceMethod(ObjCMethodDecl *method) {
11180416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff    InstanceMethods.push_back(method);
11190416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff  }
1120a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  void addClassMethod(ObjCMethodDecl *method) {
11210416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff    ClassMethods.push_back(method);
11220416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff  }
1123f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian
1124f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian  void addPropertyImplementation(ObjCPropertyImplDecl *property) {
1125f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian    PropertyImplementations.push_back(property);
1126f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian  }
1127ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian
1128ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian  ObjCPropertyImplDecl *FindPropertyImplDecl(IdentifierInfo *propertyId) const;
1129ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian  ObjCPropertyImplDecl *FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const;
1130ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian
1131559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  typedef llvm::SmallVector<ObjCPropertyImplDecl*, 8>::const_iterator
1132559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  propimpl_iterator;
1133559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  propimpl_iterator propimpl_begin() const {
1134559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian    return PropertyImplementations.begin();
1135559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  }
1136559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  propimpl_iterator propimpl_end() const {
1137559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian    return PropertyImplementations.end();
1138559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  }
1139f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian
11400416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff  // Location information, modeled after the Stmt API.
11410416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff  SourceLocation getLocStart() const { return getLocation(); }
11420416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff  SourceLocation getLocEnd() const { return EndLoc; }
11430416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff  void setLocEnd(SourceLocation LE) { EndLoc = LE; };
11440416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff
1145e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; }
1146e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
1147e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  const ObjCInterfaceDecl *getSuperClass() const { return SuperClass; }
1148e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner  ObjCInterfaceDecl *getSuperClass() { return SuperClass; }
1149980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
1150f3a7af901231535191d14cb524d58f22907ac4d2Chris Lattner  void setSuperClass(ObjCInterfaceDecl * superCls) { SuperClass = superCls; }
1151980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
1152b5feb35360526da42ad7e3fa7ef3d44a5992b83cChris Lattner  unsigned getNumInstanceMethods() const { return InstanceMethods.size(); }
115362db2f4214c1589082960f12c9cb8924fe0cf8c5Chris Lattner  unsigned getNumClassMethods() const { return ClassMethods.size(); }
1154f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian
1155f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian  unsigned getNumPropertyImplementations() const
1156f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian    { return PropertyImplementations.size(); }
1157c43d868355374d48296ad3be2c9c536698a5e9a8Steve Naroff
1158a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  typedef llvm::SmallVector<ObjCMethodDecl*, 32>::const_iterator
11590157c5144513438bb74aebf50d18f95df4104acbChris Lattner       instmeth_iterator;
11600157c5144513438bb74aebf50d18f95df4104acbChris Lattner  instmeth_iterator instmeth_begin() const { return InstanceMethods.begin(); }
11610157c5144513438bb74aebf50d18f95df4104acbChris Lattner  instmeth_iterator instmeth_end() const { return InstanceMethods.end(); }
11620157c5144513438bb74aebf50d18f95df4104acbChris Lattner
1163a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  typedef llvm::SmallVector<ObjCMethodDecl*, 32>::const_iterator
11640157c5144513438bb74aebf50d18f95df4104acbChris Lattner    classmeth_iterator;
11650157c5144513438bb74aebf50d18f95df4104acbChris Lattner  classmeth_iterator classmeth_begin() const { return ClassMethods.begin(); }
11660157c5144513438bb74aebf50d18f95df4104acbChris Lattner  classmeth_iterator classmeth_end() const { return ClassMethods.end(); }
11670157c5144513438bb74aebf50d18f95df4104acbChris Lattner
116894a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // Get the instance method definition for this implementation.
11693216dcdebb8ae0f2993ac5f5249caa217444bacfDaniel Dunbar  ObjCMethodDecl *getInstanceMethod(Selector Sel) const;
11700157c5144513438bb74aebf50d18f95df4104acbChris Lattner
117194a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff  // Get the class method definition for this implementation.
11723216dcdebb8ae0f2993ac5f5249caa217444bacfDaniel Dunbar  ObjCMethodDecl *getClassMethod(Selector Sel) const;
11730157c5144513438bb74aebf50d18f95df4104acbChris Lattner
1174a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  typedef ObjCIvarDecl * const *ivar_iterator;
11750157c5144513438bb74aebf50d18f95df4104acbChris Lattner  ivar_iterator ivar_begin() const { return Ivars; }
1176f3a7af901231535191d14cb524d58f22907ac4d2Chris Lattner  ivar_iterator ivar_end() const { return Ivars+NumIvars; }
1177f3a7af901231535191d14cb524d58f22907ac4d2Chris Lattner  unsigned ivar_size() const { return NumIvars; }
1178f3a7af901231535191d14cb524d58f22907ac4d2Chris Lattner  bool ivar_empty() const { return NumIvars == 0; }
11790157c5144513438bb74aebf50d18f95df4104acbChris Lattner
1180980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  static bool classof(const Decl *D) {
1181a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek    return D->getKind() == ObjCImplementation;
1182980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff  }
1183a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCImplementationDecl *D) { return true; }
1184b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff  static DeclContext *castToDeclContext(const ObjCImplementationDecl *D) {
1185b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff    return static_cast<DeclContext *>(const_cast<ObjCImplementationDecl*>(D));
1186b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff  }
1187b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff  static ObjCImplementationDecl *castFromDeclContext(const DeclContext *DC) {
1188b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff    return static_cast<ObjCImplementationDecl *>(const_cast<DeclContext*>(DC));
1189b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff  }
1190980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff};
1191243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian
1192a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCCompatibleAliasDecl - Represents alias of a class. This alias is
1193243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian/// declared as @compatibility_alias alias class.
1194e8043c39176e7f253fbd92982b077eca6bf2fd59Steve Naroffclass ObjCCompatibleAliasDecl : public NamedDecl {
1195243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian  /// Class that this is an alias of.
1196a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *AliasedClass;
1197243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian
1198a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCCompatibleAliasDecl(SourceLocation L, IdentifierInfo *Id,
1199e8043c39176e7f253fbd92982b077eca6bf2fd59Steve Naroff                          ObjCInterfaceDecl* aliasedClass)
1200e8043c39176e7f253fbd92982b077eca6bf2fd59Steve Naroff    : NamedDecl(ObjCCompatibleAlias, L, Id), AliasedClass(aliasedClass) {}
1201f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattnerpublic:
12020ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner  static ObjCCompatibleAliasDecl *Create(ASTContext &C,
12030ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner                                         SourceLocation L, IdentifierInfo *Id,
1204f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner                                         ObjCInterfaceDecl* aliasedClass);
1205f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner
1206f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner  const ObjCInterfaceDecl *getClassInterface() const { return AliasedClass; }
1207f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner  ObjCInterfaceDecl *getClassInterface() { return AliasedClass; }
1208980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
1209243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian  static bool classof(const Decl *D) {
12108a934233d1582b5bde9d270bc0705aa81e471a79Chris Lattner    return D->getKind() == ObjCCompatibleAlias;
1211243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian  }
1212a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCCompatibleAliasDecl *D) { return true; }
1213243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian
1214243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian};
12151de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian
12161de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian/// ObjCPropertyDecl - Represents one property declaration in an interface.
12171de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian/// For example:
12181de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian/// @property (assign, readwrite) int MyProperty;
12191de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian///
12201de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanianclass ObjCPropertyDecl : public NamedDecl {
122182a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanianpublic:
1222a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner  enum PropertyAttributeKind {
1223a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_noattr    = 0x00,
1224a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_readonly  = 0x01,
1225a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_getter    = 0x02,
1226a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_assign    = 0x04,
1227a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_readwrite = 0x08,
1228a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_retain    = 0x10,
1229a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_copy      = 0x20,
1230a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_nonatomic = 0x40,
1231a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    OBJC_PR_setter    = 0x80
1232a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner  };
1233af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
1234af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  enum SetterKind { Assign, Retain, Copy };
123546b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  enum PropertyControl { None, Required, Optional };
123682a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanianprivate:
1237dae1a1a2aa4f245b1958dc8db6089f24c575ef13Fariborz Jahanian  QualType DeclType;
1238ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  unsigned PropertyAttributes : 8;
123982a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian
124046b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  // @required/@optional
124146b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  unsigned PropertyImplementation : 2;
124246b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian
12435251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  Selector GetterName;    // getter name of NULL if no getter
12445251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  Selector SetterName;    // setter name of NULL if no setter
124582a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian
124633de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  ObjCMethodDecl *GetterMethodDecl; // Declaration of getter instance method
124733de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  ObjCMethodDecl *SetterMethodDecl; // Declaration of setter instance method
124833de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian
12491de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian  ObjCPropertyDecl(SourceLocation L, IdentifierInfo *Id, QualType T)
12501de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian    : NamedDecl(ObjCProperty, L, Id), DeclType(T),
125133de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian      PropertyAttributes(OBJC_PR_noattr), PropertyImplementation(None),
125233de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian      GetterName(Selector()),
125333de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian      SetterName(Selector()),
125433de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian      GetterMethodDecl(0), SetterMethodDecl(0) {}
1255f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattnerpublic:
12561de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian  static ObjCPropertyDecl *Create(ASTContext &C, SourceLocation L,
125746b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian                                  IdentifierInfo *Id, QualType T,
125846b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian                                  PropertyControl propControl = None);
1259dae1a1a2aa4f245b1958dc8db6089f24c575ef13Fariborz Jahanian  QualType getType() const { return DeclType; }
1260c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian
1261a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner  PropertyAttributeKind getPropertyAttributes() const {
1262f4af5154571e0c5eadb19df10e65464766ef6683Chris Lattner    return PropertyAttributeKind(PropertyAttributes);
1263f4af5154571e0c5eadb19df10e65464766ef6683Chris Lattner  }
1264564576b225386cbff375351597dd5e2a92872d38Fariborz Jahanian  void setPropertyAttributes(PropertyAttributeKind PRVal) {
1265a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner    PropertyAttributes |= PRVal;
126682a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian  }
1267394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar
12688cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian void makeitReadWriteAttribute(void) {
12698cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian    PropertyAttributes &= ~OBJC_PR_readonly;
12708cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian    PropertyAttributes |= OBJC_PR_readwrite;
12718cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian }
12728cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian
1273af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  // Helper methods for accessing attributes.
1274af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
1275af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  /// isReadOnly - Return true iff the property has a setter.
1276394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar  bool isReadOnly() const {
1277394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar    return (PropertyAttributes & OBJC_PR_readonly);
1278394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar  }
1279af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
1280af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  /// getSetterKind - Return the method used for doing assignment in
1281af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  /// the property setter. This is only valid if the property has been
1282af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  /// defined to have a setter.
1283af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  SetterKind getSetterKind() const {
1284af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar    if (PropertyAttributes & OBJC_PR_retain)
1285af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar      return Retain;
1286af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar    if (PropertyAttributes & OBJC_PR_copy)
1287af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar      return Copy;
1288af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar    return Assign;
1289af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  }
1290af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
12915251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  Selector getGetterName() const { return GetterName; }
12925251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  void setGetterName(Selector Sel) { GetterName = Sel; }
129382a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian
12945251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  Selector getSetterName() const { return SetterName; }
12955251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian  void setSetterName(Selector Sel) { SetterName = Sel; }
129682a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian
129733de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  ObjCMethodDecl *getGetterMethodDecl() const { return GetterMethodDecl; }
129833de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  void setGetterMethodDecl(ObjCMethodDecl *gDecl) { GetterMethodDecl = gDecl; }
129933de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian
130033de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  ObjCMethodDecl *getSetterMethodDecl() const { return SetterMethodDecl; }
130133de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian  void setSetterMethodDecl(ObjCMethodDecl *gDecl) { SetterMethodDecl = gDecl; }
130233de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian
130346b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  // Related to @optional/@required declared in @protocol
130446b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  void setPropertyImplementation(PropertyControl pc) {
130546b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian    PropertyImplementation = pc;
130646b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  }
130746b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  PropertyControl getPropertyImplementation() const {
130846b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian    return PropertyControl(PropertyImplementation);
130946b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian  }
131046b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian
131182a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian  static bool classof(const Decl *D) {
1312670aa9d7639278f507930e95dc89c12032ab7c7eSam Bishop    return D->getKind() == ObjCProperty;
131382a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian  }
1314a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCPropertyDecl *D) { return true; }
131582a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian};
1316980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff
131761d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian/// ObjCPropertyImplDecl - Represents implementation declaration of a property
131861d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian/// in a class or category implementation block. For example:
131961d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian/// @synthesize prop1 = ivar1;
132061d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian///
132161d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanianclass ObjCPropertyImplDecl : public Decl {
132261d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanianpublic:
13239f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar  enum Kind {
13249f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar    Synthesize,
13259f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar    Dynamic
132661d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  };
132761d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanianprivate:
1328559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian  SourceLocation AtLoc;   // location of @synthesize or @dynamic
132961d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  /// Property declaration being implemented
133061d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  ObjCPropertyDecl *PropertyDecl;
1331be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek
133261d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  /// Null for @dynamic. Required for @synthesize.
133361d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  ObjCIvarDecl *PropertyIvarDecl;
1334be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek
1335628b96f34e93b643b6e15e75eabb8d96079a7e27Fariborz Jahanian  ObjCPropertyImplDecl(SourceLocation atLoc, SourceLocation L,
1336628b96f34e93b643b6e15e75eabb8d96079a7e27Fariborz Jahanian                       ObjCPropertyDecl *property,
13379f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar                       Kind PK,
1338628b96f34e93b643b6e15e75eabb8d96079a7e27Fariborz Jahanian                       ObjCIvarDecl *ivarDecl)
13399f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar    : Decl(ObjCPropertyImpl, L), AtLoc(atLoc), PropertyDecl(property),
13409f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar      PropertyIvarDecl(ivarDecl) {
13419f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar    assert (PK == Dynamic || PropertyIvarDecl);
13429f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar  }
1343628b96f34e93b643b6e15e75eabb8d96079a7e27Fariborz Jahanian
13449f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbarpublic:
1345628b96f34e93b643b6e15e75eabb8d96079a7e27Fariborz Jahanian  static ObjCPropertyImplDecl *Create(ASTContext &C, SourceLocation atLoc,
1346628b96f34e93b643b6e15e75eabb8d96079a7e27Fariborz Jahanian                                      SourceLocation L,
1347628b96f34e93b643b6e15e75eabb8d96079a7e27Fariborz Jahanian                                      ObjCPropertyDecl *property,
13489f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar                                      Kind PK,
1349628b96f34e93b643b6e15e75eabb8d96079a7e27Fariborz Jahanian                                      ObjCIvarDecl *ivarDecl);
135061d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian
1351d40910b581b09c937a8c1fdcde9b8ec724398fb9Steve Naroff  SourceLocation getLocStart() const { return AtLoc; }
1352d40910b581b09c937a8c1fdcde9b8ec724398fb9Steve Naroff
1353be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek  ObjCPropertyDecl *getPropertyDecl() const {
1354be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek    return PropertyDecl;
1355be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek  }
135661d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian
13579f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar  Kind getPropertyImplementation() const {
13589f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar    return PropertyIvarDecl ? Synthesize : Dynamic;
1359be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek  }
136061d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian
1361af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  ObjCIvarDecl *getPropertyIvarDecl() const {
1362be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek    return PropertyIvarDecl;
1363be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek  }
136461d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian
136561d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  static bool classof(const Decl *D) {
136661d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian    return D->getKind() == ObjCPropertyImpl;
136761d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  }
136861d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian  static bool classof(const ObjCPropertyImplDecl *D) { return true; }
136961d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian};
137061d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian
1371980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff}  // end namespace clang
1372980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff#endif
1373