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 "clang/AST/SelectorLocationsKind.h"
19 #include "llvm/ADT/STLExtras.h"
20 #include "llvm/Support/Compiler.h"
29 class ObjCProtocolDecl;
30 class ObjCCategoryDecl;
31 class ObjCPropertyDecl;
32 class ObjCPropertyImplDecl;
33 class CXXCtorInitializer;
36 void operator=(const ObjCListBase &); // DO NOT IMPLEMENT
37 ObjCListBase(const ObjCListBase&); // DO NOT IMPLEMENT
39 /// List is an array of pointers to objects that are not owned by this object.
44 ObjCListBase() : List(0), NumElts(0) {}
45 unsigned size() const { return NumElts; }
46 bool empty() const { return NumElts == 0; }
49 void set(void *const* InList, unsigned Elts, ASTContext &Ctx);
53 /// ObjCList - This is a simple template class used to hold various lists of
54 /// decls etc, which is heavily used by the ObjC front-end. This only use case
55 /// this supports is setting the list all at once and then reading elements out
58 class ObjCList : public ObjCListBase {
60 void set(T* const* InList, unsigned Elts, ASTContext &Ctx) {
61 ObjCListBase::set(reinterpret_cast<void*const*>(InList), Elts, Ctx);
64 typedef T* const * iterator;
65 iterator begin() const { return (iterator)List; }
66 iterator end() const { return (iterator)List+NumElts; }
68 T* operator[](unsigned Idx) const {
69 assert(Idx < NumElts && "Invalid access");
74 /// \brief A list of Objective-C protocols, along with the source
75 /// locations at which they were referenced.
76 class ObjCProtocolList : public ObjCList<ObjCProtocolDecl> {
77 SourceLocation *Locations;
79 using ObjCList<ObjCProtocolDecl>::set;
82 ObjCProtocolList() : ObjCList<ObjCProtocolDecl>(), Locations(0) { }
84 typedef const SourceLocation *loc_iterator;
85 loc_iterator loc_begin() const { return Locations; }
86 loc_iterator loc_end() const { return Locations + size(); }
88 void set(ObjCProtocolDecl* const* InList, unsigned Elts,
89 const SourceLocation *Locs, ASTContext &Ctx);
93 /// ObjCMethodDecl - Represents an instance or class method declaration.
94 /// ObjC methods can be declared within 4 contexts: class interfaces,
95 /// categories, protocols, and class implementations. While C++ member
96 /// functions leverage C syntax, Objective-C method syntax is modeled after
97 /// Smalltalk (using colons to specify argument types/expressions).
98 /// Here are some brief examples:
100 /// Setter/getter instance methods:
101 /// - (void)setMenu:(NSMenu *)menu;
102 /// - (NSMenu *)menu;
104 /// Instance method that takes 2 NSView arguments:
105 /// - (void)replaceSubview:(NSView *)oldView with:(NSView *)newView;
107 /// Getter class method:
108 /// + (NSMenu *)defaultMenu;
110 /// A selector represents a unique name for a method. The selector names for
111 /// the above methods are setMenu:, menu, replaceSubview:with:, and defaultMenu.
113 class ObjCMethodDecl : public NamedDecl, public DeclContext {
115 enum ImplementationControl { None, Required, Optional };
117 // The conventional meaning of this method; an ObjCMethodFamily.
118 // This is not serialized; instead, it is computed on demand and
120 mutable unsigned Family : ObjCMethodFamilyBitWidth;
122 /// instance (true) or class (false) method.
123 unsigned IsInstance : 1;
124 unsigned IsVariadic : 1;
126 // Synthesized declaration method for a property setter/getter
127 unsigned IsSynthesized : 1;
129 // Method has a definition.
130 unsigned IsDefined : 1;
132 /// \brief Method redeclaration in the same interface.
133 unsigned IsRedeclaration : 1;
135 /// \brief Is redeclared in the same interface.
136 mutable unsigned HasRedeclaration : 1;
138 // NOTE: VC++ treats enums as signed, avoid using ImplementationControl enum
139 /// \@required/\@optional
140 unsigned DeclImplementation : 2;
142 // NOTE: VC++ treats enums as signed, avoid using the ObjCDeclQualifier enum
144 unsigned objcDeclQualifier : 6;
146 /// \brief Indicates whether this method has a related result type.
147 unsigned RelatedResultType : 1;
149 /// \brief Whether the locations of the selector identifiers are in a
150 /// "standard" position, a enum SelectorLocationsKind.
151 unsigned SelLocsKind : 2;
153 /// \brief Whether this method overrides any other in the class hierarchy.
155 /// A method is said to override any method in the class's
156 /// base classes, its protocols, or its categories' protocols, that has
157 /// the same selector and is of the same kind (class or instance).
158 /// A method in an implementation is not considered as overriding the same
159 /// method in the interface or its categories.
160 unsigned IsOverriding : 1;
162 // Result type of this method.
163 QualType MethodDeclType;
165 // Type source information for the result type.
166 TypeSourceInfo *ResultTInfo;
168 /// \brief Array of ParmVarDecls for the formal parameters of this method
169 /// and optionally followed by selector locations.
170 void *ParamsAndSelLocs;
173 /// List of attributes for this method declaration.
174 SourceLocation DeclEndLoc; // the location of the ';' or '{'.
176 // The following are only used for method definitions, null otherwise.
177 // FIXME: space savings opportunity, consider a sub-class.
180 /// SelfDecl - Decl for the implicit self parameter. This is lazily
181 /// constructed by createImplicitParams.
182 ImplicitParamDecl *SelfDecl;
183 /// CmdDecl - Decl for the implicit _cmd parameter. This is lazily
184 /// constructed by createImplicitParams.
185 ImplicitParamDecl *CmdDecl;
187 SelectorLocationsKind getSelLocsKind() const {
188 return (SelectorLocationsKind)SelLocsKind;
190 bool hasStandardSelLocs() const {
191 return getSelLocsKind() != SelLoc_NonStandard;
194 /// \brief Get a pointer to the stored selector identifiers locations array.
195 /// No locations will be stored if HasStandardSelLocs is true.
196 SourceLocation *getStoredSelLocs() {
197 return reinterpret_cast<SourceLocation*>(getParams() + NumParams);
199 const SourceLocation *getStoredSelLocs() const {
200 return reinterpret_cast<const SourceLocation*>(getParams() + NumParams);
203 /// \brief Get a pointer to the stored selector identifiers locations array.
204 /// No locations will be stored if HasStandardSelLocs is true.
205 ParmVarDecl **getParams() {
206 return reinterpret_cast<ParmVarDecl **>(ParamsAndSelLocs);
208 const ParmVarDecl *const *getParams() const {
209 return reinterpret_cast<const ParmVarDecl *const *>(ParamsAndSelLocs);
212 /// \brief Get the number of stored selector identifiers locations.
213 /// No locations will be stored if HasStandardSelLocs is true.
214 unsigned getNumStoredSelLocs() const {
215 if (hasStandardSelLocs())
217 return getNumSelectorLocs();
220 void setParamsAndSelLocs(ASTContext &C,
221 ArrayRef<ParmVarDecl*> Params,
222 ArrayRef<SourceLocation> SelLocs);
224 ObjCMethodDecl(SourceLocation beginLoc, SourceLocation endLoc,
225 Selector SelInfo, QualType T,
226 TypeSourceInfo *ResultTInfo,
227 DeclContext *contextDecl,
228 bool isInstance = true,
229 bool isVariadic = false,
230 bool isSynthesized = false,
231 bool isImplicitlyDeclared = false,
232 bool isDefined = false,
233 ImplementationControl impControl = None,
234 bool HasRelatedResultType = false)
235 : NamedDecl(ObjCMethod, contextDecl, beginLoc, SelInfo),
236 DeclContext(ObjCMethod), Family(InvalidObjCMethodFamily),
237 IsInstance(isInstance), IsVariadic(isVariadic),
238 IsSynthesized(isSynthesized),
239 IsDefined(isDefined), IsRedeclaration(0), HasRedeclaration(0),
240 DeclImplementation(impControl), objcDeclQualifier(OBJC_TQ_None),
241 RelatedResultType(HasRelatedResultType),
242 SelLocsKind(SelLoc_StandardNoSpace), IsOverriding(0),
243 MethodDeclType(T), ResultTInfo(ResultTInfo),
244 ParamsAndSelLocs(0), NumParams(0),
245 DeclEndLoc(endLoc), Body(0), SelfDecl(0), CmdDecl(0) {
246 setImplicit(isImplicitlyDeclared);
249 /// \brief A definition will return its interface declaration.
250 /// An interface declaration will return its definition.
251 /// Otherwise it will return itself.
252 virtual ObjCMethodDecl *getNextRedeclaration();
255 static ObjCMethodDecl *Create(ASTContext &C,
256 SourceLocation beginLoc,
257 SourceLocation endLoc,
260 TypeSourceInfo *ResultTInfo,
261 DeclContext *contextDecl,
262 bool isInstance = true,
263 bool isVariadic = false,
264 bool isSynthesized = false,
265 bool isImplicitlyDeclared = false,
266 bool isDefined = false,
267 ImplementationControl impControl = None,
268 bool HasRelatedResultType = false);
270 static ObjCMethodDecl *CreateDeserialized(ASTContext &C, unsigned ID);
272 virtual ObjCMethodDecl *getCanonicalDecl();
273 const ObjCMethodDecl *getCanonicalDecl() const {
274 return const_cast<ObjCMethodDecl*>(this)->getCanonicalDecl();
277 ObjCDeclQualifier getObjCDeclQualifier() const {
278 return ObjCDeclQualifier(objcDeclQualifier);
280 void setObjCDeclQualifier(ObjCDeclQualifier QV) { objcDeclQualifier = QV; }
282 /// \brief Determine whether this method has a result type that is related
283 /// to the message receiver's type.
284 bool hasRelatedResultType() const { return RelatedResultType; }
286 /// \brief Note whether this method has a related result type.
287 void SetRelatedResultType(bool RRT = true) { RelatedResultType = RRT; }
289 /// \brief True if this is a method redeclaration in the same interface.
290 bool isRedeclaration() const { return IsRedeclaration; }
291 void setAsRedeclaration(const ObjCMethodDecl *PrevMethod);
293 /// \brief Returns the location where the declarator ends. It will be
294 /// the location of ';' for a method declaration and the location of '{'
295 /// for a method definition.
296 SourceLocation getDeclaratorEndLoc() const { return DeclEndLoc; }
298 // Location information, modeled after the Stmt API.
299 SourceLocation getLocStart() const LLVM_READONLY { return getLocation(); }
300 SourceLocation getLocEnd() const LLVM_READONLY;
301 virtual SourceRange getSourceRange() const LLVM_READONLY {
302 return SourceRange(getLocation(), getLocEnd());
305 SourceLocation getSelectorStartLoc() const {
307 return getLocStart();
308 return getSelectorLoc(0);
310 SourceLocation getSelectorLoc(unsigned Index) const {
311 assert(Index < getNumSelectorLocs() && "Index out of range!");
312 if (hasStandardSelLocs())
313 return getStandardSelectorLoc(Index, getSelector(),
314 getSelLocsKind() == SelLoc_StandardWithSpace,
315 llvm::makeArrayRef(const_cast<ParmVarDecl**>(getParams()),
318 return getStoredSelLocs()[Index];
321 void getSelectorLocs(SmallVectorImpl<SourceLocation> &SelLocs) const;
323 unsigned getNumSelectorLocs() const {
326 Selector Sel = getSelector();
327 if (Sel.isUnarySelector())
329 return Sel.getNumArgs();
332 ObjCInterfaceDecl *getClassInterface();
333 const ObjCInterfaceDecl *getClassInterface() const {
334 return const_cast<ObjCMethodDecl*>(this)->getClassInterface();
337 Selector getSelector() const { return getDeclName().getObjCSelector(); }
339 QualType getResultType() const { return MethodDeclType; }
340 void setResultType(QualType T) { MethodDeclType = T; }
342 /// \brief Determine the type of an expression that sends a message to this
344 QualType getSendResultType() const {
345 return getResultType().getNonLValueExprType(getASTContext());
348 TypeSourceInfo *getResultTypeSourceInfo() const { return ResultTInfo; }
349 void setResultTypeSourceInfo(TypeSourceInfo *TInfo) { ResultTInfo = TInfo; }
351 // Iterator access to formal parameters.
352 unsigned param_size() const { return NumParams; }
353 typedef const ParmVarDecl *const *param_const_iterator;
354 typedef ParmVarDecl *const *param_iterator;
355 param_const_iterator param_begin() const { return getParams(); }
356 param_const_iterator param_end() const { return getParams() + NumParams; }
357 param_iterator param_begin() { return getParams(); }
358 param_iterator param_end() { return getParams() + NumParams; }
359 // This method returns and of the parameters which are part of the selector
360 // name mangling requirements.
361 param_const_iterator sel_param_end() const {
362 return param_begin() + getSelector().getNumArgs();
365 /// \brief Sets the method's parameters and selector source locations.
366 /// If the method is implicit (not coming from source) \arg SelLocs is
368 void setMethodParams(ASTContext &C,
369 ArrayRef<ParmVarDecl*> Params,
370 ArrayRef<SourceLocation> SelLocs =
371 ArrayRef<SourceLocation>());
373 // Iterator access to parameter types.
374 typedef std::const_mem_fun_t<QualType, ParmVarDecl> deref_fun;
375 typedef llvm::mapped_iterator<param_const_iterator, deref_fun>
378 arg_type_iterator arg_type_begin() const {
379 return llvm::map_iterator(param_begin(), deref_fun(&ParmVarDecl::getType));
381 arg_type_iterator arg_type_end() const {
382 return llvm::map_iterator(param_end(), deref_fun(&ParmVarDecl::getType));
385 /// createImplicitParams - Used to lazily create the self and cmd
386 /// implict parameters. This must be called prior to using getSelfDecl()
387 /// or getCmdDecl(). The call is ignored if the implicit paramters
388 /// have already been created.
389 void createImplicitParams(ASTContext &Context, const ObjCInterfaceDecl *ID);
391 ImplicitParamDecl * getSelfDecl() const { return SelfDecl; }
392 void setSelfDecl(ImplicitParamDecl *SD) { SelfDecl = SD; }
393 ImplicitParamDecl * getCmdDecl() const { return CmdDecl; }
394 void setCmdDecl(ImplicitParamDecl *CD) { CmdDecl = CD; }
396 /// Determines the family of this method.
397 ObjCMethodFamily getMethodFamily() const;
399 bool isInstanceMethod() const { return IsInstance; }
400 void setInstanceMethod(bool isInst) { IsInstance = isInst; }
401 bool isVariadic() const { return IsVariadic; }
402 void setVariadic(bool isVar) { IsVariadic = isVar; }
404 bool isClassMethod() const { return !IsInstance; }
406 bool isSynthesized() const { return IsSynthesized; }
407 void setSynthesized(bool isSynth) { IsSynthesized = isSynth; }
409 bool isDefined() const { return IsDefined; }
410 void setDefined(bool isDefined) { IsDefined = isDefined; }
412 /// \brief Whether this method overrides any other in the class hierarchy.
414 /// A method is said to override any method in the class's
415 /// base classes, its protocols, or its categories' protocols, that has
416 /// the same selector and is of the same kind (class or instance).
417 /// A method in an implementation is not considered as overriding the same
418 /// method in the interface or its categories.
419 bool isOverriding() const { return IsOverriding; }
420 void setOverriding(bool isOverriding) { IsOverriding = isOverriding; }
422 // Related to protocols declared in \@protocol
423 void setDeclImplementation(ImplementationControl ic) {
424 DeclImplementation = ic;
426 ImplementationControl getImplementationControl() const {
427 return ImplementationControl(DeclImplementation);
430 virtual Stmt *getBody() const {
433 CompoundStmt *getCompoundBody() { return (CompoundStmt*)Body; }
434 void setBody(Stmt *B) { Body = B; }
436 /// \brief Returns whether this specific method is a definition.
437 bool isThisDeclarationADefinition() const { return Body; }
439 // Implement isa/cast/dyncast/etc.
440 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
441 static bool classof(const ObjCMethodDecl *D) { return true; }
442 static bool classofKind(Kind K) { return K == ObjCMethod; }
443 static DeclContext *castToDeclContext(const ObjCMethodDecl *D) {
444 return static_cast<DeclContext *>(const_cast<ObjCMethodDecl*>(D));
446 static ObjCMethodDecl *castFromDeclContext(const DeclContext *DC) {
447 return static_cast<ObjCMethodDecl *>(const_cast<DeclContext*>(DC));
450 friend class ASTDeclReader;
451 friend class ASTDeclWriter;
454 /// ObjCContainerDecl - Represents a container for method declarations.
455 /// Current sub-classes are ObjCInterfaceDecl, ObjCCategoryDecl,
456 /// ObjCProtocolDecl, and ObjCImplDecl.
458 class ObjCContainerDecl : public NamedDecl, public DeclContext {
459 virtual void anchor();
461 SourceLocation AtStart;
463 // These two locations in the range mark the end of the method container.
464 // The first points to the '@' token, and the second to the 'end' token.
468 ObjCContainerDecl(Kind DK, DeclContext *DC,
469 IdentifierInfo *Id, SourceLocation nameLoc,
470 SourceLocation atStartLoc)
471 : NamedDecl(DK, DC, nameLoc, Id), DeclContext(DK), AtStart(atStartLoc) {}
473 // Iterator access to properties.
474 typedef specific_decl_iterator<ObjCPropertyDecl> prop_iterator;
475 prop_iterator prop_begin() const {
476 return prop_iterator(decls_begin());
478 prop_iterator prop_end() const {
479 return prop_iterator(decls_end());
482 // Iterator access to instance/class methods.
483 typedef specific_decl_iterator<ObjCMethodDecl> method_iterator;
484 method_iterator meth_begin() const {
485 return method_iterator(decls_begin());
487 method_iterator meth_end() const {
488 return method_iterator(decls_end());
491 typedef filtered_decl_iterator<ObjCMethodDecl,
492 &ObjCMethodDecl::isInstanceMethod>
494 instmeth_iterator instmeth_begin() const {
495 return instmeth_iterator(decls_begin());
497 instmeth_iterator instmeth_end() const {
498 return instmeth_iterator(decls_end());
501 typedef filtered_decl_iterator<ObjCMethodDecl,
502 &ObjCMethodDecl::isClassMethod>
504 classmeth_iterator classmeth_begin() const {
505 return classmeth_iterator(decls_begin());
507 classmeth_iterator classmeth_end() const {
508 return classmeth_iterator(decls_end());
511 // Get the local instance/class method declared in this interface.
512 ObjCMethodDecl *getMethod(Selector Sel, bool isInstance) const;
513 ObjCMethodDecl *getInstanceMethod(Selector Sel) const {
514 return getMethod(Sel, true/*isInstance*/);
516 ObjCMethodDecl *getClassMethod(Selector Sel) const {
517 return getMethod(Sel, false/*isInstance*/);
519 ObjCIvarDecl *getIvarDecl(IdentifierInfo *Id) const;
521 ObjCPropertyDecl *FindPropertyDeclaration(IdentifierInfo *PropertyId) const;
523 SourceLocation getAtStartLoc() const { return AtStart; }
524 void setAtStartLoc(SourceLocation Loc) { AtStart = Loc; }
526 // Marks the end of the container.
527 SourceRange getAtEndRange() const {
530 void setAtEndRange(SourceRange atEnd) {
534 virtual SourceRange getSourceRange() const LLVM_READONLY {
535 return SourceRange(AtStart, getAtEndRange().getEnd());
538 // Implement isa/cast/dyncast/etc.
539 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
540 static bool classof(const ObjCContainerDecl *D) { return true; }
541 static bool classofKind(Kind K) {
542 return K >= firstObjCContainer &&
543 K <= lastObjCContainer;
546 static DeclContext *castToDeclContext(const ObjCContainerDecl *D) {
547 return static_cast<DeclContext *>(const_cast<ObjCContainerDecl*>(D));
549 static ObjCContainerDecl *castFromDeclContext(const DeclContext *DC) {
550 return static_cast<ObjCContainerDecl *>(const_cast<DeclContext*>(DC));
554 /// \brief Represents an ObjC class declaration.
559 /// // MostPrimitive declares no super class (not particularly useful).
560 /// \@interface MostPrimitive
561 /// // no instance variables or methods.
564 /// // NSResponder inherits from NSObject & implements NSCoding (a protocol).
565 /// \@interface NSResponder : NSObject \<NSCoding>
566 /// { // instance variables are represented by ObjCIvarDecl.
567 /// id nextResponder; // nextResponder instance variable.
569 /// - (NSResponder *)nextResponder; // return a pointer to NSResponder.
570 /// - (void)mouseMoved:(NSEvent *)theEvent; // return void, takes a pointer
571 /// \@end // to an NSEvent.
574 /// Unlike C/C++, forward class declarations are accomplished with \@class.
575 /// Unlike C/C++, \@class allows for a list of classes to be forward declared.
576 /// Unlike C++, ObjC is a single-rooted class model. In Cocoa, classes
577 /// typically inherit from NSObject (an exception is NSProxy).
579 class ObjCInterfaceDecl : public ObjCContainerDecl
580 , public Redeclarable<ObjCInterfaceDecl> {
581 virtual void anchor();
583 /// TypeForDecl - This indicates the Type object that represents this
584 /// TypeDecl. It is a cache maintained by ASTContext::getObjCInterfaceType
585 mutable const Type *TypeForDecl;
586 friend class ASTContext;
588 struct DefinitionData {
589 /// \brief The definition of this class, for quick access from any
591 ObjCInterfaceDecl *Definition;
593 /// Class's super class.
594 ObjCInterfaceDecl *SuperClass;
596 /// Protocols referenced in the \@interface declaration
597 ObjCProtocolList ReferencedProtocols;
599 /// Protocols reference in both the \@interface and class extensions.
600 ObjCList<ObjCProtocolDecl> AllReferencedProtocols;
602 /// \brief List of categories and class extensions defined for this class.
604 /// Categories are stored as a linked list in the AST, since the categories
605 /// and class extensions come long after the initial interface declaration,
606 /// and we avoid dynamically-resized arrays in the AST wherever possible.
607 ObjCCategoryDecl *CategoryList;
609 /// IvarList - List of all ivars defined by this class; including class
610 /// extensions and implementation. This list is built lazily.
611 ObjCIvarDecl *IvarList;
613 /// \brief Indicates that the contents of this Objective-C class will be
614 /// completed by the external AST source when required.
615 mutable bool ExternallyCompleted : 1;
617 /// \brief The location of the superclass, if any.
618 SourceLocation SuperClassLoc;
620 /// \brief The location of the last location in this declaration, before
621 /// the properties/methods. For example, this will be the '>', '}', or
623 SourceLocation EndLoc;
625 DefinitionData() : Definition(), SuperClass(), CategoryList(), IvarList(),
626 ExternallyCompleted() { }
629 ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id,
630 SourceLocation CLoc, ObjCInterfaceDecl *PrevDecl,
633 void LoadExternalDefinition() const;
635 /// \brief Contains a pointer to the data associated with this class,
636 /// which will be NULL if this class has not yet been defined.
637 DefinitionData *Data;
639 DefinitionData &data() const {
640 assert(Data != 0 && "Declaration has no definition!");
644 /// \brief Allocate the definition data for this class.
645 void allocateDefinitionData();
647 typedef Redeclarable<ObjCInterfaceDecl> redeclarable_base;
648 virtual ObjCInterfaceDecl *getNextRedeclaration() {
649 return RedeclLink.getNext();
651 virtual ObjCInterfaceDecl *getPreviousDeclImpl() {
652 return getPreviousDecl();
654 virtual ObjCInterfaceDecl *getMostRecentDeclImpl() {
655 return getMostRecentDecl();
659 static ObjCInterfaceDecl *Create(const ASTContext &C, DeclContext *DC,
660 SourceLocation atLoc,
662 ObjCInterfaceDecl *PrevDecl,
663 SourceLocation ClassLoc = SourceLocation(),
664 bool isInternal = false);
666 static ObjCInterfaceDecl *CreateDeserialized(ASTContext &C, unsigned ID);
668 virtual SourceRange getSourceRange() const LLVM_READONLY {
669 if (isThisDeclarationADefinition())
670 return ObjCContainerDecl::getSourceRange();
672 return SourceRange(getAtStartLoc(), getLocation());
675 /// \brief Indicate that this Objective-C class is complete, but that
676 /// the external AST source will be responsible for filling in its contents
677 /// when a complete class is required.
678 void setExternallyCompleted();
680 const ObjCProtocolList &getReferencedProtocols() const {
681 assert(hasDefinition() && "Caller did not check for forward reference!");
682 if (data().ExternallyCompleted)
683 LoadExternalDefinition();
685 return data().ReferencedProtocols;
688 ObjCImplementationDecl *getImplementation() const;
689 void setImplementation(ObjCImplementationDecl *ImplD);
691 ObjCCategoryDecl *FindCategoryDeclaration(IdentifierInfo *CategoryId) const;
693 // Get the local instance/class method declared in a category.
694 ObjCMethodDecl *getCategoryInstanceMethod(Selector Sel) const;
695 ObjCMethodDecl *getCategoryClassMethod(Selector Sel) const;
696 ObjCMethodDecl *getCategoryMethod(Selector Sel, bool isInstance) const {
697 return isInstance ? getInstanceMethod(Sel)
698 : getClassMethod(Sel);
701 typedef ObjCProtocolList::iterator protocol_iterator;
703 protocol_iterator protocol_begin() const {
704 // FIXME: Should make sure no callers ever do this.
705 if (!hasDefinition())
706 return protocol_iterator();
708 if (data().ExternallyCompleted)
709 LoadExternalDefinition();
711 return data().ReferencedProtocols.begin();
713 protocol_iterator protocol_end() const {
714 // FIXME: Should make sure no callers ever do this.
715 if (!hasDefinition())
716 return protocol_iterator();
718 if (data().ExternallyCompleted)
719 LoadExternalDefinition();
721 return data().ReferencedProtocols.end();
724 typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
726 protocol_loc_iterator protocol_loc_begin() const {
727 // FIXME: Should make sure no callers ever do this.
728 if (!hasDefinition())
729 return protocol_loc_iterator();
731 if (data().ExternallyCompleted)
732 LoadExternalDefinition();
734 return data().ReferencedProtocols.loc_begin();
737 protocol_loc_iterator protocol_loc_end() const {
738 // FIXME: Should make sure no callers ever do this.
739 if (!hasDefinition())
740 return protocol_loc_iterator();
742 if (data().ExternallyCompleted)
743 LoadExternalDefinition();
745 return data().ReferencedProtocols.loc_end();
748 typedef ObjCList<ObjCProtocolDecl>::iterator all_protocol_iterator;
750 all_protocol_iterator all_referenced_protocol_begin() const {
751 // FIXME: Should make sure no callers ever do this.
752 if (!hasDefinition())
753 return all_protocol_iterator();
755 if (data().ExternallyCompleted)
756 LoadExternalDefinition();
758 return data().AllReferencedProtocols.empty()
760 : data().AllReferencedProtocols.begin();
762 all_protocol_iterator all_referenced_protocol_end() const {
763 // FIXME: Should make sure no callers ever do this.
764 if (!hasDefinition())
765 return all_protocol_iterator();
767 if (data().ExternallyCompleted)
768 LoadExternalDefinition();
770 return data().AllReferencedProtocols.empty()
772 : data().AllReferencedProtocols.end();
775 typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
777 ivar_iterator ivar_begin() const {
778 if (const ObjCInterfaceDecl *Def = getDefinition())
779 return ivar_iterator(Def->decls_begin());
781 // FIXME: Should make sure no callers ever do this.
782 return ivar_iterator();
784 ivar_iterator ivar_end() const {
785 if (const ObjCInterfaceDecl *Def = getDefinition())
786 return ivar_iterator(Def->decls_end());
788 // FIXME: Should make sure no callers ever do this.
789 return ivar_iterator();
792 unsigned ivar_size() const {
793 return std::distance(ivar_begin(), ivar_end());
796 bool ivar_empty() const { return ivar_begin() == ivar_end(); }
798 ObjCIvarDecl *all_declared_ivar_begin();
799 const ObjCIvarDecl *all_declared_ivar_begin() const {
800 // Even though this modifies IvarList, it's conceptually const:
801 // the ivar chain is essentially a cached property of ObjCInterfaceDecl.
802 return const_cast<ObjCInterfaceDecl *>(this)->all_declared_ivar_begin();
804 void setIvarList(ObjCIvarDecl *ivar) { data().IvarList = ivar; }
806 /// setProtocolList - Set the list of protocols that this interface
808 void setProtocolList(ObjCProtocolDecl *const* List, unsigned Num,
809 const SourceLocation *Locs, ASTContext &C) {
810 data().ReferencedProtocols.set(List, Num, Locs, C);
813 /// mergeClassExtensionProtocolList - Merge class extension's protocol list
814 /// into the protocol list for this class.
815 void mergeClassExtensionProtocolList(ObjCProtocolDecl *const* List,
819 /// \brief Determine whether this particular declaration of this class is
820 /// actually also a definition.
821 bool isThisDeclarationADefinition() const {
822 return Data && Data->Definition == this;
825 /// \brief Determine whether this class has been defined.
826 bool hasDefinition() const { return Data; }
828 /// \brief Retrieve the definition of this class, or NULL if this class
829 /// has been forward-declared (with \@class) but not yet defined (with
831 ObjCInterfaceDecl *getDefinition() {
832 return hasDefinition()? Data->Definition : 0;
835 /// \brief Retrieve the definition of this class, or NULL if this class
836 /// has been forward-declared (with \@class) but not yet defined (with
838 const ObjCInterfaceDecl *getDefinition() const {
839 return hasDefinition()? Data->Definition : 0;
842 /// \brief Starts the definition of this Objective-C class, taking it from
843 /// a forward declaration (\@class) to a definition (\@interface).
844 void startDefinition();
846 ObjCInterfaceDecl *getSuperClass() const {
847 // FIXME: Should make sure no callers ever do this.
848 if (!hasDefinition())
851 if (data().ExternallyCompleted)
852 LoadExternalDefinition();
854 return data().SuperClass;
857 void setSuperClass(ObjCInterfaceDecl * superCls) {
859 (superCls && superCls->hasDefinition()) ? superCls->getDefinition()
863 ObjCCategoryDecl* getCategoryList() const {
864 // FIXME: Should make sure no callers ever do this.
865 if (!hasDefinition())
868 if (data().ExternallyCompleted)
869 LoadExternalDefinition();
871 return data().CategoryList;
874 void setCategoryList(ObjCCategoryDecl *category) {
875 data().CategoryList = category;
878 ObjCCategoryDecl* getFirstClassExtension() const;
881 *FindPropertyVisibleInPrimaryClass(IdentifierInfo *PropertyId) const;
883 /// isSuperClassOf - Return true if this class is the specified class or is a
884 /// super class of the specified interface class.
885 bool isSuperClassOf(const ObjCInterfaceDecl *I) const {
886 // If RHS is derived from LHS it is OK; else it is not OK.
888 if (declaresSameEntity(this, I))
891 I = I->getSuperClass();
896 /// isArcWeakrefUnavailable - Checks for a class or one of its super classes
897 /// to be incompatible with __weak references. Returns true if it is.
898 bool isArcWeakrefUnavailable() const {
899 const ObjCInterfaceDecl *Class = this;
901 if (Class->hasAttr<ArcWeakrefUnavailableAttr>())
903 Class = Class->getSuperClass();
908 /// isObjCRequiresPropertyDefs - Checks that a class or one of its super
909 /// classes must not be auto-synthesized. Returns class decl. if it must not
910 /// be; 0, otherwise.
911 const ObjCInterfaceDecl *isObjCRequiresPropertyDefs() const {
912 const ObjCInterfaceDecl *Class = this;
914 if (Class->hasAttr<ObjCRequiresPropertyDefsAttr>())
916 Class = Class->getSuperClass();
921 ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName,
922 ObjCInterfaceDecl *&ClassDeclared);
923 ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName) {
924 ObjCInterfaceDecl *ClassDeclared;
925 return lookupInstanceVariable(IVarName, ClassDeclared);
928 // Lookup a method. First, we search locally. If a method isn't
929 // found, we search referenced protocols and class categories.
930 ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance,
931 bool shallowCategoryLookup= false) const;
932 ObjCMethodDecl *lookupInstanceMethod(Selector Sel,
933 bool shallowCategoryLookup = false) const {
934 return lookupMethod(Sel, true/*isInstance*/, shallowCategoryLookup);
936 ObjCMethodDecl *lookupClassMethod(Selector Sel,
937 bool shallowCategoryLookup = false) const {
938 return lookupMethod(Sel, false/*isInstance*/, shallowCategoryLookup);
940 ObjCInterfaceDecl *lookupInheritedClass(const IdentifierInfo *ICName);
942 /// \brief Lookup a method in the classes implementation hierarchy.
943 ObjCMethodDecl *lookupPrivateMethod(const Selector &Sel,
944 bool Instance=true) const;
946 ObjCMethodDecl *lookupPrivateClassMethod(const Selector &Sel) {
947 return lookupPrivateMethod(Sel, false);
950 SourceLocation getEndOfDefinitionLoc() const {
951 if (!hasDefinition())
952 return getLocation();
954 return data().EndLoc;
957 void setEndOfDefinitionLoc(SourceLocation LE) { data().EndLoc = LE; }
959 void setSuperClassLoc(SourceLocation Loc) { data().SuperClassLoc = Loc; }
960 SourceLocation getSuperClassLoc() const { return data().SuperClassLoc; }
962 /// isImplicitInterfaceDecl - check that this is an implicitly declared
963 /// ObjCInterfaceDecl node. This is for legacy objective-c \@implementation
964 /// declaration without an \@interface declaration.
965 bool isImplicitInterfaceDecl() const {
966 return hasDefinition() ? Data->Definition->isImplicit() : isImplicit();
969 /// ClassImplementsProtocol - Checks that 'lProto' protocol
970 /// has been implemented in IDecl class, its super class or categories (if
971 /// lookupCategory is true).
972 bool ClassImplementsProtocol(ObjCProtocolDecl *lProto,
974 bool RHSIsQualifiedID = false);
976 typedef redeclarable_base::redecl_iterator redecl_iterator;
977 using redeclarable_base::redecls_begin;
978 using redeclarable_base::redecls_end;
979 using redeclarable_base::getPreviousDecl;
980 using redeclarable_base::getMostRecentDecl;
982 /// Retrieves the canonical declaration of this Objective-C class.
983 ObjCInterfaceDecl *getCanonicalDecl() {
984 return getFirstDeclaration();
986 const ObjCInterfaceDecl *getCanonicalDecl() const {
987 return getFirstDeclaration();
990 // Low-level accessor
991 const Type *getTypeForDecl() const { return TypeForDecl; }
992 void setTypeForDecl(const Type *TD) const { TypeForDecl = TD; }
994 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
995 static bool classof(const ObjCInterfaceDecl *D) { return true; }
996 static bool classofKind(Kind K) { return K == ObjCInterface; }
998 friend class ASTReader;
999 friend class ASTDeclReader;
1000 friend class ASTDeclWriter;
1003 /// ObjCIvarDecl - Represents an ObjC instance variable. In general, ObjC
1004 /// instance variables are identical to C. The only exception is Objective-C
1005 /// supports C++ style access control. For example:
1007 /// \@interface IvarExample : NSObject
1009 /// id defaultToProtected;
1011 /// id canBePublic; // same as C++.
1013 /// id canBeProtected; // same as C++.
1015 /// id canBePackage; // framework visibility (not available in C++).
1018 class ObjCIvarDecl : public FieldDecl {
1019 virtual void anchor();
1022 enum AccessControl {
1023 None, Private, Protected, Public, Package
1027 ObjCIvarDecl(ObjCContainerDecl *DC, SourceLocation StartLoc,
1028 SourceLocation IdLoc, IdentifierInfo *Id,
1029 QualType T, TypeSourceInfo *TInfo, AccessControl ac, Expr *BW,
1031 : FieldDecl(ObjCIvar, DC, StartLoc, IdLoc, Id, T, TInfo, BW,
1032 /*Mutable=*/false, /*HasInit=*/ICIS_NoInit),
1033 NextIvar(0), DeclAccess(ac), Synthesized(synthesized) {}
1036 static ObjCIvarDecl *Create(ASTContext &C, ObjCContainerDecl *DC,
1037 SourceLocation StartLoc, SourceLocation IdLoc,
1038 IdentifierInfo *Id, QualType T,
1039 TypeSourceInfo *TInfo,
1040 AccessControl ac, Expr *BW = NULL,
1041 bool synthesized=false);
1043 static ObjCIvarDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1045 /// \brief Return the class interface that this ivar is logically contained
1046 /// in; this is either the interface where the ivar was declared, or the
1047 /// interface the ivar is conceptually a part of in the case of synthesized
1049 const ObjCInterfaceDecl *getContainingInterface() const;
1051 ObjCIvarDecl *getNextIvar() { return NextIvar; }
1052 const ObjCIvarDecl *getNextIvar() const { return NextIvar; }
1053 void setNextIvar(ObjCIvarDecl *ivar) { NextIvar = ivar; }
1055 void setAccessControl(AccessControl ac) { DeclAccess = ac; }
1057 AccessControl getAccessControl() const { return AccessControl(DeclAccess); }
1059 AccessControl getCanonicalAccessControl() const {
1060 return DeclAccess == None ? Protected : AccessControl(DeclAccess);
1063 void setSynthesize(bool synth) { Synthesized = synth; }
1064 bool getSynthesize() const { return Synthesized; }
1066 // Implement isa/cast/dyncast/etc.
1067 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1068 static bool classof(const ObjCIvarDecl *D) { return true; }
1069 static bool classofKind(Kind K) { return K == ObjCIvar; }
1071 /// NextIvar - Next Ivar in the list of ivars declared in class; class's
1072 /// extensions and class's implementation
1073 ObjCIvarDecl *NextIvar;
1075 // NOTE: VC++ treats enums as signed, avoid using the AccessControl enum
1076 unsigned DeclAccess : 3;
1077 unsigned Synthesized : 1;
1081 /// \brief Represents a field declaration created by an \@defs(...).
1082 class ObjCAtDefsFieldDecl : public FieldDecl {
1083 virtual void anchor();
1084 ObjCAtDefsFieldDecl(DeclContext *DC, SourceLocation StartLoc,
1085 SourceLocation IdLoc, IdentifierInfo *Id,
1086 QualType T, Expr *BW)
1087 : FieldDecl(ObjCAtDefsField, DC, StartLoc, IdLoc, Id, T,
1088 /*TInfo=*/0, // FIXME: Do ObjCAtDefs have declarators ?
1089 BW, /*Mutable=*/false, /*HasInit=*/ICIS_NoInit) {}
1092 static ObjCAtDefsFieldDecl *Create(ASTContext &C, DeclContext *DC,
1093 SourceLocation StartLoc,
1094 SourceLocation IdLoc, IdentifierInfo *Id,
1095 QualType T, Expr *BW);
1097 static ObjCAtDefsFieldDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1099 // Implement isa/cast/dyncast/etc.
1100 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1101 static bool classof(const ObjCAtDefsFieldDecl *D) { return true; }
1102 static bool classofKind(Kind K) { return K == ObjCAtDefsField; }
1105 /// \brief Represents an Objective-C protocol declaration.
1107 /// Objective-C protocols declare a pure abstract type (i.e., no instance
1108 /// variables are permitted). Protocols originally drew inspiration from
1109 /// C++ pure virtual functions (a C++ feature with nice semantics and lousy
1110 /// syntax:-). Here is an example:
1113 /// \@protocol NSDraggingInfo <refproto1, refproto2>
1114 /// - (NSWindow *)draggingDestinationWindow;
1115 /// - (NSImage *)draggedImage;
1119 /// This says that NSDraggingInfo requires two methods and requires everything
1120 /// that the two "referenced protocols" 'refproto1' and 'refproto2' require as
1124 /// \@interface ImplementsNSDraggingInfo : NSObject \<NSDraggingInfo>
1128 /// ObjC protocols inspired Java interfaces. Unlike Java, ObjC classes and
1129 /// protocols are in distinct namespaces. For example, Cocoa defines both
1130 /// an NSObject protocol and class (which isn't allowed in Java). As a result,
1131 /// protocols are referenced using angle brackets as follows:
1133 /// id \<NSDraggingInfo> anyObjectThatImplementsNSDraggingInfo;
1135 class ObjCProtocolDecl : public ObjCContainerDecl,
1136 public Redeclarable<ObjCProtocolDecl> {
1137 virtual void anchor();
1139 struct DefinitionData {
1140 // \brief The declaration that defines this protocol.
1141 ObjCProtocolDecl *Definition;
1143 /// \brief Referenced protocols
1144 ObjCProtocolList ReferencedProtocols;
1147 DefinitionData *Data;
1149 DefinitionData &data() const {
1150 assert(Data && "Objective-C protocol has no definition!");
1154 ObjCProtocolDecl(DeclContext *DC, IdentifierInfo *Id,
1155 SourceLocation nameLoc, SourceLocation atStartLoc,
1156 ObjCProtocolDecl *PrevDecl);
1158 void allocateDefinitionData();
1160 typedef Redeclarable<ObjCProtocolDecl> redeclarable_base;
1161 virtual ObjCProtocolDecl *getNextRedeclaration() {
1162 return RedeclLink.getNext();
1164 virtual ObjCProtocolDecl *getPreviousDeclImpl() {
1165 return getPreviousDecl();
1167 virtual ObjCProtocolDecl *getMostRecentDeclImpl() {
1168 return getMostRecentDecl();
1172 static ObjCProtocolDecl *Create(ASTContext &C, DeclContext *DC,
1174 SourceLocation nameLoc,
1175 SourceLocation atStartLoc,
1176 ObjCProtocolDecl *PrevDecl);
1178 static ObjCProtocolDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1180 const ObjCProtocolList &getReferencedProtocols() const {
1181 assert(hasDefinition() && "No definition available!");
1182 return data().ReferencedProtocols;
1184 typedef ObjCProtocolList::iterator protocol_iterator;
1185 protocol_iterator protocol_begin() const {
1186 if (!hasDefinition())
1187 return protocol_iterator();
1189 return data().ReferencedProtocols.begin();
1191 protocol_iterator protocol_end() const {
1192 if (!hasDefinition())
1193 return protocol_iterator();
1195 return data().ReferencedProtocols.end();
1197 typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
1198 protocol_loc_iterator protocol_loc_begin() const {
1199 if (!hasDefinition())
1200 return protocol_loc_iterator();
1202 return data().ReferencedProtocols.loc_begin();
1204 protocol_loc_iterator protocol_loc_end() const {
1205 if (!hasDefinition())
1206 return protocol_loc_iterator();
1208 return data().ReferencedProtocols.loc_end();
1210 unsigned protocol_size() const {
1211 if (!hasDefinition())
1214 return data().ReferencedProtocols.size();
1217 /// setProtocolList - Set the list of protocols that this interface
1219 void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num,
1220 const SourceLocation *Locs, ASTContext &C) {
1221 assert(Data && "Protocol is not defined");
1222 data().ReferencedProtocols.set(List, Num, Locs, C);
1225 ObjCProtocolDecl *lookupProtocolNamed(IdentifierInfo *PName);
1227 // Lookup a method. First, we search locally. If a method isn't
1228 // found, we search referenced protocols and class categories.
1229 ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance) const;
1230 ObjCMethodDecl *lookupInstanceMethod(Selector Sel) const {
1231 return lookupMethod(Sel, true/*isInstance*/);
1233 ObjCMethodDecl *lookupClassMethod(Selector Sel) const {
1234 return lookupMethod(Sel, false/*isInstance*/);
1237 /// \brief Determine whether this protocol has a definition.
1238 bool hasDefinition() const { return Data != 0; }
1240 /// \brief Retrieve the definition of this protocol, if any.
1241 ObjCProtocolDecl *getDefinition() {
1242 return Data? Data->Definition : 0;
1245 /// \brief Retrieve the definition of this protocol, if any.
1246 const ObjCProtocolDecl *getDefinition() const {
1247 return Data? Data->Definition : 0;
1250 /// \brief Determine whether this particular declaration is also the
1252 bool isThisDeclarationADefinition() const {
1253 return getDefinition() == this;
1256 /// \brief Starts the definition of this Objective-C protocol.
1257 void startDefinition();
1259 virtual SourceRange getSourceRange() const LLVM_READONLY {
1260 if (isThisDeclarationADefinition())
1261 return ObjCContainerDecl::getSourceRange();
1263 return SourceRange(getAtStartLoc(), getLocation());
1266 typedef redeclarable_base::redecl_iterator redecl_iterator;
1267 using redeclarable_base::redecls_begin;
1268 using redeclarable_base::redecls_end;
1269 using redeclarable_base::getPreviousDecl;
1270 using redeclarable_base::getMostRecentDecl;
1272 /// Retrieves the canonical declaration of this Objective-C protocol.
1273 ObjCProtocolDecl *getCanonicalDecl() {
1274 return getFirstDeclaration();
1276 const ObjCProtocolDecl *getCanonicalDecl() const {
1277 return getFirstDeclaration();
1280 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1281 static bool classof(const ObjCProtocolDecl *D) { return true; }
1282 static bool classofKind(Kind K) { return K == ObjCProtocol; }
1284 friend class ASTReader;
1285 friend class ASTDeclReader;
1286 friend class ASTDeclWriter;
1289 /// ObjCCategoryDecl - Represents a category declaration. A category allows
1290 /// you to add methods to an existing class (without subclassing or modifying
1291 /// the original class interface or implementation:-). Categories don't allow
1292 /// you to add instance data. The following example adds "myMethod" to all
1293 /// NSView's within a process:
1295 /// \@interface NSView (MyViewMethods)
1299 /// Categories also allow you to split the implementation of a class across
1300 /// several files (a feature more naturally supported in C++).
1302 /// Categories were originally inspired by dynamic languages such as Common
1303 /// Lisp and Smalltalk. More traditional class-based languages (C++, Java)
1304 /// don't support this level of dynamism, which is both powerful and dangerous.
1306 class ObjCCategoryDecl : public ObjCContainerDecl {
1307 virtual void anchor();
1309 /// Interface belonging to this category
1310 ObjCInterfaceDecl *ClassInterface;
1312 /// referenced protocols in this category.
1313 ObjCProtocolList ReferencedProtocols;
1315 /// Next category belonging to this class.
1316 /// FIXME: this should not be a singly-linked list. Move storage elsewhere.
1317 ObjCCategoryDecl *NextClassCategory;
1319 /// \brief The location of the category name in this declaration.
1320 SourceLocation CategoryNameLoc;
1322 /// class extension may have private ivars.
1323 SourceLocation IvarLBraceLoc;
1324 SourceLocation IvarRBraceLoc;
1326 ObjCCategoryDecl(DeclContext *DC, SourceLocation AtLoc,
1327 SourceLocation ClassNameLoc, SourceLocation CategoryNameLoc,
1328 IdentifierInfo *Id, ObjCInterfaceDecl *IDecl,
1329 SourceLocation IvarLBraceLoc=SourceLocation(),
1330 SourceLocation IvarRBraceLoc=SourceLocation())
1331 : ObjCContainerDecl(ObjCCategory, DC, Id, ClassNameLoc, AtLoc),
1332 ClassInterface(IDecl), NextClassCategory(0),
1333 CategoryNameLoc(CategoryNameLoc),
1334 IvarLBraceLoc(IvarLBraceLoc), IvarRBraceLoc(IvarRBraceLoc) {
1338 static ObjCCategoryDecl *Create(ASTContext &C, DeclContext *DC,
1339 SourceLocation AtLoc,
1340 SourceLocation ClassNameLoc,
1341 SourceLocation CategoryNameLoc,
1343 ObjCInterfaceDecl *IDecl,
1344 SourceLocation IvarLBraceLoc=SourceLocation(),
1345 SourceLocation IvarRBraceLoc=SourceLocation());
1346 static ObjCCategoryDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1348 ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
1349 const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; }
1351 ObjCCategoryImplDecl *getImplementation() const;
1352 void setImplementation(ObjCCategoryImplDecl *ImplD);
1354 /// setProtocolList - Set the list of protocols that this interface
1356 void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num,
1357 const SourceLocation *Locs, ASTContext &C) {
1358 ReferencedProtocols.set(List, Num, Locs, C);
1361 const ObjCProtocolList &getReferencedProtocols() const {
1362 return ReferencedProtocols;
1365 typedef ObjCProtocolList::iterator protocol_iterator;
1366 protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();}
1367 protocol_iterator protocol_end() const { return ReferencedProtocols.end(); }
1368 unsigned protocol_size() const { return ReferencedProtocols.size(); }
1369 typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
1370 protocol_loc_iterator protocol_loc_begin() const {
1371 return ReferencedProtocols.loc_begin();
1373 protocol_loc_iterator protocol_loc_end() const {
1374 return ReferencedProtocols.loc_end();
1377 ObjCCategoryDecl *getNextClassCategory() const { return NextClassCategory; }
1379 bool IsClassExtension() const { return getIdentifier() == 0; }
1380 const ObjCCategoryDecl *getNextClassExtension() const;
1382 typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
1383 ivar_iterator ivar_begin() const {
1384 return ivar_iterator(decls_begin());
1386 ivar_iterator ivar_end() const {
1387 return ivar_iterator(decls_end());
1389 unsigned ivar_size() const {
1390 return std::distance(ivar_begin(), ivar_end());
1392 bool ivar_empty() const {
1393 return ivar_begin() == ivar_end();
1396 SourceLocation getCategoryNameLoc() const { return CategoryNameLoc; }
1397 void setCategoryNameLoc(SourceLocation Loc) { CategoryNameLoc = Loc; }
1399 void setIvarLBraceLoc(SourceLocation Loc) { IvarLBraceLoc = Loc; }
1400 SourceLocation getIvarLBraceLoc() const { return IvarLBraceLoc; }
1401 void setIvarRBraceLoc(SourceLocation Loc) { IvarRBraceLoc = Loc; }
1402 SourceLocation getIvarRBraceLoc() const { return IvarRBraceLoc; }
1404 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1405 static bool classof(const ObjCCategoryDecl *D) { return true; }
1406 static bool classofKind(Kind K) { return K == ObjCCategory; }
1408 friend class ASTDeclReader;
1409 friend class ASTDeclWriter;
1412 class ObjCImplDecl : public ObjCContainerDecl {
1413 virtual void anchor();
1415 /// Class interface for this class/category implementation
1416 ObjCInterfaceDecl *ClassInterface;
1419 ObjCImplDecl(Kind DK, DeclContext *DC,
1420 ObjCInterfaceDecl *classInterface,
1421 SourceLocation nameLoc, SourceLocation atStartLoc)
1422 : ObjCContainerDecl(DK, DC,
1423 classInterface? classInterface->getIdentifier() : 0,
1424 nameLoc, atStartLoc),
1425 ClassInterface(classInterface) {}
1428 const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; }
1429 ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
1430 void setClassInterface(ObjCInterfaceDecl *IFace);
1432 void addInstanceMethod(ObjCMethodDecl *method) {
1433 // FIXME: Context should be set correctly before we get here.
1434 method->setLexicalDeclContext(this);
1437 void addClassMethod(ObjCMethodDecl *method) {
1438 // FIXME: Context should be set correctly before we get here.
1439 method->setLexicalDeclContext(this);
1443 void addPropertyImplementation(ObjCPropertyImplDecl *property);
1445 ObjCPropertyImplDecl *FindPropertyImplDecl(IdentifierInfo *propertyId) const;
1446 ObjCPropertyImplDecl *FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const;
1448 // Iterator access to properties.
1449 typedef specific_decl_iterator<ObjCPropertyImplDecl> propimpl_iterator;
1450 propimpl_iterator propimpl_begin() const {
1451 return propimpl_iterator(decls_begin());
1453 propimpl_iterator propimpl_end() const {
1454 return propimpl_iterator(decls_end());
1457 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1458 static bool classof(const ObjCImplDecl *D) { return true; }
1459 static bool classofKind(Kind K) {
1460 return K >= firstObjCImpl && K <= lastObjCImpl;
1464 /// ObjCCategoryImplDecl - An object of this class encapsulates a category
1465 /// \@implementation declaration. If a category class has declaration of a
1466 /// property, its implementation must be specified in the category's
1467 /// \@implementation declaration. Example:
1468 /// \@interface I \@end
1469 /// \@interface I(CATEGORY)
1470 /// \@property int p1, d1;
1472 /// \@implementation I(CATEGORY)
1473 /// \@dynamic p1,d1;
1476 /// ObjCCategoryImplDecl
1477 class ObjCCategoryImplDecl : public ObjCImplDecl {
1478 virtual void anchor();
1483 // Category name location
1484 SourceLocation CategoryNameLoc;
1486 ObjCCategoryImplDecl(DeclContext *DC, IdentifierInfo *Id,
1487 ObjCInterfaceDecl *classInterface,
1488 SourceLocation nameLoc, SourceLocation atStartLoc,
1489 SourceLocation CategoryNameLoc)
1490 : ObjCImplDecl(ObjCCategoryImpl, DC, classInterface, nameLoc, atStartLoc),
1491 Id(Id), CategoryNameLoc(CategoryNameLoc) {}
1493 static ObjCCategoryImplDecl *Create(ASTContext &C, DeclContext *DC,
1495 ObjCInterfaceDecl *classInterface,
1496 SourceLocation nameLoc,
1497 SourceLocation atStartLoc,
1498 SourceLocation CategoryNameLoc);
1499 static ObjCCategoryImplDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1501 /// getIdentifier - Get the identifier that names the category
1502 /// interface associated with this implementation.
1503 /// FIXME: This is a bad API, we are overriding the NamedDecl::getIdentifier()
1504 /// to mean something different. For example:
1505 /// ((NamedDecl *)SomeCategoryImplDecl)->getIdentifier()
1506 /// returns the class interface name, whereas
1507 /// ((ObjCCategoryImplDecl *)SomeCategoryImplDecl)->getIdentifier()
1508 /// returns the category name.
1509 IdentifierInfo *getIdentifier() const {
1512 void setIdentifier(IdentifierInfo *II) { Id = II; }
1514 ObjCCategoryDecl *getCategoryDecl() const;
1516 SourceLocation getCategoryNameLoc() const { return CategoryNameLoc; }
1518 /// getName - Get the name of identifier for the class interface associated
1519 /// with this implementation as a StringRef.
1521 // FIXME: This is a bad API, we are overriding the NamedDecl::getName, to mean
1522 // something different.
1523 StringRef getName() const {
1524 return Id ? Id->getNameStart() : "";
1527 /// @brief Get the name of the class associated with this interface.
1529 // FIXME: Deprecated, move clients to getName().
1530 std::string getNameAsString() const {
1534 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1535 static bool classof(const ObjCCategoryImplDecl *D) { return true; }
1536 static bool classofKind(Kind K) { return K == ObjCCategoryImpl;}
1538 friend class ASTDeclReader;
1539 friend class ASTDeclWriter;
1542 raw_ostream &operator<<(raw_ostream &OS, const ObjCCategoryImplDecl &CID);
1544 /// ObjCImplementationDecl - Represents a class definition - this is where
1545 /// method definitions are specified. For example:
1548 /// \@implementation MyClass
1549 /// - (void)myMethod { /* do something */ }
1553 /// Typically, instance variables are specified in the class interface,
1554 /// *not* in the implementation. Nevertheless (for legacy reasons), we
1555 /// allow instance variables to be specified in the implementation. When
1556 /// specified, they need to be *identical* to the interface.
1558 class ObjCImplementationDecl : public ObjCImplDecl {
1559 virtual void anchor();
1560 /// Implementation Class's super class.
1561 ObjCInterfaceDecl *SuperClass;
1562 /// \@implementation may have private ivars.
1563 SourceLocation IvarLBraceLoc;
1564 SourceLocation IvarRBraceLoc;
1566 /// Support for ivar initialization.
1567 /// IvarInitializers - The arguments used to initialize the ivars
1568 CXXCtorInitializer **IvarInitializers;
1569 unsigned NumIvarInitializers;
1571 /// true if class has a .cxx_[construct,destruct] method.
1572 bool HasCXXStructors : 1;
1574 ObjCImplementationDecl(DeclContext *DC,
1575 ObjCInterfaceDecl *classInterface,
1576 ObjCInterfaceDecl *superDecl,
1577 SourceLocation nameLoc, SourceLocation atStartLoc,
1578 SourceLocation IvarLBraceLoc=SourceLocation(),
1579 SourceLocation IvarRBraceLoc=SourceLocation())
1580 : ObjCImplDecl(ObjCImplementation, DC, classInterface, nameLoc, atStartLoc),
1581 SuperClass(superDecl), IvarLBraceLoc(IvarLBraceLoc),
1582 IvarRBraceLoc(IvarRBraceLoc),
1583 IvarInitializers(0), NumIvarInitializers(0),
1584 HasCXXStructors(false) {}
1586 static ObjCImplementationDecl *Create(ASTContext &C, DeclContext *DC,
1587 ObjCInterfaceDecl *classInterface,
1588 ObjCInterfaceDecl *superDecl,
1589 SourceLocation nameLoc,
1590 SourceLocation atStartLoc,
1591 SourceLocation IvarLBraceLoc=SourceLocation(),
1592 SourceLocation IvarRBraceLoc=SourceLocation());
1594 static ObjCImplementationDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1596 /// init_iterator - Iterates through the ivar initializer list.
1597 typedef CXXCtorInitializer **init_iterator;
1599 /// init_const_iterator - Iterates through the ivar initializer list.
1600 typedef CXXCtorInitializer * const * init_const_iterator;
1602 /// init_begin() - Retrieve an iterator to the first initializer.
1603 init_iterator init_begin() { return IvarInitializers; }
1604 /// begin() - Retrieve an iterator to the first initializer.
1605 init_const_iterator init_begin() const { return IvarInitializers; }
1607 /// init_end() - Retrieve an iterator past the last initializer.
1608 init_iterator init_end() {
1609 return IvarInitializers + NumIvarInitializers;
1611 /// end() - Retrieve an iterator past the last initializer.
1612 init_const_iterator init_end() const {
1613 return IvarInitializers + NumIvarInitializers;
1615 /// getNumArgs - Number of ivars which must be initialized.
1616 unsigned getNumIvarInitializers() const {
1617 return NumIvarInitializers;
1620 void setNumIvarInitializers(unsigned numNumIvarInitializers) {
1621 NumIvarInitializers = numNumIvarInitializers;
1624 void setIvarInitializers(ASTContext &C,
1625 CXXCtorInitializer ** initializers,
1626 unsigned numInitializers);
1628 bool hasCXXStructors() const { return HasCXXStructors; }
1629 void setHasCXXStructors(bool val) { HasCXXStructors = val; }
1631 /// getIdentifier - Get the identifier that names the class
1632 /// interface associated with this implementation.
1633 IdentifierInfo *getIdentifier() const {
1634 return getClassInterface()->getIdentifier();
1637 /// getName - Get the name of identifier for the class interface associated
1638 /// with this implementation as a StringRef.
1640 // FIXME: This is a bad API, we are overriding the NamedDecl::getName, to mean
1641 // something different.
1642 StringRef getName() const {
1643 assert(getIdentifier() && "Name is not a simple identifier");
1644 return getIdentifier()->getName();
1647 /// @brief Get the name of the class associated with this interface.
1649 // FIXME: Move to StringRef API.
1650 std::string getNameAsString() const {
1654 const ObjCInterfaceDecl *getSuperClass() const { return SuperClass; }
1655 ObjCInterfaceDecl *getSuperClass() { return SuperClass; }
1657 void setSuperClass(ObjCInterfaceDecl * superCls) { SuperClass = superCls; }
1659 void setIvarLBraceLoc(SourceLocation Loc) { IvarLBraceLoc = Loc; }
1660 SourceLocation getIvarLBraceLoc() const { return IvarLBraceLoc; }
1661 void setIvarRBraceLoc(SourceLocation Loc) { IvarRBraceLoc = Loc; }
1662 SourceLocation getIvarRBraceLoc() const { return IvarRBraceLoc; }
1664 typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
1665 ivar_iterator ivar_begin() const {
1666 return ivar_iterator(decls_begin());
1668 ivar_iterator ivar_end() const {
1669 return ivar_iterator(decls_end());
1671 unsigned ivar_size() const {
1672 return std::distance(ivar_begin(), ivar_end());
1674 bool ivar_empty() const {
1675 return ivar_begin() == ivar_end();
1678 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1679 static bool classof(const ObjCImplementationDecl *D) { return true; }
1680 static bool classofKind(Kind K) { return K == ObjCImplementation; }
1682 friend class ASTDeclReader;
1683 friend class ASTDeclWriter;
1686 raw_ostream &operator<<(raw_ostream &OS, const ObjCImplementationDecl &ID);
1688 /// ObjCCompatibleAliasDecl - Represents alias of a class. This alias is
1689 /// declared as \@compatibility_alias alias class.
1690 class ObjCCompatibleAliasDecl : public NamedDecl {
1691 virtual void anchor();
1692 /// Class that this is an alias of.
1693 ObjCInterfaceDecl *AliasedClass;
1695 ObjCCompatibleAliasDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
1696 ObjCInterfaceDecl* aliasedClass)
1697 : NamedDecl(ObjCCompatibleAlias, DC, L, Id), AliasedClass(aliasedClass) {}
1699 static ObjCCompatibleAliasDecl *Create(ASTContext &C, DeclContext *DC,
1700 SourceLocation L, IdentifierInfo *Id,
1701 ObjCInterfaceDecl* aliasedClass);
1703 static ObjCCompatibleAliasDecl *CreateDeserialized(ASTContext &C,
1706 const ObjCInterfaceDecl *getClassInterface() const { return AliasedClass; }
1707 ObjCInterfaceDecl *getClassInterface() { return AliasedClass; }
1708 void setClassInterface(ObjCInterfaceDecl *D) { AliasedClass = D; }
1710 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1711 static bool classof(const ObjCCompatibleAliasDecl *D) { return true; }
1712 static bool classofKind(Kind K) { return K == ObjCCompatibleAlias; }
1716 /// \brief Represents one property declaration in an Objective-C interface.
1720 /// \@property (assign, readwrite) int MyProperty;
1722 class ObjCPropertyDecl : public NamedDecl {
1723 virtual void anchor();
1725 enum PropertyAttributeKind {
1726 OBJC_PR_noattr = 0x00,
1727 OBJC_PR_readonly = 0x01,
1728 OBJC_PR_getter = 0x02,
1729 OBJC_PR_assign = 0x04,
1730 OBJC_PR_readwrite = 0x08,
1731 OBJC_PR_retain = 0x10,
1732 OBJC_PR_copy = 0x20,
1733 OBJC_PR_nonatomic = 0x40,
1734 OBJC_PR_setter = 0x80,
1735 OBJC_PR_atomic = 0x100,
1736 OBJC_PR_weak = 0x200,
1737 OBJC_PR_strong = 0x400,
1738 OBJC_PR_unsafe_unretained = 0x800
1739 // Adding a property should change NumPropertyAttrsBits
1743 /// \brief Number of bits fitting all the property attributes.
1744 NumPropertyAttrsBits = 12
1747 enum SetterKind { Assign, Retain, Copy, Weak };
1748 enum PropertyControl { None, Required, Optional };
1750 SourceLocation AtLoc; // location of \@property
1751 SourceLocation LParenLoc; // location of '(' starting attribute list or null.
1752 TypeSourceInfo *DeclType;
1753 unsigned PropertyAttributes : NumPropertyAttrsBits;
1754 unsigned PropertyAttributesAsWritten : NumPropertyAttrsBits;
1755 // \@required/\@optional
1756 unsigned PropertyImplementation : 2;
1758 Selector GetterName; // getter name of NULL if no getter
1759 Selector SetterName; // setter name of NULL if no setter
1761 ObjCMethodDecl *GetterMethodDecl; // Declaration of getter instance method
1762 ObjCMethodDecl *SetterMethodDecl; // Declaration of setter instance method
1763 ObjCIvarDecl *PropertyIvarDecl; // Synthesize ivar for this property
1765 ObjCPropertyDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
1766 SourceLocation AtLocation, SourceLocation LParenLocation,
1768 : NamedDecl(ObjCProperty, DC, L, Id), AtLoc(AtLocation),
1769 LParenLoc(LParenLocation), DeclType(T),
1770 PropertyAttributes(OBJC_PR_noattr),
1771 PropertyAttributesAsWritten(OBJC_PR_noattr),
1772 PropertyImplementation(None),
1773 GetterName(Selector()),
1774 SetterName(Selector()),
1775 GetterMethodDecl(0), SetterMethodDecl(0) , PropertyIvarDecl(0) {}
1777 static ObjCPropertyDecl *Create(ASTContext &C, DeclContext *DC,
1779 IdentifierInfo *Id, SourceLocation AtLocation,
1780 SourceLocation LParenLocation,
1782 PropertyControl propControl = None);
1784 static ObjCPropertyDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1786 SourceLocation getAtLoc() const { return AtLoc; }
1787 void setAtLoc(SourceLocation L) { AtLoc = L; }
1789 SourceLocation getLParenLoc() const { return LParenLoc; }
1790 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1792 TypeSourceInfo *getTypeSourceInfo() const { return DeclType; }
1793 QualType getType() const { return DeclType->getType(); }
1794 void setType(TypeSourceInfo *T) { DeclType = T; }
1796 PropertyAttributeKind getPropertyAttributes() const {
1797 return PropertyAttributeKind(PropertyAttributes);
1799 void setPropertyAttributes(PropertyAttributeKind PRVal) {
1800 PropertyAttributes |= PRVal;
1803 PropertyAttributeKind getPropertyAttributesAsWritten() const {
1804 return PropertyAttributeKind(PropertyAttributesAsWritten);
1807 bool hasWrittenStorageAttribute() const {
1808 return PropertyAttributesAsWritten & (OBJC_PR_assign | OBJC_PR_copy |
1809 OBJC_PR_unsafe_unretained | OBJC_PR_retain | OBJC_PR_strong |
1813 void setPropertyAttributesAsWritten(PropertyAttributeKind PRVal) {
1814 PropertyAttributesAsWritten = PRVal;
1817 void makeitReadWriteAttribute(void) {
1818 PropertyAttributes &= ~OBJC_PR_readonly;
1819 PropertyAttributes |= OBJC_PR_readwrite;
1822 // Helper methods for accessing attributes.
1824 /// isReadOnly - Return true iff the property has a setter.
1825 bool isReadOnly() const {
1826 return (PropertyAttributes & OBJC_PR_readonly);
1829 /// isAtomic - Return true if the property is atomic.
1830 bool isAtomic() const {
1831 return (PropertyAttributes & OBJC_PR_atomic);
1834 /// isRetaining - Return true if the property retains its value.
1835 bool isRetaining() const {
1836 return (PropertyAttributes &
1837 (OBJC_PR_retain | OBJC_PR_strong | OBJC_PR_copy));
1840 /// getSetterKind - Return the method used for doing assignment in
1841 /// the property setter. This is only valid if the property has been
1842 /// defined to have a setter.
1843 SetterKind getSetterKind() const {
1844 if (PropertyAttributes & OBJC_PR_strong)
1845 return getType()->isBlockPointerType() ? Copy : Retain;
1846 if (PropertyAttributes & OBJC_PR_retain)
1848 if (PropertyAttributes & OBJC_PR_copy)
1850 if (PropertyAttributes & OBJC_PR_weak)
1855 Selector getGetterName() const { return GetterName; }
1856 void setGetterName(Selector Sel) { GetterName = Sel; }
1858 Selector getSetterName() const { return SetterName; }
1859 void setSetterName(Selector Sel) { SetterName = Sel; }
1861 ObjCMethodDecl *getGetterMethodDecl() const { return GetterMethodDecl; }
1862 void setGetterMethodDecl(ObjCMethodDecl *gDecl) { GetterMethodDecl = gDecl; }
1864 ObjCMethodDecl *getSetterMethodDecl() const { return SetterMethodDecl; }
1865 void setSetterMethodDecl(ObjCMethodDecl *gDecl) { SetterMethodDecl = gDecl; }
1867 // Related to \@optional/\@required declared in \@protocol
1868 void setPropertyImplementation(PropertyControl pc) {
1869 PropertyImplementation = pc;
1871 PropertyControl getPropertyImplementation() const {
1872 return PropertyControl(PropertyImplementation);
1875 void setPropertyIvarDecl(ObjCIvarDecl *Ivar) {
1876 PropertyIvarDecl = Ivar;
1878 ObjCIvarDecl *getPropertyIvarDecl() const {
1879 return PropertyIvarDecl;
1882 virtual SourceRange getSourceRange() const LLVM_READONLY {
1883 return SourceRange(AtLoc, getLocation());
1886 /// Lookup a property by name in the specified DeclContext.
1887 static ObjCPropertyDecl *findPropertyDecl(const DeclContext *DC,
1888 IdentifierInfo *propertyID);
1890 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1891 static bool classof(const ObjCPropertyDecl *D) { return true; }
1892 static bool classofKind(Kind K) { return K == ObjCProperty; }
1895 /// ObjCPropertyImplDecl - Represents implementation declaration of a property
1896 /// in a class or category implementation block. For example:
1897 /// \@synthesize prop1 = ivar1;
1899 class ObjCPropertyImplDecl : public Decl {
1906 SourceLocation AtLoc; // location of \@synthesize or \@dynamic
1908 /// \brief For \@synthesize, the location of the ivar, if it was written in
1909 /// the source code.
1912 /// \@synthesize int a = b
1914 SourceLocation IvarLoc;
1916 /// Property declaration being implemented
1917 ObjCPropertyDecl *PropertyDecl;
1919 /// Null for \@dynamic. Required for \@synthesize.
1920 ObjCIvarDecl *PropertyIvarDecl;
1922 /// Null for \@dynamic. Non-null if property must be copy-constructed in
1924 Expr *GetterCXXConstructor;
1926 /// Null for \@dynamic. Non-null if property has assignment operator to call
1927 /// in Setter synthesis.
1928 Expr *SetterCXXAssignment;
1930 ObjCPropertyImplDecl(DeclContext *DC, SourceLocation atLoc, SourceLocation L,
1931 ObjCPropertyDecl *property,
1933 ObjCIvarDecl *ivarDecl,
1934 SourceLocation ivarLoc)
1935 : Decl(ObjCPropertyImpl, DC, L), AtLoc(atLoc),
1936 IvarLoc(ivarLoc), PropertyDecl(property), PropertyIvarDecl(ivarDecl),
1937 GetterCXXConstructor(0), SetterCXXAssignment(0) {
1938 assert (PK == Dynamic || PropertyIvarDecl);
1942 static ObjCPropertyImplDecl *Create(ASTContext &C, DeclContext *DC,
1943 SourceLocation atLoc, SourceLocation L,
1944 ObjCPropertyDecl *property,
1946 ObjCIvarDecl *ivarDecl,
1947 SourceLocation ivarLoc);
1949 static ObjCPropertyImplDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1951 virtual SourceRange getSourceRange() const LLVM_READONLY;
1953 SourceLocation getLocStart() const LLVM_READONLY { return AtLoc; }
1954 void setAtLoc(SourceLocation Loc) { AtLoc = Loc; }
1956 ObjCPropertyDecl *getPropertyDecl() const {
1957 return PropertyDecl;
1959 void setPropertyDecl(ObjCPropertyDecl *Prop) { PropertyDecl = Prop; }
1961 Kind getPropertyImplementation() const {
1962 return PropertyIvarDecl ? Synthesize : Dynamic;
1965 ObjCIvarDecl *getPropertyIvarDecl() const {
1966 return PropertyIvarDecl;
1968 SourceLocation getPropertyIvarDeclLoc() const { return IvarLoc; }
1970 void setPropertyIvarDecl(ObjCIvarDecl *Ivar,
1971 SourceLocation IvarLoc) {
1972 PropertyIvarDecl = Ivar;
1973 this->IvarLoc = IvarLoc;
1976 /// \brief For \@synthesize, returns true if an ivar name was explicitly
1980 /// \@synthesize int a = b; // true
1981 /// \@synthesize int a; // false
1983 bool isIvarNameSpecified() const {
1984 return IvarLoc.isValid() && IvarLoc != getLocation();
1987 Expr *getGetterCXXConstructor() const {
1988 return GetterCXXConstructor;
1990 void setGetterCXXConstructor(Expr *getterCXXConstructor) {
1991 GetterCXXConstructor = getterCXXConstructor;
1994 Expr *getSetterCXXAssignment() const {
1995 return SetterCXXAssignment;
1997 void setSetterCXXAssignment(Expr *setterCXXAssignment) {
1998 SetterCXXAssignment = setterCXXAssignment;
2001 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2002 static bool classof(const ObjCPropertyImplDecl *D) { return true; }
2003 static bool classofKind(Decl::Kind K) { return K == ObjCPropertyImpl; }
2005 friend class ASTDeclReader;
2008 } // end namespace clang