1 //===--- DeclObjC.h - Classes for representing declarations -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the DeclObjC interface and subclasses.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_AST_DECLOBJC_H
15 #define LLVM_CLANG_AST_DECLOBJC_H
17 #include "clang/AST/Decl.h"
18 #include "llvm/ADT/STLExtras.h"
28 class ObjCProtocolDecl;
29 class ObjCCategoryDecl;
30 class ObjCPropertyDecl;
31 class ObjCPropertyImplDecl;
32 class CXXBaseOrMemberInitializer;
35 void operator=(const ObjCListBase &); // DO NOT IMPLEMENT
36 ObjCListBase(const ObjCListBase&); // DO NOT IMPLEMENT
38 /// List is an array of pointers to objects that are not owned by this object.
43 ObjCListBase() : List(0), NumElts(0) {}
45 assert(List == 0 && "Destroy should have been called before dtor");
48 void Destroy(ASTContext &Ctx);
50 unsigned size() const { return NumElts; }
51 bool empty() const { return NumElts == 0; }
54 void set(void *const* InList, unsigned Elts, ASTContext &Ctx);
58 /// ObjCList - This is a simple template class used to hold various lists of
59 /// decls etc, which is heavily used by the ObjC front-end. This only use case
60 /// this supports is setting the list all at once and then reading elements out
63 class ObjCList : public ObjCListBase {
65 void set(T* const* InList, unsigned Elts, ASTContext &Ctx) {
66 ObjCListBase::set(reinterpret_cast<void*const*>(InList), Elts, Ctx);
69 typedef T* const * iterator;
70 iterator begin() const { return (iterator)List; }
71 iterator end() const { return (iterator)List+NumElts; }
73 T* operator[](unsigned Idx) const {
74 assert(Idx < NumElts && "Invalid access");
79 /// \brief A list of Objective-C protocols, along with the source
80 /// locations at which they were referenced.
81 class ObjCProtocolList : public ObjCList<ObjCProtocolDecl> {
82 SourceLocation *Locations;
84 using ObjCList<ObjCProtocolDecl>::set;
87 ObjCProtocolList() : ObjCList<ObjCProtocolDecl>(), Locations(0) { }
89 typedef const SourceLocation *loc_iterator;
90 loc_iterator loc_begin() const { return Locations; }
91 loc_iterator loc_end() const { return Locations + size(); }
93 void set(ObjCProtocolDecl* const* InList, unsigned Elts,
94 const SourceLocation *Locs, ASTContext &Ctx);
95 void Destroy(ASTContext &Ctx);
99 /// ObjCMethodDecl - Represents an instance or class method declaration.
100 /// ObjC methods can be declared within 4 contexts: class interfaces,
101 /// categories, protocols, and class implementations. While C++ member
102 /// functions leverage C syntax, Objective-C method syntax is modeled after
103 /// Smalltalk (using colons to specify argument types/expressions).
104 /// Here are some brief examples:
106 /// Setter/getter instance methods:
107 /// - (void)setMenu:(NSMenu *)menu;
108 /// - (NSMenu *)menu;
110 /// Instance method that takes 2 NSView arguments:
111 /// - (void)replaceSubview:(NSView *)oldView with:(NSView *)newView;
113 /// Getter class method:
114 /// + (NSMenu *)defaultMenu;
116 /// A selector represents a unique name for a method. The selector names for
117 /// the above methods are setMenu:, menu, replaceSubview:with:, and defaultMenu.
119 class ObjCMethodDecl : public NamedDecl, public DeclContext {
121 enum ImplementationControl { None, Required, Optional };
123 /// Bitfields must be first fields in this class so they pack with those
124 /// declared in class Decl.
125 /// instance (true) or class (false) method.
129 // Synthesized declaration method for a property setter/getter
130 bool IsSynthesized : 1;
132 // NOTE: VC++ treats enums as signed, avoid using ImplementationControl enum
133 /// @required/@optional
134 unsigned DeclImplementation : 2;
136 // NOTE: VC++ treats enums as signed, avoid using the ObjCDeclQualifier enum
138 unsigned objcDeclQualifier : 6;
140 // Number of args separated by ':' in a method declaration.
141 unsigned NumSelectorArgs;
143 // Result type of this method.
144 QualType MethodDeclType;
146 // Type source information for the result type.
147 TypeSourceInfo *ResultTInfo;
149 /// ParamInfo - List of pointers to VarDecls for the formal parameters of this
151 ObjCList<ParmVarDecl> ParamInfo;
153 /// List of attributes for this method declaration.
154 SourceLocation EndLoc; // the location of the ';' or '}'.
156 // The following are only used for method definitions, null otherwise.
157 // FIXME: space savings opportunity, consider a sub-class.
160 /// SelfDecl - Decl for the implicit self parameter. This is lazily
161 /// constructed by createImplicitParams.
162 ImplicitParamDecl *SelfDecl;
163 /// CmdDecl - Decl for the implicit _cmd parameter. This is lazily
164 /// constructed by createImplicitParams.
165 ImplicitParamDecl *CmdDecl;
167 ObjCMethodDecl(SourceLocation beginLoc, SourceLocation endLoc,
168 Selector SelInfo, QualType T,
169 TypeSourceInfo *ResultTInfo,
170 DeclContext *contextDecl,
171 bool isInstance = true,
172 bool isVariadic = false,
173 bool isSynthesized = false,
174 ImplementationControl impControl = None,
175 unsigned numSelectorArgs = 0)
176 : NamedDecl(ObjCMethod, contextDecl, beginLoc, SelInfo),
177 DeclContext(ObjCMethod),
178 IsInstance(isInstance), IsVariadic(isVariadic),
179 IsSynthesized(isSynthesized),
180 DeclImplementation(impControl), objcDeclQualifier(OBJC_TQ_None),
181 NumSelectorArgs(numSelectorArgs), MethodDeclType(T),
182 ResultTInfo(ResultTInfo),
183 EndLoc(endLoc), Body(0), SelfDecl(0), CmdDecl(0) {}
185 virtual ~ObjCMethodDecl() {}
187 /// \brief A definition will return its interface declaration.
188 /// An interface declaration will return its definition.
189 /// Otherwise it will return itself.
190 virtual ObjCMethodDecl *getNextRedeclaration();
194 /// Destroy - Call destructors and release memory.
195 virtual void Destroy(ASTContext& C);
197 static ObjCMethodDecl *Create(ASTContext &C,
198 SourceLocation beginLoc,
199 SourceLocation endLoc, Selector SelInfo,
201 TypeSourceInfo *ResultTInfo,
202 DeclContext *contextDecl,
203 bool isInstance = true,
204 bool isVariadic = false,
205 bool isSynthesized = false,
206 ImplementationControl impControl = None,
207 unsigned numSelectorArgs = 0);
209 virtual ObjCMethodDecl *getCanonicalDecl();
210 const ObjCMethodDecl *getCanonicalDecl() const {
211 return const_cast<ObjCMethodDecl*>(this)->getCanonicalDecl();
214 ObjCDeclQualifier getObjCDeclQualifier() const {
215 return ObjCDeclQualifier(objcDeclQualifier);
217 void setObjCDeclQualifier(ObjCDeclQualifier QV) { objcDeclQualifier = QV; }
219 unsigned getNumSelectorArgs() const { return NumSelectorArgs; }
220 void setNumSelectorArgs(unsigned numSelectorArgs) {
221 NumSelectorArgs = numSelectorArgs;
224 // Location information, modeled after the Stmt API.
225 SourceLocation getLocStart() const { return getLocation(); }
226 SourceLocation getLocEnd() const { return EndLoc; }
227 void setEndLoc(SourceLocation Loc) { EndLoc = Loc; }
228 virtual SourceRange getSourceRange() const {
229 return SourceRange(getLocation(), EndLoc);
232 ObjCInterfaceDecl *getClassInterface();
233 const ObjCInterfaceDecl *getClassInterface() const {
234 return const_cast<ObjCMethodDecl*>(this)->getClassInterface();
237 Selector getSelector() const { return getDeclName().getObjCSelector(); }
239 QualType getResultType() const { return MethodDeclType; }
240 void setResultType(QualType T) { MethodDeclType = T; }
242 TypeSourceInfo *getResultTypeSourceInfo() const { return ResultTInfo; }
243 void setResultTypeSourceInfo(TypeSourceInfo *TInfo) { ResultTInfo = TInfo; }
245 // Iterator access to formal parameters.
246 unsigned param_size() const { return ParamInfo.size(); }
247 typedef ObjCList<ParmVarDecl>::iterator param_iterator;
248 param_iterator param_begin() const { return ParamInfo.begin(); }
249 param_iterator param_end() const { return ParamInfo.end(); }
250 // This method returns and of the parameters which are part of the selector
251 // name mangling requirements.
252 param_iterator sel_param_end() const {
253 return ParamInfo.begin() + NumSelectorArgs;
256 void setMethodParams(ASTContext &C, ParmVarDecl *const *List, unsigned Num,
257 unsigned numSelectorArgs) {
258 ParamInfo.set(List, Num, C);
259 NumSelectorArgs = numSelectorArgs;
262 // Iterator access to parameter types.
263 typedef std::const_mem_fun_t<QualType, ParmVarDecl> deref_fun;
264 typedef llvm::mapped_iterator<param_iterator, deref_fun> arg_type_iterator;
266 arg_type_iterator arg_type_begin() const {
267 return llvm::map_iterator(param_begin(), deref_fun(&ParmVarDecl::getType));
269 arg_type_iterator arg_type_end() const {
270 return llvm::map_iterator(param_end(), deref_fun(&ParmVarDecl::getType));
273 /// createImplicitParams - Used to lazily create the self and cmd
274 /// implict parameters. This must be called prior to using getSelfDecl()
275 /// or getCmdDecl(). The call is ignored if the implicit paramters
276 /// have already been created.
277 void createImplicitParams(ASTContext &Context, const ObjCInterfaceDecl *ID);
279 ImplicitParamDecl * getSelfDecl() const { return SelfDecl; }
280 void setSelfDecl(ImplicitParamDecl *SD) { SelfDecl = SD; }
281 ImplicitParamDecl * getCmdDecl() const { return CmdDecl; }
282 void setCmdDecl(ImplicitParamDecl *CD) { CmdDecl = CD; }
284 bool isInstanceMethod() const { return IsInstance; }
285 void setInstanceMethod(bool isInst) { IsInstance = isInst; }
286 bool isVariadic() const { return IsVariadic; }
287 void setVariadic(bool isVar) { IsVariadic = isVar; }
289 bool isClassMethod() const { return !IsInstance; }
291 bool isSynthesized() const { return IsSynthesized; }
292 void setSynthesized(bool isSynth) { IsSynthesized = isSynth; }
294 // Related to protocols declared in @protocol
295 void setDeclImplementation(ImplementationControl ic) {
296 DeclImplementation = ic;
298 ImplementationControl getImplementationControl() const {
299 return ImplementationControl(DeclImplementation);
302 virtual Stmt *getBody() const {
305 CompoundStmt *getCompoundBody() { return (CompoundStmt*)Body; }
306 void setBody(Stmt *B) { Body = B; }
308 /// \brief Returns whether this specific method is a definition.
309 bool isThisDeclarationADefinition() const { return Body; }
311 // Implement isa/cast/dyncast/etc.
312 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
313 static bool classof(const ObjCMethodDecl *D) { return true; }
314 static bool classofKind(Kind K) { return K == ObjCMethod; }
315 static DeclContext *castToDeclContext(const ObjCMethodDecl *D) {
316 return static_cast<DeclContext *>(const_cast<ObjCMethodDecl*>(D));
318 static ObjCMethodDecl *castFromDeclContext(const DeclContext *DC) {
319 return static_cast<ObjCMethodDecl *>(const_cast<DeclContext*>(DC));
323 /// ObjCMethodList - a linked list of methods with different signatures.
324 struct ObjCMethodList {
325 ObjCMethodDecl *Method;
326 ObjCMethodList *Next;
332 ObjCMethodList(ObjCMethodDecl *M, ObjCMethodList *C) {
338 /// ObjCContainerDecl - Represents a container for method declarations.
339 /// Current sub-classes are ObjCInterfaceDecl, ObjCCategoryDecl,
340 /// ObjCProtocolDecl, and ObjCImplDecl.
342 class ObjCContainerDecl : public NamedDecl, public DeclContext {
343 // These two locations in the range mark the end of the method container.
344 // The first points to the '@' token, and the second to the 'end' token.
348 ObjCContainerDecl(Kind DK, DeclContext *DC, SourceLocation L,
350 : NamedDecl(DK, DC, L, Id), DeclContext(DK) {}
352 virtual ~ObjCContainerDecl() {}
354 // Iterator access to properties.
355 typedef specific_decl_iterator<ObjCPropertyDecl> prop_iterator;
356 prop_iterator prop_begin() const {
357 return prop_iterator(decls_begin());
359 prop_iterator prop_end() const {
360 return prop_iterator(decls_end());
363 // Iterator access to instance/class methods.
364 typedef specific_decl_iterator<ObjCMethodDecl> method_iterator;
365 method_iterator meth_begin() const {
366 return method_iterator(decls_begin());
368 method_iterator meth_end() const {
369 return method_iterator(decls_end());
372 typedef filtered_decl_iterator<ObjCMethodDecl,
373 &ObjCMethodDecl::isInstanceMethod>
375 instmeth_iterator instmeth_begin() const {
376 return instmeth_iterator(decls_begin());
378 instmeth_iterator instmeth_end() const {
379 return instmeth_iterator(decls_end());
382 typedef filtered_decl_iterator<ObjCMethodDecl,
383 &ObjCMethodDecl::isClassMethod>
385 classmeth_iterator classmeth_begin() const {
386 return classmeth_iterator(decls_begin());
388 classmeth_iterator classmeth_end() const {
389 return classmeth_iterator(decls_end());
392 // Get the local instance/class method declared in this interface.
393 ObjCMethodDecl *getMethod(Selector Sel, bool isInstance) const;
394 ObjCMethodDecl *getInstanceMethod(Selector Sel) const {
395 return getMethod(Sel, true/*isInstance*/);
397 ObjCMethodDecl *getClassMethod(Selector Sel) const {
398 return getMethod(Sel, false/*isInstance*/);
400 ObjCIvarDecl *getIvarDecl(IdentifierInfo *Id) const;
402 ObjCPropertyDecl *FindPropertyDeclaration(IdentifierInfo *PropertyId) const;
404 // Marks the end of the container.
405 SourceRange getAtEndRange() const {
408 void setAtEndRange(SourceRange atEnd) {
412 virtual SourceRange getSourceRange() const {
413 return SourceRange(getLocation(), getAtEndRange().getEnd());
416 // Implement isa/cast/dyncast/etc.
417 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
418 static bool classof(const ObjCContainerDecl *D) { return true; }
419 static bool classofKind(Kind K) {
420 return K >= ObjCContainerFirst &&
421 K <= ObjCContainerLast;
424 static DeclContext *castToDeclContext(const ObjCContainerDecl *D) {
425 return static_cast<DeclContext *>(const_cast<ObjCContainerDecl*>(D));
427 static ObjCContainerDecl *castFromDeclContext(const DeclContext *DC) {
428 return static_cast<ObjCContainerDecl *>(const_cast<DeclContext*>(DC));
432 /// ObjCInterfaceDecl - Represents an ObjC class declaration. For example:
434 /// // MostPrimitive declares no super class (not particularly useful).
435 /// @interface MostPrimitive
436 /// // no instance variables or methods.
439 /// // NSResponder inherits from NSObject & implements NSCoding (a protocol).
440 /// @interface NSResponder : NSObject <NSCoding>
441 /// { // instance variables are represented by ObjCIvarDecl.
442 /// id nextResponder; // nextResponder instance variable.
444 /// - (NSResponder *)nextResponder; // return a pointer to NSResponder.
445 /// - (void)mouseMoved:(NSEvent *)theEvent; // return void, takes a pointer
446 /// @end // to an NSEvent.
448 /// Unlike C/C++, forward class declarations are accomplished with @class.
449 /// Unlike C/C++, @class allows for a list of classes to be forward declared.
450 /// Unlike C++, ObjC is a single-rooted class model. In Cocoa, classes
451 /// typically inherit from NSObject (an exception is NSProxy).
453 class ObjCInterfaceDecl : public ObjCContainerDecl {
454 /// TypeForDecl - This indicates the Type object that represents this
455 /// TypeDecl. It is a cache maintained by ASTContext::getObjCInterfaceType
456 mutable Type *TypeForDecl;
457 friend class ASTContext;
459 /// Class's super class.
460 ObjCInterfaceDecl *SuperClass;
462 /// Protocols referenced in interface header declaration
463 ObjCProtocolList ReferencedProtocols;
465 /// List of categories defined for this class.
466 /// FIXME: Why is this a linked list??
467 ObjCCategoryDecl *CategoryList;
469 bool ForwardDecl:1; // declared with @class.
470 bool InternalInterface:1; // true - no @interface for @implementation
472 SourceLocation ClassLoc; // location of the class identifier.
473 SourceLocation SuperClassLoc; // location of the super class identifier.
474 SourceLocation EndLoc; // marks the '>', '}', or identifier.
476 ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id,
477 SourceLocation CLoc, bool FD, bool isInternal);
479 virtual ~ObjCInterfaceDecl() {}
483 /// Destroy - Call destructors and release memory.
484 virtual void Destroy(ASTContext& C);
486 static ObjCInterfaceDecl *Create(ASTContext &C, DeclContext *DC,
487 SourceLocation atLoc,
489 SourceLocation ClassLoc = SourceLocation(),
490 bool ForwardDecl = false,
491 bool isInternal = false);
492 const ObjCProtocolList &getReferencedProtocols() const {
493 return ReferencedProtocols;
496 ObjCImplementationDecl *getImplementation() const;
497 void setImplementation(ObjCImplementationDecl *ImplD);
499 ObjCCategoryDecl *FindCategoryDeclaration(IdentifierInfo *CategoryId) const;
501 // Get the local instance/class method declared in a category.
502 ObjCMethodDecl *getCategoryInstanceMethod(Selector Sel) const;
503 ObjCMethodDecl *getCategoryClassMethod(Selector Sel) const;
504 ObjCMethodDecl *getCategoryMethod(Selector Sel, bool isInstance) const {
505 return isInstance ? getInstanceMethod(Sel)
506 : getClassMethod(Sel);
509 typedef ObjCProtocolList::iterator protocol_iterator;
510 protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();}
511 protocol_iterator protocol_end() const { return ReferencedProtocols.end(); }
512 typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
513 protocol_loc_iterator protocol_loc_begin() const {
514 return ReferencedProtocols.loc_begin();
516 protocol_loc_iterator protocol_loc_end() const {
517 return ReferencedProtocols.loc_end();
519 unsigned protocol_size() const { return ReferencedProtocols.size(); }
521 typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
522 ivar_iterator ivar_begin() const { return ivar_iterator(decls_begin()); }
523 ivar_iterator ivar_end() const { return ivar_iterator(decls_end()); }
524 unsigned ivar_size() const {
525 return std::distance(ivar_begin(), ivar_end());
527 bool ivar_empty() const { return ivar_begin() == ivar_end(); }
529 /// setProtocolList - Set the list of protocols that this interface
531 void setProtocolList(ObjCProtocolDecl *const* List, unsigned Num,
532 const SourceLocation *Locs, ASTContext &C) {
533 ReferencedProtocols.set(List, Num, Locs, C);
536 /// mergeClassExtensionProtocolList - Merge class extension's protocol list
537 /// into the protocol list for this class.
538 void mergeClassExtensionProtocolList(ObjCProtocolDecl *const* List,
540 const SourceLocation *Locs,
543 bool isForwardDecl() const { return ForwardDecl; }
544 void setForwardDecl(bool val) { ForwardDecl = val; }
546 ObjCInterfaceDecl *getSuperClass() const { return SuperClass; }
547 void setSuperClass(ObjCInterfaceDecl * superCls) { SuperClass = superCls; }
549 ObjCCategoryDecl* getCategoryList() const { return CategoryList; }
550 void setCategoryList(ObjCCategoryDecl *category) {
551 CategoryList = category;
554 ObjCCategoryDecl* getClassExtension() const;
557 *FindPropertyVisibleInPrimaryClass(IdentifierInfo *PropertyId) const;
559 /// isSuperClassOf - Return true if this class is the specified class or is a
560 /// super class of the specified interface class.
561 bool isSuperClassOf(const ObjCInterfaceDecl *I) const {
562 // If RHS is derived from LHS it is OK; else it is not OK.
566 I = I->getSuperClass();
571 ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName,
572 ObjCInterfaceDecl *&ClassDeclared);
573 ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName) {
574 ObjCInterfaceDecl *ClassDeclared;
575 return lookupInstanceVariable(IVarName, ClassDeclared);
578 // Lookup a method. First, we search locally. If a method isn't
579 // found, we search referenced protocols and class categories.
580 ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance) const;
581 ObjCMethodDecl *lookupInstanceMethod(Selector Sel) const {
582 return lookupMethod(Sel, true/*isInstance*/);
584 ObjCMethodDecl *lookupClassMethod(Selector Sel) const {
585 return lookupMethod(Sel, false/*isInstance*/);
587 ObjCInterfaceDecl *lookupInheritedClass(const IdentifierInfo *ICName);
589 // Lookup a method in the classes implementation hierarchy.
590 ObjCMethodDecl *lookupPrivateInstanceMethod(const Selector &Sel);
592 // Location information, modeled after the Stmt API.
593 SourceLocation getLocStart() const { return getLocation(); } // '@'interface
594 SourceLocation getLocEnd() const { return EndLoc; }
595 void setLocEnd(SourceLocation LE) { EndLoc = LE; }
597 void setClassLoc(SourceLocation Loc) { ClassLoc = Loc; }
598 SourceLocation getClassLoc() const { return ClassLoc; }
599 void setSuperClassLoc(SourceLocation Loc) { SuperClassLoc = Loc; }
600 SourceLocation getSuperClassLoc() const { return SuperClassLoc; }
602 /// isImplicitInterfaceDecl - check that this is an implicitly declared
603 /// ObjCInterfaceDecl node. This is for legacy objective-c @implementation
604 /// declaration without an @interface declaration.
605 bool isImplicitInterfaceDecl() const { return InternalInterface; }
606 void setImplicitInterfaceDecl(bool val) { InternalInterface = val; }
608 /// ClassImplementsProtocol - Checks that 'lProto' protocol
609 /// has been implemented in IDecl class, its super class or categories (if
610 /// lookupCategory is true).
611 bool ClassImplementsProtocol(ObjCProtocolDecl *lProto,
613 bool RHSIsQualifiedID = false);
615 // Low-level accessor
616 Type *getTypeForDecl() const { return TypeForDecl; }
617 void setTypeForDecl(Type *TD) const { TypeForDecl = TD; }
619 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
620 static bool classof(const ObjCInterfaceDecl *D) { return true; }
621 static bool classofKind(Kind K) { return K == ObjCInterface; }
624 /// ObjCIvarDecl - Represents an ObjC instance variable. In general, ObjC
625 /// instance variables are identical to C. The only exception is Objective-C
626 /// supports C++ style access control. For example:
628 /// @interface IvarExample : NSObject
630 /// id defaultToProtected;
632 /// id canBePublic; // same as C++.
634 /// id canBeProtected; // same as C++.
636 /// id canBePackage; // framework visibility (not available in C++).
639 class ObjCIvarDecl : public FieldDecl {
642 None, Private, Protected, Public, Package
646 ObjCIvarDecl(ObjCContainerDecl *DC, SourceLocation L, IdentifierInfo *Id,
647 QualType T, TypeSourceInfo *TInfo, AccessControl ac, Expr *BW)
648 : FieldDecl(ObjCIvar, DC, L, Id, T, TInfo, BW, /*Mutable=*/false),
652 static ObjCIvarDecl *Create(ASTContext &C, ObjCContainerDecl *DC,
653 SourceLocation L, IdentifierInfo *Id, QualType T,
654 TypeSourceInfo *TInfo,
655 AccessControl ac, Expr *BW = NULL);
657 /// \brief Return the class interface that this ivar is logically contained
658 /// in; this is either the interface where the ivar was declared, or the
659 /// interface the ivar is conceptually a part of in the case of synthesized
661 const ObjCInterfaceDecl *getContainingInterface() const;
663 void setAccessControl(AccessControl ac) { DeclAccess = ac; }
665 AccessControl getAccessControl() const { return AccessControl(DeclAccess); }
667 AccessControl getCanonicalAccessControl() const {
668 return DeclAccess == None ? Protected : AccessControl(DeclAccess);
671 // Implement isa/cast/dyncast/etc.
672 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
673 static bool classof(const ObjCIvarDecl *D) { return true; }
674 static bool classofKind(Kind K) { return K == ObjCIvar; }
676 // NOTE: VC++ treats enums as signed, avoid using the AccessControl enum
677 unsigned DeclAccess : 3;
681 /// ObjCAtDefsFieldDecl - Represents a field declaration created by an
683 class ObjCAtDefsFieldDecl : public FieldDecl {
685 ObjCAtDefsFieldDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
686 QualType T, Expr *BW)
687 : FieldDecl(ObjCAtDefsField, DC, L, Id, T,
688 /*TInfo=*/0, // FIXME: Do ObjCAtDefs have declarators ?
689 BW, /*Mutable=*/false) {}
692 static ObjCAtDefsFieldDecl *Create(ASTContext &C, DeclContext *DC,
694 IdentifierInfo *Id, QualType T,
697 virtual void Destroy(ASTContext& C);
699 // Implement isa/cast/dyncast/etc.
700 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
701 static bool classof(const ObjCAtDefsFieldDecl *D) { return true; }
702 static bool classofKind(Kind K) { return K == ObjCAtDefsField; }
705 /// ObjCProtocolDecl - Represents a protocol declaration. ObjC protocols
706 /// declare a pure abstract type (i.e no instance variables are permitted).
707 /// Protocols orginally drew inspiration from C++ pure virtual functions (a C++
708 /// feature with nice semantics and lousy syntax:-). Here is an example:
710 /// @protocol NSDraggingInfo <refproto1, refproto2>
711 /// - (NSWindow *)draggingDestinationWindow;
712 /// - (NSImage *)draggedImage;
715 /// This says that NSDraggingInfo requires two methods and requires everything
716 /// that the two "referenced protocols" 'refproto1' and 'refproto2' require as
719 /// @interface ImplementsNSDraggingInfo : NSObject <NSDraggingInfo>
722 /// ObjC protocols inspired Java interfaces. Unlike Java, ObjC classes and
723 /// protocols are in distinct namespaces. For example, Cocoa defines both
724 /// an NSObject protocol and class (which isn't allowed in Java). As a result,
725 /// protocols are referenced using angle brackets as follows:
727 /// id <NSDraggingInfo> anyObjectThatImplementsNSDraggingInfo;
729 class ObjCProtocolDecl : public ObjCContainerDecl {
730 /// Referenced protocols
731 ObjCProtocolList ReferencedProtocols;
733 bool isForwardProtoDecl; // declared with @protocol.
735 SourceLocation EndLoc; // marks the '>' or identifier.
737 ObjCProtocolDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id)
738 : ObjCContainerDecl(ObjCProtocol, DC, L, Id),
739 isForwardProtoDecl(true) {
742 virtual ~ObjCProtocolDecl() {}
745 static ObjCProtocolDecl *Create(ASTContext &C, DeclContext *DC,
746 SourceLocation L, IdentifierInfo *Id);
748 /// Destroy - Call destructors and release memory.
749 virtual void Destroy(ASTContext& C);
751 const ObjCProtocolList &getReferencedProtocols() const {
752 return ReferencedProtocols;
754 typedef ObjCProtocolList::iterator protocol_iterator;
755 protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();}
756 protocol_iterator protocol_end() const { return ReferencedProtocols.end(); }
757 typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
758 protocol_loc_iterator protocol_loc_begin() const {
759 return ReferencedProtocols.loc_begin();
761 protocol_loc_iterator protocol_loc_end() const {
762 return ReferencedProtocols.loc_end();
764 unsigned protocol_size() const { return ReferencedProtocols.size(); }
766 /// setProtocolList - Set the list of protocols that this interface
768 void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num,
769 const SourceLocation *Locs, ASTContext &C) {
770 ReferencedProtocols.set(List, Num, Locs, C);
773 ObjCProtocolDecl *lookupProtocolNamed(IdentifierInfo *PName);
775 // Lookup a method. First, we search locally. If a method isn't
776 // found, we search referenced protocols and class categories.
777 ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance) const;
778 ObjCMethodDecl *lookupInstanceMethod(Selector Sel) const {
779 return lookupMethod(Sel, true/*isInstance*/);
781 ObjCMethodDecl *lookupClassMethod(Selector Sel) const {
782 return lookupMethod(Sel, false/*isInstance*/);
785 bool isForwardDecl() const { return isForwardProtoDecl; }
786 void setForwardDecl(bool val) { isForwardProtoDecl = val; }
788 // Location information, modeled after the Stmt API.
789 SourceLocation getLocStart() const { return getLocation(); } // '@'protocol
790 SourceLocation getLocEnd() const { return EndLoc; }
791 void setLocEnd(SourceLocation LE) { EndLoc = LE; }
793 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
794 static bool classof(const ObjCProtocolDecl *D) { return true; }
795 static bool classofKind(Kind K) { return K == ObjCProtocol; }
798 /// ObjCClassDecl - Specifies a list of forward class declarations. For example:
800 /// @class NSCursor, NSImage, NSPasteboard, NSWindow;
802 class ObjCClassDecl : public Decl {
805 ObjCInterfaceDecl *ID;
808 ObjCClassRef(ObjCInterfaceDecl *d, SourceLocation l) : ID(d), L(l) {}
809 SourceLocation getLocation() const { return L; }
810 ObjCInterfaceDecl *getInterface() const { return ID; }
813 ObjCClassRef *ForwardDecls;
816 ObjCClassDecl(DeclContext *DC, SourceLocation L,
817 ObjCInterfaceDecl *const *Elts, const SourceLocation *Locs,
818 unsigned nElts, ASTContext &C);
819 virtual ~ObjCClassDecl() {}
822 /// Destroy - Call destructors and release memory.
823 virtual void Destroy(ASTContext& C);
825 static ObjCClassDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L,
826 ObjCInterfaceDecl *const *Elts = 0,
827 const SourceLocation *Locs = 0,
830 virtual SourceRange getSourceRange() const;
832 typedef const ObjCClassRef* iterator;
833 iterator begin() const { return ForwardDecls; }
834 iterator end() const { return ForwardDecls + NumDecls; }
835 unsigned size() const { return NumDecls; }
837 /// setClassList - Set the list of forward classes.
838 void setClassList(ASTContext &C, ObjCInterfaceDecl*const*List,
839 const SourceLocation *Locs, unsigned Num);
841 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
842 static bool classof(const ObjCClassDecl *D) { return true; }
843 static bool classofKind(Kind K) { return K == ObjCClass; }
846 /// ObjCForwardProtocolDecl - Specifies a list of forward protocol declarations.
849 /// @protocol NSTextInput, NSChangeSpelling, NSDraggingInfo;
851 class ObjCForwardProtocolDecl : public Decl {
852 ObjCProtocolList ReferencedProtocols;
854 ObjCForwardProtocolDecl(DeclContext *DC, SourceLocation L,
855 ObjCProtocolDecl *const *Elts, unsigned nElts,
856 const SourceLocation *Locs, ASTContext &C);
857 virtual ~ObjCForwardProtocolDecl() {}
860 static ObjCForwardProtocolDecl *Create(ASTContext &C, DeclContext *DC,
862 ObjCProtocolDecl *const *Elts,
864 const SourceLocation *Locs);
866 static ObjCForwardProtocolDecl *Create(ASTContext &C, DeclContext *DC,
868 return Create(C, DC, L, 0, 0, 0);
871 /// Destroy - Call destructors and release memory.
872 virtual void Destroy(ASTContext& C);
874 typedef ObjCProtocolList::iterator protocol_iterator;
875 protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();}
876 protocol_iterator protocol_end() const { return ReferencedProtocols.end(); }
877 typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
878 protocol_loc_iterator protocol_loc_begin() const {
879 return ReferencedProtocols.loc_begin();
881 protocol_loc_iterator protocol_loc_end() const {
882 return ReferencedProtocols.loc_end();
885 unsigned protocol_size() const { return ReferencedProtocols.size(); }
887 /// setProtocolList - Set the list of forward protocols.
888 void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num,
889 const SourceLocation *Locs, ASTContext &C) {
890 ReferencedProtocols.set(List, Num, Locs, C);
892 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
893 static bool classof(const ObjCForwardProtocolDecl *D) { return true; }
894 static bool classofKind(Kind K) { return K == ObjCForwardProtocol; }
897 /// ObjCCategoryDecl - Represents a category declaration. A category allows
898 /// you to add methods to an existing class (without subclassing or modifying
899 /// the original class interface or implementation:-). Categories don't allow
900 /// you to add instance data. The following example adds "myMethod" to all
901 /// NSView's within a process:
903 /// @interface NSView (MyViewMethods)
907 /// Categories also allow you to split the implementation of a class across
908 /// several files (a feature more naturally supported in C++).
910 /// Categories were originally inspired by dynamic languages such as Common
911 /// Lisp and Smalltalk. More traditional class-based languages (C++, Java)
912 /// don't support this level of dynamism, which is both powerful and dangerous.
914 class ObjCCategoryDecl : public ObjCContainerDecl {
915 /// Interface belonging to this category
916 ObjCInterfaceDecl *ClassInterface;
918 /// referenced protocols in this category.
919 ObjCProtocolList ReferencedProtocols;
921 /// Next category belonging to this class.
922 /// FIXME: this should not be a singly-linked list. Move storage elsewhere.
923 ObjCCategoryDecl *NextClassCategory;
925 /// \brief The location of the '@' in '@interface'
926 SourceLocation AtLoc;
928 /// \brief The location of the category name in this declaration.
929 SourceLocation CategoryNameLoc;
931 ObjCCategoryDecl(DeclContext *DC, SourceLocation AtLoc,
932 SourceLocation ClassNameLoc, SourceLocation CategoryNameLoc,
934 : ObjCContainerDecl(ObjCCategory, DC, ClassNameLoc, Id),
935 ClassInterface(0), NextClassCategory(0), AtLoc(AtLoc),
936 CategoryNameLoc(CategoryNameLoc) {
940 static ObjCCategoryDecl *Create(ASTContext &C, DeclContext *DC,
941 SourceLocation AtLoc,
942 SourceLocation ClassNameLoc,
943 SourceLocation CategoryNameLoc,
946 ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
947 const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; }
948 void setClassInterface(ObjCInterfaceDecl *IDecl) { ClassInterface = IDecl; }
950 ObjCCategoryImplDecl *getImplementation() const;
951 void setImplementation(ObjCCategoryImplDecl *ImplD);
953 /// setProtocolList - Set the list of protocols that this interface
955 void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num,
956 const SourceLocation *Locs, ASTContext &C) {
957 ReferencedProtocols.set(List, Num, Locs, C);
960 const ObjCProtocolList &getReferencedProtocols() const {
961 return ReferencedProtocols;
964 typedef ObjCProtocolList::iterator protocol_iterator;
965 protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();}
966 protocol_iterator protocol_end() const { return ReferencedProtocols.end(); }
967 unsigned protocol_size() const { return ReferencedProtocols.size(); }
968 typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
969 protocol_loc_iterator protocol_loc_begin() const {
970 return ReferencedProtocols.loc_begin();
972 protocol_loc_iterator protocol_loc_end() const {
973 return ReferencedProtocols.loc_end();
976 ObjCCategoryDecl *getNextClassCategory() const { return NextClassCategory; }
977 void setNextClassCategory(ObjCCategoryDecl *Cat) {
978 NextClassCategory = Cat;
980 void insertNextClassCategory() {
981 NextClassCategory = ClassInterface->getCategoryList();
982 ClassInterface->setCategoryList(this);
985 bool IsClassExtension() const { return getIdentifier() == 0; }
987 typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
988 ivar_iterator ivar_begin() const {
989 return ivar_iterator(decls_begin());
991 ivar_iterator ivar_end() const {
992 return ivar_iterator(decls_end());
994 unsigned ivar_size() const {
995 return std::distance(ivar_begin(), ivar_end());
997 bool ivar_empty() const {
998 return ivar_begin() == ivar_end();
1001 SourceLocation getAtLoc() const { return AtLoc; }
1002 void setAtLoc(SourceLocation At) { AtLoc = At; }
1004 SourceLocation getCategoryNameLoc() const { return CategoryNameLoc; }
1005 void setCategoryNameLoc(SourceLocation Loc) { CategoryNameLoc = Loc; }
1007 virtual SourceRange getSourceRange() const {
1008 return SourceRange(AtLoc, getAtEndRange().getEnd());
1011 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1012 static bool classof(const ObjCCategoryDecl *D) { return true; }
1013 static bool classofKind(Kind K) { return K == ObjCCategory; }
1016 class ObjCImplDecl : public ObjCContainerDecl {
1017 /// Class interface for this class/category implementation
1018 ObjCInterfaceDecl *ClassInterface;
1021 ObjCImplDecl(Kind DK, DeclContext *DC, SourceLocation L,
1022 ObjCInterfaceDecl *classInterface)
1023 : ObjCContainerDecl(DK, DC, L,
1024 classInterface? classInterface->getIdentifier() : 0),
1025 ClassInterface(classInterface) {}
1028 virtual ~ObjCImplDecl() {}
1030 const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; }
1031 ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
1032 void setClassInterface(ObjCInterfaceDecl *IFace);
1034 void addInstanceMethod(ObjCMethodDecl *method) {
1035 // FIXME: Context should be set correctly before we get here.
1036 method->setLexicalDeclContext(this);
1039 void addClassMethod(ObjCMethodDecl *method) {
1040 // FIXME: Context should be set correctly before we get here.
1041 method->setLexicalDeclContext(this);
1045 void addPropertyImplementation(ObjCPropertyImplDecl *property);
1047 ObjCPropertyImplDecl *FindPropertyImplDecl(IdentifierInfo *propertyId) const;
1048 ObjCPropertyImplDecl *FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const;
1050 // Iterator access to properties.
1051 typedef specific_decl_iterator<ObjCPropertyImplDecl> propimpl_iterator;
1052 propimpl_iterator propimpl_begin() const {
1053 return propimpl_iterator(decls_begin());
1055 propimpl_iterator propimpl_end() const {
1056 return propimpl_iterator(decls_end());
1059 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1060 static bool classof(const ObjCImplDecl *D) { return true; }
1061 static bool classofKind(Kind K) {
1062 return K >= ObjCImplFirst && K <= ObjCImplLast;
1066 /// ObjCCategoryImplDecl - An object of this class encapsulates a category
1067 /// @implementation declaration. If a category class has declaration of a
1068 /// property, its implementation must be specified in the category's
1069 /// @implementation declaration. Example:
1070 /// @interface I @end
1071 /// @interface I(CATEGORY)
1072 /// @property int p1, d1;
1074 /// @implementation I(CATEGORY)
1078 /// ObjCCategoryImplDecl
1079 class ObjCCategoryImplDecl : public ObjCImplDecl {
1083 ObjCCategoryImplDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
1084 ObjCInterfaceDecl *classInterface)
1085 : ObjCImplDecl(ObjCCategoryImpl, DC, L, classInterface), Id(Id) {}
1087 static ObjCCategoryImplDecl *Create(ASTContext &C, DeclContext *DC,
1088 SourceLocation L, IdentifierInfo *Id,
1089 ObjCInterfaceDecl *classInterface);
1091 /// getIdentifier - Get the identifier that names the category
1092 /// interface associated with this implementation.
1093 /// FIXME: This is a bad API, we are overriding the NamedDecl::getIdentifier()
1094 /// to mean something different. For example:
1095 /// ((NamedDecl *)SomeCategoryImplDecl)->getIdentifier()
1096 /// returns the class interface name, whereas
1097 /// ((ObjCCategoryImplDecl *)SomeCategoryImplDecl)->getIdentifier()
1098 /// returns the category name.
1099 IdentifierInfo *getIdentifier() const {
1102 void setIdentifier(IdentifierInfo *II) { Id = II; }
1104 ObjCCategoryDecl *getCategoryDecl() const;
1106 /// getName - Get the name of identifier for the class interface associated
1107 /// with this implementation as a StringRef.
1109 // FIXME: This is a bad API, we are overriding the NamedDecl::getName, to mean
1110 // something different.
1111 llvm::StringRef getName() const {
1112 return Id ? Id->getNameStart() : "";
1115 /// getNameAsCString - Get the name of identifier for the class
1116 /// interface associated with this implementation as a C string
1119 // FIXME: Deprecated, move clients to getName().
1120 const char *getNameAsCString() const {
1121 return Id ? Id->getNameStart() : "";
1124 /// @brief Get the name of the class associated with this interface.
1126 // FIXME: Deprecated, move clients to getName().
1127 std::string getNameAsString() const {
1131 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1132 static bool classof(const ObjCCategoryImplDecl *D) { return true; }
1133 static bool classofKind(Kind K) { return K == ObjCCategoryImpl;}
1136 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
1137 const ObjCCategoryImplDecl *CID);
1139 /// ObjCImplementationDecl - Represents a class definition - this is where
1140 /// method definitions are specified. For example:
1143 /// @implementation MyClass
1144 /// - (void)myMethod { /* do something */ }
1148 /// Typically, instance variables are specified in the class interface,
1149 /// *not* in the implementation. Nevertheless (for legacy reasons), we
1150 /// allow instance variables to be specified in the implementation. When
1151 /// specified, they need to be *identical* to the interface.
1153 class ObjCImplementationDecl : public ObjCImplDecl {
1154 /// Implementation Class's super class.
1155 ObjCInterfaceDecl *SuperClass;
1156 /// Support for ivar initialization.
1157 /// IvarInitializers - The arguments used to initialize the ivars
1158 CXXBaseOrMemberInitializer **IvarInitializers;
1159 unsigned NumIvarInitializers;
1161 ObjCImplementationDecl(DeclContext *DC, SourceLocation L,
1162 ObjCInterfaceDecl *classInterface,
1163 ObjCInterfaceDecl *superDecl)
1164 : ObjCImplDecl(ObjCImplementation, DC, L, classInterface),
1165 SuperClass(superDecl), IvarInitializers(0), NumIvarInitializers(0) {}
1167 static ObjCImplementationDecl *Create(ASTContext &C, DeclContext *DC,
1169 ObjCInterfaceDecl *classInterface,
1170 ObjCInterfaceDecl *superDecl);
1172 /// init_iterator - Iterates through the ivar initializer list.
1173 typedef CXXBaseOrMemberInitializer **init_iterator;
1175 /// init_const_iterator - Iterates through the ivar initializer list.
1176 typedef CXXBaseOrMemberInitializer * const * init_const_iterator;
1178 /// init_begin() - Retrieve an iterator to the first initializer.
1179 init_iterator init_begin() { return IvarInitializers; }
1180 /// begin() - Retrieve an iterator to the first initializer.
1181 init_const_iterator init_begin() const { return IvarInitializers; }
1183 /// init_end() - Retrieve an iterator past the last initializer.
1184 init_iterator init_end() {
1185 return IvarInitializers + NumIvarInitializers;
1187 /// end() - Retrieve an iterator past the last initializer.
1188 init_const_iterator init_end() const {
1189 return IvarInitializers + NumIvarInitializers;
1191 /// getNumArgs - Number of ivars which must be initialized.
1192 unsigned getNumIvarInitializers() const {
1193 return NumIvarInitializers;
1196 void setNumIvarInitializers(unsigned numNumIvarInitializers) {
1197 NumIvarInitializers = numNumIvarInitializers;
1200 void setIvarInitializers(ASTContext &C,
1201 CXXBaseOrMemberInitializer ** initializers,
1202 unsigned numInitializers);
1204 /// getIdentifier - Get the identifier that names the class
1205 /// interface associated with this implementation.
1206 IdentifierInfo *getIdentifier() const {
1207 return getClassInterface()->getIdentifier();
1210 /// getName - Get the name of identifier for the class interface associated
1211 /// with this implementation as a StringRef.
1213 // FIXME: This is a bad API, we are overriding the NamedDecl::getName, to mean
1214 // something different.
1215 llvm::StringRef getName() const {
1216 assert(getIdentifier() && "Name is not a simple identifier");
1217 return getIdentifier()->getName();
1220 /// getNameAsCString - Get the name of identifier for the class
1221 /// interface associated with this implementation as a C string
1224 // FIXME: Move to StringRef API.
1225 const char *getNameAsCString() const {
1226 return getName().data();
1229 /// @brief Get the name of the class associated with this interface.
1231 // FIXME: Move to StringRef API.
1232 std::string getNameAsString() const {
1236 const ObjCInterfaceDecl *getSuperClass() const { return SuperClass; }
1237 ObjCInterfaceDecl *getSuperClass() { return SuperClass; }
1239 void setSuperClass(ObjCInterfaceDecl * superCls) { SuperClass = superCls; }
1241 typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
1242 ivar_iterator ivar_begin() const {
1243 return ivar_iterator(decls_begin());
1245 ivar_iterator ivar_end() const {
1246 return ivar_iterator(decls_end());
1248 unsigned ivar_size() const {
1249 return std::distance(ivar_begin(), ivar_end());
1251 bool ivar_empty() const {
1252 return ivar_begin() == ivar_end();
1255 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1256 static bool classof(const ObjCImplementationDecl *D) { return true; }
1257 static bool classofKind(Kind K) { return K == ObjCImplementation; }
1260 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
1261 const ObjCImplementationDecl *ID);
1263 /// ObjCCompatibleAliasDecl - Represents alias of a class. This alias is
1264 /// declared as @compatibility_alias alias class.
1265 class ObjCCompatibleAliasDecl : public NamedDecl {
1266 /// Class that this is an alias of.
1267 ObjCInterfaceDecl *AliasedClass;
1269 ObjCCompatibleAliasDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
1270 ObjCInterfaceDecl* aliasedClass)
1271 : NamedDecl(ObjCCompatibleAlias, DC, L, Id), AliasedClass(aliasedClass) {}
1273 static ObjCCompatibleAliasDecl *Create(ASTContext &C, DeclContext *DC,
1274 SourceLocation L, IdentifierInfo *Id,
1275 ObjCInterfaceDecl* aliasedClass);
1277 const ObjCInterfaceDecl *getClassInterface() const { return AliasedClass; }
1278 ObjCInterfaceDecl *getClassInterface() { return AliasedClass; }
1279 void setClassInterface(ObjCInterfaceDecl *D) { AliasedClass = D; }
1281 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1282 static bool classof(const ObjCCompatibleAliasDecl *D) { return true; }
1283 static bool classofKind(Kind K) { return K == ObjCCompatibleAlias; }
1287 /// ObjCPropertyDecl - Represents one property declaration in an interface.
1289 /// @property (assign, readwrite) int MyProperty;
1291 class ObjCPropertyDecl : public NamedDecl {
1293 enum PropertyAttributeKind {
1294 OBJC_PR_noattr = 0x00,
1295 OBJC_PR_readonly = 0x01,
1296 OBJC_PR_getter = 0x02,
1297 OBJC_PR_assign = 0x04,
1298 OBJC_PR_readwrite = 0x08,
1299 OBJC_PR_retain = 0x10,
1300 OBJC_PR_copy = 0x20,
1301 OBJC_PR_nonatomic = 0x40,
1302 OBJC_PR_setter = 0x80
1305 enum SetterKind { Assign, Retain, Copy };
1306 enum PropertyControl { None, Required, Optional };
1308 SourceLocation AtLoc; // location of @property
1310 unsigned PropertyAttributes : 8;
1312 // @required/@optional
1313 unsigned PropertyImplementation : 2;
1315 Selector GetterName; // getter name of NULL if no getter
1316 Selector SetterName; // setter name of NULL if no setter
1318 ObjCMethodDecl *GetterMethodDecl; // Declaration of getter instance method
1319 ObjCMethodDecl *SetterMethodDecl; // Declaration of setter instance method
1320 ObjCIvarDecl *PropertyIvarDecl; // Synthesize ivar for this property
1322 ObjCPropertyDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
1323 SourceLocation AtLocation, QualType T)
1324 : NamedDecl(ObjCProperty, DC, L, Id), AtLoc(AtLocation), DeclType(T),
1325 PropertyAttributes(OBJC_PR_noattr), PropertyImplementation(None),
1326 GetterName(Selector()),
1327 SetterName(Selector()),
1328 GetterMethodDecl(0), SetterMethodDecl(0) , PropertyIvarDecl(0) {}
1330 static ObjCPropertyDecl *Create(ASTContext &C, DeclContext *DC,
1332 IdentifierInfo *Id, SourceLocation AtLocation,
1334 PropertyControl propControl = None);
1335 SourceLocation getAtLoc() const { return AtLoc; }
1336 void setAtLoc(SourceLocation L) { AtLoc = L; }
1338 QualType getType() const { return DeclType; }
1339 void setType(QualType T) { DeclType = T; }
1341 PropertyAttributeKind getPropertyAttributes() const {
1342 return PropertyAttributeKind(PropertyAttributes);
1344 void setPropertyAttributes(PropertyAttributeKind PRVal) {
1345 PropertyAttributes |= PRVal;
1348 void makeitReadWriteAttribute(void) {
1349 PropertyAttributes &= ~OBJC_PR_readonly;
1350 PropertyAttributes |= OBJC_PR_readwrite;
1353 // Helper methods for accessing attributes.
1355 /// isReadOnly - Return true iff the property has a setter.
1356 bool isReadOnly() const {
1357 return (PropertyAttributes & OBJC_PR_readonly);
1360 /// getSetterKind - Return the method used for doing assignment in
1361 /// the property setter. This is only valid if the property has been
1362 /// defined to have a setter.
1363 SetterKind getSetterKind() const {
1364 if (PropertyAttributes & OBJC_PR_retain)
1366 if (PropertyAttributes & OBJC_PR_copy)
1371 Selector getGetterName() const { return GetterName; }
1372 void setGetterName(Selector Sel) { GetterName = Sel; }
1374 Selector getSetterName() const { return SetterName; }
1375 void setSetterName(Selector Sel) { SetterName = Sel; }
1377 ObjCMethodDecl *getGetterMethodDecl() const { return GetterMethodDecl; }
1378 void setGetterMethodDecl(ObjCMethodDecl *gDecl) { GetterMethodDecl = gDecl; }
1380 ObjCMethodDecl *getSetterMethodDecl() const { return SetterMethodDecl; }
1381 void setSetterMethodDecl(ObjCMethodDecl *gDecl) { SetterMethodDecl = gDecl; }
1383 // Related to @optional/@required declared in @protocol
1384 void setPropertyImplementation(PropertyControl pc) {
1385 PropertyImplementation = pc;
1387 PropertyControl getPropertyImplementation() const {
1388 return PropertyControl(PropertyImplementation);
1391 void setPropertyIvarDecl(ObjCIvarDecl *Ivar) {
1392 PropertyIvarDecl = Ivar;
1394 ObjCIvarDecl *getPropertyIvarDecl() const {
1395 return PropertyIvarDecl;
1398 /// Lookup a property by name in the specified DeclContext.
1399 static ObjCPropertyDecl *findPropertyDecl(const DeclContext *DC,
1400 IdentifierInfo *propertyID);
1402 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1403 static bool classof(const ObjCPropertyDecl *D) { return true; }
1404 static bool classofKind(Kind K) { return K == ObjCProperty; }
1407 /// ObjCPropertyImplDecl - Represents implementation declaration of a property
1408 /// in a class or category implementation block. For example:
1409 /// @synthesize prop1 = ivar1;
1411 class ObjCPropertyImplDecl : public Decl {
1418 SourceLocation AtLoc; // location of @synthesize or @dynamic
1419 /// Property declaration being implemented
1420 ObjCPropertyDecl *PropertyDecl;
1422 /// Null for @dynamic. Required for @synthesize.
1423 ObjCIvarDecl *PropertyIvarDecl;
1425 /// Null for @dynamic. Non-null if property must be copy-constructed in getter
1426 Expr *GetterCXXConstructor;
1428 /// Null for @dynamic. Non-null if property has assignment operator to call
1429 /// in Setter synthesis.
1430 Expr *SetterCXXAssignment;
1432 ObjCPropertyImplDecl(DeclContext *DC, SourceLocation atLoc, SourceLocation L,
1433 ObjCPropertyDecl *property,
1435 ObjCIvarDecl *ivarDecl)
1436 : Decl(ObjCPropertyImpl, DC, L), AtLoc(atLoc),
1437 PropertyDecl(property), PropertyIvarDecl(ivarDecl),
1438 GetterCXXConstructor(0), SetterCXXAssignment(0) {
1439 assert (PK == Dynamic || PropertyIvarDecl);
1443 static ObjCPropertyImplDecl *Create(ASTContext &C, DeclContext *DC,
1444 SourceLocation atLoc, SourceLocation L,
1445 ObjCPropertyDecl *property,
1447 ObjCIvarDecl *ivarDecl);
1449 virtual SourceRange getSourceRange() const {
1450 return SourceRange(AtLoc, getLocation());
1452 SourceLocation getLocStart() const { return AtLoc; }
1453 void setAtLoc(SourceLocation Loc) { AtLoc = Loc; }
1455 ObjCPropertyDecl *getPropertyDecl() const {
1456 return PropertyDecl;
1458 void setPropertyDecl(ObjCPropertyDecl *Prop) { PropertyDecl = Prop; }
1460 Kind getPropertyImplementation() const {
1461 return PropertyIvarDecl ? Synthesize : Dynamic;
1464 ObjCIvarDecl *getPropertyIvarDecl() const {
1465 return PropertyIvarDecl;
1467 void setPropertyIvarDecl(ObjCIvarDecl *Ivar) { PropertyIvarDecl = Ivar; }
1469 Expr *getGetterCXXConstructor() const {
1470 return GetterCXXConstructor;
1472 void setGetterCXXConstructor(Expr *getterCXXConstructor) {
1473 GetterCXXConstructor = getterCXXConstructor;
1476 Expr *getSetterCXXAssignment() const {
1477 return SetterCXXAssignment;
1479 void setSetterCXXAssignment(Expr *setterCXXAssignment) {
1480 SetterCXXAssignment = setterCXXAssignment;
1483 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1484 static bool classof(const ObjCPropertyImplDecl *D) { return true; }
1485 static bool classofKind(Decl::Kind K) { return K == ObjCPropertyImpl; }
1488 } // end namespace clang