DeclObjC.h revision b31cb7f1752ea011fd06ac9574ce24667d11cbdb
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" 18980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 19980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffnamespace clang { 20980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffclass Expr; 21980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffclass Stmt; 22980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffclass FunctionDecl; 23980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffclass AttributeList; 2460f8c868ffb346b78451a3eccaecd0461d2ae498Fariborz Jahanianclass RecordDecl; 25a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCIvarDecl; 26a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCMethodDecl; 27a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCProtocolDecl; 28a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCCategoryDecl; 29a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCPropertyDecl; 30f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanianclass ObjCPropertyImplDecl; 3168835718c4125f2f66740cd04de7088645ec695dChris Lattner 32793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnerclass ObjCListBase { 33793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner void operator=(const ObjCListBase &); // DO NOT IMPLEMENT 34793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner ObjCListBase(const ObjCListBase&); // DO NOT IMPLEMENT 35793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnerprotected: 36793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner /// List is an array of pointers to objects that are not owned by this object. 37793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner void **List; 383db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner unsigned NumElts; 39793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner 403db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattnerpublic: 41793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner ObjCListBase() : List(0), NumElts(0) {} 42793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner ~ObjCListBase() { 4388cf7a16902a9189d16653e1061cfda333187b58Chris Lattner assert(List == 0 && "Destroy should have been called before dtor"); 443db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner } 45793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner 4638af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner void Destroy(ASTContext &Ctx); 47e881483a3bc22ffad62367501aa09ad8508fe363Chris Lattner 48793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner unsigned size() const { return NumElts; } 49793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner bool empty() const { return NumElts == 0; } 50793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner 51793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnerprotected: 5238af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner void set(void *const* InList, unsigned Elts, ASTContext &Ctx); 53793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner}; 543db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner 553db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner 56793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner/// ObjCList - This is a simple template class used to hold various lists of 57793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner/// decls etc, which is heavily used by the ObjC front-end. This only use case 58793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner/// this supports is setting the list all at once and then reading elements out 59793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner/// of it. 60793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnertemplate <typename T> 61793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnerclass ObjCList : public ObjCListBase { 62793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnerpublic: 6338af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner void set(T* const* InList, unsigned Elts, ASTContext &Ctx) { 6438af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner ObjCListBase::set(reinterpret_cast<void*const*>(InList), Elts, Ctx); 65793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner } 66793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner 67793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner typedef T* const * iterator; 68793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner iterator begin() const { return (iterator)List; } 69793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner iterator end() const { return (iterator)List+NumElts; } 703db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner 71793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner T* operator[](unsigned Idx) const { 72793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner assert(Idx < NumElts && "Invalid access"); 73793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner return (T*)List[Idx]; 743db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner } 753db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner}; 763db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner 773db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner 7858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff 79a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCMethodDecl - Represents an instance or class method declaration. 8058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// ObjC methods can be declared within 4 contexts: class interfaces, 8158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// categories, protocols, and class implementations. While C++ member 8258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// functions leverage C syntax, Objective-C method syntax is modeled after 8358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Smalltalk (using colons to specify argument types/expressions). 8458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Here are some brief examples: 8558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// 8658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Setter/getter instance methods: 8758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// - (void)setMenu:(NSMenu *)menu; 8858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// - (NSMenu *)menu; 8958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// 9058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Instance method that takes 2 NSView arguments: 9158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// - (void)replaceSubview:(NSView *)oldView with:(NSView *)newView; 9258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// 9358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Getter class method: 9458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// + (NSMenu *)defaultMenu; 9558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// 9658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// A selector represents a unique name for a method. The selector names for 9758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// the above methods are setMenu:, menu, replaceSubview:with:, and defaultMenu. 9858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// 994afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCMethodDecl : public NamedDecl, public DeclContext { 10058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroffpublic: 10158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff enum ImplementationControl { None, Required, Optional }; 10258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroffprivate: 10358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff /// Bitfields must be first fields in this class so they pack with those 10458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff /// declared in class Decl. 10558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff /// instance (true) or class (false) method. 10658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff bool IsInstance : 1; 10758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff bool IsVariadic : 1; 10858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff 1094607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian // Synthesized declaration method for a property setter/getter 1104607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian bool IsSynthesized : 1; 1114607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian 112ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek // NOTE: VC++ treats enums as signed, avoid using ImplementationControl enum 11358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff /// @required/@optional 114ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek unsigned DeclImplementation : 2; 11558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff 116ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek // NOTE: VC++ treats enums as signed, avoid using the ObjCDeclQualifier enum 11758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff /// in, inout, etc. 118ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek unsigned objcDeclQualifier : 6; 11958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff 12058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff // Type of this method. 12158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff QualType MethodDeclType; 1222073216a1075767b5d25c23d1462b7034686d94dChris Lattner /// ParamInfo - List of pointers to VarDecls for the formal parameters of this 1232073216a1075767b5d25c23d1462b7034686d94dChris Lattner /// Method. 1242073216a1075767b5d25c23d1462b7034686d94dChris Lattner ObjCList<ParmVarDecl> ParamInfo; 12558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff 12658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff /// List of attributes for this method declaration. 12758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff SourceLocation EndLoc; // the location of the ';' or '{'. 12858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff 12958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff // The following are only used for method definitions, null otherwise. 13058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff // FIXME: space savings opportunity, consider a sub-class. 13158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff Stmt *Body; 132451318c08a6342c10b8986060386fd9274418437Daniel Dunbar 133451318c08a6342c10b8986060386fd9274418437Daniel Dunbar /// SelfDecl - Decl for the implicit self parameter. This is lazily 134451318c08a6342c10b8986060386fd9274418437Daniel Dunbar /// constructed by createImplicitParams. 1354111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner ImplicitParamDecl *SelfDecl; 136451318c08a6342c10b8986060386fd9274418437Daniel Dunbar /// CmdDecl - Decl for the implicit _cmd parameter. This is lazily 137451318c08a6342c10b8986060386fd9274418437Daniel Dunbar /// constructed by createImplicitParams. 1384111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner ImplicitParamDecl *CmdDecl; 1396c4ae5de0c356777446f823b573821fb95560d91Chris Lattner 140a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCMethodDecl(SourceLocation beginLoc, SourceLocation endLoc, 14158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff Selector SelInfo, QualType T, 1420701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff DeclContext *contextDecl, 143f6414927e67e27d9324d8d179c5f7ea620443924Daniel Dunbar bool isInstance = true, 14458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff bool isVariadic = false, 1454607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian bool isSynthesized = false, 14658cce3b0dcbdcc95b7e713795834b4cb2c8a008aChris Lattner ImplementationControl impControl = None) 1474afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor : NamedDecl(ObjCMethod, contextDecl, beginLoc, SelInfo), 148b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner DeclContext(ObjCMethod), 14958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff IsInstance(isInstance), IsVariadic(isVariadic), 1504607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian IsSynthesized(isSynthesized), 15158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff DeclImplementation(impControl), objcDeclQualifier(OBJC_TQ_None), 1522e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor MethodDeclType(T), 1534111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner EndLoc(endLoc), Body(0), SelfDecl(0), CmdDecl(0) {} 1548a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek 1552073216a1075767b5d25c23d1462b7034686d94dChris Lattner virtual ~ObjCMethodDecl() {} 1561c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek 1576c4ae5de0c356777446f823b573821fb95560d91Chris Lattnerpublic: 1588a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek 1598a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek /// Destroy - Call destructors and release memory. 1608a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek virtual void Destroy(ASTContext& C); 1616c4ae5de0c356777446f823b573821fb95560d91Chris Lattner 1620ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner static ObjCMethodDecl *Create(ASTContext &C, 1630ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner SourceLocation beginLoc, 1646c4ae5de0c356777446f823b573821fb95560d91Chris Lattner SourceLocation endLoc, Selector SelInfo, 1650701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff QualType T, DeclContext *contextDecl, 166f6414927e67e27d9324d8d179c5f7ea620443924Daniel Dunbar bool isInstance = true, 1676c4ae5de0c356777446f823b573821fb95560d91Chris Lattner bool isVariadic = false, 1684607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian bool isSynthesized = false, 169b06fa3b86951b9f179c99c3768331536c32e902dChris Lattner ImplementationControl impControl = None); 17058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff 171ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek ObjCDeclQualifier getObjCDeclQualifier() const { 172ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek return ObjCDeclQualifier(objcDeclQualifier); 173ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek } 174a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek void setObjCDeclQualifier(ObjCDeclQualifier QV) { objcDeclQualifier = QV; } 17558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff 17658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff // Location information, modeled after the Stmt API. 17758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff SourceLocation getLocStart() const { return getLocation(); } 17858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff SourceLocation getLocEnd() const { return EndLoc; } 1799776ba0d844cf9f6888e871e3fd246ae782f76f4Daniel Dunbar SourceRange getSourceRange() const { 1809776ba0d844cf9f6888e871e3fd246ae782f76f4Daniel Dunbar return SourceRange(getLocation(), EndLoc); 1819776ba0d844cf9f6888e871e3fd246ae782f76f4Daniel Dunbar } 1823e0a540b6d846178857289ec0eb8470a278d11a3Steve Naroff 1835619688510185081cbb4621d703daf7ee24cf39aChris Lattner ObjCInterfaceDecl *getClassInterface(); 1845619688510185081cbb4621d703daf7ee24cf39aChris Lattner const ObjCInterfaceDecl *getClassInterface() const { 1855619688510185081cbb4621d703daf7ee24cf39aChris Lattner return const_cast<ObjCMethodDecl*>(this)->getClassInterface(); 186e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner } 18758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff 1882e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor Selector getSelector() const { return getDeclName().getObjCSelector(); } 189faf5e779d16bb4590f2a97e1c7ded255eddd90f3Fariborz Jahanian unsigned getSynthesizedMethodSize() const; 19058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff QualType getResultType() const { return MethodDeclType; } 19158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff 192d57f635d520e8cb5b93d3d770ff58db06c62de54Chris Lattner // Iterator access to formal parameters. 1932073216a1075767b5d25c23d1462b7034686d94dChris Lattner unsigned param_size() const { return ParamInfo.size(); } 1942073216a1075767b5d25c23d1462b7034686d94dChris Lattner typedef ObjCList<ParmVarDecl>::iterator param_iterator; 1952073216a1075767b5d25c23d1462b7034686d94dChris Lattner param_iterator param_begin() const { return ParamInfo.begin(); } 1962073216a1075767b5d25c23d1462b7034686d94dChris Lattner param_iterator param_end() const { return ParamInfo.end(); } 19789951a86b594513c2a013532ed45d197413b1087Chris Lattner 19838af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner void setMethodParams(ParmVarDecl *const *List, unsigned Num, 19938af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner ASTContext &C) { 20038af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner ParamInfo.set(List, Num, C); 2012073216a1075767b5d25c23d1462b7034686d94dChris Lattner } 2024111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner 203451318c08a6342c10b8986060386fd9274418437Daniel Dunbar /// createImplicitParams - Used to lazily create the self and cmd 204451318c08a6342c10b8986060386fd9274418437Daniel Dunbar /// implict parameters. This must be called prior to using getSelfDecl() 205451318c08a6342c10b8986060386fd9274418437Daniel Dunbar /// or getCmdDecl(). The call is ignored if the implicit paramters 206451318c08a6342c10b8986060386fd9274418437Daniel Dunbar /// have already been created. 207fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian void createImplicitParams(ASTContext &Context, const ObjCInterfaceDecl *ID); 208451318c08a6342c10b8986060386fd9274418437Daniel Dunbar 2094111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner ImplicitParamDecl * getSelfDecl() const { return SelfDecl; } 2104111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner ImplicitParamDecl * getCmdDecl() const { return CmdDecl; } 21158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff 212f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor bool isInstanceMethod() const { return IsInstance; } 21358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff bool isVariadic() const { return IsVariadic; } 21458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff 215f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor bool isClassMethod() const { return !IsInstance; } 216f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 2174607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian bool isSynthesized() const { return IsSynthesized; } 21891b51a92f2e9fc8025b6a9df88442840eb62823aFariborz Jahanian void setIsSynthesized() { IsSynthesized = true; } 2194607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian 22058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff // Related to protocols declared in @protocol 22158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff void setDeclImplementation(ImplementationControl ic) { 22258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff DeclImplementation = ic; 22358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff } 22458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff ImplementationControl getImplementationControl() const { 225ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek return ImplementationControl(DeclImplementation); 22658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff } 227792481eec23d8c1aa92173be589e2ae9d02514a5Ted Kremenek 228dc192323e740eec20d6d7c3162067242403aa37bTed Kremenek virtual CompoundStmt *getBody() const { return (CompoundStmt*) Body; } 229dc192323e740eec20d6d7c3162067242403aa37bTed Kremenek void setBody(CompoundStmt *B) { Body = (Stmt*) B; } 23058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff 23158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff // Implement isa/cast/dyncast/etc. 232a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const Decl *D) { return D->getKind() == ObjCMethod; } 233a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCMethodDecl *D) { return true; } 23442220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis static DeclContext *castToDeclContext(const ObjCMethodDecl *D) { 23542220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis return static_cast<DeclContext *>(const_cast<ObjCMethodDecl*>(D)); 23642220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis } 23742220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis static ObjCMethodDecl *castFromDeclContext(const DeclContext *DC) { 23842220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis return static_cast<ObjCMethodDecl *>(const_cast<DeclContext*>(DC)); 23942220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis } 24058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff}; 241e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff 242e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff/// ObjCContainerDecl - Represents a container for method declarations. 243e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff/// Current sub-classes are ObjCInterfaceDecl, ObjCCategoryDecl, and 2440701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff/// ObjCProtocolDecl. 2450701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff/// FIXME: Use for ObjC implementation decls. 246e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff/// 2474afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCContainerDecl : public NamedDecl, public DeclContext { 248e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff SourceLocation AtEndLoc; // marks the end of the method container. 249e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroffpublic: 250e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff 251d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor ObjCContainerDecl(Kind DK, DeclContext *DC, SourceLocation L, 252d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor IdentifierInfo *Id) 2534afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor : NamedDecl(DK, DC, L, Id), DeclContext(DK) {} 254e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff 2550b7ebb3dba0df0a6cbf221e5edbc6a4b8848478cChris Lattner virtual ~ObjCContainerDecl() {} 25609c4719788a5cea09897525e528fa00420f1677bSteve Naroff 25793983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff // Iterator access to properties. 25893983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff typedef specific_decl_iterator<ObjCPropertyDecl> prop_iterator; 25993983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff prop_iterator prop_begin() const { 260d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor return prop_iterator(decls_begin()); 26193983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff } 26293983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff prop_iterator prop_end() const { 263d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor return prop_iterator(decls_end()); 26409c4719788a5cea09897525e528fa00420f1677bSteve Naroff } 26509c4719788a5cea09897525e528fa00420f1677bSteve Naroff 2660701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff // Iterator access to instance/class methods. 267f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor typedef specific_decl_iterator<ObjCMethodDecl> method_iterator; 268f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor method_iterator meth_begin() const { 269d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor return method_iterator(decls_begin()); 2707ed4faca5162b3ab85be7f7e57aa40e6ec170971Ted Kremenek } 271f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor method_iterator meth_end() const { 272d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor return method_iterator(decls_end()); 2737ed4faca5162b3ab85be7f7e57aa40e6ec170971Ted Kremenek } 2740701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff 275669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor typedef filtered_decl_iterator<ObjCMethodDecl, 276669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor &ObjCMethodDecl::isInstanceMethod> 277669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor instmeth_iterator; 2780701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff instmeth_iterator instmeth_begin() const { 279669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor return instmeth_iterator(decls_begin()); 280e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff } 2810701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff instmeth_iterator instmeth_end() const { 282669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor return instmeth_iterator(decls_end()); 283e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff } 284e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff 285669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor typedef filtered_decl_iterator<ObjCMethodDecl, 286669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor &ObjCMethodDecl::isClassMethod> 287669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor classmeth_iterator; 2880701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff classmeth_iterator classmeth_begin() const { 289669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor return classmeth_iterator(decls_begin()); 290e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff } 2910701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff classmeth_iterator classmeth_end() const { 292669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor return classmeth_iterator(decls_end()); 2930701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff } 2940701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff 2950701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff // Get the local instance/class method declared in this interface. 2960701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff ObjCMethodDecl *getInstanceMethod(Selector Sel) const; 2970701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff ObjCMethodDecl *getClassMethod(Selector Sel) const; 29853df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner ObjCMethodDecl *getMethod(Selector Sel, bool isInstance) const { 29953df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner return isInstance ? getInstanceMethod(Sel) : getClassMethod(Sel); 30053df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner } 301b31cb7f1752ea011fd06ac9574ce24667d11cbdbFariborz Jahanian 30293983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff ObjCPropertyDecl *FindPropertyDeclaration(IdentifierInfo *PropertyId) const; 30393983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff 304e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff // Marks the end of the container. 305e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff SourceLocation getAtEndLoc() const { return AtEndLoc; } 3060701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff void setAtEndLoc(SourceLocation L) { AtEndLoc = L; } 30709c4719788a5cea09897525e528fa00420f1677bSteve Naroff 30809c4719788a5cea09897525e528fa00420f1677bSteve Naroff // Implement isa/cast/dyncast/etc. 30909c4719788a5cea09897525e528fa00420f1677bSteve Naroff static bool classof(const Decl *D) { 31009c4719788a5cea09897525e528fa00420f1677bSteve Naroff return D->getKind() >= ObjCContainerFirst && 31109c4719788a5cea09897525e528fa00420f1677bSteve Naroff D->getKind() <= ObjCContainerLast; 31209c4719788a5cea09897525e528fa00420f1677bSteve Naroff } 31309c4719788a5cea09897525e528fa00420f1677bSteve Naroff static bool classof(const ObjCContainerDecl *D) { return true; } 31409c4719788a5cea09897525e528fa00420f1677bSteve Naroff 31509c4719788a5cea09897525e528fa00420f1677bSteve Naroff static DeclContext *castToDeclContext(const ObjCContainerDecl *D) { 31609c4719788a5cea09897525e528fa00420f1677bSteve Naroff return static_cast<DeclContext *>(const_cast<ObjCContainerDecl*>(D)); 31709c4719788a5cea09897525e528fa00420f1677bSteve Naroff } 31809c4719788a5cea09897525e528fa00420f1677bSteve Naroff static ObjCContainerDecl *castFromDeclContext(const DeclContext *DC) { 31909c4719788a5cea09897525e528fa00420f1677bSteve Naroff return static_cast<ObjCContainerDecl *>(const_cast<DeclContext*>(DC)); 32009c4719788a5cea09897525e528fa00420f1677bSteve Naroff } 321e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff}; 322e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff 323a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCInterfaceDecl - Represents an ObjC class declaration. For example: 3240c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 3250c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// // MostPrimitive declares no super class (not particularly useful). 3260c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @interface MostPrimitive 3270c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// // no instance variables or methods. 3280c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end 3290c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 330fd5de471478a507dd2495c4ea9bcab801ea5fa65Chris Lattner/// // NSResponder inherits from NSObject & implements NSCoding (a protocol). 3310c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @interface NSResponder : NSObject <NSCoding> 332a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// { // instance variables are represented by ObjCIvarDecl. 3330c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// id nextResponder; // nextResponder instance variable. 3340c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// } 3350c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (NSResponder *)nextResponder; // return a pointer to NSResponder. 3360c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (void)mouseMoved:(NSEvent *)theEvent; // return void, takes a pointer 3370c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end // to an NSEvent. 3380c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 3390c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// Unlike C/C++, forward class declarations are accomplished with @class. 3400c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// Unlike C/C++, @class allows for a list of classes to be forward declared. 3410c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// Unlike C++, ObjC is a single-rooted class model. In Cocoa, classes 3420c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// typically inherit from NSObject (an exception is NSProxy). 3430c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 3440701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroffclass ObjCInterfaceDecl : public ObjCContainerDecl { 3453110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff /// TypeForDecl - This indicates the Type object that represents this 3463110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff /// TypeDecl. It is a cache maintained by ASTContext::getObjCInterfaceType 3473110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff Type *TypeForDecl; 3483110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff friend class ASTContext; 349980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 350980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff /// Class's super class. 351a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *SuperClass; 352980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 353980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff /// Protocols referenced in interface header declaration 3543db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner ObjCList<ObjCProtocolDecl> ReferencedProtocols; 355980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 356e881483a3bc22ffad62367501aa09ad8508fe363Chris Lattner /// Instance variables in the interface. 357e881483a3bc22ffad62367501aa09ad8508fe363Chris Lattner ObjCList<ObjCIvarDecl> IVars; 358980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 359980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff /// List of categories defined for this class. 360a8ff9f455d94d9609766cfd5186b6e21dc2102f1Chris Lattner /// FIXME: Why is this a linked list?? 361a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCCategoryDecl *CategoryList; 36282a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian 3633a3ca1b35a7121aea0bf465a192dce748465e10fFariborz Jahanian bool ForwardDecl:1; // declared with @class. 3643a3ca1b35a7121aea0bf465a192dce748465e10fFariborz Jahanian bool InternalInterface:1; // true - no @interface for @implementation 36560fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff 366d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff SourceLocation ClassLoc; // location of the class identifier. 367d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff SourceLocation SuperClassLoc; // location of the super class identifier. 368f908a87299d278164540f90b5b6e6cab7b14fb41Steve Naroff SourceLocation EndLoc; // marks the '>', '}', or identifier. 3690e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner 370d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id, 3710b7ebb3dba0df0a6cbf221e5edbc6a4b8848478cChris Lattner SourceLocation CLoc, bool FD, bool isInternal); 3728a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek 373e881483a3bc22ffad62367501aa09ad8508fe363Chris Lattner virtual ~ObjCInterfaceDecl() {} 3748a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek 3750e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattnerpublic: 3760e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner 3778a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek /// Destroy - Call destructors and release memory. 3788a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek virtual void Destroy(ASTContext& C); 3798a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek 380d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor static ObjCInterfaceDecl *Create(ASTContext &C, DeclContext *DC, 3810ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner SourceLocation atLoc, 382d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff IdentifierInfo *Id, 383d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff SourceLocation ClassLoc = SourceLocation(), 3840e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner bool ForwardDecl = false, 3850e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner bool isInternal = false); 3863db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner const ObjCList<ObjCProtocolDecl> &getReferencedProtocols() const { 3877ed9e0f97f4645edc5d4670385b985ea4c617ce7Fariborz Jahanian return ReferencedProtocols; 3887ed9e0f97f4645edc5d4670385b985ea4c617ce7Fariborz Jahanian } 389980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 390559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian ObjCCategoryDecl *FindCategoryDeclaration(IdentifierInfo *CategoryId) const; 3913db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner 3923db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner typedef ObjCList<ObjCProtocolDecl>::iterator protocol_iterator; 3933db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();} 3943db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner protocol_iterator protocol_end() const { return ReferencedProtocols.end(); } 395aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian 396e881483a3bc22ffad62367501aa09ad8508fe363Chris Lattner typedef ObjCList<ObjCIvarDecl>::iterator ivar_iterator; 397e881483a3bc22ffad62367501aa09ad8508fe363Chris Lattner ivar_iterator ivar_begin() const { return IVars.begin(); } 398e881483a3bc22ffad62367501aa09ad8508fe363Chris Lattner ivar_iterator ivar_end() const { return IVars.end(); } 399e881483a3bc22ffad62367501aa09ad8508fe363Chris Lattner unsigned ivar_size() const { return IVars.size(); } 400e881483a3bc22ffad62367501aa09ad8508fe363Chris Lattner bool ivar_empty() const { return IVars.empty(); } 401e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff 40238af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner /// setProtocolList - Set the list of protocols that this interface 403b752f289026ad8e5f44851b20e009a27ed61eefcChris Lattner /// implements. 40438af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner void setProtocolList(ObjCProtocolDecl *const* List, unsigned Num, 40538af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner ASTContext &C) { 40638af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner ReferencedProtocols.set(List, Num, C); 4073db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner } 408b752f289026ad8e5f44851b20e009a27ed61eefcChris Lattner 40938af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner void setIVarList(ObjCIvarDecl * const *List, unsigned Num, ASTContext &C) { 41038af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner IVars.set(List, Num, C); 411e881483a3bc22ffad62367501aa09ad8508fe363Chris Lattner } 412fd64bb635dc221baa19f81d5d2a084f7eb269f7fFariborz Jahanian FieldDecl *lookupFieldDeclForIvar(ASTContext &Context, 413fd64bb635dc221baa19f81d5d2a084f7eb269f7fFariborz Jahanian const ObjCIvarDecl *ivar); 414980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 415768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff bool isForwardDecl() const { return ForwardDecl; } 416768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff void setForwardDecl(bool val) { ForwardDecl = val; } 417980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 418a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *getSuperClass() const { return SuperClass; } 419a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek void setSuperClass(ObjCInterfaceDecl * superCls) { SuperClass = superCls; } 420980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 421a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCCategoryDecl* getCategoryList() const { return CategoryList; } 422a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek void setCategoryList(ObjCCategoryDecl *category) { 42353efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner CategoryList = category; 424980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff } 42553efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner 42653efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner /// isSuperClassOf - Return true if this class is the specified class or is a 42753efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner /// super class of the specified interface class. 42853efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner bool isSuperClassOf(const ObjCInterfaceDecl *I) const { 42953efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner // If RHS is derived from LHS it is OK; else it is not OK. 43053efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner while (I != NULL) { 43153efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner if (this == I) 43253efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner return true; 43353efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner I = I->getSuperClass(); 43453efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner } 43553efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner return false; 43653efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner } 43753efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner 43868a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName, 43968a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner ObjCInterfaceDecl *&ClassDeclared); 44068a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName) { 44168a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner ObjCInterfaceDecl *ClassDeclared; 44268a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner return lookupInstanceVariable(IVarName, ClassDeclared); 44368a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner } 44468a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner 44594a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff // Lookup a method. First, we search locally. If a method isn't 44694a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff // found, we search referenced protocols and class categories. 447a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCMethodDecl *lookupInstanceMethod(Selector Sel); 448a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCMethodDecl *lookupClassMethod(Selector Sel); 44960fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff 450f908a87299d278164540f90b5b6e6cab7b14fb41Steve Naroff // Location information, modeled after the Stmt API. 45160fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff SourceLocation getLocStart() const { return getLocation(); } // '@'interface 452f908a87299d278164540f90b5b6e6cab7b14fb41Steve Naroff SourceLocation getLocEnd() const { return EndLoc; } 453f908a87299d278164540f90b5b6e6cab7b14fb41Steve Naroff void setLocEnd(SourceLocation LE) { EndLoc = LE; }; 45460fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff 455d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff SourceLocation getClassLoc() const { return ClassLoc; } 456d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff void setSuperClassLoc(SourceLocation Loc) { SuperClassLoc = Loc; } 457d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff SourceLocation getSuperClassLoc() const { return SuperClassLoc; } 458e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff 4594b6df3fa953267c5d755628c8afd818bb571e579Fariborz Jahanian /// ImplicitInterfaceDecl - check that this is an implicitely declared 460a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek /// ObjCInterfaceDecl node. This is for legacy objective-c @implementation 4614b6df3fa953267c5d755628c8afd818bb571e579Fariborz Jahanian /// declaration without an @interface declaration. 4623a3ca1b35a7121aea0bf465a192dce748465e10fFariborz Jahanian bool ImplicitInterfaceDecl() const { return InternalInterface; } 4634b6df3fa953267c5d755628c8afd818bb571e579Fariborz Jahanian 464a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const Decl *D) { return D->getKind() == ObjCInterface; } 465a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCInterfaceDecl *D) { return true; } 466980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff}; 467980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 468a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCIvarDecl - Represents an ObjC instance variable. In general, ObjC 4690c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// instance variables are identical to C. The only exception is Objective-C 4700c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// supports C++ style access control. For example: 4710c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 4720c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @interface IvarExample : NSObject 4730c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// { 474f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek/// id defaultToProtected; 4750c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @public: 4760c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// id canBePublic; // same as C++. 4770c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @protected: 4780c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// id canBeProtected; // same as C++. 4790c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @package: 4800c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// id canBePackage; // framework visibility (not available in C++). 4810c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// } 4820c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 483a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCIvarDecl : public FieldDecl { 4840e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattnerpublic: 485980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff enum AccessControl { 486980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff None, Private, Protected, Public, Package 487980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff }; 488f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek 489b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenekprivate: 4900c00aac5d618f39afc406c5b2e07642930af1d56Argyrios Kyrtzidis ObjCIvarDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id, 4910c00aac5d618f39afc406c5b2e07642930af1d56Argyrios Kyrtzidis QualType T, AccessControl ac, Expr *BW) 4920c00aac5d618f39afc406c5b2e07642930af1d56Argyrios Kyrtzidis : FieldDecl(ObjCIvar, DC, L, Id, T, BW, /*Mutable=*/false), 49344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor DeclAccess(ac) {} 494b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenek 495b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenekpublic: 4960c00aac5d618f39afc406c5b2e07642930af1d56Argyrios Kyrtzidis static ObjCIvarDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L, 497b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenek IdentifierInfo *Id, QualType T, 498b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenek AccessControl ac, Expr *BW = NULL); 499b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenek 500980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff void setAccessControl(AccessControl ac) { DeclAccess = ac; } 501f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek 502ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek AccessControl getAccessControl() const { return AccessControl(DeclAccess); } 503f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek 504f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek AccessControl getCanonicalAccessControl() const { 505f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek return DeclAccess == None ? Protected : AccessControl(DeclAccess); 506f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek } 507980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 508980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff // Implement isa/cast/dyncast/etc. 509a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const Decl *D) { return D->getKind() == ObjCIvar; } 510a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCIvarDecl *D) { return true; } 511980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffprivate: 512ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek // NOTE: VC++ treats enums as signed, avoid using the AccessControl enum 513ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek unsigned DeclAccess : 3; 514980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff}; 515980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 51601e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek 51701e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek/// ObjCAtDefsFieldDecl - Represents a field declaration created by an 51801e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek/// @defs(...). 51901e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenekclass ObjCAtDefsFieldDecl : public FieldDecl { 52001e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenekprivate: 52144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor ObjCAtDefsFieldDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id, 52201e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek QualType T, Expr *BW) 5234afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor : FieldDecl(ObjCAtDefsField, DC, L, Id, T, BW, /*Mutable=*/false) {} 52401e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek 52501e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenekpublic: 52644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor static ObjCAtDefsFieldDecl *Create(ASTContext &C, DeclContext *DC, 52744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor SourceLocation L, 52801e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek IdentifierInfo *Id, QualType T, 52901e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek Expr *BW); 53001e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek 53101e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek virtual void Destroy(ASTContext& C); 53201e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek 53301e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek // Implement isa/cast/dyncast/etc. 53401e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek static bool classof(const Decl *D) { return D->getKind() == ObjCAtDefsField; } 53501e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek static bool classof(const ObjCAtDefsFieldDecl *D) { return true; } 53601e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek}; 537980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 538a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCProtocolDecl - Represents a protocol declaration. ObjC protocols 5390c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// declare a pure abstract type (i.e no instance variables are permitted). 5400c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// Protocols orginally drew inspiration from C++ pure virtual functions (a C++ 5410c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// feature with nice semantics and lousy syntax:-). Here is an example: 5420c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 543eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// @protocol NSDraggingInfo <refproto1, refproto2> 5440c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (NSWindow *)draggingDestinationWindow; 5450c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (NSImage *)draggedImage; 5460c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end 5470c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 548eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// This says that NSDraggingInfo requires two methods and requires everything 549eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// that the two "referenced protocols" 'refproto1' and 'refproto2' require as 550eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// well. 551eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// 5520c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @interface ImplementsNSDraggingInfo : NSObject <NSDraggingInfo> 5530c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end 5540c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 555a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjC protocols inspired Java interfaces. Unlike Java, ObjC classes and 5560c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// protocols are in distinct namespaces. For example, Cocoa defines both 5570c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// an NSObject protocol and class (which isn't allowed in Java). As a result, 5580c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// protocols are referenced using angle brackets as follows: 5590c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 5600c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// id <NSDraggingInfo> anyObjectThatImplementsNSDraggingInfo; 5610c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 562e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroffclass ObjCProtocolDecl : public ObjCContainerDecl { 563780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner /// Referenced protocols 564780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner ObjCList<ObjCProtocolDecl> ReferencedProtocols; 565980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 566980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff bool isForwardProtoDecl; // declared with @protocol. 567423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff 568423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff SourceLocation EndLoc; // marks the '>' or identifier. 569423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff SourceLocation AtEndLoc; // marks the end of the entire interface. 570cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattner 571d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor ObjCProtocolDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id) 572d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor : ObjCContainerDecl(ObjCProtocol, DC, L, Id), 573c858105d41602a2dadb2efbc1af80a7b791ebac3Chris Lattner isForwardProtoDecl(true) { 574cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattner } 5751c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek 5764a323d94e50c8f570cbfaf0392e68215b8ca87bfChris Lattner virtual ~ObjCProtocolDecl() {} 5771c8a413c1e00636c77666ddf1e3b0311f3fa8c81Ted Kremenek 578cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattnerpublic: 579d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor static ObjCProtocolDecl *Create(ASTContext &C, DeclContext *DC, 580d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor SourceLocation L, IdentifierInfo *Id); 581cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattner 582411280e5b25ba7dcd7c8a82a5c23880fe7632a3cChris Lattner /// Destroy - Call destructors and release memory. 583411280e5b25ba7dcd7c8a82a5c23880fe7632a3cChris Lattner virtual void Destroy(ASTContext& C); 584411280e5b25ba7dcd7c8a82a5c23880fe7632a3cChris Lattner 585780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner const ObjCList<ObjCProtocolDecl> &getReferencedProtocols() const { 586780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner return ReferencedProtocols; 587980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff } 588dbc933701d20918add13b6a3c9d47ff8c75419cfDaniel Dunbar typedef ObjCList<ObjCProtocolDecl>::iterator protocol_iterator; 589780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();} 590780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner protocol_iterator protocol_end() const { return ReferencedProtocols.end(); } 591780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner 59238af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner /// setProtocolList - Set the list of protocols that this interface 593780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner /// implements. 59438af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num, 59538af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner ASTContext &C) { 59638af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner ReferencedProtocols.set(List, Num, C); 597aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian } 598aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian 59991b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff ObjCProtocolDecl *lookupProtocolNamed(IdentifierInfo *PName); 60091b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff 60194a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff // Lookup a method. First, we search locally. If a method isn't 60294a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff // found, we search referenced protocols and class categories. 603a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCMethodDecl *lookupInstanceMethod(Selector Sel); 604a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCMethodDecl *lookupClassMethod(Selector Sel); 605a66793ee8d2589ead81739d9b8a968650db3d452Fariborz Jahanian 606768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff bool isForwardDecl() const { return isForwardProtoDecl; } 607768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff void setForwardDecl(bool val) { isForwardProtoDecl = val; } 608980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 609423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff // Location information, modeled after the Stmt API. 610423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff SourceLocation getLocStart() const { return getLocation(); } // '@'protocol 611423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff SourceLocation getLocEnd() const { return EndLoc; } 612423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff void setLocEnd(SourceLocation LE) { EndLoc = LE; }; 613423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff 614a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const Decl *D) { return D->getKind() == ObjCProtocol; } 615a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCProtocolDecl *D) { return true; } 616980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff}; 617980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 618a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCClassDecl - Specifies a list of forward class declarations. For example: 61906ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff/// 62006ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff/// @class NSCursor, NSImage, NSPasteboard, NSWindow; 6210c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 6224afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCClassDecl : public Decl { 62367956052ea5fb0cd7f443de96a11f9a0176dc681Chris Lattner ObjCList<ObjCInterfaceDecl> ForwardDecls; 62461f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner 625d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor ObjCClassDecl(DeclContext *DC, SourceLocation L, 62638af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner ObjCInterfaceDecl *const *Elts, unsigned nElts, ASTContext &C); 62767956052ea5fb0cd7f443de96a11f9a0176dc681Chris Lattner virtual ~ObjCClassDecl() {} 62861f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattnerpublic: 629400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek 630400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek /// Destroy - Call destructors and release memory. 631400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek virtual void Destroy(ASTContext& C); 632400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek 633d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor static ObjCClassDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L, 63467956052ea5fb0cd7f443de96a11f9a0176dc681Chris Lattner ObjCInterfaceDecl *const *Elts, unsigned nElts); 63561f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner 63667956052ea5fb0cd7f443de96a11f9a0176dc681Chris Lattner typedef ObjCList<ObjCInterfaceDecl>::iterator iterator; 63767956052ea5fb0cd7f443de96a11f9a0176dc681Chris Lattner iterator begin() const { return ForwardDecls.begin(); } 63867956052ea5fb0cd7f443de96a11f9a0176dc681Chris Lattner iterator end() const { return ForwardDecls.end(); } 639400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek 640a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const Decl *D) { return D->getKind() == ObjCClass; } 641a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCClassDecl *D) { return true; } 64206ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff}; 64306ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff 644a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCForwardProtocolDecl - Specifies a list of forward protocol declarations. 64506ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff/// For example: 64606ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff/// 6470c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @protocol NSTextInput, NSChangeSpelling, NSDraggingInfo; 6480c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 6494afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCForwardProtocolDecl : public Decl { 65007fa7749da805969f2ed467a4eb5b405a4ff9a23Chris Lattner ObjCList<ObjCProtocolDecl> ReferencedProtocols; 65161f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner 652d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor ObjCForwardProtocolDecl(DeclContext *DC, SourceLocation L, 65338af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner ObjCProtocolDecl *const *Elts, unsigned nElts, 65438af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner ASTContext &C); 65507fa7749da805969f2ed467a4eb5b405a4ff9a23Chris Lattner virtual ~ObjCForwardProtocolDecl() {} 65605ac3ef08f9d06e0a4439073c9edabf7f912f946Ted Kremenek 65761f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattnerpublic: 658d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor static ObjCForwardProtocolDecl *Create(ASTContext &C, DeclContext *DC, 659d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor SourceLocation L, 66007fa7749da805969f2ed467a4eb5b405a4ff9a23Chris Lattner ObjCProtocolDecl *const *Elts, 66107fa7749da805969f2ed467a4eb5b405a4ff9a23Chris Lattner unsigned Num); 66261f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner 6630b7ebb3dba0df0a6cbf221e5edbc6a4b8848478cChris Lattner /// Destroy - Call destructors and release memory. 6640b7ebb3dba0df0a6cbf221e5edbc6a4b8848478cChris Lattner virtual void Destroy(ASTContext& C); 6659fa5e65d08aee1875c5f2a841c8b0b4069bd00e5Chris Lattner 66607fa7749da805969f2ed467a4eb5b405a4ff9a23Chris Lattner typedef ObjCList<ObjCProtocolDecl>::iterator iterator; 66707fa7749da805969f2ed467a4eb5b405a4ff9a23Chris Lattner iterator begin() const { return ReferencedProtocols.begin(); } 66807fa7749da805969f2ed467a4eb5b405a4ff9a23Chris Lattner iterator end() const { return ReferencedProtocols.end(); } 66905ac3ef08f9d06e0a4439073c9edabf7f912f946Ted Kremenek 67006ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff static bool classof(const Decl *D) { 671a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek return D->getKind() == ObjCForwardProtocol; 67206ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff } 673a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCForwardProtocolDecl *D) { return true; } 674980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff}; 675980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 676a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCCategoryDecl - Represents a category declaration. A category allows 6770c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// you to add methods to an existing class (without subclassing or modifying 6780c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// the original class interface or implementation:-). Categories don't allow 6790c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// you to add instance data. The following example adds "myMethod" to all 6800c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// NSView's within a process: 6810c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 6820c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @interface NSView (MyViewMethods) 6830c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - myMethod; 6840c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end 6850c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 6860c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// Cateogries also allow you to split the implementation of a class across 6870c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// several files (a feature more naturally supported in C++). 6880c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 6890c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// Categories were originally inspired by dynamic languages such as Common 69068c82cf61228102aba1194efef222fa1478af2a8Chris Lattner/// Lisp and Smalltalk. More traditional class-based languages (C++, Java) 6910c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// don't support this level of dynamism, which is both powerful and dangerous. 6920c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 693e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroffclass ObjCCategoryDecl : public ObjCContainerDecl { 694980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff /// Interface belonging to this category 695a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *ClassInterface; 696980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 69768c82cf61228102aba1194efef222fa1478af2a8Chris Lattner /// referenced protocols in this category. 698780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner ObjCList<ObjCProtocolDecl> ReferencedProtocols; 699980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 700a8ff9f455d94d9609766cfd5186b6e21dc2102f1Chris Lattner /// Next category belonging to this class. 701a8ff9f455d94d9609766cfd5186b6e21dc2102f1Chris Lattner /// FIXME: this should not be a singly-linked list. Move storage elsewhere. 702a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCCategoryDecl *NextClassCategory; 703ca3adf7e8cac8c9fbaf592b1e5c2be6f082de7baFariborz Jahanian 704423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff SourceLocation EndLoc; // marks the '>' or identifier. 70561f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner 706d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor ObjCCategoryDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id) 707d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor : ObjCContainerDecl(ObjCCategory, DC, L, Id), 7082f0fe337f499c78710b718324b25510670d885b1Chris Lattner ClassInterface(0), NextClassCategory(0){ 709a906135721c350435319347d2672bbb3bf494f91Chris Lattner } 71061f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattnerpublic: 71161f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner 712d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor static ObjCCategoryDecl *Create(ASTContext &C, DeclContext *DC, 7130ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner SourceLocation L, IdentifierInfo *Id); 71461f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner 715e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner ObjCInterfaceDecl *getClassInterface() { return ClassInterface; } 716e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; } 717a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek void setClassInterface(ObjCInterfaceDecl *IDecl) { ClassInterface = IDecl; } 718980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 71938af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner /// setProtocolList - Set the list of protocols that this interface 720f7b2c98c16dfb2261ea57d40a1d5bc4738e73175Chris Lattner /// implements. 72138af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num, 72238af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner ASTContext &C) { 72338af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner ReferencedProtocols.set(List, Num, C); 724780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner } 725980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 726780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner const ObjCList<ObjCProtocolDecl> &getReferencedProtocols() const { 727780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner return ReferencedProtocols; 7288f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian } 729780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner 730a8ff9f455d94d9609766cfd5186b6e21dc2102f1Chris Lattner typedef ObjCList<ObjCProtocolDecl>::iterator protocol_iterator; 731780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();} 732780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner protocol_iterator protocol_end() const { return ReferencedProtocols.end(); } 733780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner 734a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCCategoryDecl *getNextClassCategory() const { return NextClassCategory; } 735980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff void insertNextClassCategory() { 7363d58138992b9bc7b34aaa680f3ddf3971292eb7dSteve Naroff NextClassCategory = ClassInterface->getCategoryList(); 7373d58138992b9bc7b34aaa680f3ddf3971292eb7dSteve Naroff ClassInterface->setCategoryList(this); 738980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff } 739423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff // Location information, modeled after the Stmt API. 740423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff SourceLocation getLocStart() const { return getLocation(); } // '@'interface 741423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff SourceLocation getLocEnd() const { return EndLoc; } 742423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff void setLocEnd(SourceLocation LE) { EndLoc = LE; }; 743423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff 744a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const Decl *D) { return D->getKind() == ObjCCategory; } 745a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCCategoryDecl *D) { return true; } 746980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff}; 7470c6b6243d3efd958c17943130e2a773653511edcSteve Naroff 7483aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattnerclass ObjCImplDecl : public Decl, public DeclContext { 7498f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian /// Class interface for this category implementation 750a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *ClassInterface; 7513aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner 752e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff /// implemented instance methods 753a8ff9f455d94d9609766cfd5186b6e21dc2102f1Chris Lattner llvm::SmallVector<ObjCMethodDecl*, 16> InstanceMethods; 7548f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian 755e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff /// implemented class methods 756a8ff9f455d94d9609766cfd5186b6e21dc2102f1Chris Lattner llvm::SmallVector<ObjCMethodDecl*, 16> ClassMethods; 757f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian 758559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian /// Property Implementations in this category 759f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian llvm::SmallVector<ObjCPropertyImplDecl*, 8> PropertyImplementations; 7603aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner 761e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff SourceLocation EndLoc; 762cddc88800bbd1213ec70ae5153c6a7f2e380fd8dChris Lattner 7633aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattnerprotected: 7643aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner ObjCImplDecl(Kind DK, DeclContext *DC, SourceLocation L, 7653aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner ObjCInterfaceDecl *classInterface) 766cddc88800bbd1213ec70ae5153c6a7f2e380fd8dChris Lattner : Decl(DK, DC, L), DeclContext(DK), 767cddc88800bbd1213ec70ae5153c6a7f2e380fd8dChris Lattner ClassInterface(classInterface) {} 7683aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner 76975c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattnerpublic: 770cddc88800bbd1213ec70ae5153c6a7f2e380fd8dChris Lattner virtual ~ObjCImplDecl() {} 771cddc88800bbd1213ec70ae5153c6a7f2e380fd8dChris Lattner 772e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; } 773e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner ObjCInterfaceDecl *getClassInterface() { return ClassInterface; } 7748f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian 775a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek void addInstanceMethod(ObjCMethodDecl *method) { 776e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff InstanceMethods.push_back(method); 777e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff } 778a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek void addClassMethod(ObjCMethodDecl *method) { 779e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff ClassMethods.push_back(method); 780f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian } 7813aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner 78253df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner // Get the local instance/class method declared in this interface. 7833216dcdebb8ae0f2993ac5f5249caa217444bacfDaniel Dunbar ObjCMethodDecl *getInstanceMethod(Selector Sel) const; 7843216dcdebb8ae0f2993ac5f5249caa217444bacfDaniel Dunbar ObjCMethodDecl *getClassMethod(Selector Sel) const; 78553df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner ObjCMethodDecl *getMethod(Selector Sel, bool isInstance) const { 78653df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner return isInstance ? getInstanceMethod(Sel) : getClassMethod(Sel); 78753df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner } 788f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian 789f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian void addPropertyImplementation(ObjCPropertyImplDecl *property) { 790f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian PropertyImplementations.push_back(property); 791f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanian } 7923aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner 793ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian ObjCPropertyImplDecl *FindPropertyImplDecl(IdentifierInfo *propertyId) const; 794ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian ObjCPropertyImplDecl *FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const; 795ae6f6fd1527a1da84679a6f0439dec3bbbd6ca7bFariborz Jahanian 796559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian typedef llvm::SmallVector<ObjCPropertyImplDecl*, 8>::const_iterator 797559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian propimpl_iterator; 798559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian propimpl_iterator propimpl_begin() const { 799559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian return PropertyImplementations.begin(); 800559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian } 801559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian propimpl_iterator propimpl_end() const { 802559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian return PropertyImplementations.end(); 803559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian } 804559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian 805a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek typedef llvm::SmallVector<ObjCMethodDecl*, 32>::const_iterator 806ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner instmeth_iterator; 807ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner instmeth_iterator instmeth_begin() const { return InstanceMethods.begin(); } 808ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner instmeth_iterator instmeth_end() const { return InstanceMethods.end(); } 809ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner 810a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek typedef llvm::SmallVector<ObjCMethodDecl*, 32>::const_iterator 811ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner classmeth_iterator; 812ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner classmeth_iterator classmeth_begin() const { return ClassMethods.begin(); } 813ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner classmeth_iterator classmeth_end() const { return ClassMethods.end(); } 814ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner 815ab4c4d5e5ececa77aae7e291fafcba3049319cdcChris Lattner 816e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff // Location information, modeled after the Stmt API. 817e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff SourceLocation getLocStart() const { return getLocation(); } 818e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff SourceLocation getLocEnd() const { return EndLoc; } 819e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff void setLocEnd(SourceLocation LE) { EndLoc = LE; }; 8203aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner}; 8213aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner 8223aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// ObjCCategoryImplDecl - An object of this class encapsulates a category 8233aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @implementation declaration. If a category class has declaration of a 8243aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// property, its implementation must be specified in the category's 8253aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @implementation declaration. Example: 8263aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @interface I @end 8273aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @interface I(CATEGORY) 8283aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @property int p1, d1; 8293aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @end 8303aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @implementation I(CATEGORY) 8313aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @dynamic p1,d1; 8323aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @end 8333aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// 8343aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// ObjCCategoryImplDecl 8353aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattnerclass ObjCCategoryImplDecl : public ObjCImplDecl { 8363aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner // Category name 8373aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner IdentifierInfo *Id; 8383aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner 8393aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner ObjCCategoryImplDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id, 8403aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner ObjCInterfaceDecl *classInterface) 8413aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner : ObjCImplDecl(ObjCCategoryImpl, DC, L, classInterface), Id(Id) {} 8423aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattnerpublic: 8433aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner static ObjCCategoryImplDecl *Create(ASTContext &C, DeclContext *DC, 8443aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner SourceLocation L, IdentifierInfo *Id, 8453aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner ObjCInterfaceDecl *classInterface); 8463aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner 8473aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner /// getIdentifier - Get the identifier that names the class 8483aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner /// interface associated with this implementation. 8493aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner IdentifierInfo *getIdentifier() const { 8503aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner return Id; 8513aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner } 8523aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner 8533aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner /// getNameAsCString - Get the name of identifier for the class 8543aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner /// interface associated with this implementation as a C string 8553aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner /// (const char*). 8563aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner const char *getNameAsCString() const { 857cddc88800bbd1213ec70ae5153c6a7f2e380fd8dChris Lattner return Id ? Id->getName() : ""; 8583aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner } 8593aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner 8603aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner /// @brief Get the name of the class associated with this interface. 8613aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner std::string getNameAsString() const { 862cddc88800bbd1213ec70ae5153c6a7f2e380fd8dChris Lattner return Id ? Id->getName() : ""; 8633aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner } 8643aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner 865a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const Decl *D) { return D->getKind() == ObjCCategoryImpl;} 866a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCCategoryImplDecl *D) { return true; } 867b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff static DeclContext *castToDeclContext(const ObjCCategoryImplDecl *D) { 868b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff return static_cast<DeclContext *>(const_cast<ObjCCategoryImplDecl*>(D)); 869b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff } 870b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff static ObjCCategoryImplDecl *castFromDeclContext(const DeclContext *DC) { 871b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff return static_cast<ObjCCategoryImplDecl *>(const_cast<DeclContext*>(DC)); 872b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff } 8738f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian}; 8748f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian 875a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCImplementationDecl - Represents a class definition - this is where 8760c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// method definitions are specified. For example: 8770c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 87898abf4bd3526a00a0e5cf71a9462c181f97b1c81Fariborz Jahanian/// @code 8790c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @implementation MyClass 8800c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (void)myMethod { /* do something */ } 8810c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end 88298abf4bd3526a00a0e5cf71a9462c181f97b1c81Fariborz Jahanian/// @endcode 8830c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 8840c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// Typically, instance variables are specified in the class interface, 885ec0d7a6f4b0699cc9960e6d9fee0f957c64d1cf9Douglas Gregor/// *not* in the implementation. Nevertheless (for legacy reasons), we 88653df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner/// allow instance variables to be specified in the implementation. When 88753df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner/// specified, they need to be *identical* to the interface. 8880c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 8893aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattnerclass ObjCImplementationDecl : public ObjCImplDecl { 890980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff /// Implementation Class's super class. 891a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *SuperClass; 892980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 8937a21bd046fe57629ab074980cf8193f5e0c15735Chris Lattner /// Instance variables declared in the @implementation. 8947a21bd046fe57629ab074980cf8193f5e0c15735Chris Lattner ObjCList<ObjCIvarDecl> IVars; 8950416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff 8964afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor ObjCImplementationDecl(DeclContext *DC, SourceLocation L, 897a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *classInterface, 898a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *superDecl) 8993aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner : ObjCImplDecl(ObjCImplementation, DC, L, classInterface), 9003aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner SuperClass(superDecl){} 90175c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattnerpublic: 902d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor static ObjCImplementationDecl *Create(ASTContext &C, DeclContext *DC, 9034afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor SourceLocation L, 90475c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner ObjCInterfaceDecl *classInterface, 90575c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner ObjCInterfaceDecl *superDecl); 90675c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner 9077a21bd046fe57629ab074980cf8193f5e0c15735Chris Lattner /// Destroy - Call destructors and release memory. 9087a21bd046fe57629ab074980cf8193f5e0c15735Chris Lattner virtual void Destroy(ASTContext& C); 9097a21bd046fe57629ab074980cf8193f5e0c15735Chris Lattner 91038af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner void setIVarList(ObjCIvarDecl *const *InArray, unsigned Num, ASTContext &C) { 91138af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner IVars.set(InArray, Num, C); 9127a21bd046fe57629ab074980cf8193f5e0c15735Chris Lattner } 913980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 9144afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// getIdentifier - Get the identifier that names the class 9154afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// interface associated with this implementation. 9164afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor IdentifierInfo *getIdentifier() const { 9174afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return getClassInterface()->getIdentifier(); 9184afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 9194afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 9204afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// getNameAsCString - Get the name of identifier for the class 9214afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// interface associated with this implementation as a C string 9224afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// (const char*). 9234afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor const char *getNameAsCString() const { 9244afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor assert(getIdentifier() && "Name is not a simple identifier"); 9254afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return getIdentifier()->getName(); 9264afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 9274afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 9284afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// @brief Get the name of the class associated with this interface. 9294afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor std::string getNameAsString() const { 9304afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return getClassInterface()->getNameAsString(); 9314afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 9324afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 933e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner const ObjCInterfaceDecl *getSuperClass() const { return SuperClass; } 934e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner ObjCInterfaceDecl *getSuperClass() { return SuperClass; } 935980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 936f3a7af901231535191d14cb524d58f22907ac4d2Chris Lattner void setSuperClass(ObjCInterfaceDecl * superCls) { SuperClass = superCls; } 9373aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner 9387a21bd046fe57629ab074980cf8193f5e0c15735Chris Lattner typedef ObjCList<ObjCIvarDecl>::iterator ivar_iterator; 9397a21bd046fe57629ab074980cf8193f5e0c15735Chris Lattner ivar_iterator ivar_begin() const { return IVars.begin(); } 9407a21bd046fe57629ab074980cf8193f5e0c15735Chris Lattner ivar_iterator ivar_end() const { return IVars.end(); } 9417a21bd046fe57629ab074980cf8193f5e0c15735Chris Lattner unsigned ivar_size() const { return IVars.size(); } 9427a21bd046fe57629ab074980cf8193f5e0c15735Chris Lattner bool ivar_empty() const { return IVars.empty(); } 9430157c5144513438bb74aebf50d18f95df4104acbChris Lattner 944980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff static bool classof(const Decl *D) { 945a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek return D->getKind() == ObjCImplementation; 946980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff } 947a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCImplementationDecl *D) { return true; } 948b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff static DeclContext *castToDeclContext(const ObjCImplementationDecl *D) { 949b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff return static_cast<DeclContext *>(const_cast<ObjCImplementationDecl*>(D)); 950b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff } 951b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff static ObjCImplementationDecl *castFromDeclContext(const DeclContext *DC) { 952b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff return static_cast<ObjCImplementationDecl *>(const_cast<DeclContext*>(DC)); 953b718b407db1f921c5a2dc0164a23582c322f8ce0Steve Naroff } 954980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff}; 955243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian 956a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCCompatibleAliasDecl - Represents alias of a class. This alias is 957243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian/// declared as @compatibility_alias alias class. 9584afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCCompatibleAliasDecl : public NamedDecl { 959243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian /// Class that this is an alias of. 960a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *AliasedClass; 961243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian 962d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor ObjCCompatibleAliasDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id, 963e8043c39176e7f253fbd92982b077eca6bf2fd59Steve Naroff ObjCInterfaceDecl* aliasedClass) 9644afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor : NamedDecl(ObjCCompatibleAlias, DC, L, Id), AliasedClass(aliasedClass) {} 965f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattnerpublic: 966d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor static ObjCCompatibleAliasDecl *Create(ASTContext &C, DeclContext *DC, 9670ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner SourceLocation L, IdentifierInfo *Id, 968f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner ObjCInterfaceDecl* aliasedClass); 969f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner 970f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner const ObjCInterfaceDecl *getClassInterface() const { return AliasedClass; } 971f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner ObjCInterfaceDecl *getClassInterface() { return AliasedClass; } 972980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 973243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian static bool classof(const Decl *D) { 9748a934233d1582b5bde9d270bc0705aa81e471a79Chris Lattner return D->getKind() == ObjCCompatibleAlias; 975243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian } 976a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCCompatibleAliasDecl *D) { return true; } 977243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian 978243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian}; 9791de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian 9801de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian/// ObjCPropertyDecl - Represents one property declaration in an interface. 9811de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian/// For example: 9821de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian/// @property (assign, readwrite) int MyProperty; 9831de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian/// 9844afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCPropertyDecl : public NamedDecl { 98582a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanianpublic: 986a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner enum PropertyAttributeKind { 987a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner OBJC_PR_noattr = 0x00, 988a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner OBJC_PR_readonly = 0x01, 989a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner OBJC_PR_getter = 0x02, 990a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner OBJC_PR_assign = 0x04, 991a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner OBJC_PR_readwrite = 0x08, 992a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner OBJC_PR_retain = 0x10, 993a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner OBJC_PR_copy = 0x20, 994a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner OBJC_PR_nonatomic = 0x40, 995a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner OBJC_PR_setter = 0x80 996a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner }; 997af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 998af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar enum SetterKind { Assign, Retain, Copy }; 99946b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian enum PropertyControl { None, Required, Optional }; 100082a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanianprivate: 1001dae1a1a2aa4f245b1958dc8db6089f24c575ef13Fariborz Jahanian QualType DeclType; 1002ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek unsigned PropertyAttributes : 8; 100382a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian 100446b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian // @required/@optional 100546b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian unsigned PropertyImplementation : 2; 100646b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian 10075251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian Selector GetterName; // getter name of NULL if no getter 10085251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian Selector SetterName; // setter name of NULL if no setter 100982a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian 101033de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian ObjCMethodDecl *GetterMethodDecl; // Declaration of getter instance method 101133de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian ObjCMethodDecl *SetterMethodDecl; // Declaration of setter instance method 101233de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian 1013d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor ObjCPropertyDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id, 1014d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor QualType T) 10154afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor : NamedDecl(ObjCProperty, DC, L, Id), DeclType(T), 101633de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian PropertyAttributes(OBJC_PR_noattr), PropertyImplementation(None), 101733de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian GetterName(Selector()), 101833de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian SetterName(Selector()), 101933de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian GetterMethodDecl(0), SetterMethodDecl(0) {} 1020f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattnerpublic: 1021d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor static ObjCPropertyDecl *Create(ASTContext &C, DeclContext *DC, 1022d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor SourceLocation L, 102346b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian IdentifierInfo *Id, QualType T, 102446b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian PropertyControl propControl = None); 1025dae1a1a2aa4f245b1958dc8db6089f24c575ef13Fariborz Jahanian QualType getType() const { return DeclType; } 1026c35b9e4e2efad727538c848cf30d4b0eb1031dc9Fariborz Jahanian 1027a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner PropertyAttributeKind getPropertyAttributes() const { 1028f4af5154571e0c5eadb19df10e65464766ef6683Chris Lattner return PropertyAttributeKind(PropertyAttributes); 1029f4af5154571e0c5eadb19df10e65464766ef6683Chris Lattner } 1030564576b225386cbff375351597dd5e2a92872d38Fariborz Jahanian void setPropertyAttributes(PropertyAttributeKind PRVal) { 1031a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner PropertyAttributes |= PRVal; 103282a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian } 1033394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar 10348cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian void makeitReadWriteAttribute(void) { 10358cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian PropertyAttributes &= ~OBJC_PR_readonly; 10368cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian PropertyAttributes |= OBJC_PR_readwrite; 10378cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian } 10388cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian 1039af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar // Helper methods for accessing attributes. 1040af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 1041af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar /// isReadOnly - Return true iff the property has a setter. 1042394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar bool isReadOnly() const { 1043394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar return (PropertyAttributes & OBJC_PR_readonly); 1044394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar } 1045af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 1046af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar /// getSetterKind - Return the method used for doing assignment in 1047af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar /// the property setter. This is only valid if the property has been 1048af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar /// defined to have a setter. 1049af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar SetterKind getSetterKind() const { 1050af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar if (PropertyAttributes & OBJC_PR_retain) 1051af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar return Retain; 1052af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar if (PropertyAttributes & OBJC_PR_copy) 1053af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar return Copy; 1054af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar return Assign; 1055af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar } 1056af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 10575251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian Selector getGetterName() const { return GetterName; } 10585251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian void setGetterName(Selector Sel) { GetterName = Sel; } 105982a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian 10605251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian Selector getSetterName() const { return SetterName; } 10615251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian void setSetterName(Selector Sel) { SetterName = Sel; } 106282a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian 106333de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian ObjCMethodDecl *getGetterMethodDecl() const { return GetterMethodDecl; } 106433de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian void setGetterMethodDecl(ObjCMethodDecl *gDecl) { GetterMethodDecl = gDecl; } 106533de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian 106633de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian ObjCMethodDecl *getSetterMethodDecl() const { return SetterMethodDecl; } 106733de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian void setSetterMethodDecl(ObjCMethodDecl *gDecl) { SetterMethodDecl = gDecl; } 106833de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian 106946b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian // Related to @optional/@required declared in @protocol 107046b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian void setPropertyImplementation(PropertyControl pc) { 107146b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian PropertyImplementation = pc; 107246b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian } 107346b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian PropertyControl getPropertyImplementation() const { 107446b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian return PropertyControl(PropertyImplementation); 107546b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian } 107646b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian 107782a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian static bool classof(const Decl *D) { 1078670aa9d7639278f507930e95dc89c12032ab7c7eSam Bishop return D->getKind() == ObjCProperty; 107982a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian } 1080a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCPropertyDecl *D) { return true; } 108182a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian}; 1082980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 108361d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian/// ObjCPropertyImplDecl - Represents implementation declaration of a property 108461d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian/// in a class or category implementation block. For example: 108561d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian/// @synthesize prop1 = ivar1; 108661d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian/// 10874afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCPropertyImplDecl : public Decl { 108861d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanianpublic: 10899f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar enum Kind { 10909f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar Synthesize, 10919f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar Dynamic 109261d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian }; 109361d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanianprivate: 1094559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian SourceLocation AtLoc; // location of @synthesize or @dynamic 109561d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian /// Property declaration being implemented 109661d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian ObjCPropertyDecl *PropertyDecl; 1097be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek 109861d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian /// Null for @dynamic. Required for @synthesize. 109961d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian ObjCIvarDecl *PropertyIvarDecl; 1100be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek 1101d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor ObjCPropertyImplDecl(DeclContext *DC, SourceLocation atLoc, SourceLocation L, 1102628b96f34e93b643b6e15e75eabb8d96079a7e27Fariborz Jahanian ObjCPropertyDecl *property, 11039f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar Kind PK, 1104628b96f34e93b643b6e15e75eabb8d96079a7e27Fariborz Jahanian ObjCIvarDecl *ivarDecl) 11054afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor : Decl(ObjCPropertyImpl, DC, L), AtLoc(atLoc), 1106d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor PropertyDecl(property), PropertyIvarDecl(ivarDecl) { 11079f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar assert (PK == Dynamic || PropertyIvarDecl); 11089f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar } 1109628b96f34e93b643b6e15e75eabb8d96079a7e27Fariborz Jahanian 11109f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbarpublic: 1111d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor static ObjCPropertyImplDecl *Create(ASTContext &C, DeclContext *DC, 1112d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor SourceLocation atLoc, SourceLocation L, 1113628b96f34e93b643b6e15e75eabb8d96079a7e27Fariborz Jahanian ObjCPropertyDecl *property, 11149f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar Kind PK, 1115628b96f34e93b643b6e15e75eabb8d96079a7e27Fariborz Jahanian ObjCIvarDecl *ivarDecl); 111661d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian 1117d40910b581b09c937a8c1fdcde9b8ec724398fb9Steve Naroff SourceLocation getLocStart() const { return AtLoc; } 1118d40910b581b09c937a8c1fdcde9b8ec724398fb9Steve Naroff 1119be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek ObjCPropertyDecl *getPropertyDecl() const { 1120be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek return PropertyDecl; 1121be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek } 112261d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian 11239f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar Kind getPropertyImplementation() const { 11249f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar return PropertyIvarDecl ? Synthesize : Dynamic; 1125be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek } 112661d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian 1127af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar ObjCIvarDecl *getPropertyIvarDecl() const { 1128be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek return PropertyIvarDecl; 1129be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek } 113061d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian 113161d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian static bool classof(const Decl *D) { 113261d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian return D->getKind() == ObjCPropertyImpl; 113361d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian } 113461d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian static bool classof(const ObjCPropertyImplDecl *D) { return true; } 113561d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian}; 113661d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian 1137980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff} // end namespace clang 1138980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff#endif 1139