]> CyberLeo.Net >> Repos - FreeBSD/releng/9.0.git/blob - contrib/llvm/tools/clang/include/clang/AST/DeclObjC.h
Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
[FreeBSD/releng/9.0.git] / contrib / llvm / tools / clang / include / clang / AST / DeclObjC.h
1 //===--- DeclObjC.h - Classes for representing declarations -----*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 //  This file defines the DeclObjC interface and subclasses.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_CLANG_AST_DECLOBJC_H
15 #define LLVM_CLANG_AST_DECLOBJC_H
16
17 #include "clang/AST/Decl.h"
18 #include "clang/AST/SelectorLocationsKind.h"
19 #include "llvm/ADT/STLExtras.h"
20
21 namespace clang {
22 class Expr;
23 class Stmt;
24 class FunctionDecl;
25 class RecordDecl;
26 class ObjCIvarDecl;
27 class ObjCMethodDecl;
28 class ObjCProtocolDecl;
29 class ObjCCategoryDecl;
30 class ObjCPropertyDecl;
31 class ObjCPropertyImplDecl;
32 class CXXCtorInitializer;
33
34 class ObjCListBase {
35   void operator=(const ObjCListBase &);     // DO NOT IMPLEMENT
36   ObjCListBase(const ObjCListBase&);        // DO NOT IMPLEMENT
37 protected:
38   /// List is an array of pointers to objects that are not owned by this object.
39   void **List;
40   unsigned NumElts;
41
42 public:
43   ObjCListBase() : List(0), NumElts(0) {}
44   unsigned size() const { return NumElts; }
45   bool empty() const { return NumElts == 0; }
46
47 protected:
48   void set(void *const* InList, unsigned Elts, ASTContext &Ctx);
49 };
50
51
52 /// ObjCList - This is a simple template class used to hold various lists of
53 /// decls etc, which is heavily used by the ObjC front-end.  This only use case
54 /// this supports is setting the list all at once and then reading elements out
55 /// of it.
56 template <typename T>
57 class ObjCList : public ObjCListBase {
58 public:
59   void set(T* const* InList, unsigned Elts, ASTContext &Ctx) {
60     ObjCListBase::set(reinterpret_cast<void*const*>(InList), Elts, Ctx);
61   }
62
63   typedef T* const * iterator;
64   iterator begin() const { return (iterator)List; }
65   iterator end() const { return (iterator)List+NumElts; }
66
67   T* operator[](unsigned Idx) const {
68     assert(Idx < NumElts && "Invalid access");
69     return (T*)List[Idx];
70   }
71 };
72
73 /// \brief A list of Objective-C protocols, along with the source
74 /// locations at which they were referenced.
75 class ObjCProtocolList : public ObjCList<ObjCProtocolDecl> {
76   SourceLocation *Locations;
77
78   using ObjCList<ObjCProtocolDecl>::set;
79
80 public:
81   ObjCProtocolList() : ObjCList<ObjCProtocolDecl>(), Locations(0) { }
82
83   typedef const SourceLocation *loc_iterator;
84   loc_iterator loc_begin() const { return Locations; }
85   loc_iterator loc_end() const { return Locations + size(); }
86
87   void set(ObjCProtocolDecl* const* InList, unsigned Elts, 
88            const SourceLocation *Locs, ASTContext &Ctx);
89 };
90
91
92 /// ObjCMethodDecl - Represents an instance or class method declaration.
93 /// ObjC methods can be declared within 4 contexts: class interfaces,
94 /// categories, protocols, and class implementations. While C++ member
95 /// functions leverage C syntax, Objective-C method syntax is modeled after
96 /// Smalltalk (using colons to specify argument types/expressions).
97 /// Here are some brief examples:
98 ///
99 /// Setter/getter instance methods:
100 /// - (void)setMenu:(NSMenu *)menu;
101 /// - (NSMenu *)menu;
102 ///
103 /// Instance method that takes 2 NSView arguments:
104 /// - (void)replaceSubview:(NSView *)oldView with:(NSView *)newView;
105 ///
106 /// Getter class method:
107 /// + (NSMenu *)defaultMenu;
108 ///
109 /// A selector represents a unique name for a method. The selector names for
110 /// the above methods are setMenu:, menu, replaceSubview:with:, and defaultMenu.
111 ///
112 class ObjCMethodDecl : public NamedDecl, public DeclContext {
113 public:
114   enum ImplementationControl { None, Required, Optional };
115 private:
116   // The conventional meaning of this method; an ObjCMethodFamily.
117   // This is not serialized; instead, it is computed on demand and
118   // cached.
119   mutable unsigned Family : ObjCMethodFamilyBitWidth;
120
121   /// instance (true) or class (false) method.
122   unsigned IsInstance : 1;
123   unsigned IsVariadic : 1;
124
125   // Synthesized declaration method for a property setter/getter
126   unsigned IsSynthesized : 1;
127   
128   // Method has a definition.
129   unsigned IsDefined : 1;
130
131   /// \brief Method redeclaration in the same interface.
132   unsigned IsRedeclaration : 1;
133
134   /// \brief Is redeclared in the same interface.
135   mutable unsigned HasRedeclaration : 1;
136
137   // NOTE: VC++ treats enums as signed, avoid using ImplementationControl enum
138   /// @required/@optional
139   unsigned DeclImplementation : 2;
140
141   // NOTE: VC++ treats enums as signed, avoid using the ObjCDeclQualifier enum
142   /// in, inout, etc.
143   unsigned objcDeclQualifier : 6;
144
145   /// \brief Indicates whether this method has a related result type.
146   unsigned RelatedResultType : 1;
147   
148   /// \brief Whether the locations of the selector identifiers are in a
149   /// "standard" position, a enum SelectorLocationsKind.
150   unsigned SelLocsKind : 2;
151
152   // Result type of this method.
153   QualType MethodDeclType;
154   
155   // Type source information for the result type.
156   TypeSourceInfo *ResultTInfo;
157
158   /// \brief Array of ParmVarDecls for the formal parameters of this method
159   /// and optionally followed by selector locations.
160   void *ParamsAndSelLocs;
161   unsigned NumParams;
162
163   /// List of attributes for this method declaration.
164   SourceLocation EndLoc; // the location of the ';' or '}'.
165
166   // The following are only used for method definitions, null otherwise.
167   // FIXME: space savings opportunity, consider a sub-class.
168   Stmt *Body;
169
170   /// SelfDecl - Decl for the implicit self parameter. This is lazily
171   /// constructed by createImplicitParams.
172   ImplicitParamDecl *SelfDecl;
173   /// CmdDecl - Decl for the implicit _cmd parameter. This is lazily
174   /// constructed by createImplicitParams.
175   ImplicitParamDecl *CmdDecl;
176
177   SelectorLocationsKind getSelLocsKind() const {
178     return (SelectorLocationsKind)SelLocsKind;
179   }
180   bool hasStandardSelLocs() const {
181     return getSelLocsKind() != SelLoc_NonStandard;
182   }
183
184   /// \brief Get a pointer to the stored selector identifiers locations array.
185   /// No locations will be stored if HasStandardSelLocs is true.
186   SourceLocation *getStoredSelLocs() {
187     return reinterpret_cast<SourceLocation*>(getParams() + NumParams);
188   }
189   const SourceLocation *getStoredSelLocs() const {
190     return reinterpret_cast<const SourceLocation*>(getParams() + NumParams);
191   }
192
193   /// \brief Get a pointer to the stored selector identifiers locations array.
194   /// No locations will be stored if HasStandardSelLocs is true.
195   ParmVarDecl **getParams() {
196     return reinterpret_cast<ParmVarDecl **>(ParamsAndSelLocs);
197   }
198   const ParmVarDecl *const *getParams() const {
199     return reinterpret_cast<const ParmVarDecl *const *>(ParamsAndSelLocs);
200   }
201
202   /// \brief Get the number of stored selector identifiers locations.
203   /// No locations will be stored if HasStandardSelLocs is true.
204   unsigned getNumStoredSelLocs() const {
205     if (hasStandardSelLocs())
206       return 0;
207     return getNumSelectorLocs();
208   }
209
210   void setParamsAndSelLocs(ASTContext &C,
211                            ArrayRef<ParmVarDecl*> Params,
212                            ArrayRef<SourceLocation> SelLocs);
213
214   ObjCMethodDecl(SourceLocation beginLoc, SourceLocation endLoc,
215                  Selector SelInfo, QualType T,
216                  TypeSourceInfo *ResultTInfo,
217                  DeclContext *contextDecl,
218                  bool isInstance = true,
219                  bool isVariadic = false,
220                  bool isSynthesized = false,
221                  bool isImplicitlyDeclared = false,
222                  bool isDefined = false,
223                  ImplementationControl impControl = None,
224                  bool HasRelatedResultType = false)
225   : NamedDecl(ObjCMethod, contextDecl, beginLoc, SelInfo),
226     DeclContext(ObjCMethod), Family(InvalidObjCMethodFamily),
227     IsInstance(isInstance), IsVariadic(isVariadic),
228     IsSynthesized(isSynthesized),
229     IsDefined(isDefined), IsRedeclaration(0), HasRedeclaration(0),
230     DeclImplementation(impControl), objcDeclQualifier(OBJC_TQ_None),
231     RelatedResultType(HasRelatedResultType),
232     SelLocsKind(SelLoc_StandardNoSpace),
233     MethodDeclType(T), ResultTInfo(ResultTInfo),
234     ParamsAndSelLocs(0), NumParams(0),
235     EndLoc(endLoc), Body(0), SelfDecl(0), CmdDecl(0) {
236     setImplicit(isImplicitlyDeclared);
237   }
238
239   /// \brief A definition will return its interface declaration.
240   /// An interface declaration will return its definition.
241   /// Otherwise it will return itself.
242   virtual ObjCMethodDecl *getNextRedeclaration();
243
244 public:
245   static ObjCMethodDecl *Create(ASTContext &C,
246                                 SourceLocation beginLoc,
247                                 SourceLocation endLoc,
248                                 Selector SelInfo,
249                                 QualType T, 
250                                 TypeSourceInfo *ResultTInfo,
251                                 DeclContext *contextDecl,
252                                 bool isInstance = true,
253                                 bool isVariadic = false,
254                                 bool isSynthesized = false,
255                                 bool isImplicitlyDeclared = false,
256                                 bool isDefined = false,
257                                 ImplementationControl impControl = None,
258                                 bool HasRelatedResultType = false);
259
260   virtual ObjCMethodDecl *getCanonicalDecl();
261   const ObjCMethodDecl *getCanonicalDecl() const {
262     return const_cast<ObjCMethodDecl*>(this)->getCanonicalDecl();
263   }
264
265   ObjCDeclQualifier getObjCDeclQualifier() const {
266     return ObjCDeclQualifier(objcDeclQualifier);
267   }
268   void setObjCDeclQualifier(ObjCDeclQualifier QV) { objcDeclQualifier = QV; }
269
270   /// \brief Determine whether this method has a result type that is related
271   /// to the message receiver's type.
272   bool hasRelatedResultType() const { return RelatedResultType; }
273   
274   /// \brief Note whether this method has a related result type.
275   void SetRelatedResultType(bool RRT = true) { RelatedResultType = RRT; }
276
277   /// \brief True if this is a method redeclaration in the same interface.
278   bool isRedeclaration() const { return IsRedeclaration; }
279   void setAsRedeclaration(const ObjCMethodDecl *PrevMethod);
280   
281   // Location information, modeled after the Stmt API.
282   SourceLocation getLocStart() const { return getLocation(); }
283   SourceLocation getLocEnd() const { return EndLoc; }
284   void setEndLoc(SourceLocation Loc) { EndLoc = Loc; }
285   virtual SourceRange getSourceRange() const {
286     return SourceRange(getLocation(), EndLoc);
287   }
288
289   SourceLocation getSelectorStartLoc() const { return getSelectorLoc(0); }
290   SourceLocation getSelectorLoc(unsigned Index) const {
291     assert(Index < getNumSelectorLocs() && "Index out of range!");
292     if (hasStandardSelLocs())
293       return getStandardSelectorLoc(Index, getSelector(),
294                                    getSelLocsKind() == SelLoc_StandardWithSpace,
295                       llvm::makeArrayRef(const_cast<ParmVarDecl**>(getParams()),
296                                          NumParams),
297                                    EndLoc);
298     return getStoredSelLocs()[Index];
299   }
300
301   void getSelectorLocs(SmallVectorImpl<SourceLocation> &SelLocs) const;
302
303   unsigned getNumSelectorLocs() const {
304     if (isImplicit())
305       return 0;
306     Selector Sel = getSelector();
307     if (Sel.isUnarySelector())
308       return 1;
309     return Sel.getNumArgs();
310   }
311
312   ObjCInterfaceDecl *getClassInterface();
313   const ObjCInterfaceDecl *getClassInterface() const {
314     return const_cast<ObjCMethodDecl*>(this)->getClassInterface();
315   }
316
317   Selector getSelector() const { return getDeclName().getObjCSelector(); }
318
319   QualType getResultType() const { return MethodDeclType; }
320   void setResultType(QualType T) { MethodDeclType = T; }
321
322   /// \brief Determine the type of an expression that sends a message to this 
323   /// function.
324   QualType getSendResultType() const {
325     return getResultType().getNonLValueExprType(getASTContext());
326   }
327   
328   TypeSourceInfo *getResultTypeSourceInfo() const { return ResultTInfo; }
329   void setResultTypeSourceInfo(TypeSourceInfo *TInfo) { ResultTInfo = TInfo; }
330
331   // Iterator access to formal parameters.
332   unsigned param_size() const { return NumParams; }
333   typedef const ParmVarDecl *const *param_const_iterator;
334   typedef ParmVarDecl *const *param_iterator;
335   param_const_iterator param_begin() const { return getParams(); }
336   param_const_iterator param_end() const { return getParams() + NumParams; }
337   param_iterator param_begin() { return getParams(); }
338   param_iterator param_end() { return getParams() + NumParams; }
339   // This method returns and of the parameters which are part of the selector
340   // name mangling requirements.
341   param_const_iterator sel_param_end() const { 
342     return param_begin() + getSelector().getNumArgs(); 
343   }
344
345   /// \brief Sets the method's parameters and selector source locations.
346   /// If the method is implicit (not coming from source) \arg SelLocs is
347   /// ignored.
348   void setMethodParams(ASTContext &C,
349                        ArrayRef<ParmVarDecl*> Params,
350                        ArrayRef<SourceLocation> SelLocs =
351                            ArrayRef<SourceLocation>());
352
353   // Iterator access to parameter types.
354   typedef std::const_mem_fun_t<QualType, ParmVarDecl> deref_fun;
355   typedef llvm::mapped_iterator<param_const_iterator, deref_fun>
356       arg_type_iterator;
357
358   arg_type_iterator arg_type_begin() const {
359     return llvm::map_iterator(param_begin(), deref_fun(&ParmVarDecl::getType));
360   }
361   arg_type_iterator arg_type_end() const {
362     return llvm::map_iterator(param_end(), deref_fun(&ParmVarDecl::getType));
363   }
364
365   /// createImplicitParams - Used to lazily create the self and cmd
366   /// implict parameters. This must be called prior to using getSelfDecl()
367   /// or getCmdDecl(). The call is ignored if the implicit paramters
368   /// have already been created.
369   void createImplicitParams(ASTContext &Context, const ObjCInterfaceDecl *ID);
370
371   ImplicitParamDecl * getSelfDecl() const { return SelfDecl; }
372   void setSelfDecl(ImplicitParamDecl *SD) { SelfDecl = SD; }
373   ImplicitParamDecl * getCmdDecl() const { return CmdDecl; }
374   void setCmdDecl(ImplicitParamDecl *CD) { CmdDecl = CD; }
375
376   /// Determines the family of this method.
377   ObjCMethodFamily getMethodFamily() const;
378
379   bool isInstanceMethod() const { return IsInstance; }
380   void setInstanceMethod(bool isInst) { IsInstance = isInst; }
381   bool isVariadic() const { return IsVariadic; }
382   void setVariadic(bool isVar) { IsVariadic = isVar; }
383
384   bool isClassMethod() const { return !IsInstance; }
385
386   bool isSynthesized() const { return IsSynthesized; }
387   void setSynthesized(bool isSynth) { IsSynthesized = isSynth; }
388   
389   bool isDefined() const { return IsDefined; }
390   void setDefined(bool isDefined) { IsDefined = isDefined; }
391
392   // Related to protocols declared in  @protocol
393   void setDeclImplementation(ImplementationControl ic) {
394     DeclImplementation = ic;
395   }
396   ImplementationControl getImplementationControl() const {
397     return ImplementationControl(DeclImplementation);
398   }
399
400   virtual Stmt *getBody() const {
401     return (Stmt*) Body;
402   }
403   CompoundStmt *getCompoundBody() { return (CompoundStmt*)Body; }
404   void setBody(Stmt *B) { Body = B; }
405
406   /// \brief Returns whether this specific method is a definition.
407   bool isThisDeclarationADefinition() const { return Body; }
408
409   // Implement isa/cast/dyncast/etc.
410   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
411   static bool classof(const ObjCMethodDecl *D) { return true; }
412   static bool classofKind(Kind K) { return K == ObjCMethod; }
413   static DeclContext *castToDeclContext(const ObjCMethodDecl *D) {
414     return static_cast<DeclContext *>(const_cast<ObjCMethodDecl*>(D));
415   }
416   static ObjCMethodDecl *castFromDeclContext(const DeclContext *DC) {
417     return static_cast<ObjCMethodDecl *>(const_cast<DeclContext*>(DC));
418   }
419
420   friend class ASTDeclReader;
421   friend class ASTDeclWriter;
422 };
423
424 /// ObjCContainerDecl - Represents a container for method declarations.
425 /// Current sub-classes are ObjCInterfaceDecl, ObjCCategoryDecl,
426 /// ObjCProtocolDecl, and ObjCImplDecl.
427 ///
428 class ObjCContainerDecl : public NamedDecl, public DeclContext {
429   SourceLocation AtStart;
430
431   // These two locations in the range mark the end of the method container.
432   // The first points to the '@' token, and the second to the 'end' token.
433   SourceRange AtEnd;
434 public:
435
436   ObjCContainerDecl(Kind DK, DeclContext *DC,
437                     IdentifierInfo *Id, SourceLocation nameLoc,
438                     SourceLocation atStartLoc)
439     : NamedDecl(DK, DC, nameLoc, Id), DeclContext(DK), AtStart(atStartLoc) {}
440
441   // Iterator access to properties.
442   typedef specific_decl_iterator<ObjCPropertyDecl> prop_iterator;
443   prop_iterator prop_begin() const {
444     return prop_iterator(decls_begin());
445   }
446   prop_iterator prop_end() const {
447     return prop_iterator(decls_end());
448   }
449
450   // Iterator access to instance/class methods.
451   typedef specific_decl_iterator<ObjCMethodDecl> method_iterator;
452   method_iterator meth_begin() const {
453     return method_iterator(decls_begin());
454   }
455   method_iterator meth_end() const {
456     return method_iterator(decls_end());
457   }
458
459   typedef filtered_decl_iterator<ObjCMethodDecl,
460                                  &ObjCMethodDecl::isInstanceMethod>
461     instmeth_iterator;
462   instmeth_iterator instmeth_begin() const {
463     return instmeth_iterator(decls_begin());
464   }
465   instmeth_iterator instmeth_end() const {
466     return instmeth_iterator(decls_end());
467   }
468
469   typedef filtered_decl_iterator<ObjCMethodDecl,
470                                  &ObjCMethodDecl::isClassMethod>
471     classmeth_iterator;
472   classmeth_iterator classmeth_begin() const {
473     return classmeth_iterator(decls_begin());
474   }
475   classmeth_iterator classmeth_end() const {
476     return classmeth_iterator(decls_end());
477   }
478
479   // Get the local instance/class method declared in this interface.
480   ObjCMethodDecl *getMethod(Selector Sel, bool isInstance) const;
481   ObjCMethodDecl *getInstanceMethod(Selector Sel) const {
482     return getMethod(Sel, true/*isInstance*/);
483   }
484   ObjCMethodDecl *getClassMethod(Selector Sel) const {
485     return getMethod(Sel, false/*isInstance*/);
486   }
487   ObjCIvarDecl *getIvarDecl(IdentifierInfo *Id) const;
488
489   ObjCPropertyDecl *FindPropertyDeclaration(IdentifierInfo *PropertyId) const;
490
491   SourceLocation getAtStartLoc() const { return AtStart; }
492   void setAtStartLoc(SourceLocation Loc) { AtStart = Loc; }
493
494   // Marks the end of the container.
495   SourceRange getAtEndRange() const {
496     return AtEnd;
497   }
498   void setAtEndRange(SourceRange atEnd) {
499     AtEnd = atEnd;
500   }
501
502   virtual SourceRange getSourceRange() const {
503     return SourceRange(AtStart, getAtEndRange().getEnd());
504   }
505
506   // Implement isa/cast/dyncast/etc.
507   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
508   static bool classof(const ObjCContainerDecl *D) { return true; }
509   static bool classofKind(Kind K) {
510     return K >= firstObjCContainer &&
511            K <= lastObjCContainer;
512   }
513
514   static DeclContext *castToDeclContext(const ObjCContainerDecl *D) {
515     return static_cast<DeclContext *>(const_cast<ObjCContainerDecl*>(D));
516   }
517   static ObjCContainerDecl *castFromDeclContext(const DeclContext *DC) {
518     return static_cast<ObjCContainerDecl *>(const_cast<DeclContext*>(DC));
519   }
520 };
521
522 /// ObjCInterfaceDecl - Represents an ObjC class declaration. For example:
523 ///
524 ///   // MostPrimitive declares no super class (not particularly useful).
525 ///   @interface MostPrimitive
526 ///     // no instance variables or methods.
527 ///   @end
528 ///
529 ///   // NSResponder inherits from NSObject & implements NSCoding (a protocol).
530 ///   @interface NSResponder : NSObject <NSCoding>
531 ///   { // instance variables are represented by ObjCIvarDecl.
532 ///     id nextResponder; // nextResponder instance variable.
533 ///   }
534 ///   - (NSResponder *)nextResponder; // return a pointer to NSResponder.
535 ///   - (void)mouseMoved:(NSEvent *)theEvent; // return void, takes a pointer
536 ///   @end                                    // to an NSEvent.
537 ///
538 ///   Unlike C/C++, forward class declarations are accomplished with @class.
539 ///   Unlike C/C++, @class allows for a list of classes to be forward declared.
540 ///   Unlike C++, ObjC is a single-rooted class model. In Cocoa, classes
541 ///   typically inherit from NSObject (an exception is NSProxy).
542 ///
543 class ObjCInterfaceDecl : public ObjCContainerDecl {
544   /// TypeForDecl - This indicates the Type object that represents this
545   /// TypeDecl.  It is a cache maintained by ASTContext::getObjCInterfaceType
546   mutable const Type *TypeForDecl;
547   friend class ASTContext;
548
549   /// Class's super class.
550   ObjCInterfaceDecl *SuperClass;
551
552   /// Protocols referenced in the @interface  declaration
553   ObjCProtocolList ReferencedProtocols;
554   
555   /// Protocols reference in both the @interface and class extensions.
556   ObjCList<ObjCProtocolDecl> AllReferencedProtocols;
557
558   /// \brief List of categories and class extensions defined for this class.
559   ///
560   /// Categories are stored as a linked list in the AST, since the categories
561   /// and class extensions come long after the initial interface declaration,
562   /// and we avoid dynamically-resized arrays in the AST wherever possible.
563   ObjCCategoryDecl *CategoryList;
564   
565   /// IvarList - List of all ivars defined by this class; including class
566   /// extensions and implementation. This list is built lazily.
567   ObjCIvarDecl *IvarList;
568
569   bool ForwardDecl:1; // declared with @class.
570   bool InternalInterface:1; // true - no @interface for @implementation
571   
572   /// \brief Indicates that the contents of this Objective-C class will be
573   /// completed by the external AST source when required.
574   mutable bool ExternallyCompleted : 1;
575   
576   SourceLocation SuperClassLoc; // location of the super class identifier.
577   SourceLocation EndLoc; // marks the '>', '}', or identifier.
578
579   ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id,
580                     SourceLocation CLoc, bool FD, bool isInternal);
581
582   void LoadExternalDefinition() const;
583 public:
584   static ObjCInterfaceDecl *Create(ASTContext &C, DeclContext *DC,
585                                    SourceLocation atLoc,
586                                    IdentifierInfo *Id,
587                                    SourceLocation ClassLoc = SourceLocation(),
588                                    bool ForwardDecl = false,
589                                    bool isInternal = false);
590   
591   /// \brief Indicate that this Objective-C class is complete, but that
592   /// the external AST source will be responsible for filling in its contents
593   /// when a complete class is required.
594   void setExternallyCompleted();
595   
596   const ObjCProtocolList &getReferencedProtocols() const {
597     if (ExternallyCompleted)
598       LoadExternalDefinition();
599     
600     return ReferencedProtocols;
601   }
602
603   ObjCImplementationDecl *getImplementation() const;
604   void setImplementation(ObjCImplementationDecl *ImplD);
605
606   ObjCCategoryDecl *FindCategoryDeclaration(IdentifierInfo *CategoryId) const;
607
608   // Get the local instance/class method declared in a category.
609   ObjCMethodDecl *getCategoryInstanceMethod(Selector Sel) const;
610   ObjCMethodDecl *getCategoryClassMethod(Selector Sel) const;
611   ObjCMethodDecl *getCategoryMethod(Selector Sel, bool isInstance) const {
612     return isInstance ? getInstanceMethod(Sel)
613                       : getClassMethod(Sel);
614   }
615
616   typedef ObjCProtocolList::iterator protocol_iterator;
617   
618   protocol_iterator protocol_begin() const {
619     if (ExternallyCompleted)
620       LoadExternalDefinition();
621
622     return ReferencedProtocols.begin();
623   }
624   protocol_iterator protocol_end() const {
625     if (ExternallyCompleted)
626       LoadExternalDefinition();
627
628     return ReferencedProtocols.end();
629   }
630
631   typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
632
633   protocol_loc_iterator protocol_loc_begin() const { 
634     if (ExternallyCompleted)
635       LoadExternalDefinition();
636
637     return ReferencedProtocols.loc_begin(); 
638   }
639
640   protocol_loc_iterator protocol_loc_end() const { 
641     if (ExternallyCompleted)
642       LoadExternalDefinition();
643
644     return ReferencedProtocols.loc_end(); 
645   }
646   
647   typedef ObjCList<ObjCProtocolDecl>::iterator all_protocol_iterator;
648   
649   all_protocol_iterator all_referenced_protocol_begin() const {
650     if (ExternallyCompleted)
651       LoadExternalDefinition();
652
653     return AllReferencedProtocols.empty() ? protocol_begin()
654       : AllReferencedProtocols.begin();
655   }
656   all_protocol_iterator all_referenced_protocol_end() const {
657     if (ExternallyCompleted)
658       LoadExternalDefinition();
659
660     return AllReferencedProtocols.empty() ? protocol_end() 
661       : AllReferencedProtocols.end();
662   }
663
664   typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
665
666   ivar_iterator ivar_begin() const { return ivar_iterator(decls_begin()); }
667   ivar_iterator ivar_end() const { return ivar_iterator(decls_end()); }
668
669   unsigned ivar_size() const {
670     return std::distance(ivar_begin(), ivar_end());
671   }
672   
673   bool ivar_empty() const { return ivar_begin() == ivar_end(); }
674   
675   ObjCIvarDecl *all_declared_ivar_begin();
676   const ObjCIvarDecl *all_declared_ivar_begin() const {
677     // Even though this modifies IvarList, it's conceptually const:
678     // the ivar chain is essentially a cached property of ObjCInterfaceDecl.
679     return const_cast<ObjCInterfaceDecl *>(this)->all_declared_ivar_begin();
680   }
681   void setIvarList(ObjCIvarDecl *ivar) { IvarList = ivar; }
682   
683   /// setProtocolList - Set the list of protocols that this interface
684   /// implements.
685   void setProtocolList(ObjCProtocolDecl *const* List, unsigned Num,
686                        const SourceLocation *Locs, ASTContext &C) {
687     ReferencedProtocols.set(List, Num, Locs, C);
688   }
689
690   /// mergeClassExtensionProtocolList - Merge class extension's protocol list
691   /// into the protocol list for this class.
692   void mergeClassExtensionProtocolList(ObjCProtocolDecl *const* List, 
693                                        unsigned Num,
694                                        ASTContext &C);
695
696   bool isForwardDecl() const { return ForwardDecl; }
697   void setForwardDecl(bool val) { ForwardDecl = val; }
698
699   ObjCInterfaceDecl *getSuperClass() const { 
700     if (ExternallyCompleted)
701       LoadExternalDefinition();
702
703     return SuperClass; 
704   }
705   
706   void setSuperClass(ObjCInterfaceDecl * superCls) { SuperClass = superCls; }
707
708   ObjCCategoryDecl* getCategoryList() const { 
709     if (ExternallyCompleted)
710       LoadExternalDefinition();
711
712     return CategoryList; 
713   }
714   
715   void setCategoryList(ObjCCategoryDecl *category) {
716     CategoryList = category;
717   }
718   
719   ObjCCategoryDecl* getFirstClassExtension() const;
720
721   ObjCPropertyDecl
722     *FindPropertyVisibleInPrimaryClass(IdentifierInfo *PropertyId) const;
723
724   /// isSuperClassOf - Return true if this class is the specified class or is a
725   /// super class of the specified interface class.
726   bool isSuperClassOf(const ObjCInterfaceDecl *I) const {
727     // If RHS is derived from LHS it is OK; else it is not OK.
728     while (I != NULL) {
729       if (this == I)
730         return true;
731       I = I->getSuperClass();
732     }
733     return false;
734   }
735
736   /// isArcWeakrefUnavailable - Checks for a class or one of its super classes
737   /// to be incompatible with __weak references. Returns true if it is.
738   bool isArcWeakrefUnavailable() const {
739     const ObjCInterfaceDecl *Class = this;
740     while (Class) {
741       if (Class->hasAttr<ArcWeakrefUnavailableAttr>())
742         return true;
743       Class = Class->getSuperClass();
744    }
745    return false; 
746   }
747
748   ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName,
749                                        ObjCInterfaceDecl *&ClassDeclared);
750   ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName) {
751     ObjCInterfaceDecl *ClassDeclared;
752     return lookupInstanceVariable(IVarName, ClassDeclared);
753   }
754
755   // Lookup a method. First, we search locally. If a method isn't
756   // found, we search referenced protocols and class categories.
757   ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance) const;
758   ObjCMethodDecl *lookupInstanceMethod(Selector Sel) const {
759     return lookupMethod(Sel, true/*isInstance*/);
760   }
761   ObjCMethodDecl *lookupClassMethod(Selector Sel) const {
762     return lookupMethod(Sel, false/*isInstance*/);
763   }
764   ObjCInterfaceDecl *lookupInheritedClass(const IdentifierInfo *ICName);
765   
766   // Lookup a method in the classes implementation hierarchy.
767   ObjCMethodDecl *lookupPrivateMethod(const Selector &Sel, bool Instance=true);
768
769   // Location information, modeled after the Stmt API.
770   SourceLocation getLocStart() const { return getAtStartLoc(); } // '@'interface
771   SourceLocation getLocEnd() const { return EndLoc; }
772   void setLocEnd(SourceLocation LE) { EndLoc = LE; }
773
774   void setSuperClassLoc(SourceLocation Loc) { SuperClassLoc = Loc; }
775   SourceLocation getSuperClassLoc() const { return SuperClassLoc; }
776
777   /// isImplicitInterfaceDecl - check that this is an implicitly declared
778   /// ObjCInterfaceDecl node. This is for legacy objective-c @implementation
779   /// declaration without an @interface declaration.
780   bool isImplicitInterfaceDecl() const { return InternalInterface; }
781   void setImplicitInterfaceDecl(bool val) { InternalInterface = val; }
782
783   /// ClassImplementsProtocol - Checks that 'lProto' protocol
784   /// has been implemented in IDecl class, its super class or categories (if
785   /// lookupCategory is true).
786   bool ClassImplementsProtocol(ObjCProtocolDecl *lProto,
787                                bool lookupCategory,
788                                bool RHSIsQualifiedID = false);
789
790   // Low-level accessor
791   const Type *getTypeForDecl() const { return TypeForDecl; }
792   void setTypeForDecl(const Type *TD) const { TypeForDecl = TD; }
793
794   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
795   static bool classof(const ObjCInterfaceDecl *D) { return true; }
796   static bool classofKind(Kind K) { return K == ObjCInterface; }
797
798   friend class ASTDeclReader;
799   friend class ASTDeclWriter;
800 };
801
802 /// ObjCIvarDecl - Represents an ObjC instance variable. In general, ObjC
803 /// instance variables are identical to C. The only exception is Objective-C
804 /// supports C++ style access control. For example:
805 ///
806 ///   @interface IvarExample : NSObject
807 ///   {
808 ///     id defaultToProtected;
809 ///   @public:
810 ///     id canBePublic; // same as C++.
811 ///   @protected:
812 ///     id canBeProtected; // same as C++.
813 ///   @package:
814 ///     id canBePackage; // framework visibility (not available in C++).
815 ///   }
816 ///
817 class ObjCIvarDecl : public FieldDecl {
818 public:
819   enum AccessControl {
820     None, Private, Protected, Public, Package
821   };
822
823 private:
824   ObjCIvarDecl(ObjCContainerDecl *DC, SourceLocation StartLoc,
825                SourceLocation IdLoc, IdentifierInfo *Id,
826                QualType T, TypeSourceInfo *TInfo, AccessControl ac, Expr *BW,
827                bool synthesized)
828     : FieldDecl(ObjCIvar, DC, StartLoc, IdLoc, Id, T, TInfo, BW,
829                 /*Mutable=*/false, /*HasInit=*/false),
830       NextIvar(0), DeclAccess(ac), Synthesized(synthesized) {}
831
832 public:
833   static ObjCIvarDecl *Create(ASTContext &C, ObjCContainerDecl *DC,
834                               SourceLocation StartLoc, SourceLocation IdLoc,
835                               IdentifierInfo *Id, QualType T,
836                               TypeSourceInfo *TInfo,
837                               AccessControl ac, Expr *BW = NULL,
838                               bool synthesized=false);
839
840   /// \brief Return the class interface that this ivar is logically contained
841   /// in; this is either the interface where the ivar was declared, or the
842   /// interface the ivar is conceptually a part of in the case of synthesized
843   /// ivars.
844   const ObjCInterfaceDecl *getContainingInterface() const;
845   
846   ObjCIvarDecl *getNextIvar() { return NextIvar; }
847   const ObjCIvarDecl *getNextIvar() const { return NextIvar; }
848   void setNextIvar(ObjCIvarDecl *ivar) { NextIvar = ivar; }
849
850   void setAccessControl(AccessControl ac) { DeclAccess = ac; }
851
852   AccessControl getAccessControl() const { return AccessControl(DeclAccess); }
853
854   AccessControl getCanonicalAccessControl() const {
855     return DeclAccess == None ? Protected : AccessControl(DeclAccess);
856   }
857
858   void setSynthesize(bool synth) { Synthesized = synth; }
859   bool getSynthesize() const { return Synthesized; }
860   
861   // Implement isa/cast/dyncast/etc.
862   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
863   static bool classof(const ObjCIvarDecl *D) { return true; }
864   static bool classofKind(Kind K) { return K == ObjCIvar; }
865 private:
866   /// NextIvar - Next Ivar in the list of ivars declared in class; class's 
867   /// extensions and class's implementation
868   ObjCIvarDecl *NextIvar;
869   
870   // NOTE: VC++ treats enums as signed, avoid using the AccessControl enum
871   unsigned DeclAccess : 3;
872   unsigned Synthesized : 1;
873 };
874
875
876 /// ObjCAtDefsFieldDecl - Represents a field declaration created by an
877 ///  @defs(...).
878 class ObjCAtDefsFieldDecl : public FieldDecl {
879 private:
880   ObjCAtDefsFieldDecl(DeclContext *DC, SourceLocation StartLoc,
881                       SourceLocation IdLoc, IdentifierInfo *Id,
882                       QualType T, Expr *BW)
883     : FieldDecl(ObjCAtDefsField, DC, StartLoc, IdLoc, Id, T,
884                 /*TInfo=*/0, // FIXME: Do ObjCAtDefs have declarators ?
885                 BW, /*Mutable=*/false, /*HasInit=*/false) {}
886
887 public:
888   static ObjCAtDefsFieldDecl *Create(ASTContext &C, DeclContext *DC,
889                                      SourceLocation StartLoc,
890                                      SourceLocation IdLoc, IdentifierInfo *Id,
891                                      QualType T, Expr *BW);
892
893   // Implement isa/cast/dyncast/etc.
894   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
895   static bool classof(const ObjCAtDefsFieldDecl *D) { return true; }
896   static bool classofKind(Kind K) { return K == ObjCAtDefsField; }
897 };
898
899 /// ObjCProtocolDecl - Represents a protocol declaration. ObjC protocols
900 /// declare a pure abstract type (i.e no instance variables are permitted).
901 /// Protocols originally drew inspiration from C++ pure virtual functions (a C++
902 /// feature with nice semantics and lousy syntax:-). Here is an example:
903 ///
904 /// @protocol NSDraggingInfo <refproto1, refproto2>
905 /// - (NSWindow *)draggingDestinationWindow;
906 /// - (NSImage *)draggedImage;
907 /// @end
908 ///
909 /// This says that NSDraggingInfo requires two methods and requires everything
910 /// that the two "referenced protocols" 'refproto1' and 'refproto2' require as
911 /// well.
912 ///
913 /// @interface ImplementsNSDraggingInfo : NSObject <NSDraggingInfo>
914 /// @end
915 ///
916 /// ObjC protocols inspired Java interfaces. Unlike Java, ObjC classes and
917 /// protocols are in distinct namespaces. For example, Cocoa defines both
918 /// an NSObject protocol and class (which isn't allowed in Java). As a result,
919 /// protocols are referenced using angle brackets as follows:
920 ///
921 /// id <NSDraggingInfo> anyObjectThatImplementsNSDraggingInfo;
922 ///
923 class ObjCProtocolDecl : public ObjCContainerDecl {
924   /// Referenced protocols
925   ObjCProtocolList ReferencedProtocols;
926
927   bool isForwardProtoDecl; // declared with @protocol.
928
929   SourceLocation EndLoc; // marks the '>' or identifier.
930
931   ObjCProtocolDecl(DeclContext *DC, IdentifierInfo *Id,
932                    SourceLocation nameLoc, SourceLocation atStartLoc)
933     : ObjCContainerDecl(ObjCProtocol, DC, Id, nameLoc, atStartLoc),
934       isForwardProtoDecl(true) {
935   }
936
937 public:
938   static ObjCProtocolDecl *Create(ASTContext &C, DeclContext *DC,
939                                   IdentifierInfo *Id,
940                                   SourceLocation nameLoc,
941                                   SourceLocation atStartLoc);
942
943   const ObjCProtocolList &getReferencedProtocols() const {
944     return ReferencedProtocols;
945   }
946   typedef ObjCProtocolList::iterator protocol_iterator;
947   protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();}
948   protocol_iterator protocol_end() const { return ReferencedProtocols.end(); }
949   typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
950   protocol_loc_iterator protocol_loc_begin() const { 
951     return ReferencedProtocols.loc_begin(); 
952   }
953   protocol_loc_iterator protocol_loc_end() const { 
954     return ReferencedProtocols.loc_end(); 
955   }
956   unsigned protocol_size() const { return ReferencedProtocols.size(); }
957
958   /// setProtocolList - Set the list of protocols that this interface
959   /// implements.
960   void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num,
961                        const SourceLocation *Locs, ASTContext &C) {
962     ReferencedProtocols.set(List, Num, Locs, C);
963   }
964
965   ObjCProtocolDecl *lookupProtocolNamed(IdentifierInfo *PName);
966
967   // Lookup a method. First, we search locally. If a method isn't
968   // found, we search referenced protocols and class categories.
969   ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance) const;
970   ObjCMethodDecl *lookupInstanceMethod(Selector Sel) const {
971     return lookupMethod(Sel, true/*isInstance*/);
972   }
973   ObjCMethodDecl *lookupClassMethod(Selector Sel) const {
974     return lookupMethod(Sel, false/*isInstance*/);
975   }
976   
977   bool isForwardDecl() const { return isForwardProtoDecl; }
978   void setForwardDecl(bool val) { isForwardProtoDecl = val; }
979
980   // Location information, modeled after the Stmt API.
981   SourceLocation getLocStart() const { return getAtStartLoc(); } // '@'protocol
982   SourceLocation getLocEnd() const { return EndLoc; }
983   void setLocEnd(SourceLocation LE) { EndLoc = LE; }
984
985   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
986   static bool classof(const ObjCProtocolDecl *D) { return true; }
987   static bool classofKind(Kind K) { return K == ObjCProtocol; }
988 };
989
990 /// ObjCClassDecl - Specifies a list of forward class declarations. For example:
991 ///
992 /// @class NSCursor, NSImage, NSPasteboard, NSWindow;
993 ///
994 class ObjCClassDecl : public Decl {
995 public:
996   class ObjCClassRef {
997     ObjCInterfaceDecl *ID;
998     SourceLocation L;
999   public:
1000     ObjCClassRef(ObjCInterfaceDecl *d, SourceLocation l) : ID(d), L(l) {}
1001     SourceLocation getLocation() const { return L; }
1002     ObjCInterfaceDecl *getInterface() const { return ID; }
1003   };
1004 private:
1005   ObjCClassRef *ForwardDecl;
1006
1007   ObjCClassDecl(DeclContext *DC, SourceLocation L,
1008                 ObjCInterfaceDecl *const Elt, const SourceLocation Loc,                
1009                 ASTContext &C);
1010 public:
1011   static ObjCClassDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L,
1012                                ObjCInterfaceDecl *const Elt = 0,
1013                                const SourceLocation Locs = SourceLocation());
1014     
1015   ObjCInterfaceDecl *getForwardInterfaceDecl() { return ForwardDecl->getInterface(); }
1016   ObjCClassRef *getForwardDecl() { return ForwardDecl; }
1017   void setClass(ASTContext &C, ObjCInterfaceDecl*const Cls,
1018                 const SourceLocation Locs);
1019   
1020   virtual SourceRange getSourceRange() const;
1021
1022   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1023   static bool classof(const ObjCClassDecl *D) { return true; }
1024   static bool classofKind(Kind K) { return K == ObjCClass; }
1025 };
1026
1027 /// ObjCForwardProtocolDecl - Specifies a list of forward protocol declarations.
1028 /// For example:
1029 ///
1030 /// @protocol NSTextInput, NSChangeSpelling, NSDraggingInfo;
1031 ///
1032 class ObjCForwardProtocolDecl : public Decl {
1033   ObjCProtocolList ReferencedProtocols;
1034
1035   ObjCForwardProtocolDecl(DeclContext *DC, SourceLocation L,
1036                           ObjCProtocolDecl *const *Elts, unsigned nElts,
1037                           const SourceLocation *Locs, ASTContext &C);
1038
1039 public:
1040   static ObjCForwardProtocolDecl *Create(ASTContext &C, DeclContext *DC,
1041                                          SourceLocation L,
1042                                          ObjCProtocolDecl *const *Elts,
1043                                          unsigned Num,
1044                                          const SourceLocation *Locs);
1045
1046   static ObjCForwardProtocolDecl *Create(ASTContext &C, DeclContext *DC,
1047                                          SourceLocation L) {
1048     return Create(C, DC, L, 0, 0, 0);
1049   }
1050
1051   typedef ObjCProtocolList::iterator protocol_iterator;
1052   protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();}
1053   protocol_iterator protocol_end() const { return ReferencedProtocols.end(); }
1054   typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
1055   protocol_loc_iterator protocol_loc_begin() const { 
1056     return ReferencedProtocols.loc_begin(); 
1057   }
1058   protocol_loc_iterator protocol_loc_end() const { 
1059     return ReferencedProtocols.loc_end(); 
1060   }
1061
1062   unsigned protocol_size() const { return ReferencedProtocols.size(); }
1063
1064   /// setProtocolList - Set the list of forward protocols.
1065   void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num,
1066                        const SourceLocation *Locs, ASTContext &C) {
1067     ReferencedProtocols.set(List, Num, Locs, C);
1068   }
1069   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1070   static bool classof(const ObjCForwardProtocolDecl *D) { return true; }
1071   static bool classofKind(Kind K) { return K == ObjCForwardProtocol; }
1072 };
1073
1074 /// ObjCCategoryDecl - Represents a category declaration. A category allows
1075 /// you to add methods to an existing class (without subclassing or modifying
1076 /// the original class interface or implementation:-). Categories don't allow
1077 /// you to add instance data. The following example adds "myMethod" to all
1078 /// NSView's within a process:
1079 ///
1080 /// @interface NSView (MyViewMethods)
1081 /// - myMethod;
1082 /// @end
1083 ///
1084 /// Categories also allow you to split the implementation of a class across
1085 /// several files (a feature more naturally supported in C++).
1086 ///
1087 /// Categories were originally inspired by dynamic languages such as Common
1088 /// Lisp and Smalltalk.  More traditional class-based languages (C++, Java)
1089 /// don't support this level of dynamism, which is both powerful and dangerous.
1090 ///
1091 class ObjCCategoryDecl : public ObjCContainerDecl {
1092   /// Interface belonging to this category
1093   ObjCInterfaceDecl *ClassInterface;
1094
1095   /// referenced protocols in this category.
1096   ObjCProtocolList ReferencedProtocols;
1097
1098   /// Next category belonging to this class.
1099   /// FIXME: this should not be a singly-linked list.  Move storage elsewhere.
1100   ObjCCategoryDecl *NextClassCategory;
1101
1102   /// true of class extension has at least one bitfield ivar.
1103   bool HasSynthBitfield : 1;
1104
1105   /// \brief The location of the category name in this declaration.
1106   SourceLocation CategoryNameLoc;
1107
1108   ObjCCategoryDecl(DeclContext *DC, SourceLocation AtLoc, 
1109                    SourceLocation ClassNameLoc, SourceLocation CategoryNameLoc,
1110                    IdentifierInfo *Id, ObjCInterfaceDecl *IDecl)
1111     : ObjCContainerDecl(ObjCCategory, DC, Id, ClassNameLoc, AtLoc),
1112       ClassInterface(IDecl), NextClassCategory(0), HasSynthBitfield(false),
1113       CategoryNameLoc(CategoryNameLoc) {
1114   }
1115 public:
1116
1117   static ObjCCategoryDecl *Create(ASTContext &C, DeclContext *DC,
1118                                   SourceLocation AtLoc, 
1119                                   SourceLocation ClassNameLoc,
1120                                   SourceLocation CategoryNameLoc,
1121                                   IdentifierInfo *Id,
1122                                   ObjCInterfaceDecl *IDecl);
1123   static ObjCCategoryDecl *Create(ASTContext &C, EmptyShell Empty);
1124
1125   ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
1126   const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; }
1127
1128   ObjCCategoryImplDecl *getImplementation() const;
1129   void setImplementation(ObjCCategoryImplDecl *ImplD);
1130
1131   /// setProtocolList - Set the list of protocols that this interface
1132   /// implements.
1133   void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num,
1134                        const SourceLocation *Locs, ASTContext &C) {
1135     ReferencedProtocols.set(List, Num, Locs, C);
1136   }
1137
1138   const ObjCProtocolList &getReferencedProtocols() const {
1139     return ReferencedProtocols;
1140   }
1141
1142   typedef ObjCProtocolList::iterator protocol_iterator;
1143   protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();}
1144   protocol_iterator protocol_end() const { return ReferencedProtocols.end(); }
1145   unsigned protocol_size() const { return ReferencedProtocols.size(); }
1146   typedef ObjCProtocolList::loc_iterator protocol_loc_iterator;
1147   protocol_loc_iterator protocol_loc_begin() const { 
1148     return ReferencedProtocols.loc_begin(); 
1149   }
1150   protocol_loc_iterator protocol_loc_end() const { 
1151     return ReferencedProtocols.loc_end(); 
1152   }
1153
1154   ObjCCategoryDecl *getNextClassCategory() const { return NextClassCategory; }
1155
1156   bool IsClassExtension() const { return getIdentifier() == 0; }
1157   const ObjCCategoryDecl *getNextClassExtension() const;
1158   
1159   bool hasSynthBitfield() const { return HasSynthBitfield; }
1160   void setHasSynthBitfield (bool val) { HasSynthBitfield = val; }
1161   
1162   typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
1163   ivar_iterator ivar_begin() const {
1164     return ivar_iterator(decls_begin());
1165   }
1166   ivar_iterator ivar_end() const {
1167     return ivar_iterator(decls_end());
1168   }
1169   unsigned ivar_size() const {
1170     return std::distance(ivar_begin(), ivar_end());
1171   }
1172   bool ivar_empty() const {
1173     return ivar_begin() == ivar_end();
1174   }
1175
1176   SourceLocation getCategoryNameLoc() const { return CategoryNameLoc; }
1177   void setCategoryNameLoc(SourceLocation Loc) { CategoryNameLoc = Loc; }
1178
1179   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1180   static bool classof(const ObjCCategoryDecl *D) { return true; }
1181   static bool classofKind(Kind K) { return K == ObjCCategory; }
1182
1183   friend class ASTDeclReader;
1184   friend class ASTDeclWriter;
1185 };
1186
1187 class ObjCImplDecl : public ObjCContainerDecl {
1188   /// Class interface for this class/category implementation
1189   ObjCInterfaceDecl *ClassInterface;
1190
1191 protected:
1192   ObjCImplDecl(Kind DK, DeclContext *DC,
1193                ObjCInterfaceDecl *classInterface,
1194                SourceLocation nameLoc, SourceLocation atStartLoc)
1195     : ObjCContainerDecl(DK, DC,
1196                         classInterface? classInterface->getIdentifier() : 0,
1197                         nameLoc, atStartLoc),
1198       ClassInterface(classInterface) {}
1199
1200 public:
1201   const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; }
1202   ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
1203   void setClassInterface(ObjCInterfaceDecl *IFace);
1204
1205   void addInstanceMethod(ObjCMethodDecl *method) {
1206     // FIXME: Context should be set correctly before we get here.
1207     method->setLexicalDeclContext(this);
1208     addDecl(method);
1209   }
1210   void addClassMethod(ObjCMethodDecl *method) {
1211     // FIXME: Context should be set correctly before we get here.
1212     method->setLexicalDeclContext(this);
1213     addDecl(method);
1214   }
1215
1216   void addPropertyImplementation(ObjCPropertyImplDecl *property);
1217
1218   ObjCPropertyImplDecl *FindPropertyImplDecl(IdentifierInfo *propertyId) const;
1219   ObjCPropertyImplDecl *FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const;
1220
1221   // Iterator access to properties.
1222   typedef specific_decl_iterator<ObjCPropertyImplDecl> propimpl_iterator;
1223   propimpl_iterator propimpl_begin() const {
1224     return propimpl_iterator(decls_begin());
1225   }
1226   propimpl_iterator propimpl_end() const {
1227     return propimpl_iterator(decls_end());
1228   }
1229
1230   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1231   static bool classof(const ObjCImplDecl *D) { return true; }
1232   static bool classofKind(Kind K) {
1233     return K >= firstObjCImpl && K <= lastObjCImpl;
1234   }
1235 };
1236
1237 /// ObjCCategoryImplDecl - An object of this class encapsulates a category
1238 /// @implementation declaration. If a category class has declaration of a
1239 /// property, its implementation must be specified in the category's
1240 /// @implementation declaration. Example:
1241 /// @interface I @end
1242 /// @interface I(CATEGORY)
1243 ///    @property int p1, d1;
1244 /// @end
1245 /// @implementation I(CATEGORY)
1246 ///  @dynamic p1,d1;
1247 /// @end
1248 ///
1249 /// ObjCCategoryImplDecl
1250 class ObjCCategoryImplDecl : public ObjCImplDecl {
1251   // Category name
1252   IdentifierInfo *Id;
1253
1254   ObjCCategoryImplDecl(DeclContext *DC, IdentifierInfo *Id,
1255                        ObjCInterfaceDecl *classInterface,
1256                        SourceLocation nameLoc, SourceLocation atStartLoc)
1257     : ObjCImplDecl(ObjCCategoryImpl, DC, classInterface, nameLoc, atStartLoc),
1258       Id(Id) {}
1259 public:
1260   static ObjCCategoryImplDecl *Create(ASTContext &C, DeclContext *DC,
1261                                       IdentifierInfo *Id,
1262                                       ObjCInterfaceDecl *classInterface,
1263                                       SourceLocation nameLoc,
1264                                       SourceLocation atStartLoc);
1265
1266   /// getIdentifier - Get the identifier that names the category
1267   /// interface associated with this implementation.
1268   /// FIXME: This is a bad API, we are overriding the NamedDecl::getIdentifier()
1269   /// to mean something different. For example:
1270   /// ((NamedDecl *)SomeCategoryImplDecl)->getIdentifier() 
1271   /// returns the class interface name, whereas 
1272   /// ((ObjCCategoryImplDecl *)SomeCategoryImplDecl)->getIdentifier() 
1273   /// returns the category name.
1274   IdentifierInfo *getIdentifier() const {
1275     return Id;
1276   }
1277   void setIdentifier(IdentifierInfo *II) { Id = II; }
1278
1279   ObjCCategoryDecl *getCategoryDecl() const;
1280
1281   /// getName - Get the name of identifier for the class interface associated
1282   /// with this implementation as a StringRef.
1283   //
1284   // FIXME: This is a bad API, we are overriding the NamedDecl::getName, to mean
1285   // something different.
1286   StringRef getName() const {
1287     return Id ? Id->getNameStart() : "";
1288   }
1289
1290   /// getNameAsCString - Get the name of identifier for the class
1291   /// interface associated with this implementation as a C string
1292   /// (const char*).
1293   //
1294   // FIXME: Deprecated, move clients to getName().
1295   const char *getNameAsCString() const {
1296     return Id ? Id->getNameStart() : "";
1297   }
1298
1299   /// @brief Get the name of the class associated with this interface.
1300   //
1301   // FIXME: Deprecated, move clients to getName().
1302   std::string getNameAsString() const {
1303     return getName();
1304   }
1305
1306   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1307   static bool classof(const ObjCCategoryImplDecl *D) { return true; }
1308   static bool classofKind(Kind K) { return K == ObjCCategoryImpl;}
1309 };
1310
1311 raw_ostream &operator<<(raw_ostream &OS,
1312                               const ObjCCategoryImplDecl *CID);
1313
1314 /// ObjCImplementationDecl - Represents a class definition - this is where
1315 /// method definitions are specified. For example:
1316 ///
1317 /// @code
1318 /// @implementation MyClass
1319 /// - (void)myMethod { /* do something */ }
1320 /// @end
1321 /// @endcode
1322 ///
1323 /// Typically, instance variables are specified in the class interface,
1324 /// *not* in the implementation. Nevertheless (for legacy reasons), we
1325 /// allow instance variables to be specified in the implementation.  When
1326 /// specified, they need to be *identical* to the interface.
1327 ///
1328 class ObjCImplementationDecl : public ObjCImplDecl {
1329   /// Implementation Class's super class.
1330   ObjCInterfaceDecl *SuperClass;
1331   /// Support for ivar initialization.
1332   /// IvarInitializers - The arguments used to initialize the ivars
1333   CXXCtorInitializer **IvarInitializers;
1334   unsigned NumIvarInitializers;
1335
1336   /// true if class has a .cxx_[construct,destruct] method.
1337   bool HasCXXStructors : 1;
1338   
1339   /// true of class extension has at least one bitfield ivar.
1340   bool HasSynthBitfield : 1;
1341   
1342   ObjCImplementationDecl(DeclContext *DC,
1343                          ObjCInterfaceDecl *classInterface,
1344                          ObjCInterfaceDecl *superDecl,
1345                          SourceLocation nameLoc, SourceLocation atStartLoc)
1346     : ObjCImplDecl(ObjCImplementation, DC, classInterface, nameLoc, atStartLoc),
1347        SuperClass(superDecl), IvarInitializers(0), NumIvarInitializers(0),
1348        HasCXXStructors(false), HasSynthBitfield(false) {}
1349 public:
1350   static ObjCImplementationDecl *Create(ASTContext &C, DeclContext *DC,
1351                                         ObjCInterfaceDecl *classInterface,
1352                                         ObjCInterfaceDecl *superDecl,
1353                                         SourceLocation nameLoc,
1354                                         SourceLocation atStartLoc);
1355   
1356   /// init_iterator - Iterates through the ivar initializer list.
1357   typedef CXXCtorInitializer **init_iterator;
1358   
1359   /// init_const_iterator - Iterates through the ivar initializer list.
1360   typedef CXXCtorInitializer * const * init_const_iterator;
1361   
1362   /// init_begin() - Retrieve an iterator to the first initializer.
1363   init_iterator       init_begin()       { return IvarInitializers; }
1364   /// begin() - Retrieve an iterator to the first initializer.
1365   init_const_iterator init_begin() const { return IvarInitializers; }
1366   
1367   /// init_end() - Retrieve an iterator past the last initializer.
1368   init_iterator       init_end()       {
1369     return IvarInitializers + NumIvarInitializers;
1370   }
1371   /// end() - Retrieve an iterator past the last initializer.
1372   init_const_iterator init_end() const {
1373     return IvarInitializers + NumIvarInitializers;
1374   }
1375   /// getNumArgs - Number of ivars which must be initialized.
1376   unsigned getNumIvarInitializers() const {
1377     return NumIvarInitializers;
1378   }
1379   
1380   void setNumIvarInitializers(unsigned numNumIvarInitializers) {
1381     NumIvarInitializers = numNumIvarInitializers;
1382   }
1383   
1384   void setIvarInitializers(ASTContext &C,
1385                            CXXCtorInitializer ** initializers,
1386                            unsigned numInitializers);
1387
1388   bool hasCXXStructors() const { return HasCXXStructors; }
1389   void setHasCXXStructors(bool val) { HasCXXStructors = val; }
1390   
1391   bool hasSynthBitfield() const { return HasSynthBitfield; }
1392   void setHasSynthBitfield (bool val) { HasSynthBitfield = val; }
1393     
1394   /// getIdentifier - Get the identifier that names the class
1395   /// interface associated with this implementation.
1396   IdentifierInfo *getIdentifier() const {
1397     return getClassInterface()->getIdentifier();
1398   }
1399
1400   /// getName - Get the name of identifier for the class interface associated
1401   /// with this implementation as a StringRef.
1402   //
1403   // FIXME: This is a bad API, we are overriding the NamedDecl::getName, to mean
1404   // something different.
1405   StringRef getName() const {
1406     assert(getIdentifier() && "Name is not a simple identifier");
1407     return getIdentifier()->getName();
1408   }
1409
1410   /// getNameAsCString - Get the name of identifier for the class
1411   /// interface associated with this implementation as a C string
1412   /// (const char*).
1413   //
1414   // FIXME: Move to StringRef API.
1415   const char *getNameAsCString() const {
1416     return getName().data();
1417   }
1418
1419   /// @brief Get the name of the class associated with this interface.
1420   //
1421   // FIXME: Move to StringRef API.
1422   std::string getNameAsString() const {
1423     return getName();
1424   }
1425
1426   const ObjCInterfaceDecl *getSuperClass() const { return SuperClass; }
1427   ObjCInterfaceDecl *getSuperClass() { return SuperClass; }
1428
1429   void setSuperClass(ObjCInterfaceDecl * superCls) { SuperClass = superCls; }
1430
1431   typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
1432   ivar_iterator ivar_begin() const {
1433     return ivar_iterator(decls_begin());
1434   }
1435   ivar_iterator ivar_end() const {
1436     return ivar_iterator(decls_end());
1437   }
1438   unsigned ivar_size() const {
1439     return std::distance(ivar_begin(), ivar_end());
1440   }
1441   bool ivar_empty() const {
1442     return ivar_begin() == ivar_end();
1443   }
1444
1445   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1446   static bool classof(const ObjCImplementationDecl *D) { return true; }
1447   static bool classofKind(Kind K) { return K == ObjCImplementation; }
1448
1449   friend class ASTDeclReader;
1450   friend class ASTDeclWriter;
1451 };
1452
1453 raw_ostream &operator<<(raw_ostream &OS,
1454                               const ObjCImplementationDecl *ID);
1455
1456 /// ObjCCompatibleAliasDecl - Represents alias of a class. This alias is
1457 /// declared as @compatibility_alias alias class.
1458 class ObjCCompatibleAliasDecl : public NamedDecl {
1459   /// Class that this is an alias of.
1460   ObjCInterfaceDecl *AliasedClass;
1461
1462   ObjCCompatibleAliasDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
1463                           ObjCInterfaceDecl* aliasedClass)
1464     : NamedDecl(ObjCCompatibleAlias, DC, L, Id), AliasedClass(aliasedClass) {}
1465 public:
1466   static ObjCCompatibleAliasDecl *Create(ASTContext &C, DeclContext *DC,
1467                                          SourceLocation L, IdentifierInfo *Id,
1468                                          ObjCInterfaceDecl* aliasedClass);
1469
1470   const ObjCInterfaceDecl *getClassInterface() const { return AliasedClass; }
1471   ObjCInterfaceDecl *getClassInterface() { return AliasedClass; }
1472   void setClassInterface(ObjCInterfaceDecl *D) { AliasedClass = D; }
1473
1474   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1475   static bool classof(const ObjCCompatibleAliasDecl *D) { return true; }
1476   static bool classofKind(Kind K) { return K == ObjCCompatibleAlias; }
1477
1478 };
1479
1480 /// ObjCPropertyDecl - Represents one property declaration in an interface.
1481 /// For example:
1482 /// @property (assign, readwrite) int MyProperty;
1483 ///
1484 class ObjCPropertyDecl : public NamedDecl {
1485 public:
1486   enum PropertyAttributeKind {
1487     OBJC_PR_noattr    = 0x00,
1488     OBJC_PR_readonly  = 0x01,
1489     OBJC_PR_getter    = 0x02,
1490     OBJC_PR_assign    = 0x04,
1491     OBJC_PR_readwrite = 0x08,
1492     OBJC_PR_retain    = 0x10,
1493     OBJC_PR_copy      = 0x20,
1494     OBJC_PR_nonatomic = 0x40,
1495     OBJC_PR_setter    = 0x80,
1496     OBJC_PR_atomic    = 0x100,
1497     OBJC_PR_weak      = 0x200,
1498     OBJC_PR_strong    = 0x400,
1499     OBJC_PR_unsafe_unretained = 0x800
1500     // Adding a property should change NumPropertyAttrsBits
1501   };
1502
1503   enum {
1504     /// \brief Number of bits fitting all the property attributes.
1505     NumPropertyAttrsBits = 12
1506   };
1507
1508   enum SetterKind { Assign, Retain, Copy, Weak };
1509   enum PropertyControl { None, Required, Optional };
1510 private:
1511   SourceLocation AtLoc;   // location of @property
1512   TypeSourceInfo *DeclType;
1513   unsigned PropertyAttributes : NumPropertyAttrsBits;
1514   unsigned PropertyAttributesAsWritten : NumPropertyAttrsBits;
1515   // @required/@optional
1516   unsigned PropertyImplementation : 2;
1517
1518   Selector GetterName;    // getter name of NULL if no getter
1519   Selector SetterName;    // setter name of NULL if no setter
1520
1521   ObjCMethodDecl *GetterMethodDecl; // Declaration of getter instance method
1522   ObjCMethodDecl *SetterMethodDecl; // Declaration of setter instance method
1523   ObjCIvarDecl *PropertyIvarDecl;   // Synthesize ivar for this property
1524
1525   ObjCPropertyDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
1526                    SourceLocation AtLocation, TypeSourceInfo *T)
1527     : NamedDecl(ObjCProperty, DC, L, Id), AtLoc(AtLocation), DeclType(T),
1528       PropertyAttributes(OBJC_PR_noattr), 
1529       PropertyAttributesAsWritten(OBJC_PR_noattr),
1530       PropertyImplementation(None),
1531       GetterName(Selector()),
1532       SetterName(Selector()),
1533       GetterMethodDecl(0), SetterMethodDecl(0) , PropertyIvarDecl(0) {}
1534 public:
1535   static ObjCPropertyDecl *Create(ASTContext &C, DeclContext *DC,
1536                                   SourceLocation L,
1537                                   IdentifierInfo *Id, SourceLocation AtLocation,
1538                                   TypeSourceInfo *T,
1539                                   PropertyControl propControl = None);
1540   SourceLocation getAtLoc() const { return AtLoc; }
1541   void setAtLoc(SourceLocation L) { AtLoc = L; }
1542   
1543   TypeSourceInfo *getTypeSourceInfo() const { return DeclType; }
1544   QualType getType() const { return DeclType->getType(); }
1545   void setType(TypeSourceInfo *T) { DeclType = T; }
1546
1547   PropertyAttributeKind getPropertyAttributes() const {
1548     return PropertyAttributeKind(PropertyAttributes);
1549   }
1550   void setPropertyAttributes(PropertyAttributeKind PRVal) {
1551     PropertyAttributes |= PRVal;
1552   }
1553
1554   PropertyAttributeKind getPropertyAttributesAsWritten() const {
1555     return PropertyAttributeKind(PropertyAttributesAsWritten);
1556   }
1557
1558   bool hasWrittenStorageAttribute() const {
1559     return PropertyAttributesAsWritten & (OBJC_PR_assign | OBJC_PR_copy |
1560         OBJC_PR_unsafe_unretained | OBJC_PR_retain | OBJC_PR_strong |
1561         OBJC_PR_weak);
1562   }
1563   
1564   void setPropertyAttributesAsWritten(PropertyAttributeKind PRVal) {
1565     PropertyAttributesAsWritten = PRVal;
1566   }
1567   
1568  void makeitReadWriteAttribute(void) {
1569     PropertyAttributes &= ~OBJC_PR_readonly;
1570     PropertyAttributes |= OBJC_PR_readwrite;
1571  }
1572
1573   // Helper methods for accessing attributes.
1574
1575   /// isReadOnly - Return true iff the property has a setter.
1576   bool isReadOnly() const {
1577     return (PropertyAttributes & OBJC_PR_readonly);
1578   }
1579
1580   /// isAtomic - Return true if the property is atomic.
1581   bool isAtomic() const {
1582     return (PropertyAttributes & OBJC_PR_atomic);
1583   }
1584
1585   /// isRetaining - Return true if the property retains its value.
1586   bool isRetaining() const {
1587     return (PropertyAttributes &
1588             (OBJC_PR_retain | OBJC_PR_strong | OBJC_PR_copy));
1589   }
1590
1591   /// getSetterKind - Return the method used for doing assignment in
1592   /// the property setter. This is only valid if the property has been
1593   /// defined to have a setter.
1594   SetterKind getSetterKind() const {
1595     if (PropertyAttributes & OBJC_PR_strong)
1596       return getType()->isBlockPointerType() ? Copy : Retain;
1597     if (PropertyAttributes & OBJC_PR_retain)
1598       return Retain;
1599     if (PropertyAttributes & OBJC_PR_copy)
1600       return Copy;
1601     if (PropertyAttributes & OBJC_PR_weak)
1602       return Weak;
1603     return Assign;
1604   }
1605
1606   Selector getGetterName() const { return GetterName; }
1607   void setGetterName(Selector Sel) { GetterName = Sel; }
1608
1609   Selector getSetterName() const { return SetterName; }
1610   void setSetterName(Selector Sel) { SetterName = Sel; }
1611
1612   ObjCMethodDecl *getGetterMethodDecl() const { return GetterMethodDecl; }
1613   void setGetterMethodDecl(ObjCMethodDecl *gDecl) { GetterMethodDecl = gDecl; }
1614
1615   ObjCMethodDecl *getSetterMethodDecl() const { return SetterMethodDecl; }
1616   void setSetterMethodDecl(ObjCMethodDecl *gDecl) { SetterMethodDecl = gDecl; }
1617
1618   // Related to @optional/@required declared in @protocol
1619   void setPropertyImplementation(PropertyControl pc) {
1620     PropertyImplementation = pc;
1621   }
1622   PropertyControl getPropertyImplementation() const {
1623     return PropertyControl(PropertyImplementation);
1624   }
1625
1626   void setPropertyIvarDecl(ObjCIvarDecl *Ivar) {
1627     PropertyIvarDecl = Ivar;
1628   }
1629   ObjCIvarDecl *getPropertyIvarDecl() const {
1630     return PropertyIvarDecl;
1631   }
1632
1633   virtual SourceRange getSourceRange() const {
1634     return SourceRange(AtLoc, getLocation());
1635   }
1636
1637   /// Lookup a property by name in the specified DeclContext.
1638   static ObjCPropertyDecl *findPropertyDecl(const DeclContext *DC,
1639                                             IdentifierInfo *propertyID);
1640
1641   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1642   static bool classof(const ObjCPropertyDecl *D) { return true; }
1643   static bool classofKind(Kind K) { return K == ObjCProperty; }
1644 };
1645
1646 /// ObjCPropertyImplDecl - Represents implementation declaration of a property
1647 /// in a class or category implementation block. For example:
1648 /// @synthesize prop1 = ivar1;
1649 ///
1650 class ObjCPropertyImplDecl : public Decl {
1651 public:
1652   enum Kind {
1653     Synthesize,
1654     Dynamic
1655   };
1656 private:
1657   SourceLocation AtLoc;   // location of @synthesize or @dynamic
1658   
1659   /// \brief For @synthesize, the location of the ivar, if it was written in
1660   /// the source code.
1661   ///
1662   /// \code
1663   /// @synthesize int a = b
1664   /// \endcode
1665   SourceLocation IvarLoc;
1666   
1667   /// Property declaration being implemented
1668   ObjCPropertyDecl *PropertyDecl;
1669
1670   /// Null for @dynamic. Required for @synthesize.
1671   ObjCIvarDecl *PropertyIvarDecl;
1672   
1673   /// Null for @dynamic. Non-null if property must be copy-constructed in getter
1674   Expr *GetterCXXConstructor;
1675   
1676   /// Null for @dynamic. Non-null if property has assignment operator to call
1677   /// in Setter synthesis.
1678   Expr *SetterCXXAssignment;
1679
1680   ObjCPropertyImplDecl(DeclContext *DC, SourceLocation atLoc, SourceLocation L,
1681                        ObjCPropertyDecl *property,
1682                        Kind PK,
1683                        ObjCIvarDecl *ivarDecl,
1684                        SourceLocation ivarLoc)
1685     : Decl(ObjCPropertyImpl, DC, L), AtLoc(atLoc),
1686       IvarLoc(ivarLoc), PropertyDecl(property), PropertyIvarDecl(ivarDecl), 
1687       GetterCXXConstructor(0), SetterCXXAssignment(0) {
1688     assert (PK == Dynamic || PropertyIvarDecl);
1689   }
1690
1691 public:
1692   static ObjCPropertyImplDecl *Create(ASTContext &C, DeclContext *DC,
1693                                       SourceLocation atLoc, SourceLocation L,
1694                                       ObjCPropertyDecl *property,
1695                                       Kind PK,
1696                                       ObjCIvarDecl *ivarDecl,
1697                                       SourceLocation ivarLoc);
1698
1699   virtual SourceRange getSourceRange() const;
1700   
1701   SourceLocation getLocStart() const { return AtLoc; }
1702   void setAtLoc(SourceLocation Loc) { AtLoc = Loc; }
1703
1704   ObjCPropertyDecl *getPropertyDecl() const {
1705     return PropertyDecl;
1706   }
1707   void setPropertyDecl(ObjCPropertyDecl *Prop) { PropertyDecl = Prop; }
1708
1709   Kind getPropertyImplementation() const {
1710     return PropertyIvarDecl ? Synthesize : Dynamic;
1711   }
1712
1713   ObjCIvarDecl *getPropertyIvarDecl() const {
1714     return PropertyIvarDecl;
1715   }
1716   SourceLocation getPropertyIvarDeclLoc() const { return IvarLoc; }
1717   
1718   void setPropertyIvarDecl(ObjCIvarDecl *Ivar,
1719                            SourceLocation IvarLoc) { 
1720     PropertyIvarDecl = Ivar; 
1721     this->IvarLoc = IvarLoc;
1722   }
1723   
1724   Expr *getGetterCXXConstructor() const {
1725     return GetterCXXConstructor;
1726   }
1727   void setGetterCXXConstructor(Expr *getterCXXConstructor) {
1728     GetterCXXConstructor = getterCXXConstructor;
1729   }
1730
1731   Expr *getSetterCXXAssignment() const {
1732     return SetterCXXAssignment;
1733   }
1734   void setSetterCXXAssignment(Expr *setterCXXAssignment) {
1735     SetterCXXAssignment = setterCXXAssignment;
1736   }
1737   
1738   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1739   static bool classof(const ObjCPropertyImplDecl *D) { return true; }
1740   static bool classofKind(Decl::Kind K) { return K == ObjCPropertyImpl; }
1741   
1742   friend class ASTDeclReader;
1743 };
1744
1745 }  // end namespace clang
1746 #endif