DeclObjC.h revision 45937ae10a0f70f74508165aab4f2b63e18ea747
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; 2460f8c868ffb346b78451a3eccaecd0461d2ae498Fariborz Jahanianclass RecordDecl; 25a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCIvarDecl; 26a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCMethodDecl; 27a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCProtocolDecl; 28a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCCategoryDecl; 29a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCPropertyDecl; 30f624f8186d8fe474350051c6d3f00b2c204fbeaeFariborz Jahanianclass ObjCPropertyImplDecl; 31cbb67480094b3bcb5b715acd827cbad55e2a204cSean Huntclass CXXCtorInitializer; 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 unsigned size() const { return NumElts; } 44793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner bool empty() const { return NumElts == 0; } 451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 46793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnerprotected: 4738af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner void set(void *const* InList, unsigned Elts, ASTContext &Ctx); 48793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner}; 491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 51793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner/// ObjCList - This is a simple template class used to hold various lists of 52793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner/// decls etc, which is heavily used by the ObjC front-end. This only use case 53793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner/// this supports is setting the list all at once and then reading elements out 54793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner/// of it. 55793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnertemplate <typename T> 56793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnerclass ObjCList : public ObjCListBase { 57793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattnerpublic: 5838af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner void set(T* const* InList, unsigned Elts, ASTContext &Ctx) { 5938af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner ObjCListBase::set(reinterpret_cast<void*const*>(InList), Elts, Ctx); 60793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner } 611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 62793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner typedef T* const * iterator; 63793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner iterator begin() const { return (iterator)List; } 64793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner iterator end() const { return (iterator)List+NumElts; } 651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 66793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner T* operator[](unsigned Idx) const { 67793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner assert(Idx < NumElts && "Invalid access"); 68793ccfd646d0388e06c587e962a18fa723b72f02Chris Lattner return (T*)List[Idx]; 693db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner } 703db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner}; 713db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner 7218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor/// \brief A list of Objective-C protocols, along with the source 7318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor/// locations at which they were referenced. 7418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregorclass ObjCProtocolList : public ObjCList<ObjCProtocolDecl> { 7518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor SourceLocation *Locations; 7618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor 7718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor using ObjCList<ObjCProtocolDecl>::set; 7818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor 7918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregorpublic: 8018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor ObjCProtocolList() : ObjCList<ObjCProtocolDecl>(), Locations(0) { } 8118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor 8218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor typedef const SourceLocation *loc_iterator; 8318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor loc_iterator loc_begin() const { return Locations; } 8418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor loc_iterator loc_end() const { return Locations + size(); } 8518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor 8618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor void set(ObjCProtocolDecl* const* InList, unsigned Elts, 8718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor const SourceLocation *Locs, ASTContext &Ctx); 8818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor}; 891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff 91a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCMethodDecl - Represents an instance or class method declaration. 9258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// ObjC methods can be declared within 4 contexts: class interfaces, 9358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// categories, protocols, and class implementations. While C++ member 941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// functions leverage C syntax, Objective-C method syntax is modeled after 951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Smalltalk (using colons to specify argument types/expressions). 9658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Here are some brief examples: 9758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// 9858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Setter/getter instance methods: 9958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// - (void)setMenu:(NSMenu *)menu; 1001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// - (NSMenu *)menu; 1011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 10258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Instance method that takes 2 NSView arguments: 10358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// - (void)replaceSubview:(NSView *)oldView with:(NSView *)newView; 10458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// 10558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// Getter class method: 10658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// + (NSMenu *)defaultMenu; 10758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// 10858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// A selector represents a unique name for a method. The selector names for 10958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// the above methods are setMenu:, menu, replaceSubview:with:, and defaultMenu. 11058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff/// 1114afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCMethodDecl : public NamedDecl, public DeclContext { 11258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroffpublic: 11358dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff enum ImplementationControl { None, Required, Optional }; 11458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroffprivate: 11585f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall // The conventional meaning of this method; an ObjCMethodFamily. 11685f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall // This is not serialized; instead, it is computed on demand and 11785f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall // cached. 11885f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall mutable unsigned Family : ObjCMethodFamilyBitWidth; 11985f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall 12058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff /// instance (true) or class (false) method. 12185f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall unsigned IsInstance : 1; 12285f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall unsigned IsVariadic : 1; 1231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1244607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian // Synthesized declaration method for a property setter/getter 12585f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall unsigned IsSynthesized : 1; 1263fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian 1273fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian // Method has a definition. 12885f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall unsigned IsDefined : 1; 1291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 130ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek // NOTE: VC++ treats enums as signed, avoid using ImplementationControl enum 13158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff /// @required/@optional 132ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek unsigned DeclImplementation : 2; 1331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 134ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek // NOTE: VC++ treats enums as signed, avoid using the ObjCDeclQualifier enum 13558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff /// in, inout, etc. 136ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek unsigned objcDeclQualifier : 6; 1371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1387732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian // Number of args separated by ':' in a method declaration. 1397732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian unsigned NumSelectorArgs; 1407732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian 1414bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor // Result type of this method. 14258dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff QualType MethodDeclType; 1434bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor 1444bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor // Type source information for the result type. 1454bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor TypeSourceInfo *ResultTInfo; 1464bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor 1472073216a1075767b5d25c23d1462b7034686d94dChris Lattner /// ParamInfo - List of pointers to VarDecls for the formal parameters of this 1482073216a1075767b5d25c23d1462b7034686d94dChris Lattner /// Method. 1492073216a1075767b5d25c23d1462b7034686d94dChris Lattner ObjCList<ParmVarDecl> ParamInfo; 1501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff /// List of attributes for this method declaration. 152a2e85ada1dfef36201a31f6646bc4ea3bd76a89aArgyrios Kyrtzidis SourceLocation EndLoc; // the location of the ';' or '}'. 1531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff // The following are only used for method definitions, null otherwise. 15558dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff // FIXME: space savings opportunity, consider a sub-class. 15658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff Stmt *Body; 157451318c08a6342c10b8986060386fd9274418437Daniel Dunbar 158451318c08a6342c10b8986060386fd9274418437Daniel Dunbar /// SelfDecl - Decl for the implicit self parameter. This is lazily 159451318c08a6342c10b8986060386fd9274418437Daniel Dunbar /// constructed by createImplicitParams. 1604111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner ImplicitParamDecl *SelfDecl; 161451318c08a6342c10b8986060386fd9274418437Daniel Dunbar /// CmdDecl - Decl for the implicit _cmd parameter. This is lazily 162451318c08a6342c10b8986060386fd9274418437Daniel Dunbar /// constructed by createImplicitParams. 1634111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner ImplicitParamDecl *CmdDecl; 1641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 165a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCMethodDecl(SourceLocation beginLoc, SourceLocation endLoc, 16658dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff Selector SelInfo, QualType T, 1674bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor TypeSourceInfo *ResultTInfo, 1680701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff DeclContext *contextDecl, 169f6414927e67e27d9324d8d179c5f7ea620443924Daniel Dunbar bool isInstance = true, 17058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff bool isVariadic = false, 1714607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian bool isSynthesized = false, 1723fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian bool isDefined = false, 1737732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian ImplementationControl impControl = None, 1747732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian unsigned numSelectorArgs = 0) 1754afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor : NamedDecl(ObjCMethod, contextDecl, beginLoc, SelInfo), 17685f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall DeclContext(ObjCMethod), Family(InvalidObjCMethodFamily), 17758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff IsInstance(isInstance), IsVariadic(isVariadic), 1784607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian IsSynthesized(isSynthesized), 1793fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian IsDefined(isDefined), 18058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff DeclImplementation(impControl), objcDeclQualifier(OBJC_TQ_None), 1817732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian NumSelectorArgs(numSelectorArgs), MethodDeclType(T), 1827732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian ResultTInfo(ResultTInfo), 1834111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner EndLoc(endLoc), Body(0), SelfDecl(0), CmdDecl(0) {} 1848a779314870760848e61da2c428a78971fe3f1c3Ted Kremenek 18557ea6bee79cc60ba20c7886b453f40f380dce1b1Argyrios Kyrtzidis /// \brief A definition will return its interface declaration. 18657ea6bee79cc60ba20c7886b453f40f380dce1b1Argyrios Kyrtzidis /// An interface declaration will return its definition. 18757ea6bee79cc60ba20c7886b453f40f380dce1b1Argyrios Kyrtzidis /// Otherwise it will return itself. 188da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor virtual ObjCMethodDecl *getNextRedeclaration(); 189da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor 1906c4ae5de0c356777446f823b573821fb95560d91Chris Lattnerpublic: 1910ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner static ObjCMethodDecl *Create(ASTContext &C, 1921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation beginLoc, 1936c4ae5de0c356777446f823b573821fb95560d91Chris Lattner SourceLocation endLoc, Selector SelInfo, 1944bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor QualType T, 1954bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor TypeSourceInfo *ResultTInfo, 1964bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor DeclContext *contextDecl, 197f6414927e67e27d9324d8d179c5f7ea620443924Daniel Dunbar bool isInstance = true, 1986c4ae5de0c356777446f823b573821fb95560d91Chris Lattner bool isVariadic = false, 1994607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian bool isSynthesized = false, 2003fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian bool isDefined = false, 2017732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian ImplementationControl impControl = None, 2027732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian unsigned numSelectorArgs = 0); 203e7f9d301a10b4b3223e91d9be4362b44cba0a212Argyrios Kyrtzidis 204da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor virtual ObjCMethodDecl *getCanonicalDecl(); 20513e635c55eb23f736d38abf9c954801bd6482db4Ted Kremenek const ObjCMethodDecl *getCanonicalDecl() const { 20613e635c55eb23f736d38abf9c954801bd6482db4Ted Kremenek return const_cast<ObjCMethodDecl*>(this)->getCanonicalDecl(); 20713e635c55eb23f736d38abf9c954801bd6482db4Ted Kremenek } 208e7f9d301a10b4b3223e91d9be4362b44cba0a212Argyrios Kyrtzidis 209ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek ObjCDeclQualifier getObjCDeclQualifier() const { 210ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek return ObjCDeclQualifier(objcDeclQualifier); 211ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek } 212a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek void setObjCDeclQualifier(ObjCDeclQualifier QV) { objcDeclQualifier = QV; } 2131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2147732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian unsigned getNumSelectorArgs() const { return NumSelectorArgs; } 2157732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian void setNumSelectorArgs(unsigned numSelectorArgs) { 2167732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian NumSelectorArgs = numSelectorArgs; 2177732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian } 2187732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian 21958dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff // Location information, modeled after the Stmt API. 22058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff SourceLocation getLocStart() const { return getLocation(); } 22158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff SourceLocation getLocEnd() const { return EndLoc; } 22253c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff void setEndLoc(SourceLocation Loc) { EndLoc = Loc; } 223da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor virtual SourceRange getSourceRange() const { 2241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(getLocation(), EndLoc); 2259776ba0d844cf9f6888e871e3fd246ae782f76f4Daniel Dunbar } 2261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2275619688510185081cbb4621d703daf7ee24cf39aChris Lattner ObjCInterfaceDecl *getClassInterface(); 2285619688510185081cbb4621d703daf7ee24cf39aChris Lattner const ObjCInterfaceDecl *getClassInterface() const { 2295619688510185081cbb4621d703daf7ee24cf39aChris Lattner return const_cast<ObjCMethodDecl*>(this)->getClassInterface(); 230e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner } 2311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2322e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor Selector getSelector() const { return getDeclName().getObjCSelector(); } 2333a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 23458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff QualType getResultType() const { return MethodDeclType; } 23553c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff void setResultType(QualType T) { MethodDeclType = T; } 2361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2375291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor /// \brief Determine the type of an expression that sends a message to this 2385291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor /// function. 2395291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor QualType getSendResultType() const { 2406398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor return getResultType().getNonLValueExprType(getASTContext()); 2415291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor } 2425291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 2434bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor TypeSourceInfo *getResultTypeSourceInfo() const { return ResultTInfo; } 2444bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor void setResultTypeSourceInfo(TypeSourceInfo *TInfo) { ResultTInfo = TInfo; } 2454bc1cb6aa635a5bf8fae99bf69c56c724c1e786cDouglas Gregor 246d57f635d520e8cb5b93d3d770ff58db06c62de54Chris Lattner // Iterator access to formal parameters. 2472073216a1075767b5d25c23d1462b7034686d94dChris Lattner unsigned param_size() const { return ParamInfo.size(); } 2482073216a1075767b5d25c23d1462b7034686d94dChris Lattner typedef ObjCList<ParmVarDecl>::iterator param_iterator; 2492073216a1075767b5d25c23d1462b7034686d94dChris Lattner param_iterator param_begin() const { return ParamInfo.begin(); } 2502073216a1075767b5d25c23d1462b7034686d94dChris Lattner param_iterator param_end() const { return ParamInfo.end(); } 2517732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian // This method returns and of the parameters which are part of the selector 2527732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian // name mangling requirements. 2537732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian param_iterator sel_param_end() const { 2547732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian return ParamInfo.begin() + NumSelectorArgs; 2557732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian } 25689951a86b594513c2a013532ed45d197413b1087Chris Lattner 2574ecb25fa94897b2c03510292acace710e5262ba5Fariborz Jahanian void setMethodParams(ASTContext &C, ParmVarDecl *const *List, unsigned Num, 2584ecb25fa94897b2c03510292acace710e5262ba5Fariborz Jahanian unsigned numSelectorArgs) { 25938af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner ParamInfo.set(List, Num, C); 2604ecb25fa94897b2c03510292acace710e5262ba5Fariborz Jahanian NumSelectorArgs = numSelectorArgs; 2612073216a1075767b5d25c23d1462b7034686d94dChris Lattner } 2624111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner 2636ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson // Iterator access to parameter types. 2646ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson typedef std::const_mem_fun_t<QualType, ParmVarDecl> deref_fun; 2656ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson typedef llvm::mapped_iterator<param_iterator, deref_fun> arg_type_iterator; 2666ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson 2676ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson arg_type_iterator arg_type_begin() const { 2686ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson return llvm::map_iterator(param_begin(), deref_fun(&ParmVarDecl::getType)); 2696ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson } 2706ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson arg_type_iterator arg_type_end() const { 2716ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson return llvm::map_iterator(param_end(), deref_fun(&ParmVarDecl::getType)); 2726ea8e2152e1ba93b4c80e7268403a582896dc3dcAnders Carlsson } 2731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 274451318c08a6342c10b8986060386fd9274418437Daniel Dunbar /// createImplicitParams - Used to lazily create the self and cmd 275451318c08a6342c10b8986060386fd9274418437Daniel Dunbar /// implict parameters. This must be called prior to using getSelfDecl() 276451318c08a6342c10b8986060386fd9274418437Daniel Dunbar /// or getCmdDecl(). The call is ignored if the implicit paramters 277451318c08a6342c10b8986060386fd9274418437Daniel Dunbar /// have already been created. 278fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian void createImplicitParams(ASTContext &Context, const ObjCInterfaceDecl *ID); 279451318c08a6342c10b8986060386fd9274418437Daniel Dunbar 2804111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner ImplicitParamDecl * getSelfDecl() const { return SelfDecl; } 28153c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff void setSelfDecl(ImplicitParamDecl *SD) { SelfDecl = SD; } 2824111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner ImplicitParamDecl * getCmdDecl() const { return CmdDecl; } 28353c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff void setCmdDecl(ImplicitParamDecl *CD) { CmdDecl = CD; } 2841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28585f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall /// Determines the family of this method. 28685f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall ObjCMethodFamily getMethodFamily() const; 28785f3d76c0ecfdefcf83ea44a57b7a16119c8a045John McCall 288f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor bool isInstanceMethod() const { return IsInstance; } 28953c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff void setInstanceMethod(bool isInst) { IsInstance = isInst; } 29058dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff bool isVariadic() const { return IsVariadic; } 29153c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff void setVariadic(bool isVar) { IsVariadic = isVar; } 2921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 293f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor bool isClassMethod() const { return !IsInstance; } 294f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 2954607034e621aa77378ec75249d1e9eaf5de49b6aFariborz Jahanian bool isSynthesized() const { return IsSynthesized; } 29653c9d8a4b8f0a76cb9dd2fdd8c433ccf110f2eecSteve Naroff void setSynthesized(bool isSynth) { IsSynthesized = isSynth; } 2973fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian 2983fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian bool isDefined() const { return IsDefined; } 2993fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian void setDefined(bool isDefined) { IsDefined = isDefined; } 3001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30158dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff // Related to protocols declared in @protocol 3021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setDeclImplementation(ImplementationControl ic) { 3031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclImplementation = ic; 30458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff } 3051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ImplementationControl getImplementationControl() const { 3061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return ImplementationControl(DeclImplementation); 30758dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff } 308792481eec23d8c1aa92173be589e2ae9d02514a5Ted Kremenek 309da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor virtual Stmt *getBody() const { 3101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return (Stmt*) Body; 3117297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor } 3126fb0aee4f9dc261bbec72e1283ad8dc0557a6d96Argyrios Kyrtzidis CompoundStmt *getCompoundBody() { return (CompoundStmt*)Body; } 313d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl void setBody(Stmt *B) { Body = B; } 31458dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff 31566570b230941651245accbc5680b60e904eb993cArgyrios Kyrtzidis /// \brief Returns whether this specific method is a definition. 31666570b230941651245accbc5680b60e904eb993cArgyrios Kyrtzidis bool isThisDeclarationADefinition() const { return Body; } 31766570b230941651245accbc5680b60e904eb993cArgyrios Kyrtzidis 31858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff // Implement isa/cast/dyncast/etc. 31980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 320a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCMethodDecl *D) { return true; } 32180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { return K == ObjCMethod; } 32242220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis static DeclContext *castToDeclContext(const ObjCMethodDecl *D) { 32342220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis return static_cast<DeclContext *>(const_cast<ObjCMethodDecl*>(D)); 32442220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis } 32542220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis static ObjCMethodDecl *castFromDeclContext(const DeclContext *DC) { 32642220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis return static_cast<ObjCMethodDecl *>(const_cast<DeclContext*>(DC)); 32742220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis } 32858dbdeb69c063f82d644504fc638120198f7fad2Steve Naroff}; 329e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff 330e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff/// ObjCContainerDecl - Represents a container for method declarations. 331aecae629269fae3bf484baf1d109e9a89d14eeadArgyrios Kyrtzidis/// Current sub-classes are ObjCInterfaceDecl, ObjCCategoryDecl, 3321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ObjCProtocolDecl, and ObjCImplDecl. 333e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff/// 3344afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCContainerDecl : public NamedDecl, public DeclContext { 335782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek // These two locations in the range mark the end of the method container. 336782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek // The first points to the '@' token, and the second to the 'end' token. 337782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek SourceRange AtEnd; 338e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroffpublic: 339e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff 3401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCContainerDecl(Kind DK, DeclContext *DC, SourceLocation L, 341d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor IdentifierInfo *Id) 3424afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor : NamedDecl(DK, DC, L, Id), DeclContext(DK) {} 343e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff 34493983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff // Iterator access to properties. 34593983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff typedef specific_decl_iterator<ObjCPropertyDecl> prop_iterator; 3461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump prop_iterator prop_begin() const { 34717945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis return prop_iterator(decls_begin()); 34893983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff } 3491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump prop_iterator prop_end() const { 35017945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis return prop_iterator(decls_end()); 35109c4719788a5cea09897525e528fa00420f1677bSteve Naroff } 3521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3530701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff // Iterator access to instance/class methods. 354f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor typedef specific_decl_iterator<ObjCMethodDecl> method_iterator; 3551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump method_iterator meth_begin() const { 35617945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis return method_iterator(decls_begin()); 3577ed4faca5162b3ab85be7f7e57aa40e6ec170971Ted Kremenek } 3581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump method_iterator meth_end() const { 35917945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis return method_iterator(decls_end()); 3607ed4faca5162b3ab85be7f7e57aa40e6ec170971Ted Kremenek } 3610701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff 3621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump typedef filtered_decl_iterator<ObjCMethodDecl, 3631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump &ObjCMethodDecl::isInstanceMethod> 364669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor instmeth_iterator; 36517945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis instmeth_iterator instmeth_begin() const { 36617945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis return instmeth_iterator(decls_begin()); 367e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff } 36817945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis instmeth_iterator instmeth_end() const { 36917945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis return instmeth_iterator(decls_end()); 370e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff } 371e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff 3721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump typedef filtered_decl_iterator<ObjCMethodDecl, 3731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump &ObjCMethodDecl::isClassMethod> 374669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor classmeth_iterator; 37517945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis classmeth_iterator classmeth_begin() const { 37617945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis return classmeth_iterator(decls_begin()); 377e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff } 37817945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis classmeth_iterator classmeth_end() const { 37917945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis return classmeth_iterator(decls_end()); 3800701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff } 3810701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff 3820701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff // Get the local instance/class method declared in this interface. 383467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis ObjCMethodDecl *getMethod(Selector Sel, bool isInstance) const; 384467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis ObjCMethodDecl *getInstanceMethod(Selector Sel) const { 385467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis return getMethod(Sel, true/*isInstance*/); 38653df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner } 387467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis ObjCMethodDecl *getClassMethod(Selector Sel) const { 388467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis return getMethod(Sel, false/*isInstance*/); 389467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis } 390467c0b165072689ef87fe8d9cd47a5b63485bcdcArgyrios Kyrtzidis ObjCIvarDecl *getIvarDecl(IdentifierInfo *Id) const; 3911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 39217945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis ObjCPropertyDecl *FindPropertyDeclaration(IdentifierInfo *PropertyId) const; 39393983f8fa120330bf212bfde7e65da2709fb3be8Steve Naroff 394e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff // Marks the end of the container. 395782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek SourceRange getAtEndRange() const { 396782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek return AtEnd; 397782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek } 398782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek void setAtEndRange(SourceRange atEnd) { 399782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek AtEnd = atEnd; 400782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek } 401ddfd4c9eda34765b08fae4cb31ad5a365face107Argyrios Kyrtzidis 402da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor virtual SourceRange getSourceRange() const { 403782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek return SourceRange(getLocation(), getAtEndRange().getEnd()); 404ddfd4c9eda34765b08fae4cb31ad5a365face107Argyrios Kyrtzidis } 4051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 40609c4719788a5cea09897525e528fa00420f1677bSteve Naroff // Implement isa/cast/dyncast/etc. 40780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 40809c4719788a5cea09897525e528fa00420f1677bSteve Naroff static bool classof(const ObjCContainerDecl *D) { return true; } 40980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { 4109a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt return K >= firstObjCContainer && 4119a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt K <= lastObjCContainer; 41280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall } 41309c4719788a5cea09897525e528fa00420f1677bSteve Naroff 41409c4719788a5cea09897525e528fa00420f1677bSteve Naroff static DeclContext *castToDeclContext(const ObjCContainerDecl *D) { 41509c4719788a5cea09897525e528fa00420f1677bSteve Naroff return static_cast<DeclContext *>(const_cast<ObjCContainerDecl*>(D)); 41609c4719788a5cea09897525e528fa00420f1677bSteve Naroff } 41709c4719788a5cea09897525e528fa00420f1677bSteve Naroff static ObjCContainerDecl *castFromDeclContext(const DeclContext *DC) { 41809c4719788a5cea09897525e528fa00420f1677bSteve Naroff return static_cast<ObjCContainerDecl *>(const_cast<DeclContext*>(DC)); 41909c4719788a5cea09897525e528fa00420f1677bSteve Naroff } 420e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff}; 421e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroff 422a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCInterfaceDecl - Represents an ObjC class declaration. For example: 4230c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 4240c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// // MostPrimitive declares no super class (not particularly useful). 4251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// @interface MostPrimitive 4260c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// // no instance variables or methods. 4270c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end 4280c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 4291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// // NSResponder inherits from NSObject & implements NSCoding (a protocol). 4300c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @interface NSResponder : NSObject <NSCoding> 431a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// { // instance variables are represented by ObjCIvarDecl. 4320c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// id nextResponder; // nextResponder instance variable. 4330c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// } 4340c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (NSResponder *)nextResponder; // return a pointer to NSResponder. 4350c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (void)mouseMoved:(NSEvent *)theEvent; // return void, takes a pointer 4360c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end // to an NSEvent. 4370c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 4380c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// Unlike C/C++, forward class declarations are accomplished with @class. 4390c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// Unlike C/C++, @class allows for a list of classes to be forward declared. 4400c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// Unlike C++, ObjC is a single-rooted class model. In Cocoa, classes 4410c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// typically inherit from NSObject (an exception is NSProxy). 4420c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 443deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregorclass ObjCInterfaceDecl : public ObjCContainerDecl { 4443110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff /// TypeForDecl - This indicates the Type object that represents this 4453110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff /// TypeDecl. It is a cache maintained by ASTContext::getObjCInterfaceType 446f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall mutable const Type *TypeForDecl; 4473110251f13981689f384eb3c0aba2afffea18d9dSteve Naroff friend class ASTContext; 4481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 449980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff /// Class's super class. 450a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *SuperClass; 4511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 45253b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek /// Protocols referenced in the @interface declaration 45318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor ObjCProtocolList ReferencedProtocols; 45453b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek 45553b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek /// Protocols reference in both the @interface and class extensions. 45653b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek ObjCList<ObjCProtocolDecl> AllReferencedProtocols; 4571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4588c99d88a6cfa14fc2edab819d5e4325c973b2809Douglas Gregor /// \brief List of categories and class extensions defined for this class. 4598c99d88a6cfa14fc2edab819d5e4325c973b2809Douglas Gregor /// 4608c99d88a6cfa14fc2edab819d5e4325c973b2809Douglas Gregor /// Categories are stored as a linked list in the AST, since the categories 4618c99d88a6cfa14fc2edab819d5e4325c973b2809Douglas Gregor /// and class extensions come long after the initial interface declaration, 462fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner /// and we avoid dynamically-resized arrays in the AST wherever possible. 463a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCCategoryDecl *CategoryList; 4642c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian 4652c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian /// IvarList - List of all ivars defined by this class; including class 4662c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian /// extensions and implementation. This list is built lazily. 4672c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian ObjCIvarDecl *IvarList; 4681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4693a3ca1b35a7121aea0bf465a192dce748465e10fFariborz Jahanian bool ForwardDecl:1; // declared with @class. 4703a3ca1b35a7121aea0bf465a192dce748465e10fFariborz Jahanian bool InternalInterface:1; // true - no @interface for @implementation 47126ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor 47226ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor /// \brief Indicates that the contents of this Objective-C class will be 47326ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor /// completed by the external AST source when required. 47426ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor mutable bool ExternallyCompleted : 1; 47526ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor 476d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff SourceLocation ClassLoc; // location of the class identifier. 477d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff SourceLocation SuperClassLoc; // location of the super class identifier. 478f908a87299d278164540f90b5b6e6cab7b14fb41Steve Naroff SourceLocation EndLoc; // marks the '>', '}', or identifier. 4790e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner 480d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id, 481deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor SourceLocation CLoc, bool FD, bool isInternal); 4821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 48326ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor void LoadExternalDefinition() const; 4840e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattnerpublic: 485d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor static ObjCInterfaceDecl *Create(ASTContext &C, DeclContext *DC, 4860ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner SourceLocation atLoc, 4871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump IdentifierInfo *Id, 488deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor SourceLocation ClassLoc = SourceLocation(), 4890e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner bool ForwardDecl = false, 4900e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattner bool isInternal = false); 49126ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor 49226ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor /// \brief Indicate that this Objective-C class is complete, but that 49326ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor /// the external AST source will be responsible for filling in its contents 49426ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor /// when a complete class is required. 49526ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor void setExternallyCompleted(); 49626ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor 49718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor const ObjCProtocolList &getReferencedProtocols() const { 49826ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor if (ExternallyCompleted) 49926ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor LoadExternalDefinition(); 50026ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor 5011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return ReferencedProtocols; 5027ed9e0f97f4645edc5d4670385b985ea4c617ce7Fariborz Jahanian } 5038a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis 5048a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis ObjCImplementationDecl *getImplementation() const; 5058a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis void setImplementation(ObjCImplementationDecl *ImplD); 5068a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis 507559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian ObjCCategoryDecl *FindCategoryDeclaration(IdentifierInfo *CategoryId) const; 5081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5091cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis // Get the local instance/class method declared in a category. 5101cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis ObjCMethodDecl *getCategoryInstanceMethod(Selector Sel) const; 5111cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis ObjCMethodDecl *getCategoryClassMethod(Selector Sel) const; 5121cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis ObjCMethodDecl *getCategoryMethod(Selector Sel, bool isInstance) const { 5131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return isInstance ? getInstanceMethod(Sel) 5141cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis : getClassMethod(Sel); 5151cb35dd4840d21cec58648361180d5688446a9caArgyrios Kyrtzidis } 5163db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner 51718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor typedef ObjCProtocolList::iterator protocol_iterator; 51853b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek 51953b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek protocol_iterator protocol_begin() const { 52026ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor if (ExternallyCompleted) 52126ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor LoadExternalDefinition(); 52226ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor 52353b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek return ReferencedProtocols.begin(); 52453b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek } 52553b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek protocol_iterator protocol_end() const { 52626ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor if (ExternallyCompleted) 52726ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor LoadExternalDefinition(); 52826ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor 52953b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek return ReferencedProtocols.end(); 53053b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek } 53153b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek 53218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor typedef ObjCProtocolList::loc_iterator protocol_loc_iterator; 53353b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek 53418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor protocol_loc_iterator protocol_loc_begin() const { 53526ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor if (ExternallyCompleted) 53626ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor LoadExternalDefinition(); 53726ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor 53818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor return ReferencedProtocols.loc_begin(); 53918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor } 54053b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek 54118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor protocol_loc_iterator protocol_loc_end() const { 54226ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor if (ExternallyCompleted) 54326ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor LoadExternalDefinition(); 54426ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor 54518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor return ReferencedProtocols.loc_end(); 54618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor } 54753b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek 54853b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek typedef ObjCList<ObjCProtocolDecl>::iterator all_protocol_iterator; 54953b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek 55053b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek all_protocol_iterator all_referenced_protocol_begin() const { 55126ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor if (ExternallyCompleted) 55226ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor LoadExternalDefinition(); 55326ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor 55453b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek return AllReferencedProtocols.empty() ? protocol_begin() 55553b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek : AllReferencedProtocols.begin(); 55653b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek } 55753b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek all_protocol_iterator all_referenced_protocol_end() const { 55826ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor if (ExternallyCompleted) 55926ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor LoadExternalDefinition(); 56026ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor 56153b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek return AllReferencedProtocols.empty() ? protocol_end() 56253b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek : AllReferencedProtocols.end(); 56353b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek } 564291be393aa33759e6e34b6429c5ffa206ba50115Douglas Gregor 56511062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator; 56653b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek 56711062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian ivar_iterator ivar_begin() const { return ivar_iterator(decls_begin()); } 56811062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian ivar_iterator ivar_end() const { return ivar_iterator(decls_end()); } 56953b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek 57011062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian unsigned ivar_size() const { 57111062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian return std::distance(ivar_begin(), ivar_end()); 57211062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian } 57353b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek 57411062e11236b7bc689dad150e8b490fd6b063ec3Fariborz Jahanian bool ivar_empty() const { return ivar_begin() == ivar_end(); } 5752c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian 5762c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian ObjCIvarDecl *all_declared_ivar_begin(); 5772c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian void setIvarList(ObjCIvarDecl *ivar) { IvarList = ivar; } 5782c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian 57938af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner /// setProtocolList - Set the list of protocols that this interface 580b752f289026ad8e5f44851b20e009a27ed61eefcChris Lattner /// implements. 58138af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner void setProtocolList(ObjCProtocolDecl *const* List, unsigned Num, 58218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor const SourceLocation *Locs, ASTContext &C) { 58318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor ReferencedProtocols.set(List, Num, Locs, C); 5843db6cae19c236fe2cef343c90105ce7cca7de965Chris Lattner } 5851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 586339798eae1eb61c50ca68766ed028c0a16d0a284Fariborz Jahanian /// mergeClassExtensionProtocolList - Merge class extension's protocol list 587339798eae1eb61c50ca68766ed028c0a16d0a284Fariborz Jahanian /// into the protocol list for this class. 58818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor void mergeClassExtensionProtocolList(ObjCProtocolDecl *const* List, 58918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor unsigned Num, 59018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor ASTContext &C); 591339798eae1eb61c50ca68766ed028c0a16d0a284Fariborz Jahanian 592768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff bool isForwardDecl() const { return ForwardDecl; } 593768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff void setForwardDecl(bool val) { ForwardDecl = val; } 5941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 59526ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor ObjCInterfaceDecl *getSuperClass() const { 59626ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor if (ExternallyCompleted) 59726ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor LoadExternalDefinition(); 59826ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor 59926ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor return SuperClass; 60026ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor } 60126ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor 602a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek void setSuperClass(ObjCInterfaceDecl * superCls) { SuperClass = superCls; } 6031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 60426ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor ObjCCategoryDecl* getCategoryList() const { 60526ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor if (ExternallyCompleted) 60626ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor LoadExternalDefinition(); 60726ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor 60826ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor return CategoryList; 60926ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor } 61026ac3f30ecef21749c00a4b1a08dd15d772dd5aaDouglas Gregor 6111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setCategoryList(ObjCCategoryDecl *category) { 61253efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner CategoryList = category; 613980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff } 61480aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian 61580aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian ObjCCategoryDecl* getFirstClassExtension() const; 61637cafb077ad5b170acae77e566638603011ef4c0Ted Kremenek 61737cafb077ad5b170acae77e566638603011ef4c0Ted Kremenek ObjCPropertyDecl 61837cafb077ad5b170acae77e566638603011ef4c0Ted Kremenek *FindPropertyVisibleInPrimaryClass(IdentifierInfo *PropertyId) const; 61937cafb077ad5b170acae77e566638603011ef4c0Ted Kremenek 62053efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner /// isSuperClassOf - Return true if this class is the specified class or is a 62153efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner /// super class of the specified interface class. 62253efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner bool isSuperClassOf(const ObjCInterfaceDecl *I) const { 62353efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner // If RHS is derived from LHS it is OK; else it is not OK. 62453efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner while (I != NULL) { 62553efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner if (this == I) 62653efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner return true; 62753efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner I = I->getSuperClass(); 62853efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner } 62953efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner return false; 63053efc251792bf2c9c5f295bd3507facc51a1fe7eChris Lattner } 6311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 63217945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName, 63368a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner ObjCInterfaceDecl *&ClassDeclared); 63417945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName) { 63568a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner ObjCInterfaceDecl *ClassDeclared; 63617945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis return lookupInstanceVariable(IVarName, ClassDeclared); 63768a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner } 63868a057b4292f5ff814ec8da53f6cda8cdcfbd2aeChris Lattner 63994a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff // Lookup a method. First, we search locally. If a method isn't 64094a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff // found, we search referenced protocols and class categories. 641aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance) const; 642aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis ObjCMethodDecl *lookupInstanceMethod(Selector Sel) const { 643aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis return lookupMethod(Sel, true/*isInstance*/); 644aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis } 645aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis ObjCMethodDecl *lookupClassMethod(Selector Sel) const { 646aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis return lookupMethod(Sel, false/*isInstance*/); 647aa5420c1e36ab8e0e4bb87239d8b73a3a8ce75dbArgyrios Kyrtzidis } 648cd1876207f5564beba74e4b2524b664bdba0ba9fFariborz Jahanian ObjCInterfaceDecl *lookupInheritedClass(const IdentifierInfo *ICName); 649d789d3d985e28c9404e62157af46dcb7331920e0Steve Naroff 650d789d3d985e28c9404e62157af46dcb7331920e0Steve Naroff // Lookup a method in the classes implementation hierarchy. 65174b2756bc1f1f5f7c189996fe7e4cd3efef70263Fariborz Jahanian ObjCMethodDecl *lookupPrivateMethod(const Selector &Sel, bool Instance=true); 65260fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff 653ddfd4c9eda34765b08fae4cb31ad5a365face107Argyrios Kyrtzidis // Location information, modeled after the Stmt API. 65460fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff SourceLocation getLocStart() const { return getLocation(); } // '@'interface 655f908a87299d278164540f90b5b6e6cab7b14fb41Steve Naroff SourceLocation getLocEnd() const { return EndLoc; } 6567177dee8aee4b432911c91f1b788963bec0cac9fDaniel Dunbar void setLocEnd(SourceLocation LE) { EndLoc = LE; } 6571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 65833feeb019a5742b286eededd5446ec0fe87c5a61Steve Naroff void setClassLoc(SourceLocation Loc) { ClassLoc = Loc; } 659d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff SourceLocation getClassLoc() const { return ClassLoc; } 660d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff void setSuperClassLoc(SourceLocation Loc) { SuperClassLoc = Loc; } 661d6a07aaf62b40cdfbd96f6b874d02b06fc22d015Steve Naroff SourceLocation getSuperClassLoc() const { return SuperClassLoc; } 6621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 66328e71cf851b73a67604735a9a95aef800b144e2eSteve Naroff /// isImplicitInterfaceDecl - check that this is an implicitly declared 664a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek /// ObjCInterfaceDecl node. This is for legacy objective-c @implementation 6654b6df3fa953267c5d755628c8afd818bb571e579Fariborz Jahanian /// declaration without an @interface declaration. 66633feeb019a5742b286eededd5446ec0fe87c5a61Steve Naroff bool isImplicitInterfaceDecl() const { return InternalInterface; } 66733feeb019a5742b286eededd5446ec0fe87c5a61Steve Naroff void setImplicitInterfaceDecl(bool val) { InternalInterface = val; } 6681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6690fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian /// ClassImplementsProtocol - Checks that 'lProto' protocol 6700fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian /// has been implemented in IDecl class, its super class or categories (if 6710fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian /// lookupCategory is true). 6720fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian bool ClassImplementsProtocol(ObjCProtocolDecl *lProto, 6730fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian bool lookupCategory, 6740fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian bool RHSIsQualifiedID = false); 6751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 67633feeb019a5742b286eededd5446ec0fe87c5a61Steve Naroff // Low-level accessor 677f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const Type *getTypeForDecl() const { return TypeForDecl; } 678f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall void setTypeForDecl(const Type *TD) const { TypeForDecl = TD; } 67933feeb019a5742b286eededd5446ec0fe87c5a61Steve Naroff 68080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 681a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCInterfaceDecl *D) { return true; } 68280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { return K == ObjCInterface; } 68353b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek 68453b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek friend class ASTDeclReader; 68553b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek friend class ASTDeclWriter; 686980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff}; 687980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 688a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCIvarDecl - Represents an ObjC instance variable. In general, ObjC 6890c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// instance variables are identical to C. The only exception is Objective-C 6900c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// supports C++ style access control. For example: 6910c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 6920c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @interface IvarExample : NSObject 6930c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// { 694f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek/// id defaultToProtected; 6950c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @public: 6960c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// id canBePublic; // same as C++. 6970c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @protected: 6980c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// id canBeProtected; // same as C++. 6990c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @package: 7000c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// id canBePackage; // framework visibility (not available in C++). 7010c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// } 7020c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 703a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCIvarDecl : public FieldDecl { 7040e77ba0bf769e2e5a4a93c079f241b02aeb3ef93Chris Lattnerpublic: 705980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff enum AccessControl { 706980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff None, Private, Protected, Public, Package 707980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff }; 7081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 709b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenekprivate: 710ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara ObjCIvarDecl(ObjCContainerDecl *DC, SourceLocation StartLoc, 711ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara SourceLocation IdLoc, IdentifierInfo *Id, 712ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian QualType T, TypeSourceInfo *TInfo, AccessControl ac, Expr *BW, 713ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian bool synthesized) 714ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara : FieldDecl(ObjCIvar, DC, StartLoc, IdLoc, Id, T, TInfo, BW, 715ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara /*Mutable=*/false), 716ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara NextIvar(0), DeclAccess(ac), Synthesized(synthesized) {} 7171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 718b8db21d4df5fbb6ce1ace6411b82d3d623d789deTed Kremenekpublic: 719a06549226f45d5b72169a3d054415616dd1014a2Daniel Dunbar static ObjCIvarDecl *Create(ASTContext &C, ObjCContainerDecl *DC, 720ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara SourceLocation StartLoc, SourceLocation IdLoc, 721ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara IdentifierInfo *Id, QualType T, 722a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *TInfo, 723ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian AccessControl ac, Expr *BW = NULL, 724ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian bool synthesized=false); 7251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 72627a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar /// \brief Return the class interface that this ivar is logically contained 72727a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar /// in; this is either the interface where the ivar was declared, or the 72827a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar /// interface the ivar is conceptually a part of in the case of synthesized 72927a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar /// ivars. 73027a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar const ObjCInterfaceDecl *getContainingInterface() const; 7312c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian 7322c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian ObjCIvarDecl *getNextIvar() { return NextIvar; } 7332c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian void setNextIvar(ObjCIvarDecl *ivar) { NextIvar = ivar; } 73427a961a6adab85cfcf7e48485bbec9237719ae96Daniel Dunbar 735980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff void setAccessControl(AccessControl ac) { DeclAccess = ac; } 736f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek 737ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek AccessControl getAccessControl() const { return AccessControl(DeclAccess); } 738f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek 739f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek AccessControl getCanonicalAccessControl() const { 740f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek return DeclAccess == None ? Protected : AccessControl(DeclAccess); 741f079570fcad0d0053e75ebae29c883ec4276e020Ted Kremenek } 7421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 743ac0021ba802e193e0f9f8207768c7862c7603bc0Fariborz Jahanian void setSynthesize(bool synth) { Synthesized = synth; } 744ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian bool getSynthesize() const { return Synthesized; } 745ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian 746980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff // Implement isa/cast/dyncast/etc. 74780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 748a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCIvarDecl *D) { return true; } 74980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { return K == ObjCIvar; } 750980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroffprivate: 7512c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian /// NextIvar - Next Ivar in the list of ivars declared in class; class's 7522c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian /// extensions and class's implementation 7532c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian ObjCIvarDecl *NextIvar; 7542c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian 755ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek // NOTE: VC++ treats enums as signed, avoid using the AccessControl enum 756ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek unsigned DeclAccess : 3; 757ad51e74030a59a8aa4ef0ebca1d7a701602ef53bFariborz Jahanian unsigned Synthesized : 1; 758980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff}; 759980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 7601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 76101e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek/// ObjCAtDefsFieldDecl - Represents a field declaration created by an 76201e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek/// @defs(...). 76301e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenekclass ObjCAtDefsFieldDecl : public FieldDecl { 76401e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenekprivate: 765ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara ObjCAtDefsFieldDecl(DeclContext *DC, SourceLocation StartLoc, 766ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara SourceLocation IdLoc, IdentifierInfo *Id, 76701e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek QualType T, Expr *BW) 768ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara : FieldDecl(ObjCAtDefsField, DC, StartLoc, IdLoc, Id, T, 769a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall /*TInfo=*/0, // FIXME: Do ObjCAtDefs have declarators ? 770a1d5662d96465f0fddf8819d245da4d19b892effArgyrios Kyrtzidis BW, /*Mutable=*/false) {} 7711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 77201e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenekpublic: 77344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor static ObjCAtDefsFieldDecl *Create(ASTContext &C, DeclContext *DC, 774ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara SourceLocation StartLoc, 775ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara SourceLocation IdLoc, IdentifierInfo *Id, 776ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara QualType T, Expr *BW); 7771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 77801e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek // Implement isa/cast/dyncast/etc. 77980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 78001e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek static bool classof(const ObjCAtDefsFieldDecl *D) { return true; } 78180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { return K == ObjCAtDefsField; } 78201e6779faca1e3a3164c697d6e2dfee0881a6981Ted Kremenek}; 783980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 784a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCProtocolDecl - Represents a protocol declaration. ObjC protocols 7851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// declare a pure abstract type (i.e no instance variables are permitted). 786fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner/// Protocols originally drew inspiration from C++ pure virtual functions (a C++ 7870c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// feature with nice semantics and lousy syntax:-). Here is an example: 7880c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 789eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// @protocol NSDraggingInfo <refproto1, refproto2> 7900c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (NSWindow *)draggingDestinationWindow; 7910c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (NSImage *)draggedImage; 7920c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end 7930c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 794eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// This says that NSDraggingInfo requires two methods and requires everything 795eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// that the two "referenced protocols" 'refproto1' and 'refproto2' require as 796eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// well. 797eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner/// 7980c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @interface ImplementsNSDraggingInfo : NSObject <NSDraggingInfo> 7990c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end 8000c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 801a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjC protocols inspired Java interfaces. Unlike Java, ObjC classes and 8020c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// protocols are in distinct namespaces. For example, Cocoa defines both 8031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// an NSObject protocol and class (which isn't allowed in Java). As a result, 8040c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// protocols are referenced using angle brackets as follows: 8050c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 8060c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// id <NSDraggingInfo> anyObjectThatImplementsNSDraggingInfo; 8070c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 808e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroffclass ObjCProtocolDecl : public ObjCContainerDecl { 809780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner /// Referenced protocols 81018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor ObjCProtocolList ReferencedProtocols; 8111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 812980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff bool isForwardProtoDecl; // declared with @protocol. 8131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 814423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff SourceLocation EndLoc; // marks the '>' or identifier. 8151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 816d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor ObjCProtocolDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id) 8171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : ObjCContainerDecl(ObjCProtocol, DC, L, Id), 818c858105d41602a2dadb2efbc1af80a7b791ebac3Chris Lattner isForwardProtoDecl(true) { 819cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattner } 8201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 821cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattnerpublic: 8221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static ObjCProtocolDecl *Create(ASTContext &C, DeclContext *DC, 823d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor SourceLocation L, IdentifierInfo *Id); 824cca59d77c4b84fd2da268018dbaf9431a621e75bChris Lattner 82518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor const ObjCProtocolList &getReferencedProtocols() const { 826780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner return ReferencedProtocols; 827980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff } 82818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor typedef ObjCProtocolList::iterator protocol_iterator; 829780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();} 830780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner protocol_iterator protocol_end() const { return ReferencedProtocols.end(); } 83118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor typedef ObjCProtocolList::loc_iterator protocol_loc_iterator; 83218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor protocol_loc_iterator protocol_loc_begin() const { 83318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor return ReferencedProtocols.loc_begin(); 83418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor } 83518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor protocol_loc_iterator protocol_loc_end() const { 83618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor return ReferencedProtocols.loc_end(); 83718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor } 83830833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff unsigned protocol_size() const { return ReferencedProtocols.size(); } 8391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 84038af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner /// setProtocolList - Set the list of protocols that this interface 841780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner /// implements. 84238af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num, 84318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor const SourceLocation *Locs, ASTContext &C) { 84418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor ReferencedProtocols.set(List, Num, Locs, C); 845aebf0cba02c014ac8b19d615c654248e0e93779fFariborz Jahanian } 8461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 84791b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff ObjCProtocolDecl *lookupProtocolNamed(IdentifierInfo *PName); 8481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 84994a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff // Lookup a method. First, we search locally. If a method isn't 85094a5c3334bba3cc8cd1da85ba1118bc2c080add9Steve Naroff // found, we search referenced protocols and class categories. 851094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance) const; 852094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis ObjCMethodDecl *lookupInstanceMethod(Selector Sel) const { 853094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis return lookupMethod(Sel, true/*isInstance*/); 854094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis } 855094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis ObjCMethodDecl *lookupClassMethod(Selector Sel) const { 856094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis return lookupMethod(Sel, false/*isInstance*/); 857094e2bb6730d63e0f6919e4839522a43b7644181Argyrios Kyrtzidis } 858d789d3d985e28c9404e62157af46dcb7331920e0Steve Naroff 859768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff bool isForwardDecl() const { return isForwardProtoDecl; } 860768f26ee5892cd63ff0335a15d71a2385ba7c5eaSteve Naroff void setForwardDecl(bool val) { isForwardProtoDecl = val; } 861980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 8621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Location information, modeled after the Stmt API. 863423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff SourceLocation getLocStart() const { return getLocation(); } // '@'protocol 864423cb565abc681b770fb4b9b4bc24d398c98157bSteve Naroff SourceLocation getLocEnd() const { return EndLoc; } 8657177dee8aee4b432911c91f1b788963bec0cac9fDaniel Dunbar void setLocEnd(SourceLocation LE) { EndLoc = LE; } 8661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 86780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 868a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCProtocolDecl *D) { return true; } 86980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { return K == ObjCProtocol; } 870980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff}; 8711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 872a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCClassDecl - Specifies a list of forward class declarations. For example: 87306ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff/// 87406ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff/// @class NSCursor, NSImage, NSPasteboard, NSWindow; 8750c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 8764afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCClassDecl : public Decl { 877321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenekpublic: 878321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek class ObjCClassRef { 879321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek ObjCInterfaceDecl *ID; 880321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek SourceLocation L; 881321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek public: 882321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek ObjCClassRef(ObjCInterfaceDecl *d, SourceLocation l) : ID(d), L(l) {} 883321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek SourceLocation getLocation() const { return L; } 884321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek ObjCInterfaceDecl *getInterface() const { return ID; } 885321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek }; 886321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenekprivate: 887321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek ObjCClassRef *ForwardDecls; 888321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek unsigned NumDecls; 8891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCClassDecl(DeclContext *DC, SourceLocation L, 891321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek ObjCInterfaceDecl *const *Elts, const SourceLocation *Locs, 892321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek unsigned nElts, ASTContext &C); 89361f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattnerpublic: 894d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor static ObjCClassDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L, 8951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCInterfaceDecl *const *Elts = 0, 896321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek const SourceLocation *Locs = 0, 89730833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff unsigned nElts = 0); 8982dbdd622d02d1bfbe1e5bcf421b07b74c7a748f1Ted Kremenek 899da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor virtual SourceRange getSourceRange() const; 9001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 901321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek typedef const ObjCClassRef* iterator; 902321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek iterator begin() const { return ForwardDecls; } 903321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek iterator end() const { return ForwardDecls + NumDecls; } 904321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek unsigned size() const { return NumDecls; } 90530833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff 90630833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff /// setClassList - Set the list of forward classes. 907321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek void setClassList(ASTContext &C, ObjCInterfaceDecl*const*List, 908321c22f1c4271c3d9a3d4d3fc18847f948ab595bTed Kremenek const SourceLocation *Locs, unsigned Num); 9091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 91080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 911a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCClassDecl *D) { return true; } 91280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { return K == ObjCClass; } 91306ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff}; 91406ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff 915a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCForwardProtocolDecl - Specifies a list of forward protocol declarations. 91606ae8d68ef258ccd40c9cd1ce762eaae6f3d4432Steve Naroff/// For example: 9171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 9180c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @protocol NSTextInput, NSChangeSpelling, NSDraggingInfo; 9191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 9204afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCForwardProtocolDecl : public Decl { 92118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor ObjCProtocolList ReferencedProtocols; 9221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 923d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor ObjCForwardProtocolDecl(DeclContext *DC, SourceLocation L, 92438af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner ObjCProtocolDecl *const *Elts, unsigned nElts, 92518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor const SourceLocation *Locs, ASTContext &C); 9261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 92761f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattnerpublic: 928d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor static ObjCForwardProtocolDecl *Create(ASTContext &C, DeclContext *DC, 9291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation L, 93018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor ObjCProtocolDecl *const *Elts, 93118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor unsigned Num, 93218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor const SourceLocation *Locs); 93318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor 93418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor static ObjCForwardProtocolDecl *Create(ASTContext &C, DeclContext *DC, 93518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor SourceLocation L) { 93618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor return Create(C, DC, L, 0, 0, 0); 93718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor } 93861f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattner 93918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor typedef ObjCProtocolList::iterator protocol_iterator; 94030833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();} 94130833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff protocol_iterator protocol_end() const { return ReferencedProtocols.end(); } 94218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor typedef ObjCProtocolList::loc_iterator protocol_loc_iterator; 94318df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor protocol_loc_iterator protocol_loc_begin() const { 94418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor return ReferencedProtocols.loc_begin(); 94518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor } 94618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor protocol_loc_iterator protocol_loc_end() const { 94718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor return ReferencedProtocols.loc_end(); 94818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor } 94918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor 95030833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff unsigned protocol_size() const { return ReferencedProtocols.size(); } 95130833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff 95230833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff /// setProtocolList - Set the list of forward protocols. 95330833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num, 95418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor const SourceLocation *Locs, ASTContext &C) { 95518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor ReferencedProtocols.set(List, Num, Locs, C); 95630833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff } 95780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 958a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCForwardProtocolDecl *D) { return true; } 95980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { return K == ObjCForwardProtocol; } 960980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff}; 961980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 962a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCCategoryDecl - Represents a category declaration. A category allows 9630c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// you to add methods to an existing class (without subclassing or modifying 9641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// the original class interface or implementation:-). Categories don't allow 9650c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// you to add instance data. The following example adds "myMethod" to all 9660c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// NSView's within a process: 9670c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 9680c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @interface NSView (MyViewMethods) 9690c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - myMethod; 9700c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end 9710c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 97233ced0b8550f3e7169f326944731ee02e9338659Douglas Gregor/// Categories also allow you to split the implementation of a class across 9730c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// several files (a feature more naturally supported in C++). 9740c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 9750c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// Categories were originally inspired by dynamic languages such as Common 9761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Lisp and Smalltalk. More traditional class-based languages (C++, Java) 9770c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// don't support this level of dynamism, which is both powerful and dangerous. 9780c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 979e4f039e01e797a38bc97bf22aff9832ecd18ff5fSteve Naroffclass ObjCCategoryDecl : public ObjCContainerDecl { 980980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff /// Interface belonging to this category 981a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *ClassInterface; 9821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 98368c82cf61228102aba1194efef222fa1478af2a8Chris Lattner /// referenced protocols in this category. 98418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor ObjCProtocolList ReferencedProtocols; 9851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 986a8ff9f455d94d9609766cfd5186b6e21dc2102f1Chris Lattner /// Next category belonging to this class. 987a8ff9f455d94d9609766cfd5186b6e21dc2102f1Chris Lattner /// FIXME: this should not be a singly-linked list. Move storage elsewhere. 988a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCCategoryDecl *NextClassCategory; 9891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 990000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian /// true of class extension has at least one bitfield ivar. 991000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian bool HasSynthBitfield : 1; 992000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian 9933db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor /// \brief The location of the '@' in '@interface' 9943db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor SourceLocation AtLoc; 9953db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor 9963db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor /// \brief The location of the category name in this declaration. 9973db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor SourceLocation CategoryNameLoc; 9981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9993db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor ObjCCategoryDecl(DeclContext *DC, SourceLocation AtLoc, 10003db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor SourceLocation ClassNameLoc, SourceLocation CategoryNameLoc, 10013db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor IdentifierInfo *Id) 10023db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor : ObjCContainerDecl(ObjCCategory, DC, ClassNameLoc, Id), 1003000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian ClassInterface(0), NextClassCategory(0), HasSynthBitfield(false), 1004000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian AtLoc(AtLoc), CategoryNameLoc(CategoryNameLoc) { 1005a906135721c350435319347d2672bbb3bf494f91Chris Lattner } 100661f9d41036e30ff80130f99b31c0626e3ef057ccChris Lattnerpublic: 10071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1008d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor static ObjCCategoryDecl *Create(ASTContext &C, DeclContext *DC, 10093db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor SourceLocation AtLoc, 10103db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor SourceLocation ClassNameLoc, 10113db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor SourceLocation CategoryNameLoc, 10123db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor IdentifierInfo *Id); 10131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1014e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner ObjCInterfaceDecl *getClassInterface() { return ClassInterface; } 1015e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; } 1016a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek void setClassInterface(ObjCInterfaceDecl *IDecl) { ClassInterface = IDecl; } 10178a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis 10188a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis ObjCCategoryImplDecl *getImplementation() const; 10198a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis void setImplementation(ObjCCategoryImplDecl *ImplD); 10208a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis 102138af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner /// setProtocolList - Set the list of protocols that this interface 1022f7b2c98c16dfb2261ea57d40a1d5bc4738e73175Chris Lattner /// implements. 102338af2deb27cdfa1a95bde96e30dab15dce53fcefChris Lattner void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num, 102418df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor const SourceLocation *Locs, ASTContext &C) { 102518df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor ReferencedProtocols.set(List, Num, Locs, C); 1026780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner } 10271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 102818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor const ObjCProtocolList &getReferencedProtocols() const { 1029780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner return ReferencedProtocols; 10308f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian } 10311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 103218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor typedef ObjCProtocolList::iterator protocol_iterator; 1033780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();} 1034780f329cb011bff0da5763e2e9744eec093d0509Chris Lattner protocol_iterator protocol_end() const { return ReferencedProtocols.end(); } 103530833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff unsigned protocol_size() const { return ReferencedProtocols.size(); } 103618df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor typedef ObjCProtocolList::loc_iterator protocol_loc_iterator; 103718df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor protocol_loc_iterator protocol_loc_begin() const { 103818df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor return ReferencedProtocols.loc_begin(); 103918df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor } 104018df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor protocol_loc_iterator protocol_loc_end() const { 104118df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor return ReferencedProtocols.loc_end(); 104218df52bbb5d28ca082064d31ae7558dbdae52377Douglas Gregor } 10431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1044a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCCategoryDecl *getNextClassCategory() const { return NextClassCategory; } 104530833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff void setNextClassCategory(ObjCCategoryDecl *Cat) { 104630833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff NextClassCategory = Cat; 104730833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff } 1048980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff void insertNextClassCategory() { 10493d58138992b9bc7b34aaa680f3ddf3971292eb7dSteve Naroff NextClassCategory = ClassInterface->getCategoryList(); 10503d58138992b9bc7b34aaa680f3ddf3971292eb7dSteve Naroff ClassInterface->setCategoryList(this); 10515e9888c2786bfffa6879a08ff40f5a11545eec23Douglas Gregor ClassInterface->setChangedSinceDeserialization(true); 1052980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff } 10533db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor 105425760611365be23556b32332f8a66ae21ea93ecfFariborz Jahanian bool IsClassExtension() const { return getIdentifier() == 0; } 105580aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian const ObjCCategoryDecl *getNextClassExtension() const; 105625760611365be23556b32332f8a66ae21ea93ecfFariborz Jahanian 1057000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian bool hasSynthBitfield() const { return HasSynthBitfield; } 1058000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian void setHasSynthBitfield (bool val) { HasSynthBitfield = val; } 1059000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian 10600e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator; 10610e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian ivar_iterator ivar_begin() const { 10620e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian return ivar_iterator(decls_begin()); 10630e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian } 10640e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian ivar_iterator ivar_end() const { 10650e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian return ivar_iterator(decls_end()); 10660e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian } 10670e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian unsigned ivar_size() const { 10680e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian return std::distance(ivar_begin(), ivar_end()); 10690e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian } 10700e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian bool ivar_empty() const { 10710e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian return ivar_begin() == ivar_end(); 10720e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian } 10730e5ad255729ee86b8ed57e659029008984517cdeFariborz Jahanian 10743db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor SourceLocation getAtLoc() const { return AtLoc; } 10753db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor void setAtLoc(SourceLocation At) { AtLoc = At; } 10763db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor 10773db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor SourceLocation getCategoryNameLoc() const { return CategoryNameLoc; } 10783db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor void setCategoryNameLoc(SourceLocation Loc) { CategoryNameLoc = Loc; } 10793db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor 1080da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor virtual SourceRange getSourceRange() const { 10813db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor return SourceRange(AtLoc, getAtEndRange().getEnd()); 10823db211b617c5073aa70eb25d37ed44ae0dca17c4Douglas Gregor } 10831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 108480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1085a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCCategoryDecl *D) { return true; } 108680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { return K == ObjCCategory; } 1087980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff}; 10880c6b6243d3efd958c17943130e2a773653511edcSteve Naroff 1089aecae629269fae3bf484baf1d109e9a89d14eeadArgyrios Kyrtzidisclass ObjCImplDecl : public ObjCContainerDecl { 10900d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff /// Class interface for this class/category implementation 1091a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *ClassInterface; 10921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10933aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattnerprotected: 10943aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner ObjCImplDecl(Kind DK, DeclContext *DC, SourceLocation L, 10953aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner ObjCInterfaceDecl *classInterface) 10961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : ObjCContainerDecl(DK, DC, L, 10971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump classInterface? classInterface->getIdentifier() : 0), 1098aecae629269fae3bf484baf1d109e9a89d14eeadArgyrios Kyrtzidis ClassInterface(classInterface) {} 10991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 110075c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattnerpublic: 1101e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; } 1102e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner ObjCInterfaceDecl *getClassInterface() { return ClassInterface; } 11038a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis void setClassInterface(ObjCInterfaceDecl *IFace); 11042c2d43c557beca1b4ba4bd743f33978aecb46a97Douglas Gregor 11051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void addInstanceMethod(ObjCMethodDecl *method) { 11062c2d43c557beca1b4ba4bd743f33978aecb46a97Douglas Gregor // FIXME: Context should be set correctly before we get here. 1107653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor method->setLexicalDeclContext(this); 11081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump addDecl(method); 1109e1e6c0d5c79c0ee7ed62fef47a19aa7ecef40db4Steve Naroff } 11101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void addClassMethod(ObjCMethodDecl *method) { 11112c2d43c557beca1b4ba4bd743f33978aecb46a97Douglas Gregor // FIXME: Context should be set correctly before we get here. 1112653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor method->setLexicalDeclContext(this); 11131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump addDecl(method); 111453df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner } 11151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 111617945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis void addPropertyImplementation(ObjCPropertyImplDecl *property); 11171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 111817945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis ObjCPropertyImplDecl *FindPropertyImplDecl(IdentifierInfo *propertyId) const; 111917945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis ObjCPropertyImplDecl *FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const; 1120653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor 1121653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor // Iterator access to properties. 1122653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor typedef specific_decl_iterator<ObjCPropertyImplDecl> propimpl_iterator; 11231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump propimpl_iterator propimpl_begin() const { 112417945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis return propimpl_iterator(decls_begin()); 1125559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian } 11261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump propimpl_iterator propimpl_end() const { 112717945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis return propimpl_iterator(decls_end()); 1128559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian } 1129653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor 113080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1131bfb498d0996ef049efe9476f2802976fd145cd60Argyrios Kyrtzidis static bool classof(const ObjCImplDecl *D) { return true; } 113280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { 11339a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt return K >= firstObjCImpl && K <= lastObjCImpl; 113480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall } 11353aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner}; 11361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ObjCCategoryImplDecl - An object of this class encapsulates a category 11381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// @implementation declaration. If a category class has declaration of a 11391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// property, its implementation must be specified in the category's 11403aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @implementation declaration. Example: 11413aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @interface I @end 11423aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @interface I(CATEGORY) 11433aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @property int p1, d1; 11443aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @end 11453aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @implementation I(CATEGORY) 11463aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @dynamic p1,d1; 11473aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// @end 11483aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// 11493aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner/// ObjCCategoryImplDecl 11503aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattnerclass ObjCCategoryImplDecl : public ObjCImplDecl { 11513aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner // Category name 11523aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner IdentifierInfo *Id; 11533aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner 11543aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner ObjCCategoryImplDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id, 11553aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner ObjCInterfaceDecl *classInterface) 11563aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner : ObjCImplDecl(ObjCCategoryImpl, DC, L, classInterface), Id(Id) {} 11573aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattnerpublic: 11583aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner static ObjCCategoryImplDecl *Create(ASTContext &C, DeclContext *DC, 11593aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner SourceLocation L, IdentifierInfo *Id, 11603aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner ObjCInterfaceDecl *classInterface); 11611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11620d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff /// getIdentifier - Get the identifier that names the category 11633aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner /// interface associated with this implementation. 11640d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff /// FIXME: This is a bad API, we are overriding the NamedDecl::getIdentifier() 11650d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff /// to mean something different. For example: 11660d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff /// ((NamedDecl *)SomeCategoryImplDecl)->getIdentifier() 11670d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff /// returns the class interface name, whereas 11680d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff /// ((ObjCCategoryImplDecl *)SomeCategoryImplDecl)->getIdentifier() 11690d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff /// returns the category name. 11701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump IdentifierInfo *getIdentifier() const { 11711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Id; 11723aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner } 117310b0e1fa3aabd8877dbbc0df1f2414e04afd5fddDouglas Gregor void setIdentifier(IdentifierInfo *II) { Id = II; } 11741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11750d69b8cc8e90a9364771837cb42d7031b4cbb984Steve Naroff ObjCCategoryDecl *getCategoryDecl() const; 117610b0e1fa3aabd8877dbbc0df1f2414e04afd5fddDouglas Gregor 1177b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar /// getName - Get the name of identifier for the class interface associated 1178b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar /// with this implementation as a StringRef. 1179b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar // 1180b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar // FIXME: This is a bad API, we are overriding the NamedDecl::getName, to mean 1181b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar // something different. 1182b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar llvm::StringRef getName() const { 1183b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar return Id ? Id->getNameStart() : ""; 1184b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar } 1185b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar 11863aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner /// getNameAsCString - Get the name of identifier for the class 11873aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner /// interface associated with this implementation as a C string 11883aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner /// (const char*). 11897fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar // 1190b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar // FIXME: Deprecated, move clients to getName(). 11913aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner const char *getNameAsCString() const { 11927fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar return Id ? Id->getNameStart() : ""; 11933aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner } 11941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11953aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner /// @brief Get the name of the class associated with this interface. 11967fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar // 1197b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar // FIXME: Deprecated, move clients to getName(). 11983aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner std::string getNameAsString() const { 1199b5217efa5be2fd6be48d207267c8bcda6bf9206cDaniel Dunbar return getName(); 12003aa1861bd8b5121e53379b1a00f9d6ad8dead4f6Chris Lattner } 12011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 120280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1203a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCCategoryImplDecl *D) { return true; } 120480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { return K == ObjCCategoryImpl;} 12058f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian}; 12068f3fde00ad4d4f943321e338b914ae4740711c84Fariborz Jahanian 1207900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramerllvm::raw_ostream &operator<<(llvm::raw_ostream &OS, 1208900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer const ObjCCategoryImplDecl *CID); 1209900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer 1210a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCImplementationDecl - Represents a class definition - this is where 12110c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// method definitions are specified. For example: 12120c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 121398abf4bd3526a00a0e5cf71a9462c181f97b1c81Fariborz Jahanian/// @code 12140c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @implementation MyClass 12150c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// - (void)myMethod { /* do something */ } 12160c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// @end 121798abf4bd3526a00a0e5cf71a9462c181f97b1c81Fariborz Jahanian/// @endcode 12180c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 12191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Typically, instance variables are specified in the class interface, 1220ec0d7a6f4b0699cc9960e6d9fee0f957c64d1cf9Douglas Gregor/// *not* in the implementation. Nevertheless (for legacy reasons), we 122153df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner/// allow instance variables to be specified in the implementation. When 122253df12d1ba68dbd071d067f8236c16fba815aad5Chris Lattner/// specified, they need to be *identical* to the interface. 12230c6b6243d3efd958c17943130e2a773653511edcSteve Naroff/// 12241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ObjCImplementationDecl : public ObjCImplDecl { 1225980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff /// Implementation Class's super class. 1226a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *SuperClass; 1227e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian /// Support for ivar initialization. 1228e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian /// IvarInitializers - The arguments used to initialize the ivars 1229cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt CXXCtorInitializer **IvarInitializers; 1230e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian unsigned NumIvarInitializers; 1231e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian 1232000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian /// true of class extension has at least one bitfield ivar. 1233000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian bool HasSynthBitfield : 1; 1234000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian 12351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCImplementationDecl(DeclContext *DC, SourceLocation L, 1236a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *classInterface, 1237a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *superDecl) 12381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : ObjCImplDecl(ObjCImplementation, DC, L, classInterface), 1239000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian SuperClass(superDecl), IvarInitializers(0), NumIvarInitializers(0), 1240000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian HasSynthBitfield(false) {} 12411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 12421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static ObjCImplementationDecl *Create(ASTContext &C, DeclContext *DC, 12431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation L, 124475c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner ObjCInterfaceDecl *classInterface, 124575c9cae5f85c72cbb1649e93849e16ede3f07522Chris Lattner ObjCInterfaceDecl *superDecl); 1246e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian 1247e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian /// init_iterator - Iterates through the ivar initializer list. 1248cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt typedef CXXCtorInitializer **init_iterator; 1249e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian 1250e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian /// init_const_iterator - Iterates through the ivar initializer list. 1251cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt typedef CXXCtorInitializer * const * init_const_iterator; 1252e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian 1253e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian /// init_begin() - Retrieve an iterator to the first initializer. 1254e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian init_iterator init_begin() { return IvarInitializers; } 1255e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian /// begin() - Retrieve an iterator to the first initializer. 1256e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian init_const_iterator init_begin() const { return IvarInitializers; } 1257e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian 1258e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian /// init_end() - Retrieve an iterator past the last initializer. 1259e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian init_iterator init_end() { 1260e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian return IvarInitializers + NumIvarInitializers; 1261e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian } 1262e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian /// end() - Retrieve an iterator past the last initializer. 1263e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian init_const_iterator init_end() const { 1264e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian return IvarInitializers + NumIvarInitializers; 1265e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian } 1266e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian /// getNumArgs - Number of ivars which must be initialized. 1267e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian unsigned getNumIvarInitializers() const { 1268e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian return NumIvarInitializers; 1269e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian } 1270e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian 1271e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian void setNumIvarInitializers(unsigned numNumIvarInitializers) { 1272e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian NumIvarInitializers = numNumIvarInitializers; 1273e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian } 1274e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian 1275e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian void setIvarInitializers(ASTContext &C, 1276cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt CXXCtorInitializer ** initializers, 1277e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian unsigned numInitializers); 1278000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian 1279000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian bool hasSynthBitfield() const { return HasSynthBitfield; } 1280000835d0b04345c0014c603fe6339b3bc154050eFariborz Jahanian void setHasSynthBitfield (bool val) { HasSynthBitfield = val; } 1281e4498c6d66a8f472cba29b6158a2e86dfc60d0efFariborz Jahanian 12824afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// getIdentifier - Get the identifier that names the class 12834afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// interface associated with this implementation. 12841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump IdentifierInfo *getIdentifier() const { 12851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getClassInterface()->getIdentifier(); 12864afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 12874afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 1288d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar /// getName - Get the name of identifier for the class interface associated 1289d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar /// with this implementation as a StringRef. 1290d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar // 1291d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar // FIXME: This is a bad API, we are overriding the NamedDecl::getName, to mean 1292d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar // something different. 1293d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar llvm::StringRef getName() const { 1294d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar assert(getIdentifier() && "Name is not a simple identifier"); 1295d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar return getIdentifier()->getName(); 1296d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar } 1297d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar 12984afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// getNameAsCString - Get the name of identifier for the class 12994afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// interface associated with this implementation as a C string 13004afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// (const char*). 13017fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar // 13027fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar // FIXME: Move to StringRef API. 13034afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor const char *getNameAsCString() const { 1304d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar return getName().data(); 13054afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 13064afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 13074afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// @brief Get the name of the class associated with this interface. 13087fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar // 13097fe60650c1133ee74a3395cf1063690e274bb7acDaniel Dunbar // FIXME: Move to StringRef API. 13104afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor std::string getNameAsString() const { 1311d0c10e20d5ba8c1a8a077db128c03eddc3158673Daniel Dunbar return getName(); 13124afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 13134afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 1314e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner const ObjCInterfaceDecl *getSuperClass() const { return SuperClass; } 1315e0def7589a8afa8a6acef13476bb3f882c104b91Chris Lattner ObjCInterfaceDecl *getSuperClass() { return SuperClass; } 13161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1317f3a7af901231535191d14cb524d58f22907ac4d2Chris Lattner void setSuperClass(ObjCInterfaceDecl * superCls) { SuperClass = superCls; } 13181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13198f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator; 13201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ivar_iterator ivar_begin() const { 13211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return ivar_iterator(decls_begin()); 13228f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor } 13231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ivar_iterator ivar_end() const { 132417945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis return ivar_iterator(decls_end()); 13258f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor } 13261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned ivar_size() const { 132717945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis return std::distance(ivar_begin(), ivar_end()); 13288f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor } 13291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ivar_empty() const { 133017945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis return ivar_begin() == ivar_end(); 13318f36aba016c2d236a90f9ecf0a66904209202202Douglas Gregor } 13321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 133380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1334a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCImplementationDecl *D) { return true; } 133580cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { return K == ObjCImplementation; } 13369d50c0635fb213b2a1857e3f8488580f0dab2f98Argyrios Kyrtzidis 1337d527cc06d78fe5afa5f20105b51697637eb02c56Sebastian Redl friend class ASTDeclReader; 13383397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl friend class ASTDeclWriter; 1339980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff}; 1340243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian 1341900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramerllvm::raw_ostream &operator<<(llvm::raw_ostream &OS, 1342900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer const ObjCImplementationDecl *ID); 1343900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer 13441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ObjCCompatibleAliasDecl - Represents alias of a class. This alias is 1345243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian/// declared as @compatibility_alias alias class. 13464afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCCompatibleAliasDecl : public NamedDecl { 1347243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian /// Class that this is an alias of. 1348a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *AliasedClass; 13491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1350d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor ObjCCompatibleAliasDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id, 1351e8043c39176e7f253fbd92982b077eca6bf2fd59Steve Naroff ObjCInterfaceDecl* aliasedClass) 13524afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor : NamedDecl(ObjCCompatibleAlias, DC, L, Id), AliasedClass(aliasedClass) {} 1353f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattnerpublic: 1354d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor static ObjCCompatibleAliasDecl *Create(ASTContext &C, DeclContext *DC, 13550ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner SourceLocation L, IdentifierInfo *Id, 1356f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner ObjCInterfaceDecl* aliasedClass); 1357f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner 1358f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner const ObjCInterfaceDecl *getClassInterface() const { return AliasedClass; } 1359f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattner ObjCInterfaceDecl *getClassInterface() { return AliasedClass; } 136030833f8d77c08f8f16371776fde85a9fde3d9b6eSteve Naroff void setClassInterface(ObjCInterfaceDecl *D) { AliasedClass = D; } 13611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 136280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1363a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCCompatibleAliasDecl *D) { return true; } 136480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { return K == ObjCCompatibleAlias; } 13651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1366243b64b0001172405ff803c61bdcaa8e98ec1552Fariborz Jahanian}; 13671de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian 13681de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian/// ObjCPropertyDecl - Represents one property declaration in an interface. 13691de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian/// For example: 13701de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian/// @property (assign, readwrite) int MyProperty; 13711de1e74541c25c1a7b721f1c3991ea34c8403420Fariborz Jahanian/// 13724afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCPropertyDecl : public NamedDecl { 137382a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanianpublic: 1374a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner enum PropertyAttributeKind { 13751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump OBJC_PR_noattr = 0x00, 13761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump OBJC_PR_readonly = 0x01, 1377a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner OBJC_PR_getter = 0x02, 13781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump OBJC_PR_assign = 0x04, 13791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump OBJC_PR_readwrite = 0x08, 1380a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner OBJC_PR_retain = 0x10, 13811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump OBJC_PR_copy = 0x20, 1382a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner OBJC_PR_nonatomic = 0x40, 138345937ae10a0f70f74508165aab4f2b63e18ea747Fariborz Jahanian OBJC_PR_setter = 0x80, 138445937ae10a0f70f74508165aab4f2b63e18ea747Fariborz Jahanian OBJC_PR_atomic = 0x100 1385a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner }; 1386af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 1387af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar enum SetterKind { Assign, Retain, Copy }; 138846b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian enum PropertyControl { None, Required, Optional }; 138982a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanianprivate: 1390d8265b838360578032020757d9a2a84c86457edcFariborz Jahanian SourceLocation AtLoc; // location of @property 139183a230c83a54190366138c1a4f4310ef838b88fcJohn McCall TypeSourceInfo *DeclType; 1392dd4430e596fac34e9ce44228a249f71e73effd4aFariborz Jahanian unsigned PropertyAttributes : 9; 1393dd4430e596fac34e9ce44228a249f71e73effd4aFariborz Jahanian unsigned PropertyAttributesAsWritten : 9; 139446b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian // @required/@optional 139546b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian unsigned PropertyImplementation : 2; 13961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13975251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian Selector GetterName; // getter name of NULL if no getter 13985251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian Selector SetterName; // setter name of NULL if no setter 13991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 140033de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian ObjCMethodDecl *GetterMethodDecl; // Declaration of getter instance method 140133de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian ObjCMethodDecl *SetterMethodDecl; // Declaration of setter instance method 1402af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian ObjCIvarDecl *PropertyIvarDecl; // Synthesize ivar for this property 140333de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian 14041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCPropertyDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id, 140583a230c83a54190366138c1a4f4310ef838b88fcJohn McCall SourceLocation AtLocation, TypeSourceInfo *T) 1406d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian : NamedDecl(ObjCProperty, DC, L, Id), AtLoc(AtLocation), DeclType(T), 140780aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian PropertyAttributes(OBJC_PR_noattr), 140880aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian PropertyAttributesAsWritten(OBJC_PR_noattr), 140980aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian PropertyImplementation(None), 14101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump GetterName(Selector()), 141133de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian SetterName(Selector()), 1412af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian GetterMethodDecl(0), SetterMethodDecl(0) , PropertyIvarDecl(0) {} 1413f8d17a59167d9c2026506ed8813ea434d93b662aChris Lattnerpublic: 14141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static ObjCPropertyDecl *Create(ASTContext &C, DeclContext *DC, 14151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation L, 1416d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian IdentifierInfo *Id, SourceLocation AtLocation, 141783a230c83a54190366138c1a4f4310ef838b88fcJohn McCall TypeSourceInfo *T, 141846b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian PropertyControl propControl = None); 1419d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian SourceLocation getAtLoc() const { return AtLoc; } 1420d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian void setAtLoc(SourceLocation L) { AtLoc = L; } 1421d0502407c1b41b2ace326f355d7b7a6876246223Fariborz Jahanian 142283a230c83a54190366138c1a4f4310ef838b88fcJohn McCall TypeSourceInfo *getTypeSourceInfo() const { return DeclType; } 142383a230c83a54190366138c1a4f4310ef838b88fcJohn McCall QualType getType() const { return DeclType->getType(); } 142483a230c83a54190366138c1a4f4310ef838b88fcJohn McCall void setType(TypeSourceInfo *T) { DeclType = T; } 142570e5a14c6076d63833c62d1d6d628c26309897c1Douglas Gregor 1426a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner PropertyAttributeKind getPropertyAttributes() const { 1427f4af5154571e0c5eadb19df10e65464766ef6683Chris Lattner return PropertyAttributeKind(PropertyAttributes); 1428f4af5154571e0c5eadb19df10e65464766ef6683Chris Lattner } 14291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setPropertyAttributes(PropertyAttributeKind PRVal) { 1430a5674258f5e6f74f1c0ed3ece4d64fbb1b9afb11Chris Lattner PropertyAttributes |= PRVal; 143182a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian } 1432394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar 143380aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian PropertyAttributeKind getPropertyAttributesAsWritten() const { 143480aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian return PropertyAttributeKind(PropertyAttributesAsWritten); 143580aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian } 143680aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian 143780aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian void setPropertyAttributesAsWritten(PropertyAttributeKind PRVal) { 143880aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian PropertyAttributesAsWritten = PRVal; 143980aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian } 144080aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian 14418cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian void makeitReadWriteAttribute(void) { 14428cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian PropertyAttributes &= ~OBJC_PR_readonly; 14438cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian PropertyAttributes |= OBJC_PR_readwrite; 14441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 14458cf0bb3c2a798ce3acacaac2d3178648cd4c65c6Fariborz Jahanian 1446af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar // Helper methods for accessing attributes. 1447af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 1448af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar /// isReadOnly - Return true iff the property has a setter. 1449394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar bool isReadOnly() const { 1450394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar return (PropertyAttributes & OBJC_PR_readonly); 1451394d33f1f602f7681032a659dff5bb09061ee510Daniel Dunbar } 1452af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 1453af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar /// getSetterKind - Return the method used for doing assignment in 1454af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar /// the property setter. This is only valid if the property has been 1455af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar /// defined to have a setter. 1456af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar SetterKind getSetterKind() const { 1457af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar if (PropertyAttributes & OBJC_PR_retain) 1458af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar return Retain; 1459af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar if (PropertyAttributes & OBJC_PR_copy) 1460af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar return Copy; 1461af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar return Assign; 1462af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar } 1463af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 14645251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian Selector getGetterName() const { return GetterName; } 14655251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian void setGetterName(Selector Sel) { GetterName = Sel; } 14661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14675251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian Selector getSetterName() const { return SetterName; } 14685251e130a23d997f7c0dfdc250cdc41f179e5bedFariborz Jahanian void setSetterName(Selector Sel) { SetterName = Sel; } 14691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 147033de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian ObjCMethodDecl *getGetterMethodDecl() const { return GetterMethodDecl; } 147133de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian void setGetterMethodDecl(ObjCMethodDecl *gDecl) { GetterMethodDecl = gDecl; } 147233de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian 147333de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian ObjCMethodDecl *getSetterMethodDecl() const { return SetterMethodDecl; } 147433de3f0333ca0b5274291b8d76c86758c0484691Fariborz Jahanian void setSetterMethodDecl(ObjCMethodDecl *gDecl) { SetterMethodDecl = gDecl; } 14751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 147646b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian // Related to @optional/@required declared in @protocol 147746b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian void setPropertyImplementation(PropertyControl pc) { 147846b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian PropertyImplementation = pc; 147946b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian } 148046b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian PropertyControl getPropertyImplementation() const { 148146b55e56d029aec699fc2701e43d70264da9ecd8Fariborz Jahanian return PropertyControl(PropertyImplementation); 14821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 14831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1484af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian void setPropertyIvarDecl(ObjCIvarDecl *Ivar) { 1485af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian PropertyIvarDecl = Ivar; 1486af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian } 1487af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian ObjCIvarDecl *getPropertyIvarDecl() const { 1488af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian return PropertyIvarDecl; 1489af3e72285238369c2ea4ebd40a1c9a87bd3eabb7Fariborz Jahanian } 14901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1491da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor virtual SourceRange getSourceRange() const { 1492e3c60a7ce9e0f42c7ca2344b33203266aceca1dbDouglas Gregor return SourceRange(AtLoc, getLocation()); 1493e3c60a7ce9e0f42c7ca2344b33203266aceca1dbDouglas Gregor } 1494e3c60a7ce9e0f42c7ca2344b33203266aceca1dbDouglas Gregor 14959f550ff05d496e6b9480e5619a21d9da0c9e27c1Ted Kremenek /// Lookup a property by name in the specified DeclContext. 1496de09d0c9694f01a99870a8825266d44a29ebb325Ted Kremenek static ObjCPropertyDecl *findPropertyDecl(const DeclContext *DC, 14979f550ff05d496e6b9480e5619a21d9da0c9e27c1Ted Kremenek IdentifierInfo *propertyID); 14989f550ff05d496e6b9480e5619a21d9da0c9e27c1Ted Kremenek 149980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1500a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCPropertyDecl *D) { return true; } 150180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { return K == ObjCProperty; } 150282a5fe3d1cf204b672cdab24d72275b6ad2c3527Fariborz Jahanian}; 1503980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff 15041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ObjCPropertyImplDecl - Represents implementation declaration of a property 150561d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian/// in a class or category implementation block. For example: 150661d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian/// @synthesize prop1 = ivar1; 150761d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian/// 15084afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorclass ObjCPropertyImplDecl : public Decl { 150961d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanianpublic: 15109f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar enum Kind { 15119f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar Synthesize, 15129f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar Dynamic 151361d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian }; 151461d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanianprivate: 1515559c0c4bbecc017aab0716d546c4fefbcc194687Fariborz Jahanian SourceLocation AtLoc; // location of @synthesize or @dynamic 1516a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor 1517a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor /// \brief For @synthesize, the location of the ivar, if it was written in 1518a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor /// the source code. 1519a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor /// 1520a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor /// \code 1521a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor /// @synthesize int a = b 1522a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor /// \endcode 1523a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor SourceLocation IvarLoc; 1524a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor 152561d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian /// Property declaration being implemented 152661d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian ObjCPropertyDecl *PropertyDecl; 1527be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek 152861d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian /// Null for @dynamic. Required for @synthesize. 152961d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian ObjCIvarDecl *PropertyIvarDecl; 153017cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian 153117cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian /// Null for @dynamic. Non-null if property must be copy-constructed in getter 153217cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian Expr *GetterCXXConstructor; 153317cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian 153417cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian /// Null for @dynamic. Non-null if property has assignment operator to call 153517cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian /// in Setter synthesis. 153617cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian Expr *SetterCXXAssignment; 1537be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek 1538d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor ObjCPropertyImplDecl(DeclContext *DC, SourceLocation atLoc, SourceLocation L, 15391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCPropertyDecl *property, 15401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Kind PK, 1541a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor ObjCIvarDecl *ivarDecl, 1542a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor SourceLocation ivarLoc) 15431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Decl(ObjCPropertyImpl, DC, L), AtLoc(atLoc), 1544a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor IvarLoc(ivarLoc), PropertyDecl(property), PropertyIvarDecl(ivarDecl), 154517cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian GetterCXXConstructor(0), SetterCXXAssignment(0) { 15469f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar assert (PK == Dynamic || PropertyIvarDecl); 15479f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar } 15481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15499f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbarpublic: 1550d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor static ObjCPropertyImplDecl *Create(ASTContext &C, DeclContext *DC, 15511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation atLoc, SourceLocation L, 15521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCPropertyDecl *property, 15531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Kind PK, 1554a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor ObjCIvarDecl *ivarDecl, 1555a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor SourceLocation ivarLoc); 155661d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian 1557da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor virtual SourceRange getSourceRange() const; 1558a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor 1559d40910b581b09c937a8c1fdcde9b8ec724398fb9Steve Naroff SourceLocation getLocStart() const { return AtLoc; } 15608818c4fb69cb2a4eec94b217a90f94f9e075296eDouglas Gregor void setAtLoc(SourceLocation Loc) { AtLoc = Loc; } 1561d40910b581b09c937a8c1fdcde9b8ec724398fb9Steve Naroff 1562be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek ObjCPropertyDecl *getPropertyDecl() const { 1563be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek return PropertyDecl; 1564be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek } 15658818c4fb69cb2a4eec94b217a90f94f9e075296eDouglas Gregor void setPropertyDecl(ObjCPropertyDecl *Prop) { PropertyDecl = Prop; } 15668818c4fb69cb2a4eec94b217a90f94f9e075296eDouglas Gregor 15679f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar Kind getPropertyImplementation() const { 15689f0afd4e79601d9982072ff9318e6f9a982c770eDaniel Dunbar return PropertyIvarDecl ? Synthesize : Dynamic; 1569be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek } 15701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1571af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar ObjCIvarDecl *getPropertyIvarDecl() const { 1572be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek return PropertyIvarDecl; 1573be57c3a3fef0776fca57ad88b2db263f37b074c4Ted Kremenek } 1574a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor SourceLocation getPropertyIvarDeclLoc() const { return IvarLoc; } 1575a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor 1576a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor void setPropertyIvarDecl(ObjCIvarDecl *Ivar, 1577a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor SourceLocation IvarLoc) { 1578a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor PropertyIvarDecl = Ivar; 1579a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor this->IvarLoc = IvarLoc; 1580a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor } 158117cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian 158217cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian Expr *getGetterCXXConstructor() const { 158317cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian return GetterCXXConstructor; 158417cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian } 158517cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian void setGetterCXXConstructor(Expr *getterCXXConstructor) { 158617cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian GetterCXXConstructor = getterCXXConstructor; 158717cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian } 15888818c4fb69cb2a4eec94b217a90f94f9e075296eDouglas Gregor 158917cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian Expr *getSetterCXXAssignment() const { 159017cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian return SetterCXXAssignment; 159117cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian } 159217cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian void setSetterCXXAssignment(Expr *setterCXXAssignment) { 159317cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian SetterCXXAssignment = setterCXXAssignment; 159417cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian } 159517cb326cb62a59f53d92236394af40eaae4eddbdFariborz Jahanian 159680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classof(const Decl *D) { return classofKind(D->getKind()); } 15971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const ObjCPropertyImplDecl *D) { return true; } 159880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Decl::Kind K) { return K == ObjCPropertyImpl; } 1599a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor 1600a4ffd85a6684e42f900aad5459e58ad91bb88755Douglas Gregor friend class ASTDeclReader; 160161d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian}; 160261d46159af2a740207de8dc024211d531ae290d9Fariborz Jahanian 1603980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff} // end namespace clang 1604980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff#endif 1605