DeclObjC.h revision 07fa7749da805969f2ed467a4eb5b405a4ff9a23
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 54e881483a3bc22ffad62367501aa09ad8508fe363Chris Lattner void clear() { 55e881483a3bc22ffad62367501aa09ad8508fe363Chris Lattner delete[] List; 56e881483a3bc22ffad62367501aa09ad8508fe363Chris Lattner NumElts = 0; 57e881483a3bc22ffad62367501aa09ad8508fe363Chris Lattner } 58e881483a3bc22ffad62367501aa09ad8508fe363Chris Lattner 593db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner void set(T* const* InList, unsigned Elts) { 603db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner assert(List == 0 && "Elements already set!"); 61e881483a3bc22ffad62367501aa09ad8508fe363Chris Lattner if (Elts == 0) return; // Setting to an empty list is a noop. 62e881483a3bc22ffad62367501aa09ad8508fe363Chris Lattner 633db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner List = new T*[Elts]; 643db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner NumElts = Elts; 653db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner memcpy(List, InList, sizeof(T*)*Elts); 663db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner } 673db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner 683db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner typedef T* const * iterator; 693db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner iterator begin() const { return List; } 703db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner iterator end() const { return List+NumElts; } 713db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner 723db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner unsigned size() const { return NumElts; } 733db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner bool empty() const { return NumElts == 0; } 743db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner 75780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner T* operator[](unsigned idx) const { 763db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner assert(idx < NumElts && "Invalid access"); 773db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner return List[idx]; 783db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner } 793db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner}; 803db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner 813db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner 8258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff 83a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCMethodDecl - Represents an instance or class method declaration. 8458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// ObjC methods can be declared within 4 contexts: class interfaces, 8558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// categories, protocols, and class implementations. While C++ member 8658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// functions leverage C syntax, Objective-C method syntax is modeled after 8758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Smalltalk (using colons to specify argument types/expressions). 8858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Here are some brief examples: 8958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// 9058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Setter/getter instance methods: 9158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// - (void)setMenu:(NSMenu *)menu; 9258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// - (NSMenu *)menu; 9358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// 9458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Instance method that takes 2 NSView arguments: 9558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// - (void)replaceSubview:(NSView *)oldView with:(NSView *)newView; 9658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// 9758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Getter class method: 9858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// + (NSMenu *)defaultMenu; 9958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// 10058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// A selector represents a unique name for a method. The selector names for 10158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// the above methods are setMenu:, menu, replaceSubview:with:, and defaultMenu. 10258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// 1034afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCMethodDecl : public NamedDecl, public DeclContext { 10458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroffpublic: 10558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff enum ImplementationControl { None, Required, Optional }; 10658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroffprivate: 10758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff /// Bitfields must be first fields in this class so they pack with those 10858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff /// declared in class Decl. 10958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff /// instance (true) or class (false) method. 11058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff bool IsInstance : 1; 11158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff bool IsVariadic : 1; 11258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff 1134607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian // Synthesized declaration method for a property setter/getter 1144607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian bool IsSynthesized : 1; 1154607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian 116ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek // NOTE: VC++ treats enums as signed, avoid using ImplementationControl enum 11758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff /// @required/@optional 118ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek unsigned DeclImplementation : 2; 11958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff 120ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek // NOTE: VC++ treats enums as signed, avoid using the ObjCDeclQualifier enum 12158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff /// in, inout, etc. 122ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek unsigned objcDeclQualifier : 6; 12358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff 12458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff // Type of this method. 12558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff QualType MethodDeclType; 1262073216a1075767b5d25c23d1462b7034686d94dChris Lattner /// ParamInfo - List of pointers to VarDecls for the formal parameters of this 1272073216a1075767b5d25c23d1462b7034686d94dChris Lattner /// Method. 1282073216a1075767b5d25c23d1462b7034686d94dChris Lattner ObjCList<ParmVarDecl> ParamInfo; 12958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff 13058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff /// List of attributes for this method declaration. 13158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff SourceLocation EndLoc; // the location of the ';' or '{'. 13258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff 13358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff // The following are only used for method definitions, null otherwise. 13458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff // FIXME: space savings opportunity, consider a sub-class. 13558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff Stmt *Body; 136451318c08a6342c10b8986060386fd9274418437Daniel Dunbar 137451318c08a6342c10b8986060386fd9274418437Daniel Dunbar /// SelfDecl - Decl for the implicit self parameter. This is lazily 138451318c08a6342c10b8986060386fd9274418437Daniel Dunbar /// constructed by createImplicitParams. 1394111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner ImplicitParamDecl *SelfDecl; 140451318c08a6342c10b8986060386fd9274418437Daniel Dunbar /// CmdDecl - Decl for the implicit _cmd parameter. This is lazily 141451318c08a6342c10b8986060386fd9274418437Daniel Dunbar /// constructed by createImplicitParams. 1424111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner ImplicitParamDecl *CmdDecl; 1436c4ae5de0c356777446f823b573821fb95560d91Chris Lattner 144a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCMethodDecl(SourceLocation beginLoc, SourceLocation endLoc, 14558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff Selector SelInfo, QualType T, 1460701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff DeclContext *contextDecl, 147f6414927e67e27d9324d8d179c5f7ea620443924Daniel Dunbar bool isInstance = true, 14858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff bool isVariadic = false, 1494607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian bool isSynthesized = false, 15058cce3b0dcbdcc95b7e713795834b4cb2c8a008aChris Lattner ImplementationControl impControl = None) 1514afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor : NamedDecl(ObjCMethod, contextDecl, beginLoc, SelInfo), 152b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner DeclContext(ObjCMethod), 15358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff IsInstance(isInstance), IsVariadic(isVariadic), 1544607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian IsSynthesized(isSynthesized), 15558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff DeclImplementation(impControl), objcDeclQualifier(OBJC_TQ_None), 1562e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor MethodDeclType(T), 1574111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner EndLoc(endLoc), Body(0), SelfDecl(0), CmdDecl(0) {} 1588a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek 1592073216a1075767b5d25c23d1462b7034686d94dChris Lattner virtual ~ObjCMethodDecl() {} 1601c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek 1616c4ae5de0c356777446f823b573821fb95560d91Chris Lattnerpublic: 1628a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek 1638a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek /// Destroy - Call destructors and release memory. 1648a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek virtual void Destroy(ASTContext& C); 1656c4ae5de0c356777446f823b573821fb95560d91Chris Lattner 1660ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner static ObjCMethodDecl *Create(ASTContext &C, 1670ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner SourceLocation beginLoc, 1686c4ae5de0c356777446f823b573821fb95560d91Chris Lattner SourceLocation endLoc, Selector SelInfo, 1690701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff QualType T, DeclContext *contextDecl, 170f6414927e67e27d9324d8d179c5f7ea620443924Daniel Dunbar bool isInstance = true, 1716c4ae5de0c356777446f823b573821fb95560d91Chris Lattner bool isVariadic = false, 1724607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian bool isSynthesized = false, 173b06fa3b86951b9f179c99c3768331536c32e902dChris Lattner ImplementationControl impControl = None); 17458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff 175ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek ObjCDeclQualifier getObjCDeclQualifier() const { 176ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek return ObjCDeclQualifier(objcDeclQualifier); 177ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek } 178a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek void setObjCDeclQualifier(ObjCDeclQualifier QV) { objcDeclQualifier = QV; } 17958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff 18058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff // Location information, modeled after the Stmt API. 18158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff SourceLocation getLocStart() const { return getLocation(); } 18258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff SourceLocation getLocEnd() const { return EndLoc; } 1839776ba0d844cf9f6888e871e3fd246ae782f76f4Daniel Dunbar SourceRange getSourceRange() const { 1849776ba0d844cf9f6888e871e3fd246ae782f76f4Daniel Dunbar return SourceRange(getLocation(), EndLoc); 1859776ba0d844cf9f6888e871e3fd246ae782f76f4Daniel Dunbar } 1863e0a540b6d846178857289ec0eb8470a278d11a3Steve Naroff 1875619688510185081cbb4621d703daf7ee24cf39aChris Lattner ObjCInterfaceDecl *getClassInterface(); 1885619688510185081cbb4621d703daf7ee24cf39aChris Lattner const ObjCInterfaceDecl *getClassInterface() const { 1895619688510185081cbb4621d703daf7ee24cf39aChris Lattner return const_cast<ObjCMethodDecl*>(this)->getClassInterface(); 190e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner } 19158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff 1922e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor Selector getSelector() const { return getDeclName().getObjCSelector(); } 193faf5e779d16bb4590f2a97e1c7ded255eddd90f3Fariborz Jahanian unsigned getSynthesizedMethodSize() const; 19458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff QualType getResultType() const { return MethodDeclType; } 19558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff 196d57f635d520e8cb5b93d3d770ff58db06c62de54Chris Lattner // Iterator access to formal parameters. 1972073216a1075767b5d25c23d1462b7034686d94dChris Lattner unsigned param_size() const { return ParamInfo.size(); } 1982073216a1075767b5d25c23d1462b7034686d94dChris Lattner typedef ObjCList<ParmVarDecl>::iterator param_iterator; 1992073216a1075767b5d25c23d1462b7034686d94dChris Lattner param_iterator param_begin() const { return ParamInfo.begin(); } 2002073216a1075767b5d25c23d1462b7034686d94dChris Lattner param_iterator param_end() const { return ParamInfo.end(); } 2012073216a1075767b5d25c23d1462b7034686d94dChris Lattner 2022073216a1075767b5d25c23d1462b7034686d94dChris Lattner unsigned getNumParams() const { return ParamInfo.size(); } 20358cce3b0dcbdcc95b7e713795834b4cb2c8a008aChris Lattner ParmVarDecl *getParamDecl(unsigned i) const { 20458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff return ParamInfo[i]; 20558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff } 2062073216a1075767b5d25c23d1462b7034686d94dChris Lattner void setMethodParams(ParmVarDecl *const *NewParamInfo, unsigned NumParams) { 2072073216a1075767b5d25c23d1462b7034686d94dChris Lattner ParamInfo.set(NewParamInfo, NumParams); 2082073216a1075767b5d25c23d1462b7034686d94dChris Lattner } 2094111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner 210451318c08a6342c10b8986060386fd9274418437Daniel Dunbar /// createImplicitParams - Used to lazily create the self and cmd 211451318c08a6342c10b8986060386fd9274418437Daniel Dunbar /// implict parameters. This must be called prior to using getSelfDecl() 212451318c08a6342c10b8986060386fd9274418437Daniel Dunbar /// or getCmdDecl(). The call is ignored if the implicit paramters 213451318c08a6342c10b8986060386fd9274418437Daniel Dunbar /// have already been created. 214fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian void createImplicitParams(ASTContext &Context, const ObjCInterfaceDecl *ID); 215451318c08a6342c10b8986060386fd9274418437Daniel Dunbar 2164111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner ImplicitParamDecl * getSelfDecl() const { return SelfDecl; } 2174111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner ImplicitParamDecl * getCmdDecl() const { return CmdDecl; } 21858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff 219f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor bool isInstanceMethod() const { return IsInstance; } 22058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff bool isVariadic() const { return IsVariadic; } 22158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff 222f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor bool isClassMethod() const { return !IsInstance; } 223f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 2244607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian bool isSynthesized() const { return IsSynthesized; } 22591b51a92f2e9fc8025b6a9df88442840eb62823aFariborz Jahanian void setIsSynthesized() { IsSynthesized = true; } 2264607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian 22758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff // Related to protocols declared in @protocol 22858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff void setDeclImplementation(ImplementationControl ic) { 22958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff DeclImplementation = ic; 23058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff } 23158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff ImplementationControl getImplementationControl() const { 232ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek return ImplementationControl(DeclImplementation); 23358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff } 234792481eec23d8c1aa92173be589e2ae9d02514a5Ted Kremenek 23569c8f0aab655257e9e532d9d53756acf4f7a2d78Ted Kremenek virtual Stmt *getBody() const { return Body; } 23658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff void setBody(Stmt *B) { Body = B; } 23758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff 23858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff // Implement isa/cast/dyncast/etc. 239a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const Decl *D) { return D->getKind() == ObjCMethod; } 240a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCMethodDecl *D) { return true; } 24142220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis static DeclContext *castToDeclContext(const ObjCMethodDecl *D) { 24242220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis return static_cast<DeclContext *>(const_cast<ObjCMethodDecl*>(D)); 24342220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis } 24442220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis static ObjCMethodDecl *castFromDeclContext(const DeclContext *DC) { 24542220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis return static_cast<ObjCMethodDecl *>(const_cast<DeclContext*>(DC)); 24642220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis } 24758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff}; 248e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff 249e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff/// ObjCContainerDecl - Represents a container for method declarations. 250e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff/// Current sub-classes are ObjCInterfaceDecl, ObjCCategoryDecl, and 2510701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff/// ObjCProtocolDecl. 2520701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff/// FIXME: Use for ObjC implementation decls. 253e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff/// 2544afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCContainerDecl : public NamedDecl, public DeclContext { 255e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff SourceLocation AtEndLoc; // marks the end of the method container. 256e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroffpublic: 257e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff 258d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor ObjCContainerDecl(Kind DK, DeclContext *DC, SourceLocation L, 259d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor IdentifierInfo *Id) 2604afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor : NamedDecl(DK, DC, L, Id), DeclContext(DK) {} 261e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff 2620b7ebb3dba0df0a6cbf221e5edbc6a4b8848478cChris Lattner virtual ~ObjCContainerDecl() {} 26309c4719788a5cea09897525e528fa00420f1677bSteve Naroff 26493983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff // Iterator access to properties. 26593983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff typedef specific_decl_iterator<ObjCPropertyDecl> prop_iterator; 26693983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff prop_iterator prop_begin() const { 267d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor return prop_iterator(decls_begin()); 26893983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff } 26993983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff prop_iterator prop_end() const { 270d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor return prop_iterator(decls_end()); 27109c4719788a5cea09897525e528fa00420f1677bSteve Naroff } 27209c4719788a5cea09897525e528fa00420f1677bSteve Naroff 2730701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff // Iterator access to instance/class methods. 274f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor typedef specific_decl_iterator<ObjCMethodDecl> method_iterator; 275f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor method_iterator meth_begin() const { 276d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor return method_iterator(decls_begin()); 2777ed4faca5162b3ab85be7f7e57aa40e6ec170971Ted Kremenek } 278f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor method_iterator meth_end() const { 279d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor return method_iterator(decls_end()); 2807ed4faca5162b3ab85be7f7e57aa40e6ec170971Ted Kremenek } 2810701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff 282669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor typedef filtered_decl_iterator<ObjCMethodDecl, 283669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor &ObjCMethodDecl::isInstanceMethod> 284669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor instmeth_iterator; 2850701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff instmeth_iterator instmeth_begin() const { 286669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor return instmeth_iterator(decls_begin()); 287e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff } 2880701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff instmeth_iterator instmeth_end() const { 289669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor return instmeth_iterator(decls_end()); 290e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff } 291e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff 292669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor typedef filtered_decl_iterator<ObjCMethodDecl, 293669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor &ObjCMethodDecl::isClassMethod> 294669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor classmeth_iterator; 2950701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff classmeth_iterator classmeth_begin() const { 296669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor return classmeth_iterator(decls_begin()); 297e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff } 2980701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff classmeth_iterator classmeth_end() const { 299669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor return classmeth_iterator(decls_end()); 3000701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff } 3010701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff 3020701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff // Get the local instance/class method declared in this interface. 3030701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff ObjCMethodDecl *getInstanceMethod(Selector Sel) const; 3040701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff ObjCMethodDecl *getClassMethod(Selector Sel) const; 30553df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner ObjCMethodDecl *getMethod(Selector Sel, bool isInstance) const { 30653df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner return isInstance ? getInstanceMethod(Sel) : getClassMethod(Sel); 30753df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner } 3086327e0d55c590b3c2766fa76ef1db241a0467df2Steve Naroff 30993983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff ObjCPropertyDecl *FindPropertyDeclaration(IdentifierInfo *PropertyId) const; 31093983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff 3116327e0d55c590b3c2766fa76ef1db241a0467df2Steve Naroff // Get the number of methods, properties. These methods are slow, O(n). 3120701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff unsigned getNumInstanceMethods() const; 3130701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff unsigned getNumClassMethods() const; 3146327e0d55c590b3c2766fa76ef1db241a0467df2Steve Naroff unsigned getNumProperties() const; 315b245a33e6f562377946dc9cb5694a2d3cb8a98a3Fariborz Jahanian 316e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff // Marks the end of the container. 317e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff SourceLocation getAtEndLoc() const { return AtEndLoc; } 3180701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff void setAtEndLoc(SourceLocation L) { AtEndLoc = L; } 31909c4719788a5cea09897525e528fa00420f1677bSteve Naroff 32009c4719788a5cea09897525e528fa00420f1677bSteve Naroff // Implement isa/cast/dyncast/etc. 32109c4719788a5cea09897525e528fa00420f1677bSteve Naroff static bool classof(const Decl *D) { 32209c4719788a5cea09897525e528fa00420f1677bSteve Naroff return D->getKind() >= ObjCContainerFirst && 32309c4719788a5cea09897525e528fa00420f1677bSteve Naroff D->getKind() <= ObjCContainerLast; 32409c4719788a5cea09897525e528fa00420f1677bSteve Naroff } 32509c4719788a5cea09897525e528fa00420f1677bSteve Naroff static bool classof(const ObjCContainerDecl *D) { return true; } 32609c4719788a5cea09897525e528fa00420f1677bSteve Naroff 32709c4719788a5cea09897525e528fa00420f1677bSteve Naroff static DeclContext *castToDeclContext(const ObjCContainerDecl *D) { 32809c4719788a5cea09897525e528fa00420f1677bSteve Naroff return static_cast<DeclContext *>(const_cast<ObjCContainerDecl*>(D)); 32909c4719788a5cea09897525e528fa00420f1677bSteve Naroff } 33009c4719788a5cea09897525e528fa00420f1677bSteve Naroff static ObjCContainerDecl *castFromDeclContext(const DeclContext *DC) { 33109c4719788a5cea09897525e528fa00420f1677bSteve Naroff return static_cast<ObjCContainerDecl *>(const_cast<DeclContext*>(DC)); 33209c4719788a5cea09897525e528fa00420f1677bSteve Naroff } 333e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff}; 334e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff 335a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCInterfaceDecl - Represents an ObjC class declaration. For example: 3360c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 3370c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// // MostPrimitive declares no super class (not particularly useful). 3380c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @interface MostPrimitive 3390c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// // no instance variables or methods. 3400c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end 3410c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 342fd5de471478a507dd2495c4ea9bcab801ea5fa65Chris Lattner/// // NSResponder inherits from NSObject & implements NSCoding (a protocol). 3430c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @interface NSResponder : NSObject <NSCoding> 344a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// { // instance variables are represented by ObjCIvarDecl. 3450c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// id nextResponder; // nextResponder instance variable. 3460c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// } 3470c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (NSResponder *)nextResponder; // return a pointer to NSResponder. 3480c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (void)mouseMoved:(NSEvent *)theEvent; // return void, takes a pointer 3490c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end // to an NSEvent. 3500c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 3510c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// Unlike C/C++, forward class declarations are accomplished with @class. 3520c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// Unlike C/C++, @class allows for a list of classes to be forward declared. 3530c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// Unlike C++, ObjC is a single-rooted class model. In Cocoa, classes 3540c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// typically inherit from NSObject (an exception is NSProxy). 3550c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 3560701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroffclass ObjCInterfaceDecl : public ObjCContainerDecl { 3573110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff /// TypeForDecl - This indicates the Type object that represents this 3583110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff /// TypeDecl. It is a cache maintained by ASTContext::getObjCInterfaceType 3593110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff Type *TypeForDecl; 3603110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff friend class ASTContext; 361980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 362980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff /// Class's super class. 363a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *SuperClass; 364980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 365980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff /// Protocols referenced in interface header declaration 3663db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner ObjCList<ObjCProtocolDecl> ReferencedProtocols; 367980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 368e881483a3bc22ffad62367501aa09ad8508fe363Chris Lattner /// Instance variables in the interface. 369e881483a3bc22ffad62367501aa09ad8508fe363Chris Lattner ObjCList<ObjCIvarDecl> IVars; 370980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 371980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff /// List of categories defined for this class. 372a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCCategoryDecl *CategoryList; 37382a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian 3743a3ca1b35a7121aea0bf465a192dce748465e10fFariborz Jahanian bool ForwardDecl:1; // declared with @class. 3753a3ca1b35a7121aea0bf465a192dce748465e10fFariborz Jahanian bool InternalInterface:1; // true - no @interface for @implementation 37660fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff 377d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff SourceLocation ClassLoc; // location of the class identifier. 378d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff SourceLocation SuperClassLoc; // location of the super class identifier. 379f908a87299d278164540f90b5b6e6cab7b14fb41Steve Naroff SourceLocation EndLoc; // marks the '>', '}', or identifier. 3800e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner 381d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id, 3820b7ebb3dba0df0a6cbf221e5edbc6a4b8848478cChris Lattner SourceLocation CLoc, bool FD, bool isInternal); 3838a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek 384e881483a3bc22ffad62367501aa09ad8508fe363Chris Lattner virtual ~ObjCInterfaceDecl() {} 3858a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek 3860e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattnerpublic: 3870e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner 3888a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek /// Destroy - Call destructors and release memory. 3898a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek virtual void Destroy(ASTContext& C); 3908a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek 391d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor static ObjCInterfaceDecl *Create(ASTContext &C, DeclContext *DC, 3920ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner SourceLocation atLoc, 393d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff IdentifierInfo *Id, 394d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff SourceLocation ClassLoc = SourceLocation(), 3950e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner bool ForwardDecl = false, 3960e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner bool isInternal = false); 3973db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner const ObjCList<ObjCProtocolDecl> &getReferencedProtocols() const { 3987ed9e0f97f4645edc5d4670385b985ea4c617ce7Fariborz Jahanian return ReferencedProtocols; 3997ed9e0f97f4645edc5d4670385b985ea4c617ce7Fariborz Jahanian } 400980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 401559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian ObjCCategoryDecl *FindCategoryDeclaration(IdentifierInfo *CategoryId) const; 4023db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner 4033db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner typedef ObjCList<ObjCProtocolDecl>::iterator protocol_iterator; 4043db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();} 4053db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner protocol_iterator protocol_end() const { return ReferencedProtocols.end(); } 406aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian 407e881483a3bc22ffad62367501aa09ad8508fe363Chris Lattner typedef ObjCList<ObjCIvarDecl>::iterator ivar_iterator; 408e881483a3bc22ffad62367501aa09ad8508fe363Chris Lattner ivar_iterator ivar_begin() const { return IVars.begin(); } 409e881483a3bc22ffad62367501aa09ad8508fe363Chris Lattner ivar_iterator ivar_end() const { return IVars.end(); } 410e881483a3bc22ffad62367501aa09ad8508fe363Chris Lattner unsigned ivar_size() const { return IVars.size(); } 411e881483a3bc22ffad62367501aa09ad8508fe363Chris Lattner bool ivar_empty() const { return IVars.empty(); } 412e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff 413b752f289026ad8e5f44851b20e009a27ed61eefcChris Lattner /// addReferencedProtocols - Set the list of protocols that this interface 414b752f289026ad8e5f44851b20e009a27ed61eefcChris Lattner /// implements. 415780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner void addReferencedProtocols(ObjCProtocolDecl *const*List, unsigned NumRPs) { 416780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner ReferencedProtocols.set(List, NumRPs); 4173db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner } 418b752f289026ad8e5f44851b20e009a27ed61eefcChris Lattner 419e881483a3bc22ffad62367501aa09ad8508fe363Chris Lattner void addInstanceVariablesToClass(ObjCIvarDecl * const* ivars, unsigned Num, 420e881483a3bc22ffad62367501aa09ad8508fe363Chris Lattner SourceLocation RBracLoc) { 421e881483a3bc22ffad62367501aa09ad8508fe363Chris Lattner IVars.set(ivars, Num); 422e881483a3bc22ffad62367501aa09ad8508fe363Chris Lattner setLocEnd(RBracLoc); 423e881483a3bc22ffad62367501aa09ad8508fe363Chris Lattner } 424fd64bb635dc221baa19f81d5d2a084f7eb269f7fFariborz Jahanian FieldDecl *lookupFieldDeclForIvar(ASTContext &Context, 425fd64bb635dc221baa19f81d5d2a084f7eb269f7fFariborz Jahanian const ObjCIvarDecl *ivar); 426980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 427768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff bool isForwardDecl() const { return ForwardDecl; } 428768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff void setForwardDecl(bool val) { ForwardDecl = val; } 429980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 430a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *getSuperClass() const { return SuperClass; } 431a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek void setSuperClass(ObjCInterfaceDecl * superCls) { SuperClass = superCls; } 432980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 433a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCCategoryDecl* getCategoryList() const { return CategoryList; } 434a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek void setCategoryList(ObjCCategoryDecl *category) { 43553efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner CategoryList = category; 436980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff } 43753efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner 43853efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner /// isSuperClassOf - Return true if this class is the specified class or is a 43953efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner /// super class of the specified interface class. 44053efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner bool isSuperClassOf(const ObjCInterfaceDecl *I) const { 44153efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner // If RHS is derived from LHS it is OK; else it is not OK. 44253efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner while (I != NULL) { 44353efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner if (this == I) 44453efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner return true; 44553efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner I = I->getSuperClass(); 44653efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner } 44753efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner return false; 44853efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner } 44953efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner 45068a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName, 45168a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner ObjCInterfaceDecl *&ClassDeclared); 45268a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName) { 45368a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner ObjCInterfaceDecl *ClassDeclared; 45468a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner return lookupInstanceVariable(IVarName, ClassDeclared); 45568a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner } 45668a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner 45794a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff // Lookup a method. First, we search locally. If a method isn't 45894a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff // found, we search referenced protocols and class categories. 459a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCMethodDecl *lookupInstanceMethod(Selector Sel); 460a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCMethodDecl *lookupClassMethod(Selector Sel); 46160fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff 462f908a87299d278164540f90b5b6e6cab7b14fb41Steve Naroff // Location information, modeled after the Stmt API. 46360fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff SourceLocation getLocStart() const { return getLocation(); } // '@'interface 464f908a87299d278164540f90b5b6e6cab7b14fb41Steve Naroff SourceLocation getLocEnd() const { return EndLoc; } 465f908a87299d278164540f90b5b6e6cab7b14fb41Steve Naroff void setLocEnd(SourceLocation LE) { EndLoc = LE; }; 46660fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff 467d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff SourceLocation getClassLoc() const { return ClassLoc; } 468d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff void setSuperClassLoc(SourceLocation Loc) { SuperClassLoc = Loc; } 469d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff SourceLocation getSuperClassLoc() const { return SuperClassLoc; } 470e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff 4714b6df3fa953267c5d755628c8afd818bb571e579Fariborz Jahanian /// ImplicitInterfaceDecl - check that this is an implicitely declared 472a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek /// ObjCInterfaceDecl node. This is for legacy objective-c @implementation 4734b6df3fa953267c5d755628c8afd818bb571e579Fariborz Jahanian /// declaration without an @interface declaration. 4743a3ca1b35a7121aea0bf465a192dce748465e10fFariborz Jahanian bool ImplicitInterfaceDecl() const { return InternalInterface; } 4754b6df3fa953267c5d755628c8afd818bb571e579Fariborz Jahanian 476a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const Decl *D) { return D->getKind() == ObjCInterface; } 477a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCInterfaceDecl *D) { return true; } 478980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff}; 479980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 480a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCIvarDecl - Represents an ObjC instance variable. In general, ObjC 4810c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// instance variables are identical to C. The only exception is Objective-C 4820c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// supports C++ style access control. For example: 4830c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 4840c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @interface IvarExample : NSObject 4850c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// { 486f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek/// id defaultToProtected; 4870c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @public: 4880c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// id canBePublic; // same as C++. 4890c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @protected: 4900c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// id canBeProtected; // same as C++. 4910c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @package: 4920c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// id canBePackage; // framework visibility (not available in C++). 4930c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// } 4940c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 495a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCIvarDecl : public FieldDecl { 4960e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattnerpublic: 497980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff enum AccessControl { 498980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff None, Private, Protected, Public, Package 499980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff }; 500f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek 501b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenekprivate: 5020c00aac5d618f39afc406c5b2e07642930af1d56Argyrios Kyrtzidis ObjCIvarDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id, 5030c00aac5d618f39afc406c5b2e07642930af1d56Argyrios Kyrtzidis QualType T, AccessControl ac, Expr *BW) 5040c00aac5d618f39afc406c5b2e07642930af1d56Argyrios Kyrtzidis : FieldDecl(ObjCIvar, DC, L, Id, T, BW, /*Mutable=*/false), 50544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor DeclAccess(ac) {} 506b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenek 507b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenekpublic: 5080c00aac5d618f39afc406c5b2e07642930af1d56Argyrios Kyrtzidis static ObjCIvarDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L, 509b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenek IdentifierInfo *Id, QualType T, 510b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenek AccessControl ac, Expr *BW = NULL); 511b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenek 512980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff void setAccessControl(AccessControl ac) { DeclAccess = ac; } 513f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek 514ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek AccessControl getAccessControl() const { return AccessControl(DeclAccess); } 515f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek 516f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek AccessControl getCanonicalAccessControl() const { 517f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek return DeclAccess == None ? Protected : AccessControl(DeclAccess); 518f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek } 519980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 520980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff // Implement isa/cast/dyncast/etc. 521a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const Decl *D) { return D->getKind() == ObjCIvar; } 522a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCIvarDecl *D) { return true; } 523980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffprivate: 524ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek // NOTE: VC++ treats enums as signed, avoid using the AccessControl enum 525ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek unsigned DeclAccess : 3; 526980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff}; 527980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 52801e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek 52901e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek/// ObjCAtDefsFieldDecl - Represents a field declaration created by an 53001e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek/// @defs(...). 53101e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenekclass ObjCAtDefsFieldDecl : public FieldDecl { 53201e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenekprivate: 53344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor ObjCAtDefsFieldDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id, 53401e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek QualType T, Expr *BW) 5354afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor : FieldDecl(ObjCAtDefsField, DC, L, Id, T, BW, /*Mutable=*/false) {} 53601e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek 53701e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenekpublic: 53844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor static ObjCAtDefsFieldDecl *Create(ASTContext &C, DeclContext *DC, 53944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor SourceLocation L, 54001e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek IdentifierInfo *Id, QualType T, 54101e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek Expr *BW); 54201e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek 54301e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek virtual void Destroy(ASTContext& C); 54401e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek 54501e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek // Implement isa/cast/dyncast/etc. 54601e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek static bool classof(const Decl *D) { return D->getKind() == ObjCAtDefsField; } 54701e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek static bool classof(const ObjCAtDefsFieldDecl *D) { return true; } 54801e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek}; 549980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 550a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCProtocolDecl - Represents a protocol declaration. ObjC protocols 5510c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// declare a pure abstract type (i.e no instance variables are permitted). 5520c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// Protocols orginally drew inspiration from C++ pure virtual functions (a C++ 5530c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// feature with nice semantics and lousy syntax:-). Here is an example: 5540c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 555eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// @protocol NSDraggingInfo <refproto1, refproto2> 5560c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (NSWindow *)draggingDestinationWindow; 5570c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (NSImage *)draggedImage; 5580c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end 5590c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 560eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// This says that NSDraggingInfo requires two methods and requires everything 561eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// that the two "referenced protocols" 'refproto1' and 'refproto2' require as 562eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// well. 563eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// 5640c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @interface ImplementsNSDraggingInfo : NSObject <NSDraggingInfo> 5650c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end 5660c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 567a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjC protocols inspired Java interfaces. Unlike Java, ObjC classes and 5680c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// protocols are in distinct namespaces. For example, Cocoa defines both 5690c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// an NSObject protocol and class (which isn't allowed in Java). As a result, 5700c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// protocols are referenced using angle brackets as follows: 5710c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 5720c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// id <NSDraggingInfo> anyObjectThatImplementsNSDraggingInfo; 5730c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 574e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroffclass ObjCProtocolDecl : public ObjCContainerDecl { 575780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner /// Referenced protocols 576780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner ObjCList<ObjCProtocolDecl> ReferencedProtocols; 577980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 578980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff bool isForwardProtoDecl; // declared with @protocol. 579423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff 580423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff SourceLocation EndLoc; // marks the '>' or identifier. 581423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff SourceLocation AtEndLoc; // marks the end of the entire interface. 582cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattner 583d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor ObjCProtocolDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id) 584d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor : ObjCContainerDecl(ObjCProtocol, DC, L, Id), 585c858105d41602a2dadb2efbc1af80a7b791ebac3Chris Lattner isForwardProtoDecl(true) { 586cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattner } 5871c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek 5884a323d94e50c8f570cbfaf0392e68215b8ca87bfChris Lattner virtual ~ObjCProtocolDecl() {} 5891c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek 590cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattnerpublic: 591d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor static ObjCProtocolDecl *Create(ASTContext &C, DeclContext *DC, 592d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor SourceLocation L, IdentifierInfo *Id); 593cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattner 594411280e5b25ba7dcd7c8a82a5c23880fe7632a3cChris Lattner /// Destroy - Call destructors and release memory. 595411280e5b25ba7dcd7c8a82a5c23880fe7632a3cChris Lattner virtual void Destroy(ASTContext& C); 596411280e5b25ba7dcd7c8a82a5c23880fe7632a3cChris Lattner 597780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner const ObjCList<ObjCProtocolDecl> &getReferencedProtocols() const { 598780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner return ReferencedProtocols; 599980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff } 600dbc933701d20918add13b6a3c9d47ff8c75419cfDaniel Dunbar typedef ObjCList<ObjCProtocolDecl>::iterator protocol_iterator; 601780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();} 602780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner protocol_iterator protocol_end() const { return ReferencedProtocols.end(); } 603780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner 604780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner /// addReferencedProtocols - Set the list of protocols that this interface 605780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner /// implements. 606780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner void addReferencedProtocols(ObjCProtocolDecl *const*List, unsigned NumRPs) { 607780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner ReferencedProtocols.set(List, NumRPs); 608aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian } 609aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian 61094a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff // Lookup a method. First, we search locally. If a method isn't 61194a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff // found, we search referenced protocols and class categories. 612a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCMethodDecl *lookupInstanceMethod(Selector Sel); 613a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCMethodDecl *lookupClassMethod(Selector Sel); 614a66793ee8d2589ead81739d9b8a968650db3d452Fariborz Jahanian 615768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff bool isForwardDecl() const { return isForwardProtoDecl; } 616768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff void setForwardDecl(bool val) { isForwardProtoDecl = val; } 617980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 618423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff // Location information, modeled after the Stmt API. 619423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff SourceLocation getLocStart() const { return getLocation(); } // '@'protocol 620423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff SourceLocation getLocEnd() const { return EndLoc; } 621423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff void setLocEnd(SourceLocation LE) { EndLoc = LE; }; 622423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff 623a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const Decl *D) { return D->getKind() == ObjCProtocol; } 624a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCProtocolDecl *D) { return true; } 625980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff}; 626980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 627a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCClassDecl - Specifies a list of forward class declarations. For example: 62806ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff/// 62906ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff/// @class NSCursor, NSImage, NSPasteboard, NSWindow; 6300c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 6314afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCClassDecl : public Decl { 63267956052ea5fb0cd7f443de96a11f9a0176dc681Chris Lattner ObjCList<ObjCInterfaceDecl> ForwardDecls; 63361f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner 634d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor ObjCClassDecl(DeclContext *DC, SourceLocation L, 63567956052ea5fb0cd7f443de96a11f9a0176dc681Chris Lattner ObjCInterfaceDecl *const *Elts, unsigned nElts) 63667956052ea5fb0cd7f443de96a11f9a0176dc681Chris Lattner : Decl(ObjCClass, DC, L) { 63767956052ea5fb0cd7f443de96a11f9a0176dc681Chris Lattner ForwardDecls.set(Elts, nElts); 63806ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff } 63967956052ea5fb0cd7f443de96a11f9a0176dc681Chris Lattner virtual ~ObjCClassDecl() {} 64061f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattnerpublic: 641400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek 642400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek /// Destroy - Call destructors and release memory. 643400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek virtual void Destroy(ASTContext& C); 644400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek 645d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor static ObjCClassDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L, 64667956052ea5fb0cd7f443de96a11f9a0176dc681Chris Lattner ObjCInterfaceDecl *const *Elts, unsigned nElts); 64761f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner 64867956052ea5fb0cd7f443de96a11f9a0176dc681Chris Lattner typedef ObjCList<ObjCInterfaceDecl>::iterator iterator; 64967956052ea5fb0cd7f443de96a11f9a0176dc681Chris Lattner iterator begin() const { return ForwardDecls.begin(); } 65067956052ea5fb0cd7f443de96a11f9a0176dc681Chris Lattner iterator end() const { return ForwardDecls.end(); } 651400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek 652a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const Decl *D) { return D->getKind() == ObjCClass; } 653a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCClassDecl *D) { return true; } 65406ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff}; 65506ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff 656a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCForwardProtocolDecl - Specifies a list of forward protocol declarations. 65706ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff/// For example: 65806ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff/// 6590c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @protocol NSTextInput, NSChangeSpelling, NSDraggingInfo; 6600c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 6614afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCForwardProtocolDecl : public Decl { 66207fa7749da805969f2ed467a4eb5b405a4ff9a23Chris Lattner ObjCList<ObjCProtocolDecl> ReferencedProtocols; 66361f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner 664d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor ObjCForwardProtocolDecl(DeclContext *DC, SourceLocation L, 66507fa7749da805969f2ed467a4eb5b405a4ff9a23Chris Lattner ObjCProtocolDecl *const *Elts, unsigned nElts); 66607fa7749da805969f2ed467a4eb5b405a4ff9a23Chris Lattner virtual ~ObjCForwardProtocolDecl() {} 66705ac3ef08f9d06e0a4439073c9edabf7f912f946Ted Kremenek 66861f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattnerpublic: 669d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor static ObjCForwardProtocolDecl *Create(ASTContext &C, DeclContext *DC, 670d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor SourceLocation L, 67107fa7749da805969f2ed467a4eb5b405a4ff9a23Chris Lattner ObjCProtocolDecl *const *Elts, 67207fa7749da805969f2ed467a4eb5b405a4ff9a23Chris Lattner unsigned Num); 67361f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner 6740b7ebb3dba0df0a6cbf221e5edbc6a4b8848478cChris Lattner /// Destroy - Call destructors and release memory. 6750b7ebb3dba0df0a6cbf221e5edbc6a4b8848478cChris Lattner virtual void Destroy(ASTContext& C); 6769fa5e65d08aee1875c5f2a841c8b0b4069bd00e5Chris Lattner 67707fa7749da805969f2ed467a4eb5b405a4ff9a23Chris Lattner typedef ObjCList<ObjCProtocolDecl>::iterator iterator; 67807fa7749da805969f2ed467a4eb5b405a4ff9a23Chris Lattner iterator begin() const { return ReferencedProtocols.begin(); } 67907fa7749da805969f2ed467a4eb5b405a4ff9a23Chris Lattner iterator end() const { return ReferencedProtocols.end(); } 68005ac3ef08f9d06e0a4439073c9edabf7f912f946Ted Kremenek 68106ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff static bool classof(const Decl *D) { 682a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek return D->getKind() == ObjCForwardProtocol; 68306ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff } 684a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCForwardProtocolDecl *D) { return true; } 685980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff}; 686980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 687a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCCategoryDecl - Represents a category declaration. A category allows 6880c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// you to add methods to an existing class (without subclassing or modifying 6890c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// the original class interface or implementation:-). Categories don't allow 6900c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// you to add instance data. The following example adds "myMethod" to all 6910c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// NSView's within a process: 6920c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 6930c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @interface NSView (MyViewMethods) 6940c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - myMethod; 6950c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end 6960c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 6970c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// Cateogries also allow you to split the implementation of a class across 6980c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// several files (a feature more naturally supported in C++). 6990c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 7000c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// Categories were originally inspired by dynamic languages such as Common 70168c82cf61228102aba1194efef222fa1478af2a8Chris Lattner/// Lisp and Smalltalk. More traditional class-based languages (C++, Java) 7020c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// don't support this level of dynamism, which is both powerful and dangerous. 7030c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 704e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroffclass ObjCCategoryDecl : public ObjCContainerDecl { 705980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff /// Interface belonging to this category 706a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *ClassInterface; 707980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 70868c82cf61228102aba1194efef222fa1478af2a8Chris Lattner /// referenced protocols in this category. 709780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner ObjCList<ObjCProtocolDecl> ReferencedProtocols; 710980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 711980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff /// Next category belonging to this class 712a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCCategoryDecl *NextClassCategory; 713ca3adf7e8cac8c9fbaf592b1e5c2be6f082de7baFariborz Jahanian 7147e7e3872b584bc5e7de7a34c8b9c092032303b72Fariborz Jahanian /// category properties 7157e7e3872b584bc5e7de7a34c8b9c092032303b72Fariborz Jahanian ObjCPropertyDecl **PropertyDecl; // Null if no property 7167e7e3872b584bc5e7de7a34c8b9c092032303b72Fariborz Jahanian unsigned NumPropertyDecl; // 0 if none 7177e7e3872b584bc5e7de7a34c8b9c092032303b72Fariborz Jahanian 718423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff SourceLocation EndLoc; // marks the '>' or identifier. 71961f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner 720d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor ObjCCategoryDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id) 721d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor : ObjCContainerDecl(ObjCCategory, DC, L, Id), 722780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner ClassInterface(0), 7237e7e3872b584bc5e7de7a34c8b9c092032303b72Fariborz Jahanian NextClassCategory(0), PropertyDecl(0), NumPropertyDecl(0) { 724a906135721c350435319347d2672bbb3bf494f91Chris Lattner } 72561f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattnerpublic: 72661f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner 727d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor static ObjCCategoryDecl *Create(ASTContext &C, DeclContext *DC, 7280ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner SourceLocation L, IdentifierInfo *Id); 72961f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner 730e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner ObjCInterfaceDecl *getClassInterface() { return ClassInterface; } 731e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; } 732a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek void setClassInterface(ObjCInterfaceDecl *IDecl) { ClassInterface = IDecl; } 733980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 734f7b2c98c16dfb2261ea57d40a1d5bc4738e73175Chris Lattner /// addReferencedProtocols - Set the list of protocols that this interface 735f7b2c98c16dfb2261ea57d40a1d5bc4738e73175Chris Lattner /// implements. 736780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner void addReferencedProtocols(ObjCProtocolDecl *const*List, unsigned NumRPs) { 737780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner ReferencedProtocols.set(List, NumRPs); 738780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner } 739980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 740780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner const ObjCList<ObjCProtocolDecl> &getReferencedProtocols() const { 741780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner return ReferencedProtocols; 7428f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian } 743780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner 744780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner typedef ObjCProtocolDecl * const * protocol_iterator; 745780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();} 746780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner protocol_iterator protocol_end() const { return ReferencedProtocols.end(); } 747780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner 748a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCCategoryDecl *getNextClassCategory() const { return NextClassCategory; } 749980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff void insertNextClassCategory() { 7503d58138992b9bc7b34aaa680f3ddf3971292eb7dSteve Naroff NextClassCategory = ClassInterface->getCategoryList(); 7513d58138992b9bc7b34aaa680f3ddf3971292eb7dSteve Naroff ClassInterface->setCategoryList(this); 752980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff } 753423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff // Location information, modeled after the Stmt API. 754423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff SourceLocation getLocStart() const { return getLocation(); } // '@'interface 755423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff SourceLocation getLocEnd() const { return EndLoc; } 756423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff void setLocEnd(SourceLocation LE) { EndLoc = LE; }; 757423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff 758a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const Decl *D) { return D->getKind() == ObjCCategory; } 759a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCCategoryDecl *D) { return true; } 760980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff}; 7610c6b6243d3efd958c17943130e2a773653511edcSteve Naroff 762a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCCategoryImplDecl - An object of this class encapsulates a category 763559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// @implementation declaration. If a category class has declaration of a 764559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// property, its implementation must be specified in the category's 765559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// @implementation declaration. Example: 766559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// @interface I @end 767559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// @interface I(CATEGORY) 768559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// @property int p1, d1; 769559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// @end 770559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// @implementation I(CATEGORY) 771559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// @dynamic p1,d1; 772559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// @end 773559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian/// 7744afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCCategoryImplDecl : public NamedDecl, public DeclContext { 7758f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian /// Class interface for this category implementation 776a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *ClassInterface; 7778f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian 778e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff /// implemented instance methods 779a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek llvm::SmallVector<ObjCMethodDecl*, 32> InstanceMethods; 7808f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian 781e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff /// implemented class methods 782a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek llvm::SmallVector<ObjCMethodDecl*, 32> ClassMethods; 783f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian 784559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian /// Property Implementations in this category 785f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian llvm::SmallVector<ObjCPropertyImplDecl*, 8> PropertyImplementations; 786e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff 787e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff SourceLocation EndLoc; 78875c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner 789d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor ObjCCategoryImplDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id, 790a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *classInterface) 7914afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor : NamedDecl(ObjCCategoryImpl, DC, L, Id), DeclContext(ObjCCategoryImpl), 7920701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff ClassInterface(classInterface) {} 79375c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattnerpublic: 794d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor static ObjCCategoryImplDecl *Create(ASTContext &C, DeclContext *DC, 7950ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner SourceLocation L, IdentifierInfo *Id, 79675c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner ObjCInterfaceDecl *classInterface); 7978f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian 798e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; } 799e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner ObjCInterfaceDecl *getClassInterface() { return ClassInterface; } 8008f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian 801ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner unsigned getNumInstanceMethods() const { return InstanceMethods.size(); } 802ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner unsigned getNumClassMethods() const { return ClassMethods.size(); } 803e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff 804a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek void addInstanceMethod(ObjCMethodDecl *method) { 805e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff InstanceMethods.push_back(method); 806e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff } 807a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek void addClassMethod(ObjCMethodDecl *method) { 808e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff ClassMethods.push_back(method); 809f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian } 81053df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner 81153df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner // Get the local instance/class method declared in this interface. 8123216dcdebb8ae0f2993ac5f5249caa217444bacfDaniel Dunbar ObjCMethodDecl *getInstanceMethod(Selector Sel) const; 8133216dcdebb8ae0f2993ac5f5249caa217444bacfDaniel Dunbar ObjCMethodDecl *getClassMethod(Selector Sel) const; 81453df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner ObjCMethodDecl *getMethod(Selector Sel, bool isInstance) const { 81553df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner return isInstance ? getInstanceMethod(Sel) : getClassMethod(Sel); 81653df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner } 817f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian 818f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian void addPropertyImplementation(ObjCPropertyImplDecl *property) { 819f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian PropertyImplementations.push_back(property); 820f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian } 821e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff 822ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian ObjCPropertyImplDecl *FindPropertyImplDecl(IdentifierInfo *propertyId) const; 823ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian ObjCPropertyImplDecl *FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const; 824ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian 825f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian unsigned getNumPropertyImplementations() const 826f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian { return PropertyImplementations.size(); } 827f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian 828559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian 829559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian typedef llvm::SmallVector<ObjCPropertyImplDecl*, 8>::const_iterator 830559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian propimpl_iterator; 831559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian propimpl_iterator propimpl_begin() const { 832559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian return PropertyImplementations.begin(); 833559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian } 834559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian propimpl_iterator propimpl_end() const { 835559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian return PropertyImplementations.end(); 836559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian } 837559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian 838a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek typedef llvm::SmallVector<ObjCMethodDecl*, 32>::const_iterator 839ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner instmeth_iterator; 840ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner instmeth_iterator instmeth_begin() const { return InstanceMethods.begin(); } 841ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner instmeth_iterator instmeth_end() const { return InstanceMethods.end(); } 842ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner 843a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek typedef llvm::SmallVector<ObjCMethodDecl*, 32>::const_iterator 844ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner classmeth_iterator; 845ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner classmeth_iterator classmeth_begin() const { return ClassMethods.begin(); } 846ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner classmeth_iterator classmeth_end() const { return ClassMethods.end(); } 847ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner 848ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner 849e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff // Location information, modeled after the Stmt API. 850e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff SourceLocation getLocStart() const { return getLocation(); } 851e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff SourceLocation getLocEnd() const { return EndLoc; } 852e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff void setLocEnd(SourceLocation LE) { EndLoc = LE; }; 853e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff 854a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const Decl *D) { return D->getKind() == ObjCCategoryImpl;} 855a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCCategoryImplDecl *D) { return true; } 856b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff static DeclContext *castToDeclContext(const ObjCCategoryImplDecl *D) { 857b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff return static_cast<DeclContext *>(const_cast<ObjCCategoryImplDecl*>(D)); 858b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff } 859b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff static ObjCCategoryImplDecl *castFromDeclContext(const DeclContext *DC) { 860b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff return static_cast<ObjCCategoryImplDecl *>(const_cast<DeclContext*>(DC)); 861b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff } 8628f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian}; 8638f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian 864a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCImplementationDecl - Represents a class definition - this is where 8650c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// method definitions are specified. For example: 8660c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 86798abf4bd3526a00a0e5cf71a9462c181f97b1c81Fariborz Jahanian/// @code 8680c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @implementation MyClass 8690c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (void)myMethod { /* do something */ } 8700c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end 87198abf4bd3526a00a0e5cf71a9462c181f97b1c81Fariborz Jahanian/// @endcode 8720c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 8730c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// Typically, instance variables are specified in the class interface, 874ec0d7a6f4b0699cc9960e6d9fee0f957c64d1cf9Douglas Gregor/// *not* in the implementation. Nevertheless (for legacy reasons), we 87553df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner/// allow instance variables to be specified in the implementation. When 87653df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner/// specified, they need to be *identical* to the interface. 8770c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 8784afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCImplementationDecl : public Decl, public DeclContext { 879dae1a1a2aa4f245b1958dc8db6089f24c575ef13Fariborz Jahanian /// Class interface for this implementation 880a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *ClassInterface; 881f4d331dd922f92478ebf30e808c0ca97ce49418bFariborz Jahanian 882980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff /// Implementation Class's super class. 883a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *SuperClass; 884980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 885980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff /// Optional Ivars/NumIvars - This is a new[]'d array of pointers to Decls. 886a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCIvarDecl **Ivars; // Null if not specified 887f3a7af901231535191d14cb524d58f22907ac4d2Chris Lattner unsigned NumIvars; // 0 if none. 8880416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff 889980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff /// implemented instance methods 890a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek llvm::SmallVector<ObjCMethodDecl*, 32> InstanceMethods; 8910416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff 892980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff /// implemented class methods 893a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek llvm::SmallVector<ObjCMethodDecl*, 32> ClassMethods; 8940416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff 895f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian /// Propertys' being implemented 896f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian llvm::SmallVector<ObjCPropertyImplDecl*, 8> PropertyImplementations; 897f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian 8980416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff SourceLocation EndLoc; 89975c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner 9004afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor ObjCImplementationDecl(DeclContext *DC, SourceLocation L, 901a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *classInterface, 902a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *superDecl) 9034afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor : Decl(ObjCImplementation, DC, L), DeclContext(ObjCImplementation), 9040416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff ClassInterface(classInterface), SuperClass(superDecl), 905f3a7af901231535191d14cb524d58f22907ac4d2Chris Lattner Ivars(0), NumIvars(0) {} 90675c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattnerpublic: 907d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor static ObjCImplementationDecl *Create(ASTContext &C, DeclContext *DC, 9084afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor SourceLocation L, 90975c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner ObjCInterfaceDecl *classInterface, 91075c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner ObjCInterfaceDecl *superDecl); 91175c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner 912980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 913a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek void ObjCAddInstanceVariablesToClassImpl(ObjCIvarDecl **ivars, 914980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff unsigned numIvars); 915980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 916a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek void addInstanceMethod(ObjCMethodDecl *method) { 9170416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff InstanceMethods.push_back(method); 9180416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff } 919a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek void addClassMethod(ObjCMethodDecl *method) { 9200416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff ClassMethods.push_back(method); 9210416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff } 922f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian 923f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian void addPropertyImplementation(ObjCPropertyImplDecl *property) { 924f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian PropertyImplementations.push_back(property); 925f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian } 926ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian 927ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian ObjCPropertyImplDecl *FindPropertyImplDecl(IdentifierInfo *propertyId) const; 928ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian ObjCPropertyImplDecl *FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const; 929ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian 930559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian typedef llvm::SmallVector<ObjCPropertyImplDecl*, 8>::const_iterator 931559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian propimpl_iterator; 932559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian propimpl_iterator propimpl_begin() const { 933559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian return PropertyImplementations.begin(); 934559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian } 935559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian propimpl_iterator propimpl_end() const { 936559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian return PropertyImplementations.end(); 937559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian } 938f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian 9390416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff // Location information, modeled after the Stmt API. 9400416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff SourceLocation getLocStart() const { return getLocation(); } 9410416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff SourceLocation getLocEnd() const { return EndLoc; } 9420416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff void setLocEnd(SourceLocation LE) { EndLoc = LE; }; 9430416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff 9444afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// getIdentifier - Get the identifier that names the class 9454afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// interface associated with this implementation. 9464afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor IdentifierInfo *getIdentifier() const { 9474afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return getClassInterface()->getIdentifier(); 9484afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 9494afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 9504afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// getNameAsCString - Get the name of identifier for the class 9514afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// interface associated with this implementation as a C string 9524afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// (const char*). 9534afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor const char *getNameAsCString() const { 9544afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor assert(getIdentifier() && "Name is not a simple identifier"); 9554afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return getIdentifier()->getName(); 9564afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 9574afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 9584afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// @brief Get the name of the class associated with this interface. 9594afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor std::string getNameAsString() const { 9604afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return getClassInterface()->getNameAsString(); 9614afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 9624afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 963e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; } 964e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner ObjCInterfaceDecl *getClassInterface() { return ClassInterface; } 965e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner const ObjCInterfaceDecl *getSuperClass() const { return SuperClass; } 966e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner ObjCInterfaceDecl *getSuperClass() { return SuperClass; } 967980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 968f3a7af901231535191d14cb524d58f22907ac4d2Chris Lattner void setSuperClass(ObjCInterfaceDecl * superCls) { SuperClass = superCls; } 969980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 970b5feb35360526da42ad7e3fa7ef3d44a5992b83cChris Lattner unsigned getNumInstanceMethods() const { return InstanceMethods.size(); } 97162db2f4214c1589082960f12c9cb8924fe0cf8c5Chris Lattner unsigned getNumClassMethods() const { return ClassMethods.size(); } 972f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian 973f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian unsigned getNumPropertyImplementations() const 974f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian { return PropertyImplementations.size(); } 975c43d868355374d48296ad3be2c9c536698a5e9a8Steve Naroff 976a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek typedef llvm::SmallVector<ObjCMethodDecl*, 32>::const_iterator 9770157c5144513438bb74aebf50d18f95df4104acbChris Lattner instmeth_iterator; 9780157c5144513438bb74aebf50d18f95df4104acbChris Lattner instmeth_iterator instmeth_begin() const { return InstanceMethods.begin(); } 9790157c5144513438bb74aebf50d18f95df4104acbChris Lattner instmeth_iterator instmeth_end() const { return InstanceMethods.end(); } 9800157c5144513438bb74aebf50d18f95df4104acbChris Lattner 981a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek typedef llvm::SmallVector<ObjCMethodDecl*, 32>::const_iterator 9820157c5144513438bb74aebf50d18f95df4104acbChris Lattner classmeth_iterator; 9830157c5144513438bb74aebf50d18f95df4104acbChris Lattner classmeth_iterator classmeth_begin() const { return ClassMethods.begin(); } 9840157c5144513438bb74aebf50d18f95df4104acbChris Lattner classmeth_iterator classmeth_end() const { return ClassMethods.end(); } 9850157c5144513438bb74aebf50d18f95df4104acbChris Lattner 98653df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner // Get the local instance/class method declared in this interface. 9873216dcdebb8ae0f2993ac5f5249caa217444bacfDaniel Dunbar ObjCMethodDecl *getInstanceMethod(Selector Sel) const; 9883216dcdebb8ae0f2993ac5f5249caa217444bacfDaniel Dunbar ObjCMethodDecl *getClassMethod(Selector Sel) const; 98953df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner ObjCMethodDecl *getMethod(Selector Sel, bool isInstance) const { 99053df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner return isInstance ? getInstanceMethod(Sel) : getClassMethod(Sel); 99153df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner } 9920157c5144513438bb74aebf50d18f95df4104acbChris Lattner 993a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek typedef ObjCIvarDecl * const *ivar_iterator; 9940157c5144513438bb74aebf50d18f95df4104acbChris Lattner ivar_iterator ivar_begin() const { return Ivars; } 995f3a7af901231535191d14cb524d58f22907ac4d2Chris Lattner ivar_iterator ivar_end() const { return Ivars+NumIvars; } 996f3a7af901231535191d14cb524d58f22907ac4d2Chris Lattner unsigned ivar_size() const { return NumIvars; } 997f3a7af901231535191d14cb524d58f22907ac4d2Chris Lattner bool ivar_empty() const { return NumIvars == 0; } 9980157c5144513438bb74aebf50d18f95df4104acbChris Lattner 999980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff static bool classof(const Decl *D) { 1000a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek return D->getKind() == ObjCImplementation; 1001980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff } 1002a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCImplementationDecl *D) { return true; } 1003b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff static DeclContext *castToDeclContext(const ObjCImplementationDecl *D) { 1004b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff return static_cast<DeclContext *>(const_cast<ObjCImplementationDecl*>(D)); 1005b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff } 1006b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff static ObjCImplementationDecl *castFromDeclContext(const DeclContext *DC) { 1007b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff return static_cast<ObjCImplementationDecl *>(const_cast<DeclContext*>(DC)); 1008b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff } 1009980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff}; 1010243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian 1011a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCCompatibleAliasDecl - Represents alias of a class. This alias is 1012243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian/// declared as @compatibility_alias alias class. 10134afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCCompatibleAliasDecl : public NamedDecl { 1014243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian /// Class that this is an alias of. 1015a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *AliasedClass; 1016243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian 1017d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor ObjCCompatibleAliasDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id, 1018e8043c39176e7f253fbd92982b077eca6bf2fd59Steve Naroff ObjCInterfaceDecl* aliasedClass) 10194afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor : NamedDecl(ObjCCompatibleAlias, DC, L, Id), AliasedClass(aliasedClass) {} 1020f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattnerpublic: 1021d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor static ObjCCompatibleAliasDecl *Create(ASTContext &C, DeclContext *DC, 10220ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner SourceLocation L, IdentifierInfo *Id, 1023f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner ObjCInterfaceDecl* aliasedClass); 1024f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner 1025f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner const ObjCInterfaceDecl *getClassInterface() const { return AliasedClass; } 1026f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner ObjCInterfaceDecl *getClassInterface() { return AliasedClass; } 1027980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 1028243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian static bool classof(const Decl *D) { 10298a934233d1582b5bde9d270bc0705aa81e471a79Chris Lattner return D->getKind() == ObjCCompatibleAlias; 1030243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian } 1031a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCCompatibleAliasDecl *D) { return true; } 1032243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian 1033243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian}; 10341de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian 10351de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian/// ObjCPropertyDecl - Represents one property declaration in an interface. 10361de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian/// For example: 10371de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian/// @property (assign, readwrite) int MyProperty; 10381de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian/// 10394afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCPropertyDecl : public NamedDecl { 104082a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanianpublic: 1041a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner enum PropertyAttributeKind { 1042a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner OBJC_PR_noattr = 0x00, 1043a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner OBJC_PR_readonly = 0x01, 1044a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner OBJC_PR_getter = 0x02, 1045a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner OBJC_PR_assign = 0x04, 1046a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner OBJC_PR_readwrite = 0x08, 1047a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner OBJC_PR_retain = 0x10, 1048a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner OBJC_PR_copy = 0x20, 1049a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner OBJC_PR_nonatomic = 0x40, 1050a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner OBJC_PR_setter = 0x80 1051a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner }; 1052af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 1053af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar enum SetterKind { Assign, Retain, Copy }; 105446b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian enum PropertyControl { None, Required, Optional }; 105582a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanianprivate: 1056dae1a1a2aa4f245b1958dc8db6089f24c575ef13Fariborz Jahanian QualType DeclType; 1057ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek unsigned PropertyAttributes : 8; 105882a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian 105946b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian // @required/@optional 106046b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian unsigned PropertyImplementation : 2; 106146b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian 10625251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian Selector GetterName; // getter name of NULL if no getter 10635251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian Selector SetterName; // setter name of NULL if no setter 106482a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian 106533de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian ObjCMethodDecl *GetterMethodDecl; // Declaration of getter instance method 106633de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian ObjCMethodDecl *SetterMethodDecl; // Declaration of setter instance method 106733de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian 1068d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor ObjCPropertyDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id, 1069d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor QualType T) 10704afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor : NamedDecl(ObjCProperty, DC, L, Id), DeclType(T), 107133de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian PropertyAttributes(OBJC_PR_noattr), PropertyImplementation(None), 107233de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian GetterName(Selector()), 107333de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian SetterName(Selector()), 107433de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian GetterMethodDecl(0), SetterMethodDecl(0) {} 1075f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattnerpublic: 1076d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor static ObjCPropertyDecl *Create(ASTContext &C, DeclContext *DC, 1077d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor SourceLocation L, 107846b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian IdentifierInfo *Id, QualType T, 107946b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian PropertyControl propControl = None); 1080dae1a1a2aa4f245b1958dc8db6089f24c575ef13Fariborz Jahanian QualType getType() const { return DeclType; } 1081c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian 1082a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner PropertyAttributeKind getPropertyAttributes() const { 1083f4af5154571e0c5eadb19df10e65464766ef6683Chris Lattner return PropertyAttributeKind(PropertyAttributes); 1084f4af5154571e0c5eadb19df10e65464766ef6683Chris Lattner } 1085564576b225386cbff375351597dd5e2a92872d38Fariborz Jahanian void setPropertyAttributes(PropertyAttributeKind PRVal) { 1086a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner PropertyAttributes |= PRVal; 108782a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian } 1088394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar 10898cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian void makeitReadWriteAttribute(void) { 10908cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian PropertyAttributes &= ~OBJC_PR_readonly; 10918cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian PropertyAttributes |= OBJC_PR_readwrite; 10928cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian } 10938cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian 1094af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar // Helper methods for accessing attributes. 1095af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 1096af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar /// isReadOnly - Return true iff the property has a setter. 1097394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar bool isReadOnly() const { 1098394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar return (PropertyAttributes & OBJC_PR_readonly); 1099394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar } 1100af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 1101af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar /// getSetterKind - Return the method used for doing assignment in 1102af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar /// the property setter. This is only valid if the property has been 1103af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar /// defined to have a setter. 1104af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar SetterKind getSetterKind() const { 1105af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar if (PropertyAttributes & OBJC_PR_retain) 1106af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar return Retain; 1107af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar if (PropertyAttributes & OBJC_PR_copy) 1108af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar return Copy; 1109af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar return Assign; 1110af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar } 1111af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 11125251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian Selector getGetterName() const { return GetterName; } 11135251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian void setGetterName(Selector Sel) { GetterName = Sel; } 111482a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian 11155251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian Selector getSetterName() const { return SetterName; } 11165251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian void setSetterName(Selector Sel) { SetterName = Sel; } 111782a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian 111833de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian ObjCMethodDecl *getGetterMethodDecl() const { return GetterMethodDecl; } 111933de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian void setGetterMethodDecl(ObjCMethodDecl *gDecl) { GetterMethodDecl = gDecl; } 112033de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian 112133de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian ObjCMethodDecl *getSetterMethodDecl() const { return SetterMethodDecl; } 112233de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian void setSetterMethodDecl(ObjCMethodDecl *gDecl) { SetterMethodDecl = gDecl; } 112333de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian 112446b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian // Related to @optional/@required declared in @protocol 112546b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian void setPropertyImplementation(PropertyControl pc) { 112646b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian PropertyImplementation = pc; 112746b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian } 112846b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian PropertyControl getPropertyImplementation() const { 112946b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian return PropertyControl(PropertyImplementation); 113046b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian } 113146b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian 113282a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian static bool classof(const Decl *D) { 1133670aa9d7639278f507930e95dc89c12032ab7c7eSam Bishop return D->getKind() == ObjCProperty; 113482a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian } 1135a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCPropertyDecl *D) { return true; } 113682a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian}; 1137980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 113861d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian/// ObjCPropertyImplDecl - Represents implementation declaration of a property 113961d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian/// in a class or category implementation block. For example: 114061d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian/// @synthesize prop1 = ivar1; 114161d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian/// 11424afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCPropertyImplDecl : public Decl { 114361d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanianpublic: 11449f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar enum Kind { 11459f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar Synthesize, 11469f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar Dynamic 114761d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian }; 114861d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanianprivate: 1149559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian SourceLocation AtLoc; // location of @synthesize or @dynamic 115061d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian /// Property declaration being implemented 115161d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian ObjCPropertyDecl *PropertyDecl; 1152be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek 115361d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian /// Null for @dynamic. Required for @synthesize. 115461d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian ObjCIvarDecl *PropertyIvarDecl; 1155be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek 1156d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor ObjCPropertyImplDecl(DeclContext *DC, SourceLocation atLoc, SourceLocation L, 1157628b96f34e93b643b6e15e75eabb8d96079a7e27Fariborz Jahanian ObjCPropertyDecl *property, 11589f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar Kind PK, 1159628b96f34e93b643b6e15e75eabb8d96079a7e27Fariborz Jahanian ObjCIvarDecl *ivarDecl) 11604afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor : Decl(ObjCPropertyImpl, DC, L), AtLoc(atLoc), 1161d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor PropertyDecl(property), PropertyIvarDecl(ivarDecl) { 11629f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar assert (PK == Dynamic || PropertyIvarDecl); 11639f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar } 1164628b96f34e93b643b6e15e75eabb8d96079a7e27Fariborz Jahanian 11659f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbarpublic: 1166d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor static ObjCPropertyImplDecl *Create(ASTContext &C, DeclContext *DC, 1167d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor SourceLocation atLoc, SourceLocation L, 1168628b96f34e93b643b6e15e75eabb8d96079a7e27Fariborz Jahanian ObjCPropertyDecl *property, 11699f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar Kind PK, 1170628b96f34e93b643b6e15e75eabb8d96079a7e27Fariborz Jahanian ObjCIvarDecl *ivarDecl); 117161d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian 1172d40910b581b09c937a8c1fdcde9b8ec724398fb9Steve Naroff SourceLocation getLocStart() const { return AtLoc; } 1173d40910b581b09c937a8c1fdcde9b8ec724398fb9Steve Naroff 1174be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek ObjCPropertyDecl *getPropertyDecl() const { 1175be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek return PropertyDecl; 1176be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek } 117761d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian 11789f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar Kind getPropertyImplementation() const { 11799f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar return PropertyIvarDecl ? Synthesize : Dynamic; 1180be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek } 118161d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian 1182af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar ObjCIvarDecl *getPropertyIvarDecl() const { 1183be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek return PropertyIvarDecl; 1184be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek } 118561d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian 118661d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian static bool classof(const Decl *D) { 118761d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian return D->getKind() == ObjCPropertyImpl; 118861d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian } 118961d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian static bool classof(const ObjCPropertyImplDecl *D) { return true; } 119061d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian}; 119161d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian 1192980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff} // end namespace clang 1193980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff#endif 1194