DeclObjC.h revision 4ecb25fa94897b2c03510292acace710e5262ba5
1980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff//===--- DeclObjC.h - Classes for representing declarations -----*- C++ -*-===// 2980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff// 3980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff// The LLVM Compiler Infrastructure 4980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff// 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details. 7980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff// 8980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff//===----------------------------------------------------------------------===// 9980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff// 10980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff// This file defines the DeclObjC interface and subclasses. 11980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff// 12980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff//===----------------------------------------------------------------------===// 13980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 14980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff#ifndef LLVM_CLANG_AST_DECLOBJC_H 15980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff#define LLVM_CLANG_AST_DECLOBJC_H 16980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 17980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff#include "clang/AST/Decl.h" 186ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson#include "llvm/ADT/STLExtras.h" 19980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 20980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffnamespace clang { 21980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffclass Expr; 22980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffclass Stmt; 23980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffclass FunctionDecl; 24980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffclass AttributeList; 2560f8c868ffb346b78451a3eccaecd0461d2ae498Fariborz Jahanianclass RecordDecl; 26a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCIvarDecl; 27a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCMethodDecl; 28a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCProtocolDecl; 29a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCCategoryDecl; 30a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCPropertyDecl; 31f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanianclass ObjCPropertyImplDecl; 3268835718c4125f2f66740cd04de7088645ec695dChris Lattner 33793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnerclass ObjCListBase { 34793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner void operator=(const ObjCListBase &); // DO NOT IMPLEMENT 35793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner ObjCListBase(const ObjCListBase&); // DO NOT IMPLEMENT 36793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnerprotected: 37793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner /// List is an array of pointers to objects that are not owned by this object. 38793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner void **List; 393db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner unsigned NumElts; 40793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner 413db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattnerpublic: 42793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner ObjCListBase() : List(0), NumElts(0) {} 43793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner ~ObjCListBase() { 4488cf7a16902a9189d16653e1061cfda333187b58Chris Lattner assert(List == 0 && "Destroy should have been called before dtor"); 453db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner } 461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4738af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner void Destroy(ASTContext &Ctx); 481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 49793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner unsigned size() const { return NumElts; } 50793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner bool empty() const { return NumElts == 0; } 511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 52793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnerprotected: 5338af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner void set(void *const* InList, unsigned Elts, ASTContext &Ctx); 54793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner}; 551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 57793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner/// ObjCList - This is a simple template class used to hold various lists of 58793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner/// decls etc, which is heavily used by the ObjC front-end. This only use case 59793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner/// this supports is setting the list all at once and then reading elements out 60793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner/// of it. 61793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnertemplate <typename T> 62793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnerclass ObjCList : public ObjCListBase { 63793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnerpublic: 6438af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner void set(T* const* InList, unsigned Elts, ASTContext &Ctx) { 6538af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner ObjCListBase::set(reinterpret_cast<void*const*>(InList), Elts, Ctx); 66793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner } 671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 68793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner typedef T* const * iterator; 69793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner iterator begin() const { return (iterator)List; } 70793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner iterator end() const { return (iterator)List+NumElts; } 711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 72793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner T* operator[](unsigned Idx) const { 73793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner assert(Idx < NumElts && "Invalid access"); 74793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner return (T*)List[Idx]; 753db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner } 763db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner}; 773db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner 7818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor/// \brief A list of Objective-C protocols, along with the source 7918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor/// locations at which they were referenced. 8018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregorclass ObjCProtocolList : public ObjCList<ObjCProtocolDecl> { 8118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor SourceLocation *Locations; 8218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor 8318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor using ObjCList<ObjCProtocolDecl>::set; 8418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor 8518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregorpublic: 8618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor ObjCProtocolList() : ObjCList<ObjCProtocolDecl>(), Locations(0) { } 8718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor 8818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor typedef const SourceLocation *loc_iterator; 8918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor loc_iterator loc_begin() const { return Locations; } 9018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor loc_iterator loc_end() const { return Locations + size(); } 9118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor 9218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor void set(ObjCProtocolDecl* const* InList, unsigned Elts, 9318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor const SourceLocation *Locs, ASTContext &Ctx); 9418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor void Destroy(ASTContext &Ctx); 9518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor}; 961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff 98a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCMethodDecl - Represents an instance or class method declaration. 9958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// ObjC methods can be declared within 4 contexts: class interfaces, 10058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// categories, protocols, and class implementations. While C++ member 1011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// functions leverage C syntax, Objective-C method syntax is modeled after 1021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Smalltalk (using colons to specify argument types/expressions). 10358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Here are some brief examples: 10458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// 10558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Setter/getter instance methods: 10658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// - (void)setMenu:(NSMenu *)menu; 1071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// - (NSMenu *)menu; 1081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 10958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Instance method that takes 2 NSView arguments: 11058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// - (void)replaceSubview:(NSView *)oldView with:(NSView *)newView; 11158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// 11258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Getter class method: 11358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// + (NSMenu *)defaultMenu; 11458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// 11558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// A selector represents a unique name for a method. The selector names for 11658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// the above methods are setMenu:, menu, replaceSubview:with:, and defaultMenu. 11758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// 1184afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCMethodDecl : public NamedDecl, public DeclContext { 11958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroffpublic: 12058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff enum ImplementationControl { None, Required, Optional }; 12158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroffprivate: 12258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff /// Bitfields must be first fields in this class so they pack with those 12358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff /// declared in class Decl. 12458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff /// instance (true) or class (false) method. 12558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff bool IsInstance : 1; 12658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff bool IsVariadic : 1; 1271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1284607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian // Synthesized declaration method for a property setter/getter 1294607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian bool IsSynthesized : 1; 1301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 131ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek // NOTE: VC++ treats enums as signed, avoid using ImplementationControl enum 13258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff /// @required/@optional 133ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek unsigned DeclImplementation : 2; 1341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 135ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek // NOTE: VC++ treats enums as signed, avoid using the ObjCDeclQualifier enum 13658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff /// in, inout, etc. 137ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek unsigned objcDeclQualifier : 6; 1381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1397732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian // Number of args separated by ':' in a method declaration. 1407732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian unsigned NumSelectorArgs; 1417732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian 1424bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor // Result type of this method. 14358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff QualType MethodDeclType; 1444bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor 1454bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor // Type source information for the result type. 1464bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor TypeSourceInfo *ResultTInfo; 1474bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor 1482073216a1075767b5d25c23d1462b7034686d94dChris Lattner /// ParamInfo - List of pointers to VarDecls for the formal parameters of this 1492073216a1075767b5d25c23d1462b7034686d94dChris Lattner /// Method. 1502073216a1075767b5d25c23d1462b7034686d94dChris Lattner ObjCList<ParmVarDecl> ParamInfo; 1511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff /// List of attributes for this method declaration. 153a2e85ada1dfef36201a31f6646bc4ea3bd76a89aArgyrios Kyrtzidis SourceLocation EndLoc; // the location of the ';' or '}'. 1541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff // The following are only used for method definitions, null otherwise. 15658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff // FIXME: space savings opportunity, consider a sub-class. 15758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff Stmt *Body; 158451318c08a6342c10b8986060386fd9274418437Daniel Dunbar 159451318c08a6342c10b8986060386fd9274418437Daniel Dunbar /// SelfDecl - Decl for the implicit self parameter. This is lazily 160451318c08a6342c10b8986060386fd9274418437Daniel Dunbar /// constructed by createImplicitParams. 1614111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner ImplicitParamDecl *SelfDecl; 162451318c08a6342c10b8986060386fd9274418437Daniel Dunbar /// CmdDecl - Decl for the implicit _cmd parameter. This is lazily 163451318c08a6342c10b8986060386fd9274418437Daniel Dunbar /// constructed by createImplicitParams. 1644111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner ImplicitParamDecl *CmdDecl; 1651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 166a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCMethodDecl(SourceLocation beginLoc, SourceLocation endLoc, 16758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff Selector SelInfo, QualType T, 1684bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor TypeSourceInfo *ResultTInfo, 1690701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff DeclContext *contextDecl, 170f6414927e67e27d9324d8d179c5f7ea620443924Daniel Dunbar bool isInstance = true, 17158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff bool isVariadic = false, 1724607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian bool isSynthesized = false, 1737732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian ImplementationControl impControl = None, 1747732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian unsigned numSelectorArgs = 0) 1754afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor : NamedDecl(ObjCMethod, contextDecl, beginLoc, SelInfo), 176b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner DeclContext(ObjCMethod), 17758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff IsInstance(isInstance), IsVariadic(isVariadic), 1784607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian IsSynthesized(isSynthesized), 17958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff DeclImplementation(impControl), objcDeclQualifier(OBJC_TQ_None), 1807732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian NumSelectorArgs(numSelectorArgs), MethodDeclType(T), 1817732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian ResultTInfo(ResultTInfo), 1824111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner EndLoc(endLoc), Body(0), SelfDecl(0), CmdDecl(0) {} 1838a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek 1842073216a1075767b5d25c23d1462b7034686d94dChris Lattner virtual ~ObjCMethodDecl() {} 18557ea6bee79cc60ba20c7886b453f40f380dce1b1Argyrios Kyrtzidis 18657ea6bee79cc60ba20c7886b453f40f380dce1b1Argyrios Kyrtzidis /// \brief A definition will return its interface declaration. 18757ea6bee79cc60ba20c7886b453f40f380dce1b1Argyrios Kyrtzidis /// An interface declaration will return its definition. 18857ea6bee79cc60ba20c7886b453f40f380dce1b1Argyrios Kyrtzidis /// Otherwise it will return itself. 18957ea6bee79cc60ba20c7886b453f40f380dce1b1Argyrios Kyrtzidis virtual ObjCMethodDecl *getNextRedeclaration(); 19057ea6bee79cc60ba20c7886b453f40f380dce1b1Argyrios Kyrtzidis 1916c4ae5de0c356777446f823b573821fb95560d91Chris Lattnerpublic: 1921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1938a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek /// Destroy - Call destructors and release memory. 1948a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek virtual void Destroy(ASTContext& C); 1956c4ae5de0c356777446f823b573821fb95560d91Chris Lattner 1960ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner static ObjCMethodDecl *Create(ASTContext &C, 1971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation beginLoc, 1986c4ae5de0c356777446f823b573821fb95560d91Chris Lattner SourceLocation endLoc, Selector SelInfo, 1994bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor QualType T, 2004bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor TypeSourceInfo *ResultTInfo, 2014bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor DeclContext *contextDecl, 202f6414927e67e27d9324d8d179c5f7ea620443924Daniel Dunbar bool isInstance = true, 2036c4ae5de0c356777446f823b573821fb95560d91Chris Lattner bool isVariadic = false, 2044607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian bool isSynthesized = false, 2057732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian ImplementationControl impControl = None, 2067732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian unsigned numSelectorArgs = 0); 207e7f9d301a10b4b3223e91d9be4362b44cba0a212Argyrios Kyrtzidis 208e7f9d301a10b4b3223e91d9be4362b44cba0a212Argyrios Kyrtzidis virtual ObjCMethodDecl *getCanonicalDecl(); 20913e635c55eb23f736d38abf9c954801bd6482db4Ted Kremenek const ObjCMethodDecl *getCanonicalDecl() const { 21013e635c55eb23f736d38abf9c954801bd6482db4Ted Kremenek return const_cast<ObjCMethodDecl*>(this)->getCanonicalDecl(); 21113e635c55eb23f736d38abf9c954801bd6482db4Ted Kremenek } 212e7f9d301a10b4b3223e91d9be4362b44cba0a212Argyrios Kyrtzidis 213ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek ObjCDeclQualifier getObjCDeclQualifier() const { 214ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek return ObjCDeclQualifier(objcDeclQualifier); 215ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek } 216a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek void setObjCDeclQualifier(ObjCDeclQualifier QV) { objcDeclQualifier = QV; } 2171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2187732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian unsigned getNumSelectorArgs() const { return NumSelectorArgs; } 2197732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian void setNumSelectorArgs(unsigned numSelectorArgs) { 2207732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian NumSelectorArgs = numSelectorArgs; 2217732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian } 2227732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian 22358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff // Location information, modeled after the Stmt API. 22458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff SourceLocation getLocStart() const { return getLocation(); } 22558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff SourceLocation getLocEnd() const { return EndLoc; } 22653c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff void setEndLoc(SourceLocation Loc) { EndLoc = Loc; } 2271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual SourceRange getSourceRange() const { 2281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(getLocation(), EndLoc); 2299776ba0d844cf9f6888e871e3fd246ae782f76f4Daniel Dunbar } 2301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2315619688510185081cbb4621d703daf7ee24cf39aChris Lattner ObjCInterfaceDecl *getClassInterface(); 2325619688510185081cbb4621d703daf7ee24cf39aChris Lattner const ObjCInterfaceDecl *getClassInterface() const { 2335619688510185081cbb4621d703daf7ee24cf39aChris Lattner return const_cast<ObjCMethodDecl*>(this)->getClassInterface(); 234e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner } 2351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2362e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor Selector getSelector() const { return getDeclName().getObjCSelector(); } 2373a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 23858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff QualType getResultType() const { return MethodDeclType; } 23953c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff void setResultType(QualType T) { MethodDeclType = T; } 2401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2414bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor TypeSourceInfo *getResultTypeSourceInfo() const { return ResultTInfo; } 2424bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor void setResultTypeSourceInfo(TypeSourceInfo *TInfo) { ResultTInfo = TInfo; } 2434bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor 244d57f635d520e8cb5b93d3d770ff58db06c62de54Chris Lattner // Iterator access to formal parameters. 2452073216a1075767b5d25c23d1462b7034686d94dChris Lattner unsigned param_size() const { return ParamInfo.size(); } 2462073216a1075767b5d25c23d1462b7034686d94dChris Lattner typedef ObjCList<ParmVarDecl>::iterator param_iterator; 2472073216a1075767b5d25c23d1462b7034686d94dChris Lattner param_iterator param_begin() const { return ParamInfo.begin(); } 2482073216a1075767b5d25c23d1462b7034686d94dChris Lattner param_iterator param_end() const { return ParamInfo.end(); } 2497732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian // This method returns and of the parameters which are part of the selector 2507732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian // name mangling requirements. 2517732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian param_iterator sel_param_end() const { 2527732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian return ParamInfo.begin() + NumSelectorArgs; 2537732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian } 25489951a86b594513c2a013532ed45d197413b1087Chris Lattner 2554ecb25fa94897b2c03510292acace710e5262ba5Fariborz Jahanian void setMethodParams(ASTContext &C, ParmVarDecl *const *List, unsigned Num, 2564ecb25fa94897b2c03510292acace710e5262ba5Fariborz Jahanian unsigned numSelectorArgs) { 25738af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner ParamInfo.set(List, Num, C); 2584ecb25fa94897b2c03510292acace710e5262ba5Fariborz Jahanian NumSelectorArgs = numSelectorArgs; 2592073216a1075767b5d25c23d1462b7034686d94dChris Lattner } 2604111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner 2616ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson // Iterator access to parameter types. 2626ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson typedef std::const_mem_fun_t<QualType, ParmVarDecl> deref_fun; 2636ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson typedef llvm::mapped_iterator<param_iterator, deref_fun> arg_type_iterator; 2646ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson 2656ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson arg_type_iterator arg_type_begin() const { 2666ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson return llvm::map_iterator(param_begin(), deref_fun(&ParmVarDecl::getType)); 2676ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson } 2686ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson arg_type_iterator arg_type_end() const { 2696ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson return llvm::map_iterator(param_end(), deref_fun(&ParmVarDecl::getType)); 2706ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson } 2711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 272451318c08a6342c10b8986060386fd9274418437Daniel Dunbar /// createImplicitParams - Used to lazily create the self and cmd 273451318c08a6342c10b8986060386fd9274418437Daniel Dunbar /// implict parameters. This must be called prior to using getSelfDecl() 274451318c08a6342c10b8986060386fd9274418437Daniel Dunbar /// or getCmdDecl(). The call is ignored if the implicit paramters 275451318c08a6342c10b8986060386fd9274418437Daniel Dunbar /// have already been created. 276fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian void createImplicitParams(ASTContext &Context, const ObjCInterfaceDecl *ID); 277451318c08a6342c10b8986060386fd9274418437Daniel Dunbar 2784111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner ImplicitParamDecl * getSelfDecl() const { return SelfDecl; } 27953c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff void setSelfDecl(ImplicitParamDecl *SD) { SelfDecl = SD; } 2804111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner ImplicitParamDecl * getCmdDecl() const { return CmdDecl; } 28153c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff void setCmdDecl(ImplicitParamDecl *CD) { CmdDecl = CD; } 2821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 283f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor bool isInstanceMethod() const { return IsInstance; } 28453c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff void setInstanceMethod(bool isInst) { IsInstance = isInst; } 28558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff bool isVariadic() const { return IsVariadic; } 28653c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff void setVariadic(bool isVar) { IsVariadic = isVar; } 2871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 288f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor bool isClassMethod() const { return !IsInstance; } 289f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 2904607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian bool isSynthesized() const { return IsSynthesized; } 29153c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff void setSynthesized(bool isSynth) { IsSynthesized = isSynth; } 2921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff // Related to protocols declared in @protocol 2941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setDeclImplementation(ImplementationControl ic) { 2951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclImplementation = ic; 29658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff } 2971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ImplementationControl getImplementationControl() const { 2981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return ImplementationControl(DeclImplementation); 29958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff } 300792481eec23d8c1aa92173be589e2ae9d02514a5Ted Kremenek 3011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual Stmt *getBody() const { 3021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return (Stmt*) Body; 3037297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor } 3046fb0aee4f9dc261bbec72e1283ad8dc0557a6d96Argyrios Kyrtzidis CompoundStmt *getCompoundBody() { return (CompoundStmt*)Body; } 305d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl void setBody(Stmt *B) { Body = B; } 30658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff 30766570b230941651245accbc5680b60e904eb993cArgyrios Kyrtzidis /// \brief Returns whether this specific method is a definition. 30866570b230941651245accbc5680b60e904eb993cArgyrios Kyrtzidis bool isThisDeclarationADefinition() const { return Body; } 30966570b230941651245accbc5680b60e904eb993cArgyrios Kyrtzidis 31058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff // Implement isa/cast/dyncast/etc. 31180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 312a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCMethodDecl *D) { return true; } 31380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { return K == ObjCMethod; } 31442220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis static DeclContext *castToDeclContext(const ObjCMethodDecl *D) { 31542220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis return static_cast<DeclContext *>(const_cast<ObjCMethodDecl*>(D)); 31642220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis } 31742220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis static ObjCMethodDecl *castFromDeclContext(const DeclContext *DC) { 31842220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis return static_cast<ObjCMethodDecl *>(const_cast<DeclContext*>(DC)); 31942220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis } 32058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff}; 321e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff 322f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor/// ObjCMethodList - a linked list of methods with different signatures. 323f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregorstruct ObjCMethodList { 324f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor ObjCMethodDecl *Method; 325f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor ObjCMethodList *Next; 3261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 327f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor ObjCMethodList() { 3281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Method = 0; 329f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor Next = 0; 330f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor } 331f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor ObjCMethodList(ObjCMethodDecl *M, ObjCMethodList *C) { 332f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor Method = M; 333f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor Next = C; 334f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor } 335f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor}; 336f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor 337e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff/// ObjCContainerDecl - Represents a container for method declarations. 338aecae629269fae3bf484baf1d109e9a89d14eeadArgyrios Kyrtzidis/// Current sub-classes are ObjCInterfaceDecl, ObjCCategoryDecl, 3391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ObjCProtocolDecl, and ObjCImplDecl. 340e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff/// 3414afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCContainerDecl : public NamedDecl, public DeclContext { 342782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek // These two locations in the range mark the end of the method container. 343782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek // The first points to the '@' token, and the second to the 'end' token. 344782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek SourceRange AtEnd; 345e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroffpublic: 346e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff 3471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCContainerDecl(Kind DK, DeclContext *DC, SourceLocation L, 348d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor IdentifierInfo *Id) 3494afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor : NamedDecl(DK, DC, L, Id), DeclContext(DK) {} 350e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff 3510b7ebb3dba0df0a6cbf221e5edbc6a4b8848478cChris Lattner virtual ~ObjCContainerDecl() {} 35209c4719788a5cea09897525e528fa00420f1677bSteve Naroff 35393983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff // Iterator access to properties. 35493983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff typedef specific_decl_iterator<ObjCPropertyDecl> prop_iterator; 3551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump prop_iterator prop_begin() const { 35617945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis return prop_iterator(decls_begin()); 35793983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff } 3581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump prop_iterator prop_end() const { 35917945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis return prop_iterator(decls_end()); 36009c4719788a5cea09897525e528fa00420f1677bSteve Naroff } 3611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3620701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff // Iterator access to instance/class methods. 363f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor typedef specific_decl_iterator<ObjCMethodDecl> method_iterator; 3641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump method_iterator meth_begin() const { 36517945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis return method_iterator(decls_begin()); 3667ed4faca5162b3ab85be7f7e57aa40e6ec170971Ted Kremenek } 3671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump method_iterator meth_end() const { 36817945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis return method_iterator(decls_end()); 3697ed4faca5162b3ab85be7f7e57aa40e6ec170971Ted Kremenek } 3700701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff 3711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump typedef filtered_decl_iterator<ObjCMethodDecl, 3721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump &ObjCMethodDecl::isInstanceMethod> 373669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor instmeth_iterator; 37417945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis instmeth_iterator instmeth_begin() const { 37517945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis return instmeth_iterator(decls_begin()); 376e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff } 37717945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis instmeth_iterator instmeth_end() const { 37817945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis return instmeth_iterator(decls_end()); 379e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff } 380e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff 3811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump typedef filtered_decl_iterator<ObjCMethodDecl, 3821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump &ObjCMethodDecl::isClassMethod> 383669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor classmeth_iterator; 38417945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis classmeth_iterator classmeth_begin() const { 38517945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis return classmeth_iterator(decls_begin()); 386e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff } 38717945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis classmeth_iterator classmeth_end() const { 38817945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis return classmeth_iterator(decls_end()); 3890701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff } 3900701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff 3910701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff // Get the local instance/class method declared in this interface. 392467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis ObjCMethodDecl *getMethod(Selector Sel, bool isInstance) const; 393467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis ObjCMethodDecl *getInstanceMethod(Selector Sel) const { 394467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis return getMethod(Sel, true/*isInstance*/); 39553df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner } 396467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis ObjCMethodDecl *getClassMethod(Selector Sel) const { 397467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis return getMethod(Sel, false/*isInstance*/); 398467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis } 399467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis ObjCIvarDecl *getIvarDecl(IdentifierInfo *Id) const; 4001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 40117945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis ObjCPropertyDecl *FindPropertyDeclaration(IdentifierInfo *PropertyId) const; 40293983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff 403e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff // Marks the end of the container. 404782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek SourceRange getAtEndRange() const { 405782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek return AtEnd; 406782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek } 407782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek void setAtEndRange(SourceRange atEnd) { 408782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek AtEnd = atEnd; 409782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek } 410ddfd4c9eda34765b08fae4cb31ad5a365face107Argyrios Kyrtzidis 411ddfd4c9eda34765b08fae4cb31ad5a365face107Argyrios Kyrtzidis virtual SourceRange getSourceRange() const { 412782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek return SourceRange(getLocation(), getAtEndRange().getEnd()); 413ddfd4c9eda34765b08fae4cb31ad5a365face107Argyrios Kyrtzidis } 4141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 41509c4719788a5cea09897525e528fa00420f1677bSteve Naroff // Implement isa/cast/dyncast/etc. 41680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 41709c4719788a5cea09897525e528fa00420f1677bSteve Naroff static bool classof(const ObjCContainerDecl *D) { return true; } 41880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { 41980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall return K >= ObjCContainerFirst && 42080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall K <= ObjCContainerLast; 42180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall } 42209c4719788a5cea09897525e528fa00420f1677bSteve Naroff 42309c4719788a5cea09897525e528fa00420f1677bSteve Naroff static DeclContext *castToDeclContext(const ObjCContainerDecl *D) { 42409c4719788a5cea09897525e528fa00420f1677bSteve Naroff return static_cast<DeclContext *>(const_cast<ObjCContainerDecl*>(D)); 42509c4719788a5cea09897525e528fa00420f1677bSteve Naroff } 42609c4719788a5cea09897525e528fa00420f1677bSteve Naroff static ObjCContainerDecl *castFromDeclContext(const DeclContext *DC) { 42709c4719788a5cea09897525e528fa00420f1677bSteve Naroff return static_cast<ObjCContainerDecl *>(const_cast<DeclContext*>(DC)); 42809c4719788a5cea09897525e528fa00420f1677bSteve Naroff } 429e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff}; 430e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff 431a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCInterfaceDecl - Represents an ObjC class declaration. For example: 4320c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 4330c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// // MostPrimitive declares no super class (not particularly useful). 4341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// @interface MostPrimitive 4350c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// // no instance variables or methods. 4360c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end 4370c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 4381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// // NSResponder inherits from NSObject & implements NSCoding (a protocol). 4390c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @interface NSResponder : NSObject <NSCoding> 440a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// { // instance variables are represented by ObjCIvarDecl. 4410c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// id nextResponder; // nextResponder instance variable. 4420c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// } 4430c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (NSResponder *)nextResponder; // return a pointer to NSResponder. 4440c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (void)mouseMoved:(NSEvent *)theEvent; // return void, takes a pointer 4450c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end // to an NSEvent. 4460c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 4470c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// Unlike C/C++, forward class declarations are accomplished with @class. 4480c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// Unlike C/C++, @class allows for a list of classes to be forward declared. 4490c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// Unlike C++, ObjC is a single-rooted class model. In Cocoa, classes 4500c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// typically inherit from NSObject (an exception is NSProxy). 4510c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 4520701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroffclass ObjCInterfaceDecl : public ObjCContainerDecl { 4533110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff /// TypeForDecl - This indicates the Type object that represents this 4543110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff /// TypeDecl. It is a cache maintained by ASTContext::getObjCInterfaceType 4553b3a45858c6b2a45114e91902c3bf3c4b7f5f302Daniel Dunbar mutable Type *TypeForDecl; 4563110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff friend class ASTContext; 4571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 458980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff /// Class's super class. 459a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *SuperClass; 4601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 461980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff /// Protocols referenced in interface header declaration 46218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor ObjCProtocolList ReferencedProtocols; 4631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 464980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff /// List of categories defined for this class. 465a8ff9f455d94d9609766cfd5186b6e21dc2102f1Chris Lattner /// FIXME: Why is this a linked list?? 466a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCCategoryDecl *CategoryList; 4671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4683a3ca1b35a7121aea0bf465a192dce748465e10fFariborz Jahanian bool ForwardDecl:1; // declared with @class. 4693a3ca1b35a7121aea0bf465a192dce748465e10fFariborz Jahanian bool InternalInterface:1; // true - no @interface for @implementation 4701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 471d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff SourceLocation ClassLoc; // location of the class identifier. 472d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff SourceLocation SuperClassLoc; // location of the super class identifier. 473f908a87299d278164540f90b5b6e6cab7b14fb41Steve Naroff SourceLocation EndLoc; // marks the '>', '}', or identifier. 4740e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner 475d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id, 4760b7ebb3dba0df0a6cbf221e5edbc6a4b8848478cChris Lattner SourceLocation CLoc, bool FD, bool isInternal); 4771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 478e881483a3bc22ffad62367501aa09ad8508fe363Chris Lattner virtual ~ObjCInterfaceDecl() {} 4791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4800e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattnerpublic: 4810e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner 4828a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek /// Destroy - Call destructors and release memory. 4838a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek virtual void Destroy(ASTContext& C); 4848a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek 485d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor static ObjCInterfaceDecl *Create(ASTContext &C, DeclContext *DC, 4860ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner SourceLocation atLoc, 4871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump IdentifierInfo *Id, 488d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff SourceLocation ClassLoc = SourceLocation(), 4890e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner bool ForwardDecl = false, 4900e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner bool isInternal = false); 49118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor const ObjCProtocolList &getReferencedProtocols() const { 4921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return ReferencedProtocols; 4937ed9e0f97f4645edc5d4670385b985ea4c617ce7Fariborz Jahanian } 4948a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis 4958a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis ObjCImplementationDecl *getImplementation() const; 4968a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis void setImplementation(ObjCImplementationDecl *ImplD); 4978a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis 498559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian ObjCCategoryDecl *FindCategoryDeclaration(IdentifierInfo *CategoryId) const; 4991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5001cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis // Get the local instance/class method declared in a category. 5011cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis ObjCMethodDecl *getCategoryInstanceMethod(Selector Sel) const; 5021cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis ObjCMethodDecl *getCategoryClassMethod(Selector Sel) const; 5031cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis ObjCMethodDecl *getCategoryMethod(Selector Sel, bool isInstance) const { 5041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return isInstance ? getInstanceMethod(Sel) 5051cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis : getClassMethod(Sel); 5061cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis } 5073db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner 50818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor typedef ObjCProtocolList::iterator protocol_iterator; 5093db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();} 5103db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner protocol_iterator protocol_end() const { return ReferencedProtocols.end(); } 51118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor typedef ObjCProtocolList::loc_iterator protocol_loc_iterator; 51218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor protocol_loc_iterator protocol_loc_begin() const { 51318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor return ReferencedProtocols.loc_begin(); 51418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor } 51518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor protocol_loc_iterator protocol_loc_end() const { 51618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor return ReferencedProtocols.loc_end(); 51718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor } 518291be393aa33759e6e34b6429c5ffa206ba50115Douglas Gregor unsigned protocol_size() const { return ReferencedProtocols.size(); } 519291be393aa33759e6e34b6429c5ffa206ba50115Douglas Gregor 52011062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator; 52111062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian ivar_iterator ivar_begin() const { return ivar_iterator(decls_begin()); } 52211062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian ivar_iterator ivar_end() const { return ivar_iterator(decls_end()); } 52311062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian unsigned ivar_size() const { 52411062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian return std::distance(ivar_begin(), ivar_end()); 52511062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian } 52611062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian bool ivar_empty() const { return ivar_begin() == ivar_end(); } 5271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 52838af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner /// setProtocolList - Set the list of protocols that this interface 529b752f289026ad8e5f44851b20e009a27ed61eefcChris Lattner /// implements. 53038af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner void setProtocolList(ObjCProtocolDecl *const* List, unsigned Num, 53118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor const SourceLocation *Locs, ASTContext &C) { 53218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor ReferencedProtocols.set(List, Num, Locs, C); 5333db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner } 5341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 535339798eae1eb61c50ca68766ed028c0a16d0a284Fariborz Jahanian /// mergeClassExtensionProtocolList - Merge class extension's protocol list 536339798eae1eb61c50ca68766ed028c0a16d0a284Fariborz Jahanian /// into the protocol list for this class. 53718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor void mergeClassExtensionProtocolList(ObjCProtocolDecl *const* List, 53818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor unsigned Num, 53918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor const SourceLocation *Locs, 54018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor ASTContext &C); 541339798eae1eb61c50ca68766ed028c0a16d0a284Fariborz Jahanian 542768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff bool isForwardDecl() const { return ForwardDecl; } 543768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff void setForwardDecl(bool val) { ForwardDecl = val; } 5441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 545a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *getSuperClass() const { return SuperClass; } 546a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek void setSuperClass(ObjCInterfaceDecl * superCls) { SuperClass = superCls; } 5471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 548a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCCategoryDecl* getCategoryList() const { return CategoryList; } 5491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setCategoryList(ObjCCategoryDecl *category) { 55053efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner CategoryList = category; 551980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff } 5521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5530e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian ObjCCategoryDecl* getClassExtension() const; 55437cafb077ad5b170acae77e566638603011ef4c0Ted Kremenek 55537cafb077ad5b170acae77e566638603011ef4c0Ted Kremenek ObjCPropertyDecl 55637cafb077ad5b170acae77e566638603011ef4c0Ted Kremenek *FindPropertyVisibleInPrimaryClass(IdentifierInfo *PropertyId) const; 55737cafb077ad5b170acae77e566638603011ef4c0Ted Kremenek 55853efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner /// isSuperClassOf - Return true if this class is the specified class or is a 55953efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner /// super class of the specified interface class. 56053efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner bool isSuperClassOf(const ObjCInterfaceDecl *I) const { 56153efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner // If RHS is derived from LHS it is OK; else it is not OK. 56253efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner while (I != NULL) { 56353efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner if (this == I) 56453efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner return true; 56553efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner I = I->getSuperClass(); 56653efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner } 56753efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner return false; 56853efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner } 5691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 57017945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName, 57168a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner ObjCInterfaceDecl *&ClassDeclared); 57217945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName) { 57368a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner ObjCInterfaceDecl *ClassDeclared; 57417945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis return lookupInstanceVariable(IVarName, ClassDeclared); 57568a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner } 57668a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner 57794a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff // Lookup a method. First, we search locally. If a method isn't 57894a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff // found, we search referenced protocols and class categories. 579aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance) const; 580aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis ObjCMethodDecl *lookupInstanceMethod(Selector Sel) const { 581aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis return lookupMethod(Sel, true/*isInstance*/); 582aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis } 583aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis ObjCMethodDecl *lookupClassMethod(Selector Sel) const { 584aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis return lookupMethod(Sel, false/*isInstance*/); 585aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis } 586cd1876207f5564beba74e4b2524b664bdba0ba9fFariborz Jahanian ObjCInterfaceDecl *lookupInheritedClass(const IdentifierInfo *ICName); 587d789d3d985e28c9404e62157af46dcb7331920e0Steve Naroff 588d789d3d985e28c9404e62157af46dcb7331920e0Steve Naroff // Lookup a method in the classes implementation hierarchy. 589d789d3d985e28c9404e62157af46dcb7331920e0Steve Naroff ObjCMethodDecl *lookupPrivateInstanceMethod(const Selector &Sel); 59060fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff 591ddfd4c9eda34765b08fae4cb31ad5a365face107Argyrios Kyrtzidis // Location information, modeled after the Stmt API. 59260fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff SourceLocation getLocStart() const { return getLocation(); } // '@'interface 593f908a87299d278164540f90b5b6e6cab7b14fb41Steve Naroff SourceLocation getLocEnd() const { return EndLoc; } 5947177dee8aee4b432911c91f1b788963bec0cac9fDaniel Dunbar void setLocEnd(SourceLocation LE) { EndLoc = LE; } 5951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 59633feeb019a5742b286eededd5446ec0fe87c5a61Steve Naroff void setClassLoc(SourceLocation Loc) { ClassLoc = Loc; } 597d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff SourceLocation getClassLoc() const { return ClassLoc; } 598d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff void setSuperClassLoc(SourceLocation Loc) { SuperClassLoc = Loc; } 599d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff SourceLocation getSuperClassLoc() const { return SuperClassLoc; } 6001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 60128e71cf851b73a67604735a9a95aef800b144e2eSteve Naroff /// isImplicitInterfaceDecl - check that this is an implicitly declared 602a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek /// ObjCInterfaceDecl node. This is for legacy objective-c @implementation 6034b6df3fa953267c5d755628c8afd818bb571e579Fariborz Jahanian /// declaration without an @interface declaration. 60433feeb019a5742b286eededd5446ec0fe87c5a61Steve Naroff bool isImplicitInterfaceDecl() const { return InternalInterface; } 60533feeb019a5742b286eededd5446ec0fe87c5a61Steve Naroff void setImplicitInterfaceDecl(bool val) { InternalInterface = val; } 6061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6070fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian /// ClassImplementsProtocol - Checks that 'lProto' protocol 6080fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian /// has been implemented in IDecl class, its super class or categories (if 6090fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian /// lookupCategory is true). 6100fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian bool ClassImplementsProtocol(ObjCProtocolDecl *lProto, 6110fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian bool lookupCategory, 6120fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian bool RHSIsQualifiedID = false); 6131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 61433feeb019a5742b286eededd5446ec0fe87c5a61Steve Naroff // Low-level accessor 61533feeb019a5742b286eededd5446ec0fe87c5a61Steve Naroff Type *getTypeForDecl() const { return TypeForDecl; } 6163b3a45858c6b2a45114e91902c3bf3c4b7f5f302Daniel Dunbar void setTypeForDecl(Type *TD) const { TypeForDecl = TD; } 61733feeb019a5742b286eededd5446ec0fe87c5a61Steve Naroff 61880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 619a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCInterfaceDecl *D) { return true; } 62080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { return K == ObjCInterface; } 621980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff}; 622980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 623a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCIvarDecl - Represents an ObjC instance variable. In general, ObjC 6240c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// instance variables are identical to C. The only exception is Objective-C 6250c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// supports C++ style access control. For example: 6260c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 6270c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @interface IvarExample : NSObject 6280c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// { 629f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek/// id defaultToProtected; 6300c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @public: 6310c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// id canBePublic; // same as C++. 6320c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @protected: 6330c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// id canBeProtected; // same as C++. 6340c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @package: 6350c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// id canBePackage; // framework visibility (not available in C++). 6360c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// } 6370c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 638a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCIvarDecl : public FieldDecl { 6390e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattnerpublic: 640980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff enum AccessControl { 641980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff None, Private, Protected, Public, Package 642980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff }; 6431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 644b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenekprivate: 645a06549226f45d5b72169a3d054415616dd1014a2Daniel Dunbar ObjCIvarDecl(ObjCContainerDecl *DC, SourceLocation L, IdentifierInfo *Id, 646a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall QualType T, TypeSourceInfo *TInfo, AccessControl ac, Expr *BW) 647a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall : FieldDecl(ObjCIvar, DC, L, Id, T, TInfo, BW, /*Mutable=*/false), 64844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor DeclAccess(ac) {} 6491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 650b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenekpublic: 651a06549226f45d5b72169a3d054415616dd1014a2Daniel Dunbar static ObjCIvarDecl *Create(ASTContext &C, ObjCContainerDecl *DC, 652a06549226f45d5b72169a3d054415616dd1014a2Daniel Dunbar SourceLocation L, IdentifierInfo *Id, QualType T, 653a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *TInfo, 654b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenek AccessControl ac, Expr *BW = NULL); 6551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 65627a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar /// \brief Return the class interface that this ivar is logically contained 65727a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar /// in; this is either the interface where the ivar was declared, or the 65827a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar /// interface the ivar is conceptually a part of in the case of synthesized 65927a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar /// ivars. 66027a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar const ObjCInterfaceDecl *getContainingInterface() const; 66127a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar 662980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff void setAccessControl(AccessControl ac) { DeclAccess = ac; } 663f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek 664ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek AccessControl getAccessControl() const { return AccessControl(DeclAccess); } 665f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek 666f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek AccessControl getCanonicalAccessControl() const { 667f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek return DeclAccess == None ? Protected : AccessControl(DeclAccess); 668f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek } 6691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 670980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff // Implement isa/cast/dyncast/etc. 67180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 672a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCIvarDecl *D) { return true; } 67380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { return K == ObjCIvar; } 674980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffprivate: 675ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek // NOTE: VC++ treats enums as signed, avoid using the AccessControl enum 676ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek unsigned DeclAccess : 3; 677980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff}; 678980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 6791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 68001e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek/// ObjCAtDefsFieldDecl - Represents a field declaration created by an 68101e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek/// @defs(...). 68201e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenekclass ObjCAtDefsFieldDecl : public FieldDecl { 68301e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenekprivate: 68444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor ObjCAtDefsFieldDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id, 68501e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek QualType T, Expr *BW) 686a1d5662d96465f0fddf8819d245da4d19b892effArgyrios Kyrtzidis : FieldDecl(ObjCAtDefsField, DC, L, Id, T, 687a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall /*TInfo=*/0, // FIXME: Do ObjCAtDefs have declarators ? 688a1d5662d96465f0fddf8819d245da4d19b892effArgyrios Kyrtzidis BW, /*Mutable=*/false) {} 6891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 69001e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenekpublic: 69144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor static ObjCAtDefsFieldDecl *Create(ASTContext &C, DeclContext *DC, 69244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor SourceLocation L, 69301e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek IdentifierInfo *Id, QualType T, 69401e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek Expr *BW); 6951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 69601e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek virtual void Destroy(ASTContext& C); 69701e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek 69801e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek // Implement isa/cast/dyncast/etc. 69980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 70001e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek static bool classof(const ObjCAtDefsFieldDecl *D) { return true; } 70180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { return K == ObjCAtDefsField; } 70201e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek}; 703980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 704a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCProtocolDecl - Represents a protocol declaration. ObjC protocols 7051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// declare a pure abstract type (i.e no instance variables are permitted). 7061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Protocols orginally drew inspiration from C++ pure virtual functions (a C++ 7070c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// feature with nice semantics and lousy syntax:-). Here is an example: 7080c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 709eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// @protocol NSDraggingInfo <refproto1, refproto2> 7100c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (NSWindow *)draggingDestinationWindow; 7110c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (NSImage *)draggedImage; 7120c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end 7130c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 714eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// This says that NSDraggingInfo requires two methods and requires everything 715eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// that the two "referenced protocols" 'refproto1' and 'refproto2' require as 716eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// well. 717eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// 7180c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @interface ImplementsNSDraggingInfo : NSObject <NSDraggingInfo> 7190c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end 7200c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 721a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjC protocols inspired Java interfaces. Unlike Java, ObjC classes and 7220c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// protocols are in distinct namespaces. For example, Cocoa defines both 7231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// an NSObject protocol and class (which isn't allowed in Java). As a result, 7240c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// protocols are referenced using angle brackets as follows: 7250c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 7260c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// id <NSDraggingInfo> anyObjectThatImplementsNSDraggingInfo; 7270c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 728e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroffclass ObjCProtocolDecl : public ObjCContainerDecl { 729780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner /// Referenced protocols 73018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor ObjCProtocolList ReferencedProtocols; 7311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 732980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff bool isForwardProtoDecl; // declared with @protocol. 7331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 734423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff SourceLocation EndLoc; // marks the '>' or identifier. 7351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 736d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor ObjCProtocolDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id) 7371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : ObjCContainerDecl(ObjCProtocol, DC, L, Id), 738c858105d41602a2dadb2efbc1af80a7b791ebac3Chris Lattner isForwardProtoDecl(true) { 739cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattner } 7401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7414a323d94e50c8f570cbfaf0392e68215b8ca87bfChris Lattner virtual ~ObjCProtocolDecl() {} 7421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 743cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattnerpublic: 7441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static ObjCProtocolDecl *Create(ASTContext &C, DeclContext *DC, 745d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor SourceLocation L, IdentifierInfo *Id); 746cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattner 747411280e5b25ba7dcd7c8a82a5c23880fe7632a3cChris Lattner /// Destroy - Call destructors and release memory. 748411280e5b25ba7dcd7c8a82a5c23880fe7632a3cChris Lattner virtual void Destroy(ASTContext& C); 7491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 75018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor const ObjCProtocolList &getReferencedProtocols() const { 751780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner return ReferencedProtocols; 752980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff } 75318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor typedef ObjCProtocolList::iterator protocol_iterator; 754780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();} 755780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner protocol_iterator protocol_end() const { return ReferencedProtocols.end(); } 75618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor typedef ObjCProtocolList::loc_iterator protocol_loc_iterator; 75718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor protocol_loc_iterator protocol_loc_begin() const { 75818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor return ReferencedProtocols.loc_begin(); 75918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor } 76018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor protocol_loc_iterator protocol_loc_end() const { 76118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor return ReferencedProtocols.loc_end(); 76218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor } 76330833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff unsigned protocol_size() const { return ReferencedProtocols.size(); } 7641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 76538af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner /// setProtocolList - Set the list of protocols that this interface 766780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner /// implements. 76738af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num, 76818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor const SourceLocation *Locs, ASTContext &C) { 76918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor ReferencedProtocols.set(List, Num, Locs, C); 770aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian } 7711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 77291b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff ObjCProtocolDecl *lookupProtocolNamed(IdentifierInfo *PName); 7731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 77494a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff // Lookup a method. First, we search locally. If a method isn't 77594a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff // found, we search referenced protocols and class categories. 776094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance) const; 777094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis ObjCMethodDecl *lookupInstanceMethod(Selector Sel) const { 778094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis return lookupMethod(Sel, true/*isInstance*/); 779094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis } 780094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis ObjCMethodDecl *lookupClassMethod(Selector Sel) const { 781094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis return lookupMethod(Sel, false/*isInstance*/); 782094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis } 783d789d3d985e28c9404e62157af46dcb7331920e0Steve Naroff 784768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff bool isForwardDecl() const { return isForwardProtoDecl; } 785768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff void setForwardDecl(bool val) { isForwardProtoDecl = val; } 786980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 7871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Location information, modeled after the Stmt API. 788423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff SourceLocation getLocStart() const { return getLocation(); } // '@'protocol 789423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff SourceLocation getLocEnd() const { return EndLoc; } 7907177dee8aee4b432911c91f1b788963bec0cac9fDaniel Dunbar void setLocEnd(SourceLocation LE) { EndLoc = LE; } 7911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 79280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 793a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCProtocolDecl *D) { return true; } 79480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { return K == ObjCProtocol; } 795980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff}; 7961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 797a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCClassDecl - Specifies a list of forward class declarations. For example: 79806ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff/// 79906ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff/// @class NSCursor, NSImage, NSPasteboard, NSWindow; 8000c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 8014afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCClassDecl : public Decl { 802321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenekpublic: 803321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek class ObjCClassRef { 804321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek ObjCInterfaceDecl *ID; 805321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek SourceLocation L; 806321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek public: 807321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek ObjCClassRef(ObjCInterfaceDecl *d, SourceLocation l) : ID(d), L(l) {} 808321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek SourceLocation getLocation() const { return L; } 809321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek ObjCInterfaceDecl *getInterface() const { return ID; } 810321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek }; 811321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenekprivate: 812321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek ObjCClassRef *ForwardDecls; 813321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek unsigned NumDecls; 8141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCClassDecl(DeclContext *DC, SourceLocation L, 816321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek ObjCInterfaceDecl *const *Elts, const SourceLocation *Locs, 817321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek unsigned nElts, ASTContext &C); 81867956052ea5fb0cd7f443de96a11f9a0176dc681Chris Lattner virtual ~ObjCClassDecl() {} 81961f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattnerpublic: 8201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 821400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek /// Destroy - Call destructors and release memory. 822400d95fb7bb9fac609f8613862b84f3a2a7d510fTed Kremenek virtual void Destroy(ASTContext& C); 8231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 824d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor static ObjCClassDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L, 8251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCInterfaceDecl *const *Elts = 0, 826321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek const SourceLocation *Locs = 0, 82730833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff unsigned nElts = 0); 8282dbdd622d02d1bfbe1e5bcf421b07b74c7a748f1Ted Kremenek 8292dbdd622d02d1bfbe1e5bcf421b07b74c7a748f1Ted Kremenek virtual SourceRange getSourceRange() const; 8301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 831321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek typedef const ObjCClassRef* iterator; 832321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek iterator begin() const { return ForwardDecls; } 833321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek iterator end() const { return ForwardDecls + NumDecls; } 834321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek unsigned size() const { return NumDecls; } 83530833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff 83630833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff /// setClassList - Set the list of forward classes. 837321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek void setClassList(ASTContext &C, ObjCInterfaceDecl*const*List, 838321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek const SourceLocation *Locs, unsigned Num); 8391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 84080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 841a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCClassDecl *D) { return true; } 84280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { return K == ObjCClass; } 84306ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff}; 84406ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff 845a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCForwardProtocolDecl - Specifies a list of forward protocol declarations. 84606ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff/// For example: 8471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 8480c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @protocol NSTextInput, NSChangeSpelling, NSDraggingInfo; 8491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 8504afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCForwardProtocolDecl : public Decl { 85118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor ObjCProtocolList ReferencedProtocols; 8521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 853d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor ObjCForwardProtocolDecl(DeclContext *DC, SourceLocation L, 85438af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner ObjCProtocolDecl *const *Elts, unsigned nElts, 85518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor const SourceLocation *Locs, ASTContext &C); 85607fa7749da805969f2ed467a4eb5b405a4ff9a23Chris Lattner virtual ~ObjCForwardProtocolDecl() {} 8571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 85861f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattnerpublic: 859d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor static ObjCForwardProtocolDecl *Create(ASTContext &C, DeclContext *DC, 8601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation L, 86118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor ObjCProtocolDecl *const *Elts, 86218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor unsigned Num, 86318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor const SourceLocation *Locs); 86418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor 86518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor static ObjCForwardProtocolDecl *Create(ASTContext &C, DeclContext *DC, 86618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor SourceLocation L) { 86718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor return Create(C, DC, L, 0, 0, 0); 86818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor } 86961f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner 8700b7ebb3dba0df0a6cbf221e5edbc6a4b8848478cChris Lattner /// Destroy - Call destructors and release memory. 8710b7ebb3dba0df0a6cbf221e5edbc6a4b8848478cChris Lattner virtual void Destroy(ASTContext& C); 8721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 87318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor typedef ObjCProtocolList::iterator protocol_iterator; 87430833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();} 87530833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff protocol_iterator protocol_end() const { return ReferencedProtocols.end(); } 87618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor typedef ObjCProtocolList::loc_iterator protocol_loc_iterator; 87718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor protocol_loc_iterator protocol_loc_begin() const { 87818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor return ReferencedProtocols.loc_begin(); 87918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor } 88018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor protocol_loc_iterator protocol_loc_end() const { 88118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor return ReferencedProtocols.loc_end(); 88218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor } 88318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor 88430833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff unsigned protocol_size() const { return ReferencedProtocols.size(); } 88530833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff 88630833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff /// setProtocolList - Set the list of forward protocols. 88730833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num, 88818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor const SourceLocation *Locs, ASTContext &C) { 88918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor ReferencedProtocols.set(List, Num, Locs, C); 89030833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff } 89180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 892a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCForwardProtocolDecl *D) { return true; } 89380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { return K == ObjCForwardProtocol; } 894980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff}; 895980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 896a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCCategoryDecl - Represents a category declaration. A category allows 8970c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// you to add methods to an existing class (without subclassing or modifying 8981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// the original class interface or implementation:-). Categories don't allow 8990c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// you to add instance data. The following example adds "myMethod" to all 9000c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// NSView's within a process: 9010c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 9020c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @interface NSView (MyViewMethods) 9030c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - myMethod; 9040c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end 9050c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 90633ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor/// Categories also allow you to split the implementation of a class across 9070c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// several files (a feature more naturally supported in C++). 9080c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 9090c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// Categories were originally inspired by dynamic languages such as Common 9101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Lisp and Smalltalk. More traditional class-based languages (C++, Java) 9110c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// don't support this level of dynamism, which is both powerful and dangerous. 9120c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 913e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroffclass ObjCCategoryDecl : public ObjCContainerDecl { 914980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff /// Interface belonging to this category 915a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *ClassInterface; 9161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 91768c82cf61228102aba1194efef222fa1478af2a8Chris Lattner /// referenced protocols in this category. 91818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor ObjCProtocolList ReferencedProtocols; 9191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 920a8ff9f455d94d9609766cfd5186b6e21dc2102f1Chris Lattner /// Next category belonging to this class. 921a8ff9f455d94d9609766cfd5186b6e21dc2102f1Chris Lattner /// FIXME: this should not be a singly-linked list. Move storage elsewhere. 922a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCCategoryDecl *NextClassCategory; 9231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9243db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor /// \brief The location of the '@' in '@interface' 9253db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor SourceLocation AtLoc; 9263db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor 9273db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor /// \brief The location of the category name in this declaration. 9283db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor SourceLocation CategoryNameLoc; 9291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9303db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor ObjCCategoryDecl(DeclContext *DC, SourceLocation AtLoc, 9313db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor SourceLocation ClassNameLoc, SourceLocation CategoryNameLoc, 9323db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor IdentifierInfo *Id) 9333db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor : ObjCContainerDecl(ObjCCategory, DC, ClassNameLoc, Id), 9343db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor ClassInterface(0), NextClassCategory(0), AtLoc(AtLoc), 9353db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor CategoryNameLoc(CategoryNameLoc) { 936a906135721c350435319347d2672bbb3bf494f91Chris Lattner } 93761f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattnerpublic: 9381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 939d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor static ObjCCategoryDecl *Create(ASTContext &C, DeclContext *DC, 9403db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor SourceLocation AtLoc, 9413db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor SourceLocation ClassNameLoc, 9423db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor SourceLocation CategoryNameLoc, 9433db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor IdentifierInfo *Id); 9441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 945e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner ObjCInterfaceDecl *getClassInterface() { return ClassInterface; } 946e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; } 947a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek void setClassInterface(ObjCInterfaceDecl *IDecl) { ClassInterface = IDecl; } 9488a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis 9498a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis ObjCCategoryImplDecl *getImplementation() const; 9508a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis void setImplementation(ObjCCategoryImplDecl *ImplD); 9518a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis 95238af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner /// setProtocolList - Set the list of protocols that this interface 953f7b2c98c16dfb2261ea57d40a1d5bc4738e73175Chris Lattner /// implements. 95438af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num, 95518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor const SourceLocation *Locs, ASTContext &C) { 95618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor ReferencedProtocols.set(List, Num, Locs, C); 957780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner } 9581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 95918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor const ObjCProtocolList &getReferencedProtocols() const { 960780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner return ReferencedProtocols; 9618f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian } 9621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 96318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor typedef ObjCProtocolList::iterator protocol_iterator; 964780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();} 965780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner protocol_iterator protocol_end() const { return ReferencedProtocols.end(); } 96630833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff unsigned protocol_size() const { return ReferencedProtocols.size(); } 96718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor typedef ObjCProtocolList::loc_iterator protocol_loc_iterator; 96818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor protocol_loc_iterator protocol_loc_begin() const { 96918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor return ReferencedProtocols.loc_begin(); 97018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor } 97118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor protocol_loc_iterator protocol_loc_end() const { 97218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor return ReferencedProtocols.loc_end(); 97318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor } 9741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 975a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCCategoryDecl *getNextClassCategory() const { return NextClassCategory; } 97630833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff void setNextClassCategory(ObjCCategoryDecl *Cat) { 97730833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff NextClassCategory = Cat; 97830833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff } 979980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff void insertNextClassCategory() { 9803d58138992b9bc7b34aaa680f3ddf3971292eb7dSteve Naroff NextClassCategory = ClassInterface->getCategoryList(); 9813d58138992b9bc7b34aaa680f3ddf3971292eb7dSteve Naroff ClassInterface->setCategoryList(this); 982980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff } 9833db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor 98425760611365be23556b32332f8a66ae21ea93ecfFariborz Jahanian bool IsClassExtension() const { return getIdentifier() == 0; } 98525760611365be23556b32332f8a66ae21ea93ecfFariborz Jahanian 9860e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator; 9870e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian ivar_iterator ivar_begin() const { 9880e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian return ivar_iterator(decls_begin()); 9890e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian } 9900e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian ivar_iterator ivar_end() const { 9910e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian return ivar_iterator(decls_end()); 9920e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian } 9930e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian unsigned ivar_size() const { 9940e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian return std::distance(ivar_begin(), ivar_end()); 9950e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian } 9960e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian bool ivar_empty() const { 9970e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian return ivar_begin() == ivar_end(); 9980e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian } 9990e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian 10003db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor SourceLocation getAtLoc() const { return AtLoc; } 10013db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor void setAtLoc(SourceLocation At) { AtLoc = At; } 10023db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor 10033db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor SourceLocation getCategoryNameLoc() const { return CategoryNameLoc; } 10043db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor void setCategoryNameLoc(SourceLocation Loc) { CategoryNameLoc = Loc; } 10053db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor 10063db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor virtual SourceRange getSourceRange() const { 10073db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor return SourceRange(AtLoc, getAtEndRange().getEnd()); 10083db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor } 10091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 101080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1011a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCCategoryDecl *D) { return true; } 101280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { return K == ObjCCategory; } 1013980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff}; 10140c6b6243d3efd958c17943130e2a773653511edcSteve Naroff 1015aecae629269fae3bf484baf1d109e9a89d14eeadArgyrios Kyrtzidisclass ObjCImplDecl : public ObjCContainerDecl { 10160d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff /// Class interface for this class/category implementation 1017a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *ClassInterface; 10181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10193aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattnerprotected: 10203aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner ObjCImplDecl(Kind DK, DeclContext *DC, SourceLocation L, 10213aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner ObjCInterfaceDecl *classInterface) 10221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : ObjCContainerDecl(DK, DC, L, 10231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump classInterface? classInterface->getIdentifier() : 0), 1024aecae629269fae3bf484baf1d109e9a89d14eeadArgyrios Kyrtzidis ClassInterface(classInterface) {} 10251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 102675c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattnerpublic: 1027cddc88800bbd1213ec70ae5153c6a7f2e380fd8dChris Lattner virtual ~ObjCImplDecl() {} 10281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1029e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; } 1030e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner ObjCInterfaceDecl *getClassInterface() { return ClassInterface; } 10318a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis void setClassInterface(ObjCInterfaceDecl *IFace); 10322c2d43c557beca1b4ba4bd743f33978aecb46a97Douglas Gregor 10331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void addInstanceMethod(ObjCMethodDecl *method) { 10342c2d43c557beca1b4ba4bd743f33978aecb46a97Douglas Gregor // FIXME: Context should be set correctly before we get here. 1035653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor method->setLexicalDeclContext(this); 10361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump addDecl(method); 1037e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff } 10381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void addClassMethod(ObjCMethodDecl *method) { 10392c2d43c557beca1b4ba4bd743f33978aecb46a97Douglas Gregor // FIXME: Context should be set correctly before we get here. 1040653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor method->setLexicalDeclContext(this); 10411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump addDecl(method); 104253df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner } 10431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 104417945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis void addPropertyImplementation(ObjCPropertyImplDecl *property); 10451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 104617945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis ObjCPropertyImplDecl *FindPropertyImplDecl(IdentifierInfo *propertyId) const; 104717945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis ObjCPropertyImplDecl *FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const; 1048653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor 1049653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor // Iterator access to properties. 1050653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor typedef specific_decl_iterator<ObjCPropertyImplDecl> propimpl_iterator; 10511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump propimpl_iterator propimpl_begin() const { 105217945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis return propimpl_iterator(decls_begin()); 1053559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian } 10541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump propimpl_iterator propimpl_end() const { 105517945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis return propimpl_iterator(decls_end()); 1056559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian } 1057653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor 105880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1059bfb498d0996ef049efe9476f2802976fd145cd60Argyrios Kyrtzidis static bool classof(const ObjCImplDecl *D) { return true; } 106080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { 106180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall return K >= ObjCImplFirst && K <= ObjCImplLast; 106280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall } 10633aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner}; 10641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ObjCCategoryImplDecl - An object of this class encapsulates a category 10661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// @implementation declaration. If a category class has declaration of a 10671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// property, its implementation must be specified in the category's 10683aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @implementation declaration. Example: 10693aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @interface I @end 10703aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @interface I(CATEGORY) 10713aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @property int p1, d1; 10723aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @end 10733aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @implementation I(CATEGORY) 10743aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @dynamic p1,d1; 10753aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @end 10763aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// 10773aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// ObjCCategoryImplDecl 10783aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattnerclass ObjCCategoryImplDecl : public ObjCImplDecl { 10793aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner // Category name 10803aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner IdentifierInfo *Id; 10813aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner 10823aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner ObjCCategoryImplDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id, 10833aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner ObjCInterfaceDecl *classInterface) 10843aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner : ObjCImplDecl(ObjCCategoryImpl, DC, L, classInterface), Id(Id) {} 10853aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattnerpublic: 10863aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner static ObjCCategoryImplDecl *Create(ASTContext &C, DeclContext *DC, 10873aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner SourceLocation L, IdentifierInfo *Id, 10883aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner ObjCInterfaceDecl *classInterface); 10891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10900d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff /// getIdentifier - Get the identifier that names the category 10913aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner /// interface associated with this implementation. 10920d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff /// FIXME: This is a bad API, we are overriding the NamedDecl::getIdentifier() 10930d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff /// to mean something different. For example: 10940d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff /// ((NamedDecl *)SomeCategoryImplDecl)->getIdentifier() 10950d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff /// returns the class interface name, whereas 10960d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff /// ((ObjCCategoryImplDecl *)SomeCategoryImplDecl)->getIdentifier() 10970d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff /// returns the category name. 10981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump IdentifierInfo *getIdentifier() const { 10991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Id; 11003aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner } 110110b0e1fa3aabd8877dbbc0df1f2414e04afd5fddDouglas Gregor void setIdentifier(IdentifierInfo *II) { Id = II; } 11021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11030d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff ObjCCategoryDecl *getCategoryDecl() const; 110410b0e1fa3aabd8877dbbc0df1f2414e04afd5fddDouglas Gregor 1105b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar /// getName - Get the name of identifier for the class interface associated 1106b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar /// with this implementation as a StringRef. 1107b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar // 1108b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar // FIXME: This is a bad API, we are overriding the NamedDecl::getName, to mean 1109b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar // something different. 1110b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar llvm::StringRef getName() const { 1111b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar return Id ? Id->getNameStart() : ""; 1112b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar } 1113b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar 11143aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner /// getNameAsCString - Get the name of identifier for the class 11153aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner /// interface associated with this implementation as a C string 11163aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner /// (const char*). 11177fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar // 1118b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar // FIXME: Deprecated, move clients to getName(). 11193aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner const char *getNameAsCString() const { 11207fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar return Id ? Id->getNameStart() : ""; 11213aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner } 11221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11233aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner /// @brief Get the name of the class associated with this interface. 11247fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar // 1125b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar // FIXME: Deprecated, move clients to getName(). 11263aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner std::string getNameAsString() const { 1127b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar return getName(); 11283aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner } 11291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 113080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1131a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCCategoryImplDecl *D) { return true; } 113280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { return K == ObjCCategoryImpl;} 11338f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian}; 11348f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian 1135a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCImplementationDecl - Represents a class definition - this is where 11360c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// method definitions are specified. For example: 11370c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 113898abf4bd3526a00a0e5cf71a9462c181f97b1c81Fariborz Jahanian/// @code 11390c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @implementation MyClass 11400c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (void)myMethod { /* do something */ } 11410c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end 114298abf4bd3526a00a0e5cf71a9462c181f97b1c81Fariborz Jahanian/// @endcode 11430c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 11441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Typically, instance variables are specified in the class interface, 1145ec0d7a6f4b0699cc9960e6d9fee0f957c64d1cf9Douglas Gregor/// *not* in the implementation. Nevertheless (for legacy reasons), we 114653df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner/// allow instance variables to be specified in the implementation. When 114753df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner/// specified, they need to be *identical* to the interface. 11480c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 11491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ObjCImplementationDecl : public ObjCImplDecl { 1150980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff /// Implementation Class's super class. 1151a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *SuperClass; 11521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCImplementationDecl(DeclContext *DC, SourceLocation L, 1154a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *classInterface, 1155a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *superDecl) 11561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : ObjCImplDecl(ObjCImplementation, DC, L, classInterface), 11573aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner SuperClass(superDecl){} 11581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 11591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static ObjCImplementationDecl *Create(ASTContext &C, DeclContext *DC, 11601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation L, 116175c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner ObjCInterfaceDecl *classInterface, 116275c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner ObjCInterfaceDecl *superDecl); 11631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11644afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// getIdentifier - Get the identifier that names the class 11654afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// interface associated with this implementation. 11661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump IdentifierInfo *getIdentifier() const { 11671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getClassInterface()->getIdentifier(); 11684afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 11694afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 1170d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar /// getName - Get the name of identifier for the class interface associated 1171d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar /// with this implementation as a StringRef. 1172d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar // 1173d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar // FIXME: This is a bad API, we are overriding the NamedDecl::getName, to mean 1174d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar // something different. 1175d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar llvm::StringRef getName() const { 1176d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar assert(getIdentifier() && "Name is not a simple identifier"); 1177d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar return getIdentifier()->getName(); 1178d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar } 1179d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar 11804afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// getNameAsCString - Get the name of identifier for the class 11814afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// interface associated with this implementation as a C string 11824afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// (const char*). 11837fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar // 11847fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar // FIXME: Move to StringRef API. 11854afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor const char *getNameAsCString() const { 1186d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar return getName().data(); 11874afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 11884afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 11894afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// @brief Get the name of the class associated with this interface. 11907fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar // 11917fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar // FIXME: Move to StringRef API. 11924afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor std::string getNameAsString() const { 1193d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar return getName(); 11944afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 11954afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 1196e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner const ObjCInterfaceDecl *getSuperClass() const { return SuperClass; } 1197e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner ObjCInterfaceDecl *getSuperClass() { return SuperClass; } 11981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1199f3a7af901231535191d14cb524d58f22907ac4d2Chris Lattner void setSuperClass(ObjCInterfaceDecl * superCls) { SuperClass = superCls; } 12001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12018f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator; 12021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ivar_iterator ivar_begin() const { 12031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return ivar_iterator(decls_begin()); 12048f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor } 12051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ivar_iterator ivar_end() const { 120617945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis return ivar_iterator(decls_end()); 12078f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor } 12081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned ivar_size() const { 120917945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis return std::distance(ivar_begin(), ivar_end()); 12108f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor } 12111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ivar_empty() const { 121217945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis return ivar_begin() == ivar_end(); 12138f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor } 12141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 121580cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1216a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCImplementationDecl *D) { return true; } 121780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { return K == ObjCImplementation; } 1218980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff}; 1219243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian 12201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ObjCCompatibleAliasDecl - Represents alias of a class. This alias is 1221243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian/// declared as @compatibility_alias alias class. 12224afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCCompatibleAliasDecl : public NamedDecl { 1223243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian /// Class that this is an alias of. 1224a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *AliasedClass; 12251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1226d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor ObjCCompatibleAliasDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id, 1227e8043c39176e7f253fbd92982b077eca6bf2fd59Steve Naroff ObjCInterfaceDecl* aliasedClass) 12284afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor : NamedDecl(ObjCCompatibleAlias, DC, L, Id), AliasedClass(aliasedClass) {} 1229f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattnerpublic: 1230d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor static ObjCCompatibleAliasDecl *Create(ASTContext &C, DeclContext *DC, 12310ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner SourceLocation L, IdentifierInfo *Id, 1232f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner ObjCInterfaceDecl* aliasedClass); 1233f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner 1234f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner const ObjCInterfaceDecl *getClassInterface() const { return AliasedClass; } 1235f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner ObjCInterfaceDecl *getClassInterface() { return AliasedClass; } 123630833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff void setClassInterface(ObjCInterfaceDecl *D) { AliasedClass = D; } 12371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 123880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1239a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCCompatibleAliasDecl *D) { return true; } 124080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { return K == ObjCCompatibleAlias; } 12411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1242243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian}; 12431de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian 12441de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian/// ObjCPropertyDecl - Represents one property declaration in an interface. 12451de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian/// For example: 12461de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian/// @property (assign, readwrite) int MyProperty; 12471de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian/// 12484afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCPropertyDecl : public NamedDecl { 124982a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanianpublic: 1250a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner enum PropertyAttributeKind { 12511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump OBJC_PR_noattr = 0x00, 12521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump OBJC_PR_readonly = 0x01, 1253a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner OBJC_PR_getter = 0x02, 12541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump OBJC_PR_assign = 0x04, 12551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump OBJC_PR_readwrite = 0x08, 1256a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner OBJC_PR_retain = 0x10, 12571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump OBJC_PR_copy = 0x20, 1258a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner OBJC_PR_nonatomic = 0x40, 1259a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner OBJC_PR_setter = 0x80 1260a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner }; 1261af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 1262af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar enum SetterKind { Assign, Retain, Copy }; 126346b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian enum PropertyControl { None, Required, Optional }; 126482a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanianprivate: 1265d8265b838360578032020757d9a2a84c86457edcFariborz Jahanian SourceLocation AtLoc; // location of @property 1266dae1a1a2aa4f245b1958dc8db6089f24c575ef13Fariborz Jahanian QualType DeclType; 1267ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek unsigned PropertyAttributes : 8; 12681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 126946b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian // @required/@optional 127046b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian unsigned PropertyImplementation : 2; 12711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12725251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian Selector GetterName; // getter name of NULL if no getter 12735251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian Selector SetterName; // setter name of NULL if no setter 12741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 127533de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian ObjCMethodDecl *GetterMethodDecl; // Declaration of getter instance method 127633de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian ObjCMethodDecl *SetterMethodDecl; // Declaration of setter instance method 1277af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian ObjCIvarDecl *PropertyIvarDecl; // Synthesize ivar for this property 127833de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian 12791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCPropertyDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id, 1280d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian SourceLocation AtLocation, QualType T) 1281d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian : NamedDecl(ObjCProperty, DC, L, Id), AtLoc(AtLocation), DeclType(T), 128233de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian PropertyAttributes(OBJC_PR_noattr), PropertyImplementation(None), 12831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump GetterName(Selector()), 128433de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian SetterName(Selector()), 1285af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian GetterMethodDecl(0), SetterMethodDecl(0) , PropertyIvarDecl(0) {} 1286f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattnerpublic: 12871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static ObjCPropertyDecl *Create(ASTContext &C, DeclContext *DC, 12881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation L, 1289d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian IdentifierInfo *Id, SourceLocation AtLocation, 1290d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian QualType T, 129146b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian PropertyControl propControl = None); 1292d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian SourceLocation getAtLoc() const { return AtLoc; } 1293d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian void setAtLoc(SourceLocation L) { AtLoc = L; } 1294d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian 1295dae1a1a2aa4f245b1958dc8db6089f24c575ef13Fariborz Jahanian QualType getType() const { return DeclType; } 129670e5a14c6076d63833c62d1d6d628c26309897c1Douglas Gregor void setType(QualType T) { DeclType = T; } 129770e5a14c6076d63833c62d1d6d628c26309897c1Douglas Gregor 1298a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner PropertyAttributeKind getPropertyAttributes() const { 1299f4af5154571e0c5eadb19df10e65464766ef6683Chris Lattner return PropertyAttributeKind(PropertyAttributes); 1300f4af5154571e0c5eadb19df10e65464766ef6683Chris Lattner } 13011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setPropertyAttributes(PropertyAttributeKind PRVal) { 1302a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner PropertyAttributes |= PRVal; 130382a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian } 1304394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar 13058cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian void makeitReadWriteAttribute(void) { 13068cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian PropertyAttributes &= ~OBJC_PR_readonly; 13078cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian PropertyAttributes |= OBJC_PR_readwrite; 13081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 13098cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian 1310af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar // Helper methods for accessing attributes. 1311af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 1312af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar /// isReadOnly - Return true iff the property has a setter. 1313394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar bool isReadOnly() const { 1314394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar return (PropertyAttributes & OBJC_PR_readonly); 1315394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar } 1316af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 1317af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar /// getSetterKind - Return the method used for doing assignment in 1318af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar /// the property setter. This is only valid if the property has been 1319af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar /// defined to have a setter. 1320af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar SetterKind getSetterKind() const { 1321af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar if (PropertyAttributes & OBJC_PR_retain) 1322af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar return Retain; 1323af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar if (PropertyAttributes & OBJC_PR_copy) 1324af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar return Copy; 1325af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar return Assign; 1326af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar } 1327af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 13285251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian Selector getGetterName() const { return GetterName; } 13295251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian void setGetterName(Selector Sel) { GetterName = Sel; } 13301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13315251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian Selector getSetterName() const { return SetterName; } 13325251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian void setSetterName(Selector Sel) { SetterName = Sel; } 13331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 133433de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian ObjCMethodDecl *getGetterMethodDecl() const { return GetterMethodDecl; } 133533de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian void setGetterMethodDecl(ObjCMethodDecl *gDecl) { GetterMethodDecl = gDecl; } 133633de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian 133733de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian ObjCMethodDecl *getSetterMethodDecl() const { return SetterMethodDecl; } 133833de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian void setSetterMethodDecl(ObjCMethodDecl *gDecl) { SetterMethodDecl = gDecl; } 13391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 134046b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian // Related to @optional/@required declared in @protocol 134146b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian void setPropertyImplementation(PropertyControl pc) { 134246b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian PropertyImplementation = pc; 134346b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian } 134446b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian PropertyControl getPropertyImplementation() const { 134546b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian return PropertyControl(PropertyImplementation); 13461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 13471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1348af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian void setPropertyIvarDecl(ObjCIvarDecl *Ivar) { 1349af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian PropertyIvarDecl = Ivar; 1350af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian } 1351af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian ObjCIvarDecl *getPropertyIvarDecl() const { 1352af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian return PropertyIvarDecl; 1353af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian } 13541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13559f550ff05d496e6b9480e5619a21d9da0c9e27c1Ted Kremenek /// Lookup a property by name in the specified DeclContext. 1356de09d0c9694f01a99870a8825266d44a29ebb325Ted Kremenek static ObjCPropertyDecl *findPropertyDecl(const DeclContext *DC, 13579f550ff05d496e6b9480e5619a21d9da0c9e27c1Ted Kremenek IdentifierInfo *propertyID); 13589f550ff05d496e6b9480e5619a21d9da0c9e27c1Ted Kremenek 135980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1360a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCPropertyDecl *D) { return true; } 136180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { return K == ObjCProperty; } 136282a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian}; 1363980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 13641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ObjCPropertyImplDecl - Represents implementation declaration of a property 136561d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian/// in a class or category implementation block. For example: 136661d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian/// @synthesize prop1 = ivar1; 136761d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian/// 13684afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCPropertyImplDecl : public Decl { 136961d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanianpublic: 13709f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar enum Kind { 13719f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar Synthesize, 13729f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar Dynamic 137361d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian }; 137461d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanianprivate: 1375559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian SourceLocation AtLoc; // location of @synthesize or @dynamic 137661d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian /// Property declaration being implemented 137761d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian ObjCPropertyDecl *PropertyDecl; 1378be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek 137961d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian /// Null for @dynamic. Required for @synthesize. 138061d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian ObjCIvarDecl *PropertyIvarDecl; 1381be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek 1382d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor ObjCPropertyImplDecl(DeclContext *DC, SourceLocation atLoc, SourceLocation L, 13831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCPropertyDecl *property, 13841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Kind PK, 1385628b96f34e93b643b6e15e75eabb8d96079a7e27Fariborz Jahanian ObjCIvarDecl *ivarDecl) 13861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Decl(ObjCPropertyImpl, DC, L), AtLoc(atLoc), 1387d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor PropertyDecl(property), PropertyIvarDecl(ivarDecl) { 13889f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar assert (PK == Dynamic || PropertyIvarDecl); 13899f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar } 13901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13919f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbarpublic: 1392d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor static ObjCPropertyImplDecl *Create(ASTContext &C, DeclContext *DC, 13931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation atLoc, SourceLocation L, 13941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCPropertyDecl *property, 13951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Kind PK, 1396628b96f34e93b643b6e15e75eabb8d96079a7e27Fariborz Jahanian ObjCIvarDecl *ivarDecl); 139761d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian 13981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual SourceRange getSourceRange() const { 13991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(AtLoc, getLocation()); 1400ddfd4c9eda34765b08fae4cb31ad5a365face107Argyrios Kyrtzidis } 1401d40910b581b09c937a8c1fdcde9b8ec724398fb9Steve Naroff SourceLocation getLocStart() const { return AtLoc; } 14028818c4fb69cb2a4eec94b217a90f94f9e075296eDouglas Gregor void setAtLoc(SourceLocation Loc) { AtLoc = Loc; } 1403d40910b581b09c937a8c1fdcde9b8ec724398fb9Steve Naroff 1404be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek ObjCPropertyDecl *getPropertyDecl() const { 1405be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek return PropertyDecl; 1406be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek } 14078818c4fb69cb2a4eec94b217a90f94f9e075296eDouglas Gregor void setPropertyDecl(ObjCPropertyDecl *Prop) { PropertyDecl = Prop; } 14088818c4fb69cb2a4eec94b217a90f94f9e075296eDouglas Gregor 14099f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar Kind getPropertyImplementation() const { 14109f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar return PropertyIvarDecl ? Synthesize : Dynamic; 1411be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek } 14121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1413af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar ObjCIvarDecl *getPropertyIvarDecl() const { 1414be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek return PropertyIvarDecl; 1415be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek } 14168818c4fb69cb2a4eec94b217a90f94f9e075296eDouglas Gregor void setPropertyIvarDecl(ObjCIvarDecl *Ivar) { PropertyIvarDecl = Ivar; } 14178818c4fb69cb2a4eec94b217a90f94f9e075296eDouglas Gregor 141880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 14191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const ObjCPropertyImplDecl *D) { return true; } 142080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Decl::Kind K) { return K == ObjCPropertyImpl; } 142161d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian}; 142261d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian 1423980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff} // end namespace clang 1424980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff#endif 1425