]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/AST/Decl.h
Merge ACPICA 20100915.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / AST / Decl.h
1 //===--- Decl.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 Decl subclasses.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_CLANG_AST_DECL_H
15 #define LLVM_CLANG_AST_DECL_H
16
17 #include "clang/AST/APValue.h"
18 #include "clang/AST/DeclBase.h"
19 #include "clang/AST/Redeclarable.h"
20 #include "clang/AST/DeclarationName.h"
21 #include "clang/AST/ExternalASTSource.h"
22 #include "clang/Basic/Linkage.h"
23
24 namespace clang {
25 class CXXTemporary;
26 class Expr;
27 class FunctionTemplateDecl;
28 class Stmt;
29 class CompoundStmt;
30 class StringLiteral;
31 class NestedNameSpecifier;
32 class TemplateParameterList;
33 class TemplateArgumentList;
34 class MemberSpecializationInfo;
35 class FunctionTemplateSpecializationInfo;
36 class DependentFunctionTemplateSpecializationInfo;
37 class TypeLoc;
38 class UnresolvedSetImpl;
39
40 /// \brief A container of type source information.
41 ///
42 /// A client can read the relevant info using TypeLoc wrappers, e.g:
43 /// @code
44 /// TypeLoc TL = TypeSourceInfo->getTypeLoc();
45 /// if (PointerLoc *PL = dyn_cast<PointerLoc>(&TL))
46 ///   PL->getStarLoc().print(OS, SrcMgr);
47 /// @endcode
48 ///
49 class TypeSourceInfo {
50   QualType Ty;
51   // Contains a memory block after the class, used for type source information,
52   // allocated by ASTContext.
53   friend class ASTContext;
54   TypeSourceInfo(QualType ty) : Ty(ty) { }
55 public:
56   /// \brief Return the type wrapped by this type source info.
57   QualType getType() const { return Ty; }
58
59   /// \brief Return the TypeLoc wrapper for the type source info.
60   TypeLoc getTypeLoc() const; // implemented in TypeLoc.h
61 };
62
63 /// TranslationUnitDecl - The top declaration context.
64 class TranslationUnitDecl : public Decl, public DeclContext {
65   ASTContext &Ctx;
66
67   /// The (most recently entered) anonymous namespace for this
68   /// translation unit, if one has been created.
69   NamespaceDecl *AnonymousNamespace;
70
71   explicit TranslationUnitDecl(ASTContext &ctx)
72     : Decl(TranslationUnit, 0, SourceLocation()),
73       DeclContext(TranslationUnit),
74       Ctx(ctx), AnonymousNamespace(0) {}
75 public:
76   ASTContext &getASTContext() const { return Ctx; }
77
78   NamespaceDecl *getAnonymousNamespace() const { return AnonymousNamespace; }
79   void setAnonymousNamespace(NamespaceDecl *D) { AnonymousNamespace = D; }
80
81   static TranslationUnitDecl *Create(ASTContext &C);
82   // Implement isa/cast/dyncast/etc.
83   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
84   static bool classof(const TranslationUnitDecl *D) { return true; }
85   static bool classofKind(Kind K) { return K == TranslationUnit; }
86   static DeclContext *castToDeclContext(const TranslationUnitDecl *D) {
87     return static_cast<DeclContext *>(const_cast<TranslationUnitDecl*>(D));
88   }
89   static TranslationUnitDecl *castFromDeclContext(const DeclContext *DC) {
90     return static_cast<TranslationUnitDecl *>(const_cast<DeclContext*>(DC));
91   }
92 };
93
94 /// NamedDecl - This represents a decl with a name.  Many decls have names such
95 /// as ObjCMethodDecl, but not @class, etc.
96 class NamedDecl : public Decl {
97   /// Name - The name of this declaration, which is typically a normal
98   /// identifier but may also be a special kind of name (C++
99   /// constructor, Objective-C selector, etc.)
100   DeclarationName Name;
101
102 protected:
103   NamedDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N)
104     : Decl(DK, DC, L), Name(N) { }
105
106 public:
107   /// getIdentifier - Get the identifier that names this declaration,
108   /// if there is one. This will return NULL if this declaration has
109   /// no name (e.g., for an unnamed class) or if the name is a special
110   /// name (C++ constructor, Objective-C selector, etc.).
111   IdentifierInfo *getIdentifier() const { return Name.getAsIdentifierInfo(); }
112
113   /// getName - Get the name of identifier for this declaration as a StringRef.
114   /// This requires that the declaration have a name and that it be a simple
115   /// identifier.
116   llvm::StringRef getName() const {
117     assert(Name.isIdentifier() && "Name is not a simple identifier");
118     return getIdentifier() ? getIdentifier()->getName() : "";
119   }
120
121   /// getNameAsCString - Get the name of identifier for this declaration as a
122   /// C string (const char*).  This requires that the declaration have a name
123   /// and that it be a simple identifier.
124   //
125   // FIXME: Deprecated, move clients to getName().
126   const char *getNameAsCString() const {
127     assert(Name.isIdentifier() && "Name is not a simple identifier");
128     return getIdentifier() ? getIdentifier()->getNameStart() : "";
129   }
130
131   /// getNameAsString - Get a human-readable name for the declaration, even if
132   /// it is one of the special kinds of names (C++ constructor, Objective-C
133   /// selector, etc).  Creating this name requires expensive string
134   /// manipulation, so it should be called only when performance doesn't matter.
135   /// For simple declarations, getNameAsCString() should suffice.
136   //
137   // FIXME: This function should be renamed to indicate that it is not just an
138   // alternate form of getName(), and clients should move as appropriate.
139   //
140   // FIXME: Deprecated, move clients to getName().
141   std::string getNameAsString() const { return Name.getAsString(); }
142
143   void printName(llvm::raw_ostream &os) const { return Name.printName(os); }
144
145   /// getDeclName - Get the actual, stored name of the declaration,
146   /// which may be a special name.
147   DeclarationName getDeclName() const { return Name; }
148
149   /// \brief Set the name of this declaration.
150   void setDeclName(DeclarationName N) { Name = N; }
151
152   /// getQualifiedNameAsString - Returns human-readable qualified name for
153   /// declaration, like A::B::i, for i being member of namespace A::B.
154   /// If declaration is not member of context which can be named (record,
155   /// namespace), it will return same result as getNameAsString().
156   /// Creating this name is expensive, so it should be called only when
157   /// performance doesn't matter.
158   std::string getQualifiedNameAsString() const;
159   std::string getQualifiedNameAsString(const PrintingPolicy &Policy) const;
160
161   /// getNameForDiagnostic - Appends a human-readable name for this
162   /// declaration into the given string.
163   ///
164   /// This is the method invoked by Sema when displaying a NamedDecl
165   /// in a diagnostic.  It does not necessarily produce the same
166   /// result as getNameAsString(); for example, class template
167   /// specializations are printed with their template arguments.
168   ///
169   /// TODO: use an API that doesn't require so many temporary strings
170   virtual void getNameForDiagnostic(std::string &S,
171                                     const PrintingPolicy &Policy,
172                                     bool Qualified) const {
173     if (Qualified)
174       S += getQualifiedNameAsString(Policy);
175     else
176       S += getNameAsString();
177   }
178
179   /// declarationReplaces - Determine whether this declaration, if
180   /// known to be well-formed within its context, will replace the
181   /// declaration OldD if introduced into scope. A declaration will
182   /// replace another declaration if, for example, it is a
183   /// redeclaration of the same variable or function, but not if it is
184   /// a declaration of a different kind (function vs. class) or an
185   /// overloaded function.
186   bool declarationReplaces(NamedDecl *OldD) const;
187
188   /// \brief Determine whether this declaration has linkage.
189   bool hasLinkage() const;
190
191   /// \brief Determine whether this declaration is a C++ class member.
192   bool isCXXClassMember() const {
193     const DeclContext *DC = getDeclContext();
194
195     // C++0x [class.mem]p1:
196     //   The enumerators of an unscoped enumeration defined in
197     //   the class are members of the class.
198     // FIXME: support C++0x scoped enumerations.
199     if (isa<EnumDecl>(DC))
200       DC = DC->getParent();
201
202     return DC->isRecord();
203   }
204
205   /// \brief Given that this declaration is a C++ class member,
206   /// determine whether it's an instance member of its class.
207   bool isCXXInstanceMember() const;
208
209   /// \brief Determine what kind of linkage this entity has.
210   Linkage getLinkage() const;
211
212   /// \brief Looks through UsingDecls and ObjCCompatibleAliasDecls for
213   /// the underlying named decl.
214   NamedDecl *getUnderlyingDecl();
215   const NamedDecl *getUnderlyingDecl() const {
216     return const_cast<NamedDecl*>(this)->getUnderlyingDecl();
217   }
218
219   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
220   static bool classof(const NamedDecl *D) { return true; }
221   static bool classofKind(Kind K) { return K >= firstNamed && K <= lastNamed; }
222 };
223
224 inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
225                                      const NamedDecl *ND) {
226   ND->getDeclName().printName(OS);
227   return OS;
228 }
229
230 /// NamespaceDecl - Represent a C++ namespace.
231 class NamespaceDecl : public NamedDecl, public DeclContext {
232   SourceLocation LBracLoc, RBracLoc;
233
234   // For extended namespace definitions:
235   //
236   // namespace A { int x; }
237   // namespace A { int y; }
238   //
239   // there will be one NamespaceDecl for each declaration.
240   // NextNamespace points to the next extended declaration.
241   // OrigNamespace points to the original namespace declaration.
242   // OrigNamespace of the first namespace decl points to itself.
243   NamespaceDecl *NextNamespace;
244
245   /// \brief A pointer to either the original namespace definition for
246   /// this namespace (if the boolean value is false) or the anonymous
247   /// namespace that lives just inside this namespace (if the boolean
248   /// value is true).
249   ///
250   /// We can combine these two notions because the anonymous namespace
251   /// must only be stored in one of the namespace declarations (so all
252   /// of the namespace declarations can find it). We therefore choose
253   /// the original namespace declaration, since all of the namespace
254   /// declarations have a link directly to it; the original namespace
255   /// declaration itself only needs to know that it is the original
256   /// namespace declaration (which the boolean indicates).
257   llvm::PointerIntPair<NamespaceDecl *, 1, bool> OrigOrAnonNamespace;
258
259   NamespaceDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id)
260     : NamedDecl(Namespace, DC, L, Id), DeclContext(Namespace),
261       NextNamespace(0), OrigOrAnonNamespace(0, true) { }
262
263 public:
264   static NamespaceDecl *Create(ASTContext &C, DeclContext *DC,
265                                SourceLocation L, IdentifierInfo *Id);
266
267   virtual void Destroy(ASTContext& C);
268
269   // \brief Returns true if this is an anonymous namespace declaration.
270   //
271   // For example:
272   /// \code
273   //   namespace {
274   //     ...
275   //   };
276   // \endcode
277   // q.v. C++ [namespace.unnamed]
278   bool isAnonymousNamespace() const {
279     return !getIdentifier();
280   }
281
282   /// \brief Return the next extended namespace declaration or null if this
283   /// is none.
284   NamespaceDecl *getNextNamespace() { return NextNamespace; }
285   const NamespaceDecl *getNextNamespace() const { return NextNamespace; }
286
287   /// \brief Set the next extended namespace declaration.
288   void setNextNamespace(NamespaceDecl *ND) { NextNamespace = ND; }
289
290   /// \brief Get the original (first) namespace declaration.
291   NamespaceDecl *getOriginalNamespace() const {
292     if (OrigOrAnonNamespace.getInt())
293       return const_cast<NamespaceDecl *>(this);
294
295     return OrigOrAnonNamespace.getPointer();
296   }
297
298   /// \brief Return true if this declaration is an original (first) declaration
299   /// of the namespace. This is false for non-original (subsequent) namespace
300   /// declarations and anonymous namespaces.
301   bool isOriginalNamespace() const {
302     return getOriginalNamespace() == this;
303   }
304
305   /// \brief Set the original (first) namespace declaration.
306   void setOriginalNamespace(NamespaceDecl *ND) { 
307     if (ND != this) {
308       OrigOrAnonNamespace.setPointer(ND);
309       OrigOrAnonNamespace.setInt(false);
310     }
311   }
312
313   NamespaceDecl *getAnonymousNamespace() const {
314     return getOriginalNamespace()->OrigOrAnonNamespace.getPointer();
315   }
316
317   void setAnonymousNamespace(NamespaceDecl *D) {
318     assert(!D || D->isAnonymousNamespace());
319     assert(!D || D->getParent() == this);
320     getOriginalNamespace()->OrigOrAnonNamespace.setPointer(D);
321   }
322
323   virtual NamespaceDecl *getCanonicalDecl() { return getOriginalNamespace(); }
324   const NamespaceDecl *getCanonicalDecl() const { 
325     return getOriginalNamespace(); 
326   }
327
328   virtual SourceRange getSourceRange() const {
329     return SourceRange(getLocation(), RBracLoc);
330   }
331
332   SourceLocation getLBracLoc() const { return LBracLoc; }
333   SourceLocation getRBracLoc() const { return RBracLoc; }
334   void setLBracLoc(SourceLocation LBrace) { LBracLoc = LBrace; }
335   void setRBracLoc(SourceLocation RBrace) { RBracLoc = RBrace; }
336
337   // Implement isa/cast/dyncast/etc.
338   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
339   static bool classof(const NamespaceDecl *D) { return true; }
340   static bool classofKind(Kind K) { return K == Namespace; }
341   static DeclContext *castToDeclContext(const NamespaceDecl *D) {
342     return static_cast<DeclContext *>(const_cast<NamespaceDecl*>(D));
343   }
344   static NamespaceDecl *castFromDeclContext(const DeclContext *DC) {
345     return static_cast<NamespaceDecl *>(const_cast<DeclContext*>(DC));
346   }
347   
348   friend class PCHDeclReader;
349   friend class PCHDeclWriter;
350 };
351
352 /// ValueDecl - Represent the declaration of a variable (in which case it is
353 /// an lvalue) a function (in which case it is a function designator) or
354 /// an enum constant.
355 class ValueDecl : public NamedDecl {
356   QualType DeclType;
357
358 protected:
359   ValueDecl(Kind DK, DeclContext *DC, SourceLocation L,
360             DeclarationName N, QualType T)
361     : NamedDecl(DK, DC, L, N), DeclType(T) {}
362 public:
363   QualType getType() const { return DeclType; }
364   void setType(QualType newType) { DeclType = newType; }
365
366   // Implement isa/cast/dyncast/etc.
367   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
368   static bool classof(const ValueDecl *D) { return true; }
369   static bool classofKind(Kind K) { return K >= firstValue && K <= lastValue; }
370 };
371
372 /// QualifierInfo - A struct with extended info about a syntactic
373 /// name qualifier, to be used for the case of out-of-line declarations.
374 struct QualifierInfo {
375   /// NNS - The syntactic name qualifier.
376   NestedNameSpecifier *NNS;
377   /// NNSRange - The source range for the qualifier.
378   SourceRange NNSRange;
379   /// NumTemplParamLists - The number of template parameter lists
380   /// that were matched against the template-ids occurring into the NNS.
381   unsigned NumTemplParamLists;
382   /// TemplParamLists - A new-allocated array of size NumTemplParamLists,
383   /// containing pointers to the matched template parameter lists.
384   TemplateParameterList** TemplParamLists;
385
386   /// Default constructor.
387   QualifierInfo()
388     : NNS(0), NNSRange(), NumTemplParamLists(0), TemplParamLists(0) {}
389   /// setTemplateParameterListsInfo - Sets info about matched template
390   /// parameter lists.
391   void setTemplateParameterListsInfo(ASTContext &Context,
392                                      unsigned NumTPLists,
393                                      TemplateParameterList **TPLists);
394   
395   void Destroy(ASTContext &Context);
396   
397 private:
398   // Copy constructor and copy assignment are disabled.
399   QualifierInfo(const QualifierInfo&);
400   QualifierInfo& operator=(const QualifierInfo&);
401 };
402
403 /// \brief Represents a ValueDecl that came out of a declarator.
404 /// Contains type source information through TypeSourceInfo.
405 class DeclaratorDecl : public ValueDecl {
406   // A struct representing both a TInfo and a syntactic qualifier,
407   // to be used for the (uncommon) case of out-of-line declarations.
408   struct ExtInfo : public QualifierInfo {
409     TypeSourceInfo *TInfo;
410   };
411
412   llvm::PointerUnion<TypeSourceInfo*, ExtInfo*> DeclInfo;
413
414   bool hasExtInfo() const { return DeclInfo.is<ExtInfo*>(); }
415   ExtInfo *getExtInfo() { return DeclInfo.get<ExtInfo*>(); }
416   const ExtInfo *getExtInfo() const { return DeclInfo.get<ExtInfo*>(); }
417
418 protected:
419   DeclaratorDecl(Kind DK, DeclContext *DC, SourceLocation L,
420                  DeclarationName N, QualType T, TypeSourceInfo *TInfo)
421     : ValueDecl(DK, DC, L, N, T), DeclInfo(TInfo) {}
422
423 public:
424   virtual ~DeclaratorDecl();
425   virtual void Destroy(ASTContext &C);
426
427   TypeSourceInfo *getTypeSourceInfo() const {
428     return hasExtInfo()
429       ? getExtInfo()->TInfo
430       : DeclInfo.get<TypeSourceInfo*>();
431   }
432   void setTypeSourceInfo(TypeSourceInfo *TI) {
433     if (hasExtInfo())
434       getExtInfo()->TInfo = TI;
435     else
436       DeclInfo = TI;
437   }
438
439   /// getInnerLocStart - Return SourceLocation representing start of source
440   /// range ignoring outer template declarations.
441   virtual SourceLocation getInnerLocStart() const { return getLocation(); }
442
443   /// getOuterLocStart - Return SourceLocation representing start of source
444   /// range taking into account any outer template declarations.
445   SourceLocation getOuterLocStart() const;
446   SourceRange getSourceRange() const {
447     return SourceRange(getOuterLocStart(), getLocation());
448   }
449
450   NestedNameSpecifier *getQualifier() const {
451     return hasExtInfo() ? getExtInfo()->NNS : 0;
452   }
453   SourceRange getQualifierRange() const {
454     return hasExtInfo() ? getExtInfo()->NNSRange : SourceRange();
455   }
456   void setQualifierInfo(NestedNameSpecifier *Qualifier,
457                         SourceRange QualifierRange);
458
459   unsigned getNumTemplateParameterLists() const {
460     return hasExtInfo() ? getExtInfo()->NumTemplParamLists : 0;
461   }
462   TemplateParameterList *getTemplateParameterList(unsigned index) const {
463     assert(index < getNumTemplateParameterLists());
464     return getExtInfo()->TemplParamLists[index];
465   }
466   void setTemplateParameterListsInfo(ASTContext &Context, unsigned NumTPLists,
467                                      TemplateParameterList **TPLists) {
468     getExtInfo()->setTemplateParameterListsInfo(Context, NumTPLists, TPLists);
469   }
470
471   SourceLocation getTypeSpecStartLoc() const;
472
473   // Implement isa/cast/dyncast/etc.
474   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
475   static bool classof(const DeclaratorDecl *D) { return true; }
476   static bool classofKind(Kind K) {
477     return K >= firstDeclarator && K <= lastDeclarator;
478   }
479 };
480
481 /// \brief Structure used to store a statement, the constant value to
482 /// which it was evaluated (if any), and whether or not the statement
483 /// is an integral constant expression (if known).
484 struct EvaluatedStmt {
485   EvaluatedStmt() : WasEvaluated(false), IsEvaluating(false), CheckedICE(false),
486                     CheckingICE(false), IsICE(false) { }
487
488   /// \brief Whether this statement was already evaluated.
489   bool WasEvaluated : 1;
490
491   /// \brief Whether this statement is being evaluated.
492   bool IsEvaluating : 1;
493
494   /// \brief Whether we already checked whether this statement was an
495   /// integral constant expression.
496   bool CheckedICE : 1;
497
498   /// \brief Whether we are checking whether this statement is an
499   /// integral constant expression.
500   bool CheckingICE : 1;
501
502   /// \brief Whether this statement is an integral constant
503   /// expression. Only valid if CheckedICE is true.
504   bool IsICE : 1;
505
506   Stmt *Value;
507   APValue Evaluated;
508 };
509
510 // \brief Describes the kind of template specialization that a
511 // particular template specialization declaration represents.
512 enum TemplateSpecializationKind {
513   /// This template specialization was formed from a template-id but
514   /// has not yet been declared, defined, or instantiated.
515   TSK_Undeclared = 0,
516   /// This template specialization was implicitly instantiated from a
517   /// template. (C++ [temp.inst]).
518   TSK_ImplicitInstantiation,
519   /// This template specialization was declared or defined by an
520   /// explicit specialization (C++ [temp.expl.spec]) or partial
521   /// specialization (C++ [temp.class.spec]).
522   TSK_ExplicitSpecialization,
523   /// This template specialization was instantiated from a template
524   /// due to an explicit instantiation declaration request
525   /// (C++0x [temp.explicit]).
526   TSK_ExplicitInstantiationDeclaration,
527   /// This template specialization was instantiated from a template
528   /// due to an explicit instantiation definition request
529   /// (C++ [temp.explicit]).
530   TSK_ExplicitInstantiationDefinition
531 };
532   
533 /// VarDecl - An instance of this class is created to represent a variable
534 /// declaration or definition.
535 class VarDecl : public DeclaratorDecl, public Redeclarable<VarDecl> {
536 public:
537   enum StorageClass {
538     None, Auto, Register, Extern, Static, PrivateExtern
539   };
540
541   /// getStorageClassSpecifierString - Return the string used to
542   /// specify the storage class \arg SC.
543   ///
544   /// It is illegal to call this function with SC == None.
545   static const char *getStorageClassSpecifierString(StorageClass SC);
546
547 protected:
548   /// \brief Placeholder type used in Init to denote an unparsed C++ default
549   /// argument.
550   struct UnparsedDefaultArgument;
551
552   /// \brief Placeholder type used in Init to denote an uninstantiated C++
553   /// default argument.
554   struct UninstantiatedDefaultArgument;
555
556   typedef llvm::PointerUnion4<Stmt *, EvaluatedStmt *,
557                               UnparsedDefaultArgument *,
558                               UninstantiatedDefaultArgument *> InitType;
559
560   /// \brief The initializer for this variable or, for a ParmVarDecl, the
561   /// C++ default argument.
562   mutable InitType Init;
563
564 private:
565   // FIXME: This can be packed into the bitfields in Decl.
566   unsigned SClass : 3;
567   unsigned SClassAsWritten : 3;
568   bool ThreadSpecified : 1;
569   bool HasCXXDirectInit : 1;
570
571   /// DeclaredInCondition - Whether this variable was declared in a
572   /// condition, e.g., if (int x = foo()) { ... }.
573   bool DeclaredInCondition : 1;
574
575   /// \brief Whether this variable is the exception variable in a C++ catch
576   /// or an Objective-C @catch statement.
577   bool ExceptionVar : 1;
578   
579   /// \brief Whether this local variable could be allocated in the return
580   /// slot of its function, enabling the named return value optimization (NRVO).
581   bool NRVOVariable : 1;
582   
583   friend class StmtIteratorBase;
584 protected:
585   VarDecl(Kind DK, DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
586           QualType T, TypeSourceInfo *TInfo, StorageClass SC,
587           StorageClass SCAsWritten)
588     : DeclaratorDecl(DK, DC, L, Id, T, TInfo), Init(),
589       ThreadSpecified(false), HasCXXDirectInit(false),
590       DeclaredInCondition(false), ExceptionVar(false), NRVOVariable(false) {
591     SClass = SC;
592     SClassAsWritten = SCAsWritten;
593   }
594
595   typedef Redeclarable<VarDecl> redeclarable_base;
596   virtual VarDecl *getNextRedeclaration() { return RedeclLink.getNext(); }
597
598 public:
599   typedef redeclarable_base::redecl_iterator redecl_iterator;
600   redecl_iterator redecls_begin() const {
601     return redeclarable_base::redecls_begin();
602   }
603   redecl_iterator redecls_end() const {
604     return redeclarable_base::redecls_end();
605   }
606
607   static VarDecl *Create(ASTContext &C, DeclContext *DC,
608                          SourceLocation L, IdentifierInfo *Id,
609                          QualType T, TypeSourceInfo *TInfo, StorageClass S,
610                          StorageClass SCAsWritten);
611
612   virtual void Destroy(ASTContext& C);
613   virtual ~VarDecl();
614
615   virtual SourceLocation getInnerLocStart() const;
616   virtual SourceRange getSourceRange() const;
617
618   StorageClass getStorageClass() const { return (StorageClass)SClass; }
619   StorageClass getStorageClassAsWritten() const {
620     return (StorageClass) SClassAsWritten;
621   }
622   void setStorageClass(StorageClass SC) { SClass = SC; }
623   void setStorageClassAsWritten(StorageClass SC) { SClassAsWritten = SC; }
624
625   void setThreadSpecified(bool T) { ThreadSpecified = T; }
626   bool isThreadSpecified() const {
627     return ThreadSpecified;
628   }
629
630   /// hasLocalStorage - Returns true if a variable with function scope
631   ///  is a non-static local variable.
632   bool hasLocalStorage() const {
633     if (getStorageClass() == None)
634       return !isFileVarDecl();
635
636     // Return true for:  Auto, Register.
637     // Return false for: Extern, Static, PrivateExtern.
638
639     return getStorageClass() <= Register;
640   }
641
642   /// isStaticLocal - Returns true if a variable with function scope is a 
643   /// static local variable.
644   bool isStaticLocal() const {
645     return getStorageClass() == Static && !isFileVarDecl();
646   }
647   
648   /// hasExternStorage - Returns true if a variable has extern or
649   /// __private_extern__ storage.
650   bool hasExternalStorage() const {
651     return getStorageClass() == Extern || getStorageClass() == PrivateExtern;
652   }
653
654   /// hasGlobalStorage - Returns true for all variables that do not
655   ///  have local storage.  This includs all global variables as well
656   ///  as static variables declared within a function.
657   bool hasGlobalStorage() const { return !hasLocalStorage(); }
658
659   /// \brief Determines whether this variable is a variable with
660   /// external, C linkage.
661   bool isExternC() const;
662
663   /// isBlockVarDecl - Returns true for local variable declarations.  Note that
664   /// this includes static variables inside of functions. It also includes
665   /// variables inside blocks.
666   ///
667   ///   void foo() { int x; static int y; extern int z; }
668   ///
669   bool isBlockVarDecl() const {
670     if (getKind() != Decl::Var)
671       return false;
672     if (const DeclContext *DC = getDeclContext())
673       return DC->getLookupContext()->isFunctionOrMethod();
674     return false;
675   }
676
677   /// isFunctionOrMethodVarDecl - Similar to isBlockVarDecl, but excludes
678   /// variables declared in blocks.
679   bool isFunctionOrMethodVarDecl() const {
680     if (getKind() != Decl::Var)
681       return false;
682     if (const DeclContext *DC = getDeclContext())
683       return DC->getLookupContext()->isFunctionOrMethod() &&
684              DC->getLookupContext()->getDeclKind() != Decl::Block;
685     return false;
686   }
687
688   /// \brief Determines whether this is a static data member.
689   ///
690   /// This will only be true in C++, and applies to, e.g., the
691   /// variable 'x' in:
692   /// \code
693   /// struct S {
694   ///   static int x;
695   /// };
696   /// \endcode
697   bool isStaticDataMember() const {
698     // If it wasn't static, it would be a FieldDecl.
699     return getDeclContext()->isRecord();
700   }
701
702   virtual VarDecl *getCanonicalDecl();
703   const VarDecl *getCanonicalDecl() const {
704     return const_cast<VarDecl*>(this)->getCanonicalDecl();
705   }
706
707   enum DefinitionKind {
708     DeclarationOnly,      ///< This declaration is only a declaration.
709     TentativeDefinition,  ///< This declaration is a tentative definition.
710     Definition            ///< This declaration is definitely a definition.
711   };
712
713   /// \brief Check whether this declaration is a definition. If this could be
714   /// a tentative definition (in C), don't check whether there's an overriding
715   /// definition.
716   DefinitionKind isThisDeclarationADefinition() const;
717
718   /// \brief Get the tentative definition that acts as the real definition in
719   /// a TU. Returns null if there is a proper definition available.
720   VarDecl *getActingDefinition();
721   const VarDecl *getActingDefinition() const {
722     return const_cast<VarDecl*>(this)->getActingDefinition();
723   }
724
725   /// \brief Determine whether this is a tentative definition of a
726   /// variable in C.
727   bool isTentativeDefinitionNow() const;
728
729   /// \brief Get the real (not just tentative) definition for this declaration.
730   VarDecl *getDefinition();
731   const VarDecl *getDefinition() const {
732     return const_cast<VarDecl*>(this)->getDefinition();
733   }
734
735   /// \brief Determine whether this is or was instantiated from an out-of-line 
736   /// definition of a static data member.
737   virtual bool isOutOfLine() const;
738
739   /// \brief If this is a static data member, find its out-of-line definition.
740   VarDecl *getOutOfLineDefinition();
741   
742   /// isFileVarDecl - Returns true for file scoped variable declaration.
743   bool isFileVarDecl() const {
744     if (getKind() != Decl::Var)
745       return false;
746     if (const DeclContext *Ctx = getDeclContext()) {
747       Ctx = Ctx->getLookupContext();
748       if (isa<TranslationUnitDecl>(Ctx) || isa<NamespaceDecl>(Ctx) )
749         return true;
750     }
751     if (isStaticDataMember())
752       return true;
753
754     return false;
755   }
756
757   /// getAnyInitializer - Get the initializer for this variable, no matter which
758   /// declaration it is attached to.
759   const Expr *getAnyInitializer() const {
760     const VarDecl *D;
761     return getAnyInitializer(D);
762   }
763
764   /// getAnyInitializer - Get the initializer for this variable, no matter which
765   /// declaration it is attached to. Also get that declaration.
766   const Expr *getAnyInitializer(const VarDecl *&D) const;
767
768   bool hasInit() const {
769     return !Init.isNull();
770   }
771   const Expr *getInit() const {
772     if (Init.isNull())
773       return 0;
774
775     const Stmt *S = Init.dyn_cast<Stmt *>();
776     if (!S) {
777       if (EvaluatedStmt *ES = Init.dyn_cast<EvaluatedStmt*>())
778         S = ES->Value;
779     }
780     return (const Expr*) S;
781   }
782   Expr *getInit() {
783     if (Init.isNull())
784       return 0;
785
786     Stmt *S = Init.dyn_cast<Stmt *>();
787     if (!S) {
788       if (EvaluatedStmt *ES = Init.dyn_cast<EvaluatedStmt*>())
789         S = ES->Value;
790     }
791
792     return (Expr*) S;
793   }
794
795   /// \brief Retrieve the address of the initializer expression.
796   Stmt **getInitAddress() {
797     if (EvaluatedStmt *ES = Init.dyn_cast<EvaluatedStmt*>())
798       return &ES->Value;
799
800     // This union hack tip-toes around strict-aliasing rules.
801     union {
802       InitType *InitPtr;
803       Stmt **StmtPtr;
804     };
805
806     InitPtr = &Init;
807     return StmtPtr;
808   }
809
810   void setInit(Expr *I);
811
812   EvaluatedStmt *EnsureEvaluatedStmt() const {
813     EvaluatedStmt *Eval = Init.dyn_cast<EvaluatedStmt *>();
814     if (!Eval) {
815       Stmt *S = Init.get<Stmt *>();
816       Eval = new (getASTContext()) EvaluatedStmt;
817       Eval->Value = S;
818       Init = Eval;
819     }
820     return Eval;
821   }
822
823   /// \brief Check whether we are in the process of checking whether the
824   /// initializer can be evaluated.
825   bool isEvaluatingValue() const {
826     if (EvaluatedStmt *Eval = Init.dyn_cast<EvaluatedStmt *>())
827       return Eval->IsEvaluating;
828
829     return false;
830   }
831
832   /// \brief Note that we now are checking whether the initializer can be
833   /// evaluated.
834   void setEvaluatingValue() const {
835     EvaluatedStmt *Eval = EnsureEvaluatedStmt();
836     Eval->IsEvaluating = true;
837   }
838
839   /// \brief Note that constant evaluation has computed the given
840   /// value for this variable's initializer.
841   void setEvaluatedValue(const APValue &Value) const {
842     EvaluatedStmt *Eval = EnsureEvaluatedStmt();
843     Eval->IsEvaluating = false;
844     Eval->WasEvaluated = true;
845     Eval->Evaluated = Value;
846   }
847
848   /// \brief Return the already-evaluated value of this variable's
849   /// initializer, or NULL if the value is not yet known. Returns pointer
850   /// to untyped APValue if the value could not be evaluated.
851   APValue *getEvaluatedValue() const {
852     if (EvaluatedStmt *Eval = Init.dyn_cast<EvaluatedStmt *>())
853       if (Eval->WasEvaluated)
854         return &Eval->Evaluated;
855
856     return 0;
857   }
858
859   /// \brief Determines whether it is already known whether the
860   /// initializer is an integral constant expression or not.
861   bool isInitKnownICE() const {
862     if (EvaluatedStmt *Eval = Init.dyn_cast<EvaluatedStmt *>())
863       return Eval->CheckedICE;
864
865     return false;
866   }
867
868   /// \brief Determines whether the initializer is an integral
869   /// constant expression.
870   ///
871   /// \pre isInitKnownICE()
872   bool isInitICE() const {
873     assert(isInitKnownICE() &&
874            "Check whether we already know that the initializer is an ICE");
875     return Init.get<EvaluatedStmt *>()->IsICE;
876   }
877
878   /// \brief Check whether we are in the process of checking the initializer
879   /// is an integral constant expression.
880   bool isCheckingICE() const {
881     if (EvaluatedStmt *Eval = Init.dyn_cast<EvaluatedStmt *>())
882       return Eval->CheckingICE;
883
884     return false;
885   }
886
887   /// \brief Note that we now are checking whether the initializer is an
888   /// integral constant expression.
889   void setCheckingICE() const {
890     EvaluatedStmt *Eval = EnsureEvaluatedStmt();
891     Eval->CheckingICE = true;
892   }
893
894   /// \brief Note that we now know whether the initializer is an
895   /// integral constant expression.
896   void setInitKnownICE(bool IsICE) const {
897     EvaluatedStmt *Eval = EnsureEvaluatedStmt();
898     Eval->CheckingICE = false;
899     Eval->CheckedICE = true;
900     Eval->IsICE = IsICE;
901   }
902
903   void setCXXDirectInitializer(bool T) { HasCXXDirectInit = T; }
904
905   /// hasCXXDirectInitializer - If true, the initializer was a direct
906   /// initializer, e.g: "int x(1);". The Init expression will be the expression
907   /// inside the parens or a "ClassType(a,b,c)" class constructor expression for
908   /// class types. Clients can distinguish between "int x(1);" and "int x=1;"
909   /// by checking hasCXXDirectInitializer.
910   ///
911   bool hasCXXDirectInitializer() const {
912     return HasCXXDirectInit;
913   }
914
915   /// isDeclaredInCondition - Whether this variable was declared as
916   /// part of a condition in an if/switch/while statement, e.g.,
917   /// @code
918   /// if (int x = foo()) { ... }
919   /// @endcode
920   bool isDeclaredInCondition() const {
921     return DeclaredInCondition;
922   }
923   void setDeclaredInCondition(bool InCondition) {
924     DeclaredInCondition = InCondition;
925   }
926   
927   /// \brief Determine whether this variable is the exception variable in a
928   /// C++ catch statememt or an Objective-C @catch statement.
929   bool isExceptionVariable() const {
930     return ExceptionVar;
931   }
932   void setExceptionVariable(bool EV) { ExceptionVar = EV; }
933   
934   /// \brief Determine whether this local variable can be used with the named
935   /// return value optimization (NRVO).
936   ///
937   /// The named return value optimization (NRVO) works by marking certain
938   /// non-volatile local variables of class type as NRVO objects. These
939   /// locals can be allocated within the return slot of their containing
940   /// function, in which case there is no need to copy the object to the
941   /// return slot when returning from the function. Within the function body,
942   /// each return that returns the NRVO object will have this variable as its
943   /// NRVO candidate.
944   bool isNRVOVariable() const { return NRVOVariable; }
945   void setNRVOVariable(bool NRVO) { NRVOVariable = NRVO; }
946   
947   /// \brief If this variable is an instantiated static data member of a
948   /// class template specialization, returns the templated static data member
949   /// from which it was instantiated.
950   VarDecl *getInstantiatedFromStaticDataMember() const;
951
952   /// \brief If this variable is a static data member, determine what kind of 
953   /// template specialization or instantiation this is.
954   TemplateSpecializationKind getTemplateSpecializationKind() const;
955   
956   /// \brief If this variable is an instantiation of a static data member of a
957   /// class template specialization, retrieves the member specialization
958   /// information.
959   MemberSpecializationInfo *getMemberSpecializationInfo() const;
960   
961   /// \brief For a static data member that was instantiated from a static
962   /// data member of a class template, set the template specialiation kind.
963   void setTemplateSpecializationKind(TemplateSpecializationKind TSK,
964                         SourceLocation PointOfInstantiation = SourceLocation());
965
966   // Implement isa/cast/dyncast/etc.
967   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
968   static bool classof(const VarDecl *D) { return true; }
969   static bool classofKind(Kind K) { return K >= firstVar && K <= lastVar; }
970 };
971
972 class ImplicitParamDecl : public VarDecl {
973 protected:
974   ImplicitParamDecl(Kind DK, DeclContext *DC, SourceLocation L,
975                     IdentifierInfo *Id, QualType Tw)
976     : VarDecl(DK, DC, L, Id, Tw, /*TInfo=*/0, VarDecl::None, VarDecl::None) {}
977 public:
978   static ImplicitParamDecl *Create(ASTContext &C, DeclContext *DC,
979                                    SourceLocation L, IdentifierInfo *Id,
980                                    QualType T);
981   // Implement isa/cast/dyncast/etc.
982   static bool classof(const ImplicitParamDecl *D) { return true; }
983   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
984   static bool classofKind(Kind K) { return K == ImplicitParam; }
985 };
986
987 /// ParmVarDecl - Represent a parameter to a function.
988 class ParmVarDecl : public VarDecl {
989   // NOTE: VC++ treats enums as signed, avoid using the ObjCDeclQualifier enum
990   /// FIXME: Also can be paced into the bitfields in Decl.
991   /// in, inout, etc.
992   unsigned objcDeclQualifier : 6;
993   bool HasInheritedDefaultArg : 1;
994
995 protected:
996   ParmVarDecl(Kind DK, DeclContext *DC, SourceLocation L,
997               IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo,
998               StorageClass S, StorageClass SCAsWritten, Expr *DefArg)
999     : VarDecl(DK, DC, L, Id, T, TInfo, S, SCAsWritten),
1000       objcDeclQualifier(OBJC_TQ_None), HasInheritedDefaultArg(false) {
1001     setDefaultArg(DefArg);
1002   }
1003
1004 public:
1005   static ParmVarDecl *Create(ASTContext &C, DeclContext *DC,
1006                              SourceLocation L,IdentifierInfo *Id,
1007                              QualType T, TypeSourceInfo *TInfo,
1008                              StorageClass S, StorageClass SCAsWritten,
1009                              Expr *DefArg);
1010
1011   ObjCDeclQualifier getObjCDeclQualifier() const {
1012     return ObjCDeclQualifier(objcDeclQualifier);
1013   }
1014   void setObjCDeclQualifier(ObjCDeclQualifier QTVal) {
1015     objcDeclQualifier = QTVal;
1016   }
1017
1018   Expr *getDefaultArg();
1019   const Expr *getDefaultArg() const {
1020     return const_cast<ParmVarDecl *>(this)->getDefaultArg();
1021   }
1022   
1023   void setDefaultArg(Expr *defarg) {
1024     Init = reinterpret_cast<Stmt *>(defarg);
1025   }
1026
1027   unsigned getNumDefaultArgTemporaries() const;
1028   CXXTemporary *getDefaultArgTemporary(unsigned i);
1029   const CXXTemporary *getDefaultArgTemporary(unsigned i) const {
1030     return const_cast<ParmVarDecl *>(this)->getDefaultArgTemporary(i);
1031   }
1032   
1033   /// \brief Retrieve the source range that covers the entire default
1034   /// argument.
1035   SourceRange getDefaultArgRange() const;  
1036   void setUninstantiatedDefaultArg(Expr *arg) {
1037     Init = reinterpret_cast<UninstantiatedDefaultArgument *>(arg);
1038   }
1039   Expr *getUninstantiatedDefaultArg() {
1040     return (Expr *)Init.get<UninstantiatedDefaultArgument *>();
1041   }
1042   const Expr *getUninstantiatedDefaultArg() const {
1043     return (const Expr *)Init.get<UninstantiatedDefaultArgument *>();
1044   }
1045
1046   /// hasDefaultArg - Determines whether this parameter has a default argument,
1047   /// either parsed or not.
1048   bool hasDefaultArg() const {
1049     return getInit() || hasUnparsedDefaultArg() ||
1050       hasUninstantiatedDefaultArg();
1051   }
1052
1053   /// hasUnparsedDefaultArg - Determines whether this parameter has a
1054   /// default argument that has not yet been parsed. This will occur
1055   /// during the processing of a C++ class whose member functions have
1056   /// default arguments, e.g.,
1057   /// @code
1058   ///   class X {
1059   ///   public:
1060   ///     void f(int x = 17); // x has an unparsed default argument now
1061   ///   }; // x has a regular default argument now
1062   /// @endcode
1063   bool hasUnparsedDefaultArg() const {
1064     return Init.is<UnparsedDefaultArgument*>();
1065   }
1066
1067   bool hasUninstantiatedDefaultArg() const {
1068     return Init.is<UninstantiatedDefaultArgument*>();
1069   }
1070
1071   /// setUnparsedDefaultArg - Specify that this parameter has an
1072   /// unparsed default argument. The argument will be replaced with a
1073   /// real default argument via setDefaultArg when the class
1074   /// definition enclosing the function declaration that owns this
1075   /// default argument is completed.
1076   void setUnparsedDefaultArg() {
1077     Init = (UnparsedDefaultArgument *)0;
1078   }
1079
1080   bool hasInheritedDefaultArg() const {
1081     return HasInheritedDefaultArg;
1082   }
1083
1084   void setHasInheritedDefaultArg(bool I = true) {
1085     HasInheritedDefaultArg = I;
1086   }
1087
1088   QualType getOriginalType() const {
1089     if (getTypeSourceInfo())
1090       return getTypeSourceInfo()->getType();
1091     return getType();
1092   }
1093
1094   /// setOwningFunction - Sets the function declaration that owns this
1095   /// ParmVarDecl. Since ParmVarDecls are often created before the
1096   /// FunctionDecls that own them, this routine is required to update
1097   /// the DeclContext appropriately.
1098   void setOwningFunction(DeclContext *FD) { setDeclContext(FD); }
1099
1100   // Implement isa/cast/dyncast/etc.
1101   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1102   static bool classof(const ParmVarDecl *D) { return true; }
1103   static bool classofKind(Kind K) { return K == ParmVar; }
1104 };
1105
1106 /// FunctionDecl - An instance of this class is created to represent a
1107 /// function declaration or definition.
1108 ///
1109 /// Since a given function can be declared several times in a program,
1110 /// there may be several FunctionDecls that correspond to that
1111 /// function. Only one of those FunctionDecls will be found when
1112 /// traversing the list of declarations in the context of the
1113 /// FunctionDecl (e.g., the translation unit); this FunctionDecl
1114 /// contains all of the information known about the function. Other,
1115 /// previous declarations of the function are available via the
1116 /// getPreviousDeclaration() chain.
1117 class FunctionDecl : public DeclaratorDecl, public DeclContext,
1118                      public Redeclarable<FunctionDecl> {
1119 public:
1120   enum StorageClass {
1121     None, Extern, Static, PrivateExtern
1122   };
1123
1124   /// \brief The kind of templated function a FunctionDecl can be.
1125   enum TemplatedKind {
1126     TK_NonTemplate,
1127     TK_FunctionTemplate,
1128     TK_MemberSpecialization,
1129     TK_FunctionTemplateSpecialization,
1130     TK_DependentFunctionTemplateSpecialization
1131   };
1132
1133 private:
1134   /// ParamInfo - new[]'d array of pointers to VarDecls for the formal
1135   /// parameters of this function.  This is null if a prototype or if there are
1136   /// no formals.
1137   ParmVarDecl **ParamInfo;
1138
1139   LazyDeclStmtPtr Body;
1140
1141   // FIXME: This can be packed into the bitfields in Decl.
1142   // NOTE: VC++ treats enums as signed, avoid using the StorageClass enum
1143   unsigned SClass : 2;
1144   unsigned SClassAsWritten : 2;
1145   bool IsInline : 1;
1146   bool IsVirtualAsWritten : 1;
1147   bool IsPure : 1;
1148   bool HasInheritedPrototype : 1;
1149   bool HasWrittenPrototype : 1;
1150   bool IsDeleted : 1;
1151   bool IsTrivial : 1; // sunk from CXXMethodDecl
1152   bool IsCopyAssignment : 1;  // sunk from CXXMethodDecl
1153   bool HasImplicitReturnZero : 1;
1154
1155   /// \brief End part of this FunctionDecl's source range.
1156   ///
1157   /// We could compute the full range in getSourceRange(). However, when we're
1158   /// dealing with a function definition deserialized from a PCH/AST file,
1159   /// we can only compute the full range once the function body has been
1160   /// de-serialized, so it's far better to have the (sometimes-redundant)
1161   /// EndRangeLoc.
1162   SourceLocation EndRangeLoc;
1163
1164   /// \brief The template or declaration that this declaration
1165   /// describes or was instantiated from, respectively.
1166   ///
1167   /// For non-templates, this value will be NULL. For function
1168   /// declarations that describe a function template, this will be a
1169   /// pointer to a FunctionTemplateDecl. For member functions
1170   /// of class template specializations, this will be a MemberSpecializationInfo
1171   /// pointer containing information about the specialization.
1172   /// For function template specializations, this will be a
1173   /// FunctionTemplateSpecializationInfo, which contains information about
1174   /// the template being specialized and the template arguments involved in
1175   /// that specialization.
1176   llvm::PointerUnion4<FunctionTemplateDecl *, 
1177                       MemberSpecializationInfo *,
1178                       FunctionTemplateSpecializationInfo *,
1179                       DependentFunctionTemplateSpecializationInfo *>
1180     TemplateOrSpecialization;
1181
1182 protected:
1183   FunctionDecl(Kind DK, DeclContext *DC, SourceLocation L,
1184                DeclarationName N, QualType T, TypeSourceInfo *TInfo,
1185                StorageClass S, StorageClass SCAsWritten, bool isInline)
1186     : DeclaratorDecl(DK, DC, L, N, T, TInfo),
1187       DeclContext(DK),
1188       ParamInfo(0), Body(),
1189       SClass(S), SClassAsWritten(SCAsWritten), IsInline(isInline),
1190       IsVirtualAsWritten(false), IsPure(false), HasInheritedPrototype(false),
1191       HasWrittenPrototype(true), IsDeleted(false), IsTrivial(false),
1192       IsCopyAssignment(false),
1193       HasImplicitReturnZero(false),
1194       EndRangeLoc(L), TemplateOrSpecialization() {}
1195
1196   virtual ~FunctionDecl() {}
1197   virtual void Destroy(ASTContext& C);
1198
1199   typedef Redeclarable<FunctionDecl> redeclarable_base;
1200   virtual FunctionDecl *getNextRedeclaration() { return RedeclLink.getNext(); }
1201
1202 public:
1203   typedef redeclarable_base::redecl_iterator redecl_iterator;
1204   redecl_iterator redecls_begin() const {
1205     return redeclarable_base::redecls_begin();
1206   }
1207   redecl_iterator redecls_end() const {
1208     return redeclarable_base::redecls_end();
1209   }
1210
1211   static FunctionDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L,
1212                               DeclarationName N, QualType T,
1213                               TypeSourceInfo *TInfo,
1214                               StorageClass S = None,
1215                               StorageClass SCAsWritten = None,
1216                               bool isInline = false,
1217                               bool hasWrittenPrototype = true);
1218
1219   virtual void getNameForDiagnostic(std::string &S,
1220                                     const PrintingPolicy &Policy,
1221                                     bool Qualified) const;
1222
1223   virtual SourceRange getSourceRange() const {
1224     return SourceRange(getOuterLocStart(), EndRangeLoc);
1225   }
1226   void setLocEnd(SourceLocation E) {
1227     EndRangeLoc = E;
1228   }
1229
1230   /// \brief Returns true if the function has a body (definition). The
1231   /// function body might be in any of the (re-)declarations of this
1232   /// function. The variant that accepts a FunctionDecl pointer will
1233   /// set that function declaration to the actual declaration
1234   /// containing the body (if there is one).
1235   bool hasBody(const FunctionDecl *&Definition) const;
1236
1237   virtual bool hasBody() const {
1238     const FunctionDecl* Definition;
1239     return hasBody(Definition);
1240   }
1241
1242   /// getBody - Retrieve the body (definition) of the function. The
1243   /// function body might be in any of the (re-)declarations of this
1244   /// function. The variant that accepts a FunctionDecl pointer will
1245   /// set that function declaration to the actual declaration
1246   /// containing the body (if there is one).
1247   /// NOTE: For checking if there is a body, use hasBody() instead, to avoid
1248   /// unnecessary PCH de-serialization of the body.
1249   Stmt *getBody(const FunctionDecl *&Definition) const;
1250
1251   virtual Stmt *getBody() const {
1252     const FunctionDecl* Definition;
1253     return getBody(Definition);
1254   }
1255
1256   /// isThisDeclarationADefinition - Returns whether this specific
1257   /// declaration of the function is also a definition. This does not
1258   /// determine whether the function has been defined (e.g., in a
1259   /// previous definition); for that information, use getBody.
1260   /// FIXME: Should return true if function is deleted or defaulted. However,
1261   /// CodeGenModule.cpp uses it, and I don't know if this would break it.
1262   bool isThisDeclarationADefinition() const { return Body; }
1263
1264   void setBody(Stmt *B);
1265   void setLazyBody(uint64_t Offset) { Body = Offset; }
1266
1267   /// Whether this function is variadic.
1268   bool isVariadic() const;
1269
1270   /// Whether this function is marked as virtual explicitly.
1271   bool isVirtualAsWritten() const { return IsVirtualAsWritten; }
1272   void setVirtualAsWritten(bool V) { IsVirtualAsWritten = V; }
1273
1274   /// Whether this virtual function is pure, i.e. makes the containing class
1275   /// abstract.
1276   bool isPure() const { return IsPure; }
1277   void setPure(bool P = true) { IsPure = P; }
1278
1279   /// Whether this function is "trivial" in some specialized C++ senses.
1280   /// Can only be true for default constructors, copy constructors,
1281   /// copy assignment operators, and destructors.  Not meaningful until
1282   /// the class has been fully built by Sema.
1283   bool isTrivial() const { return IsTrivial; }
1284   void setTrivial(bool IT) { IsTrivial = IT; }
1285
1286   bool isCopyAssignment() const { return IsCopyAssignment; }
1287   void setCopyAssignment(bool CA) { IsCopyAssignment = CA; }
1288
1289   /// Whether falling off this function implicitly returns null/zero.
1290   /// If a more specific implicit return value is required, front-ends
1291   /// should synthesize the appropriate return statements.
1292   bool hasImplicitReturnZero() const { return HasImplicitReturnZero; }
1293   void setHasImplicitReturnZero(bool IRZ) { HasImplicitReturnZero = IRZ; }
1294
1295   /// \brief Whether this function has a prototype, either because one
1296   /// was explicitly written or because it was "inherited" by merging
1297   /// a declaration without a prototype with a declaration that has a
1298   /// prototype.
1299   bool hasPrototype() const {
1300     return HasWrittenPrototype || HasInheritedPrototype;
1301   }
1302
1303   bool hasWrittenPrototype() const { return HasWrittenPrototype; }
1304   void setHasWrittenPrototype(bool P) { HasWrittenPrototype = P; }
1305
1306   /// \brief Whether this function inherited its prototype from a
1307   /// previous declaration.
1308   bool hasInheritedPrototype() const { return HasInheritedPrototype; }
1309   void setHasInheritedPrototype(bool P = true) { HasInheritedPrototype = P; }
1310
1311   /// \brief Whether this function has been deleted.
1312   ///
1313   /// A function that is "deleted" (via the C++0x "= delete" syntax)
1314   /// acts like a normal function, except that it cannot actually be
1315   /// called or have its address taken. Deleted functions are
1316   /// typically used in C++ overload resolution to attract arguments
1317   /// whose type or lvalue/rvalue-ness would permit the use of a
1318   /// different overload that would behave incorrectly. For example,
1319   /// one might use deleted functions to ban implicit conversion from
1320   /// a floating-point number to an Integer type:
1321   ///
1322   /// @code
1323   /// struct Integer {
1324   ///   Integer(long); // construct from a long
1325   ///   Integer(double) = delete; // no construction from float or double
1326   ///   Integer(long double) = delete; // no construction from long double
1327   /// };
1328   /// @endcode
1329   bool isDeleted() const { return IsDeleted; }
1330   void setDeleted(bool D = true) { IsDeleted = D; }
1331
1332   /// \brief Determines whether this is a function "main", which is
1333   /// the entry point into an executable program.
1334   bool isMain() const;
1335
1336   /// \brief Determines whether this function is a function with
1337   /// external, C linkage.
1338   bool isExternC() const;
1339
1340   /// \brief Determines whether this is a global function.
1341   bool isGlobal() const;
1342
1343   void setPreviousDeclaration(FunctionDecl * PrevDecl);
1344
1345   virtual const FunctionDecl *getCanonicalDecl() const;
1346   virtual FunctionDecl *getCanonicalDecl();
1347
1348   unsigned getBuiltinID() const;
1349
1350   // Iterator access to formal parameters.
1351   unsigned param_size() const { return getNumParams(); }
1352   typedef ParmVarDecl **param_iterator;
1353   typedef ParmVarDecl * const *param_const_iterator;
1354
1355   param_iterator param_begin() { return ParamInfo; }
1356   param_iterator param_end()   { return ParamInfo+param_size(); }
1357
1358   param_const_iterator param_begin() const { return ParamInfo; }
1359   param_const_iterator param_end() const   { return ParamInfo+param_size(); }
1360
1361   /// getNumParams - Return the number of parameters this function must have
1362   /// based on its FunctionType.  This is the length of the ParamInfo array
1363   /// after it has been created.
1364   unsigned getNumParams() const;
1365
1366   const ParmVarDecl *getParamDecl(unsigned i) const {
1367     assert(i < getNumParams() && "Illegal param #");
1368     return ParamInfo[i];
1369   }
1370   ParmVarDecl *getParamDecl(unsigned i) {
1371     assert(i < getNumParams() && "Illegal param #");
1372     return ParamInfo[i];
1373   }
1374   void setParams(ParmVarDecl **NewParamInfo, unsigned NumParams);
1375
1376   /// getMinRequiredArguments - Returns the minimum number of arguments
1377   /// needed to call this function. This may be fewer than the number of
1378   /// function parameters, if some of the parameters have default
1379   /// arguments (in C++).
1380   unsigned getMinRequiredArguments() const;
1381
1382   QualType getResultType() const {
1383     return getType()->getAs<FunctionType>()->getResultType();
1384   }
1385   
1386   /// \brief Determine the type of an expression that calls this function.
1387   QualType getCallResultType() const {
1388     return getType()->getAs<FunctionType>()->getCallResultType(getASTContext());
1389   }
1390                        
1391   StorageClass getStorageClass() const { return StorageClass(SClass); }
1392   void setStorageClass(StorageClass SC) { SClass = SC; }
1393
1394   StorageClass getStorageClassAsWritten() const {
1395     return StorageClass(SClassAsWritten);
1396   }
1397   void setStorageClassAsWritten(StorageClass SC) { SClassAsWritten = SC; }
1398
1399   /// \brief Determine whether the "inline" keyword was specified for this
1400   /// function.
1401   bool isInlineSpecified() const { return IsInline; }
1402                        
1403   /// Set whether the "inline" keyword was specified for this function.
1404   void setInlineSpecified(bool I) { IsInline = I; }
1405
1406   /// \brief Determine whether this function should be inlined, because it is
1407   /// either marked "inline" or is a member function of a C++ class that
1408   /// was defined in the class body.
1409   bool isInlined() const;
1410                        
1411   bool isInlineDefinitionExternallyVisible() const;
1412                        
1413   /// isOverloadedOperator - Whether this function declaration
1414   /// represents an C++ overloaded operator, e.g., "operator+".
1415   bool isOverloadedOperator() const {
1416     return getOverloadedOperator() != OO_None;
1417   }
1418
1419   OverloadedOperatorKind getOverloadedOperator() const;
1420
1421   const IdentifierInfo *getLiteralIdentifier() const;
1422
1423   /// \brief If this function is an instantiation of a member function
1424   /// of a class template specialization, retrieves the function from
1425   /// which it was instantiated.
1426   ///
1427   /// This routine will return non-NULL for (non-templated) member
1428   /// functions of class templates and for instantiations of function
1429   /// templates. For example, given:
1430   ///
1431   /// \code
1432   /// template<typename T>
1433   /// struct X {
1434   ///   void f(T);
1435   /// };
1436   /// \endcode
1437   ///
1438   /// The declaration for X<int>::f is a (non-templated) FunctionDecl
1439   /// whose parent is the class template specialization X<int>. For
1440   /// this declaration, getInstantiatedFromFunction() will return
1441   /// the FunctionDecl X<T>::A. When a complete definition of
1442   /// X<int>::A is required, it will be instantiated from the
1443   /// declaration returned by getInstantiatedFromMemberFunction().
1444   FunctionDecl *getInstantiatedFromMemberFunction() const;
1445   
1446   /// \brief What kind of templated function this is.
1447   TemplatedKind getTemplatedKind() const;
1448
1449   /// \brief If this function is an instantiation of a member function of a
1450   /// class template specialization, retrieves the member specialization
1451   /// information.
1452   MemberSpecializationInfo *getMemberSpecializationInfo() const;
1453                        
1454   /// \brief Specify that this record is an instantiation of the
1455   /// member function FD.
1456   void setInstantiationOfMemberFunction(FunctionDecl *FD,
1457                                         TemplateSpecializationKind TSK);
1458
1459   /// \brief Retrieves the function template that is described by this
1460   /// function declaration.
1461   ///
1462   /// Every function template is represented as a FunctionTemplateDecl
1463   /// and a FunctionDecl (or something derived from FunctionDecl). The
1464   /// former contains template properties (such as the template
1465   /// parameter lists) while the latter contains the actual
1466   /// description of the template's
1467   /// contents. FunctionTemplateDecl::getTemplatedDecl() retrieves the
1468   /// FunctionDecl that describes the function template,
1469   /// getDescribedFunctionTemplate() retrieves the
1470   /// FunctionTemplateDecl from a FunctionDecl.
1471   FunctionTemplateDecl *getDescribedFunctionTemplate() const {
1472     return TemplateOrSpecialization.dyn_cast<FunctionTemplateDecl*>();
1473   }
1474
1475   void setDescribedFunctionTemplate(FunctionTemplateDecl *Template) {
1476     TemplateOrSpecialization = Template;
1477   }
1478
1479   /// \brief Determine whether this function is a function template 
1480   /// specialization.
1481   bool isFunctionTemplateSpecialization() const {
1482     return getPrimaryTemplate() != 0;
1483   }
1484        
1485   /// \brief If this function is actually a function template specialization,
1486   /// retrieve information about this function template specialization. 
1487   /// Otherwise, returns NULL.
1488   FunctionTemplateSpecializationInfo *getTemplateSpecializationInfo() const {
1489     return TemplateOrSpecialization.
1490              dyn_cast<FunctionTemplateSpecializationInfo*>();
1491   }
1492
1493   /// \brief Determines whether this function is a function template
1494   /// specialization or a member of a class template specialization that can
1495   /// be implicitly instantiated.
1496   bool isImplicitlyInstantiable() const;
1497               
1498   /// \brief Retrieve the function declaration from which this function could
1499   /// be instantiated, if it is an instantiation (rather than a non-template
1500   /// or a specialization, for example).
1501   FunctionDecl *getTemplateInstantiationPattern() const;
1502
1503   /// \brief Retrieve the primary template that this function template
1504   /// specialization either specializes or was instantiated from.
1505   ///
1506   /// If this function declaration is not a function template specialization,
1507   /// returns NULL.
1508   FunctionTemplateDecl *getPrimaryTemplate() const;
1509
1510   /// \brief Retrieve the template arguments used to produce this function
1511   /// template specialization from the primary template.
1512   ///
1513   /// If this function declaration is not a function template specialization,
1514   /// returns NULL.
1515   const TemplateArgumentList *getTemplateSpecializationArgs() const;
1516
1517   /// \brief Retrieve the template argument list as written in the sources,
1518   /// if any.
1519   ///
1520   /// If this function declaration is not a function template specialization
1521   /// or if it had no explicit template argument list, returns NULL.
1522   /// Note that it an explicit template argument list may be written empty,
1523   /// e.g., template<> void foo<>(char* s);
1524   const TemplateArgumentListInfo*
1525   getTemplateSpecializationArgsAsWritten() const;
1526
1527   /// \brief Specify that this function declaration is actually a function
1528   /// template specialization.
1529   ///
1530   /// \param Template the function template that this function template
1531   /// specialization specializes.
1532   ///
1533   /// \param TemplateArgs the template arguments that produced this
1534   /// function template specialization from the template.
1535   ///
1536   /// \param InsertPos If non-NULL, the position in the function template
1537   /// specialization set where the function template specialization data will
1538   /// be inserted.
1539   ///
1540   /// \param TSK the kind of template specialization this is.
1541   ///
1542   /// \param TemplateArgsAsWritten location info of template arguments.
1543   ///
1544   /// \param PointOfInstantiation point at which the function template
1545   /// specialization was first instantiated. 
1546   void setFunctionTemplateSpecialization(FunctionTemplateDecl *Template,
1547                                       const TemplateArgumentList *TemplateArgs,
1548                                          void *InsertPos,
1549                     TemplateSpecializationKind TSK = TSK_ImplicitInstantiation,
1550                     const TemplateArgumentListInfo *TemplateArgsAsWritten = 0,
1551                     SourceLocation PointOfInstantiation = SourceLocation());
1552
1553   /// \brief Specify that this function declaration is actually a function
1554   /// template specialization.
1555   ///
1556   /// \param Template the function template that this function template
1557   /// specialization specializes.
1558   ///
1559   /// \param NumTemplateArgs number of template arguments that produced this
1560   /// function template specialization from the template.
1561   ///
1562   /// \param TemplateArgs array of template arguments that produced this
1563   /// function template specialization from the template.
1564   ///
1565   /// \param TSK the kind of template specialization this is.
1566   ///
1567   /// \param NumTemplateArgsAsWritten number of template arguments that produced
1568   /// this function template specialization from the template.
1569   ///
1570   /// \param TemplateArgsAsWritten array of location info for the template
1571   /// arguments.
1572   ///
1573   /// \param LAngleLoc location of left angle token.
1574   ///
1575   /// \param RAngleLoc location of right angle token.
1576   ///
1577   /// \param PointOfInstantiation point at which the function template
1578   /// specialization was first instantiated. 
1579   void setFunctionTemplateSpecialization(FunctionTemplateDecl *Template,
1580                                          unsigned NumTemplateArgs,
1581                                          const TemplateArgument *TemplateArgs,
1582                                          TemplateSpecializationKind TSK,
1583                                          unsigned NumTemplateArgsAsWritten,
1584                                      TemplateArgumentLoc *TemplateArgsAsWritten,
1585                                           SourceLocation LAngleLoc,
1586                                           SourceLocation RAngleLoc,
1587                                           SourceLocation PointOfInstantiation);
1588
1589   /// \brief Specifies that this function declaration is actually a
1590   /// dependent function template specialization.
1591   void setDependentTemplateSpecialization(ASTContext &Context,
1592                              const UnresolvedSetImpl &Templates,
1593                       const TemplateArgumentListInfo &TemplateArgs);
1594
1595   DependentFunctionTemplateSpecializationInfo *
1596   getDependentSpecializationInfo() const {
1597     return TemplateOrSpecialization.
1598              dyn_cast<DependentFunctionTemplateSpecializationInfo*>();
1599   }
1600
1601   /// \brief Determine what kind of template instantiation this function
1602   /// represents.
1603   TemplateSpecializationKind getTemplateSpecializationKind() const;
1604
1605   /// \brief Determine what kind of template instantiation this function
1606   /// represents.
1607   void setTemplateSpecializationKind(TemplateSpecializationKind TSK,
1608                         SourceLocation PointOfInstantiation = SourceLocation());
1609
1610   /// \brief Retrieve the (first) point of instantiation of a function template
1611   /// specialization or a member of a class template specialization.
1612   ///
1613   /// \returns the first point of instantiation, if this function was 
1614   /// instantiated from a template; otherwie, returns an invalid source 
1615   /// location.
1616   SourceLocation getPointOfInstantiation() const;
1617                        
1618   /// \brief Determine whether this is or was instantiated from an out-of-line 
1619   /// definition of a member function.
1620   virtual bool isOutOfLine() const;
1621                        
1622   // Implement isa/cast/dyncast/etc.
1623   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1624   static bool classof(const FunctionDecl *D) { return true; }
1625   static bool classofKind(Kind K) {
1626     return K >= firstFunction && K <= lastFunction;
1627   }
1628   static DeclContext *castToDeclContext(const FunctionDecl *D) {
1629     return static_cast<DeclContext *>(const_cast<FunctionDecl*>(D));
1630   }
1631   static FunctionDecl *castFromDeclContext(const DeclContext *DC) {
1632     return static_cast<FunctionDecl *>(const_cast<DeclContext*>(DC));
1633   }
1634
1635   friend class PCHDeclReader;
1636   friend class PCHDeclWriter;
1637 };
1638
1639
1640 /// FieldDecl - An instance of this class is created by Sema::ActOnField to
1641 /// represent a member of a struct/union/class.
1642 class FieldDecl : public DeclaratorDecl {
1643   // FIXME: This can be packed into the bitfields in Decl.
1644   bool Mutable : 1;
1645   Expr *BitWidth;
1646 protected:
1647   FieldDecl(Kind DK, DeclContext *DC, SourceLocation L,
1648             IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo,
1649             Expr *BW, bool Mutable)
1650     : DeclaratorDecl(DK, DC, L, Id, T, TInfo), Mutable(Mutable), BitWidth(BW) {
1651   }
1652
1653 public:
1654   static FieldDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L,
1655                            IdentifierInfo *Id, QualType T,
1656                            TypeSourceInfo *TInfo, Expr *BW, bool Mutable);
1657
1658   /// isMutable - Determines whether this field is mutable (C++ only).
1659   bool isMutable() const { return Mutable; }
1660
1661   /// \brief Set whether this field is mutable (C++ only).
1662   void setMutable(bool M) { Mutable = M; }
1663
1664   /// isBitfield - Determines whether this field is a bitfield.
1665   bool isBitField() const { return BitWidth != NULL; }
1666
1667   /// @brief Determines whether this is an unnamed bitfield.
1668   bool isUnnamedBitfield() const { return BitWidth != NULL && !getDeclName(); }
1669
1670   /// isAnonymousStructOrUnion - Determines whether this field is a
1671   /// representative for an anonymous struct or union. Such fields are
1672   /// unnamed and are implicitly generated by the implementation to
1673   /// store the data for the anonymous union or struct.
1674   bool isAnonymousStructOrUnion() const;
1675
1676   Expr *getBitWidth() const { return BitWidth; }
1677   void setBitWidth(Expr *BW) { BitWidth = BW; }
1678
1679   /// getParent - Returns the parent of this field declaration, which
1680   /// is the struct in which this method is defined.
1681   const RecordDecl *getParent() const {
1682     return cast<RecordDecl>(getDeclContext());
1683   }
1684
1685   RecordDecl *getParent() {
1686     return cast<RecordDecl>(getDeclContext());
1687   }
1688   
1689   // Implement isa/cast/dyncast/etc.
1690   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1691   static bool classof(const FieldDecl *D) { return true; }
1692   static bool classofKind(Kind K) { return K >= firstField && K <= lastField; }
1693 };
1694
1695 /// EnumConstantDecl - An instance of this object exists for each enum constant
1696 /// that is defined.  For example, in "enum X {a,b}", each of a/b are
1697 /// EnumConstantDecl's, X is an instance of EnumDecl, and the type of a/b is a
1698 /// TagType for the X EnumDecl.
1699 class EnumConstantDecl : public ValueDecl {
1700   Stmt *Init; // an integer constant expression
1701   llvm::APSInt Val; // The value.
1702 protected:
1703   EnumConstantDecl(DeclContext *DC, SourceLocation L,
1704                    IdentifierInfo *Id, QualType T, Expr *E,
1705                    const llvm::APSInt &V)
1706     : ValueDecl(EnumConstant, DC, L, Id, T), Init((Stmt*)E), Val(V) {}
1707
1708   virtual ~EnumConstantDecl() {}
1709 public:
1710
1711   static EnumConstantDecl *Create(ASTContext &C, EnumDecl *DC,
1712                                   SourceLocation L, IdentifierInfo *Id,
1713                                   QualType T, Expr *E,
1714                                   const llvm::APSInt &V);
1715
1716   virtual void Destroy(ASTContext& C);
1717
1718   const Expr *getInitExpr() const { return (const Expr*) Init; }
1719   Expr *getInitExpr() { return (Expr*) Init; }
1720   const llvm::APSInt &getInitVal() const { return Val; }
1721
1722   void setInitExpr(Expr *E) { Init = (Stmt*) E; }
1723   void setInitVal(const llvm::APSInt &V) { Val = V; }
1724
1725   // Implement isa/cast/dyncast/etc.
1726   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1727   static bool classof(const EnumConstantDecl *D) { return true; }
1728   static bool classofKind(Kind K) { return K == EnumConstant; }
1729
1730   friend class StmtIteratorBase;
1731 };
1732
1733
1734 /// TypeDecl - Represents a declaration of a type.
1735 ///
1736 class TypeDecl : public NamedDecl {
1737   /// TypeForDecl - This indicates the Type object that represents
1738   /// this TypeDecl.  It is a cache maintained by
1739   /// ASTContext::getTypedefType, ASTContext::getTagDeclType, and
1740   /// ASTContext::getTemplateTypeParmType, and TemplateTypeParmDecl.
1741   mutable Type *TypeForDecl;
1742   friend class ASTContext;
1743   friend class DeclContext;
1744   friend class TagDecl;
1745   friend class TemplateTypeParmDecl;
1746   friend class TagType;
1747
1748 protected:
1749   TypeDecl(Kind DK, DeclContext *DC, SourceLocation L,
1750            IdentifierInfo *Id)
1751     : NamedDecl(DK, DC, L, Id), TypeForDecl(0) {}
1752
1753 public:
1754   // Low-level accessor
1755   Type *getTypeForDecl() const { return TypeForDecl; }
1756   void setTypeForDecl(Type *TD) { TypeForDecl = TD; }
1757
1758   // Implement isa/cast/dyncast/etc.
1759   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1760   static bool classof(const TypeDecl *D) { return true; }
1761   static bool classofKind(Kind K) { return K >= firstType && K <= lastType; }
1762 };
1763
1764
1765 class TypedefDecl : public TypeDecl, public Redeclarable<TypedefDecl> {
1766   /// UnderlyingType - This is the type the typedef is set to.
1767   TypeSourceInfo *TInfo;
1768
1769   TypedefDecl(DeclContext *DC, SourceLocation L,
1770               IdentifierInfo *Id, TypeSourceInfo *TInfo)
1771     : TypeDecl(Typedef, DC, L, Id), TInfo(TInfo) {}
1772
1773   virtual ~TypedefDecl();
1774
1775 protected:
1776   typedef Redeclarable<TypedefDecl> redeclarable_base;
1777   virtual TypedefDecl *getNextRedeclaration() { return RedeclLink.getNext(); }
1778
1779 public:
1780   typedef redeclarable_base::redecl_iterator redecl_iterator;
1781   redecl_iterator redecls_begin() const {
1782     return redeclarable_base::redecls_begin();
1783   }
1784   redecl_iterator redecls_end() const {
1785     return redeclarable_base::redecls_end();
1786   }
1787
1788   static TypedefDecl *Create(ASTContext &C, DeclContext *DC,
1789                              SourceLocation L, IdentifierInfo *Id,
1790                              TypeSourceInfo *TInfo);
1791
1792   TypeSourceInfo *getTypeSourceInfo() const {
1793     return TInfo;
1794   }
1795
1796   /// Retrieves the canonical declaration of this typedef.
1797   TypedefDecl *getCanonicalDecl() {
1798     return getFirstDeclaration();
1799   }
1800   const TypedefDecl *getCanonicalDecl() const {
1801     return getFirstDeclaration();
1802   }
1803
1804   QualType getUnderlyingType() const {
1805     return TInfo->getType();
1806   }
1807   void setTypeSourceInfo(TypeSourceInfo *newType) {
1808     TInfo = newType;
1809   }
1810
1811   // Implement isa/cast/dyncast/etc.
1812   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1813   static bool classof(const TypedefDecl *D) { return true; }
1814   static bool classofKind(Kind K) { return K == Typedef; }
1815 };
1816
1817 class TypedefDecl;
1818
1819 /// TagDecl - Represents the declaration of a struct/union/class/enum.
1820 class TagDecl
1821   : public TypeDecl, public DeclContext, public Redeclarable<TagDecl> {
1822 public:
1823   // This is really ugly.
1824   typedef TagTypeKind TagKind;
1825
1826 private:
1827   // FIXME: This can be packed into the bitfields in Decl.
1828   /// TagDeclKind - The TagKind enum.
1829   unsigned TagDeclKind : 2;
1830
1831   /// IsDefinition - True if this is a definition ("struct foo {};"), false if
1832   /// it is a declaration ("struct foo;").
1833   bool IsDefinition : 1;
1834
1835   /// IsEmbeddedInDeclarator - True if this tag declaration is
1836   /// "embedded" (i.e., defined or declared for the very first time)
1837   /// in the syntax of a declarator.
1838   bool IsEmbeddedInDeclarator : 1;
1839
1840 protected:
1841   // These are used by (and only defined for) EnumDecl.
1842   unsigned NumPositiveBits : 8;
1843   unsigned NumNegativeBits : 8;
1844
1845 private:
1846   SourceLocation TagKeywordLoc;
1847   SourceLocation RBraceLoc;
1848
1849   // A struct representing syntactic qualifier info,
1850   // to be used for the (uncommon) case of out-of-line declarations.
1851   typedef QualifierInfo ExtInfo;
1852
1853   /// TypedefDeclOrQualifier - If the (out-of-line) tag declaration name
1854   /// is qualified, it points to the qualifier info (nns and range);
1855   /// otherwise, if the tag declaration is anonymous and it is part of
1856   /// a typedef, it points to the TypedefDecl (used for mangling);
1857   /// otherwise, it is a null (TypedefDecl) pointer.
1858   llvm::PointerUnion<TypedefDecl*, ExtInfo*> TypedefDeclOrQualifier;
1859
1860   bool hasExtInfo() const { return TypedefDeclOrQualifier.is<ExtInfo*>(); }
1861   ExtInfo *getExtInfo() { return TypedefDeclOrQualifier.get<ExtInfo*>(); }
1862   const ExtInfo *getExtInfo() const {
1863     return TypedefDeclOrQualifier.get<ExtInfo*>();
1864   }
1865
1866 protected:
1867   TagDecl(Kind DK, TagKind TK, DeclContext *DC,
1868           SourceLocation L, IdentifierInfo *Id,
1869           TagDecl *PrevDecl, SourceLocation TKL = SourceLocation())
1870     : TypeDecl(DK, DC, L, Id), DeclContext(DK), TagKeywordLoc(TKL),
1871       TypedefDeclOrQualifier((TypedefDecl*) 0) {
1872     assert((DK != Enum || TK == TTK_Enum) &&
1873            "EnumDecl not matched with TTK_Enum");
1874     TagDeclKind = TK;
1875     IsDefinition = false;
1876     IsEmbeddedInDeclarator = false;
1877     setPreviousDeclaration(PrevDecl);
1878   }
1879
1880   typedef Redeclarable<TagDecl> redeclarable_base;
1881   virtual TagDecl *getNextRedeclaration() { return RedeclLink.getNext(); }
1882
1883 public:
1884   void Destroy(ASTContext &C);
1885
1886   typedef redeclarable_base::redecl_iterator redecl_iterator;
1887   redecl_iterator redecls_begin() const {
1888     return redeclarable_base::redecls_begin();
1889   }
1890   redecl_iterator redecls_end() const {
1891     return redeclarable_base::redecls_end();
1892   }
1893
1894   SourceLocation getRBraceLoc() const { return RBraceLoc; }
1895   void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
1896
1897   SourceLocation getTagKeywordLoc() const { return TagKeywordLoc; }
1898   void setTagKeywordLoc(SourceLocation TKL) { TagKeywordLoc = TKL; }
1899
1900   /// getInnerLocStart - Return SourceLocation representing start of source
1901   /// range ignoring outer template declarations.
1902   virtual SourceLocation getInnerLocStart() const { return TagKeywordLoc; }
1903
1904   /// getOuterLocStart - Return SourceLocation representing start of source
1905   /// range taking into account any outer template declarations.
1906   SourceLocation getOuterLocStart() const;
1907   virtual SourceRange getSourceRange() const;
1908
1909   virtual TagDecl* getCanonicalDecl();
1910   const TagDecl* getCanonicalDecl() const {
1911     return const_cast<TagDecl*>(this)->getCanonicalDecl();
1912   }
1913
1914   /// isDefinition - Return true if this decl has its body specified.
1915   bool isDefinition() const {
1916     return IsDefinition;
1917   }
1918
1919   bool isEmbeddedInDeclarator() const {
1920     return IsEmbeddedInDeclarator;
1921   }
1922   void setEmbeddedInDeclarator(bool isInDeclarator) {
1923     IsEmbeddedInDeclarator = isInDeclarator;
1924   }
1925
1926   /// \brief Whether this declaration declares a type that is
1927   /// dependent, i.e., a type that somehow depends on template
1928   /// parameters.
1929   bool isDependentType() const { return isDependentContext(); }
1930
1931   /// @brief Starts the definition of this tag declaration.
1932   ///
1933   /// This method should be invoked at the beginning of the definition
1934   /// of this tag declaration. It will set the tag type into a state
1935   /// where it is in the process of being defined.
1936   void startDefinition();
1937
1938   /// @brief Completes the definition of this tag declaration.
1939   void completeDefinition();
1940
1941   /// getDefinition - Returns the TagDecl that actually defines this
1942   ///  struct/union/class/enum.  When determining whether or not a
1943   ///  struct/union/class/enum is completely defined, one should use this method
1944   ///  as opposed to 'isDefinition'.  'isDefinition' indicates whether or not a
1945   ///  specific TagDecl is defining declaration, not whether or not the
1946   ///  struct/union/class/enum type is defined.  This method returns NULL if
1947   ///  there is no TagDecl that defines the struct/union/class/enum.
1948   TagDecl* getDefinition() const;
1949
1950   void setDefinition(bool V) { IsDefinition = V; }
1951
1952   const char *getKindName() const {
1953     return TypeWithKeyword::getTagTypeKindName(getTagKind());
1954   }
1955
1956   TagKind getTagKind() const {
1957     return TagKind(TagDeclKind);
1958   }
1959
1960   void setTagKind(TagKind TK) { TagDeclKind = TK; }
1961
1962   bool isStruct() const { return getTagKind() == TTK_Struct; }
1963   bool isClass()  const { return getTagKind() == TTK_Class; }
1964   bool isUnion()  const { return getTagKind() == TTK_Union; }
1965   bool isEnum()   const { return getTagKind() == TTK_Enum; }
1966
1967   TypedefDecl *getTypedefForAnonDecl() const {
1968     return hasExtInfo() ? 0 : TypedefDeclOrQualifier.get<TypedefDecl*>();
1969   }
1970
1971   void setTypedefForAnonDecl(TypedefDecl *TDD);
1972
1973   NestedNameSpecifier *getQualifier() const {
1974     return hasExtInfo() ? getExtInfo()->NNS : 0;
1975   }
1976   SourceRange getQualifierRange() const {
1977     return hasExtInfo() ? getExtInfo()->NNSRange : SourceRange();
1978   }
1979   void setQualifierInfo(NestedNameSpecifier *Qualifier,
1980                         SourceRange QualifierRange);
1981
1982   unsigned getNumTemplateParameterLists() const {
1983     return hasExtInfo() ? getExtInfo()->NumTemplParamLists : 0;
1984   }
1985   TemplateParameterList *getTemplateParameterList(unsigned i) const {
1986     assert(i < getNumTemplateParameterLists());
1987     return getExtInfo()->TemplParamLists[i];
1988   }
1989   void setTemplateParameterListsInfo(ASTContext &Context, unsigned NumTPLists,
1990                                      TemplateParameterList **TPLists) {
1991     getExtInfo()->setTemplateParameterListsInfo(Context, NumTPLists, TPLists);
1992   }
1993
1994   // Implement isa/cast/dyncast/etc.
1995   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1996   static bool classof(const TagDecl *D) { return true; }
1997   static bool classofKind(Kind K) { return K >= firstTag && K <= lastTag; }
1998
1999   static DeclContext *castToDeclContext(const TagDecl *D) {
2000     return static_cast<DeclContext *>(const_cast<TagDecl*>(D));
2001   }
2002   static TagDecl *castFromDeclContext(const DeclContext *DC) {
2003     return static_cast<TagDecl *>(const_cast<DeclContext*>(DC));
2004   }
2005
2006   friend class PCHDeclReader;
2007   friend class PCHDeclWriter;
2008 };
2009
2010 /// EnumDecl - Represents an enum.  As an extension, we allow forward-declared
2011 /// enums.
2012 class EnumDecl : public TagDecl {
2013   /// IntegerType - This represent the integer type that the enum corresponds
2014   /// to for code generation purposes.  Note that the enumerator constants may
2015   /// have a different type than this does.
2016   QualType IntegerType;
2017
2018   /// PromotionType - The integer type that values of this type should
2019   /// promote to.  In C, enumerators are generally of an integer type
2020   /// directly, but gcc-style large enumerators (and all enumerators
2021   /// in C++) are of the enum type instead.
2022   QualType PromotionType;
2023
2024   /// \brief If the enumeration was instantiated from an enumeration
2025   /// within a class or function template, this pointer refers to the
2026   /// enumeration declared within the template.
2027   EnumDecl *InstantiatedFrom;
2028
2029   // The number of positive and negative bits required by the
2030   // enumerators are stored in the SubclassBits field.
2031   enum {
2032     NumBitsWidth = 8,
2033     NumBitsMask = (1 << NumBitsWidth) - 1
2034   };
2035
2036   EnumDecl(DeclContext *DC, SourceLocation L,
2037            IdentifierInfo *Id, EnumDecl *PrevDecl, SourceLocation TKL)
2038     : TagDecl(Enum, TTK_Enum, DC, L, Id, PrevDecl, TKL), InstantiatedFrom(0) {
2039       IntegerType = QualType();
2040     }
2041 public:
2042   EnumDecl *getCanonicalDecl() {
2043     return cast<EnumDecl>(TagDecl::getCanonicalDecl());
2044   }
2045   const EnumDecl *getCanonicalDecl() const {
2046     return cast<EnumDecl>(TagDecl::getCanonicalDecl());
2047   }
2048
2049   const EnumDecl *getPreviousDeclaration() const {
2050     return cast_or_null<EnumDecl>(TagDecl::getPreviousDeclaration());
2051   }
2052   EnumDecl *getPreviousDeclaration() {
2053     return cast_or_null<EnumDecl>(TagDecl::getPreviousDeclaration());
2054   }
2055
2056   static EnumDecl *Create(ASTContext &C, DeclContext *DC,
2057                           SourceLocation L, IdentifierInfo *Id,
2058                           SourceLocation TKL, EnumDecl *PrevDecl);
2059   static EnumDecl *Create(ASTContext &C, EmptyShell Empty);
2060
2061   virtual void Destroy(ASTContext& C);
2062
2063   /// completeDefinition - When created, the EnumDecl corresponds to a
2064   /// forward-declared enum. This method is used to mark the
2065   /// declaration as being defined; it's enumerators have already been
2066   /// added (via DeclContext::addDecl). NewType is the new underlying
2067   /// type of the enumeration type.
2068   void completeDefinition(QualType NewType,
2069                           QualType PromotionType,
2070                           unsigned NumPositiveBits,
2071                           unsigned NumNegativeBits);
2072
2073   // enumerator_iterator - Iterates through the enumerators of this
2074   // enumeration.
2075   typedef specific_decl_iterator<EnumConstantDecl> enumerator_iterator;
2076
2077   enumerator_iterator enumerator_begin() const {
2078     const EnumDecl *E = cast_or_null<EnumDecl>(getDefinition());
2079     if (!E)
2080       E = this;
2081     return enumerator_iterator(E->decls_begin());
2082   }
2083
2084   enumerator_iterator enumerator_end() const {
2085     const EnumDecl *E = cast_or_null<EnumDecl>(getDefinition());
2086     if (!E)
2087       E = this;
2088     return enumerator_iterator(E->decls_end());
2089   }
2090
2091   /// getPromotionType - Return the integer type that enumerators
2092   /// should promote to.
2093   QualType getPromotionType() const { return PromotionType; }
2094
2095   /// \brief Set the promotion type.
2096   void setPromotionType(QualType T) { PromotionType = T; }
2097
2098   /// getIntegerType - Return the integer type this enum decl corresponds to.
2099   /// This returns a null qualtype for an enum forward definition.
2100   QualType getIntegerType() const { return IntegerType; }
2101
2102   /// \brief Set the underlying integer type.
2103   void setIntegerType(QualType T) { IntegerType = T; }
2104
2105   /// \brief Returns the width in bits requred to store all the
2106   /// non-negative enumerators of this enum.
2107   unsigned getNumPositiveBits() const {
2108     return NumPositiveBits;
2109   }
2110   void setNumPositiveBits(unsigned Num) {
2111     NumPositiveBits = Num;
2112     assert(NumPositiveBits == Num && "can't store this bitcount");
2113   }
2114
2115   /// \brief Returns the width in bits requred to store all the
2116   /// negative enumerators of this enum.  These widths include
2117   /// the rightmost leading 1;  that is:
2118   /// 
2119   /// MOST NEGATIVE ENUMERATOR     PATTERN     NUM NEGATIVE BITS
2120   /// ------------------------     -------     -----------------
2121   ///                       -1     1111111                     1
2122   ///                      -10     1110110                     5
2123   ///                     -101     1001011                     8
2124   unsigned getNumNegativeBits() const {
2125     return NumNegativeBits;
2126   }
2127   void setNumNegativeBits(unsigned Num) {
2128     NumNegativeBits = Num;
2129   }
2130
2131   /// \brief Returns the enumeration (declared within the template)
2132   /// from which this enumeration type was instantiated, or NULL if
2133   /// this enumeration was not instantiated from any template.
2134   EnumDecl *getInstantiatedFromMemberEnum() const {
2135     return InstantiatedFrom;
2136   }
2137
2138   void setInstantiationOfMemberEnum(EnumDecl *IF) { InstantiatedFrom = IF; }
2139
2140   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2141   static bool classof(const EnumDecl *D) { return true; }
2142   static bool classofKind(Kind K) { return K == Enum; }
2143 };
2144
2145
2146 /// RecordDecl - Represents a struct/union/class.  For example:
2147 ///   struct X;                  // Forward declaration, no "body".
2148 ///   union Y { int A, B; };     // Has body with members A and B (FieldDecls).
2149 /// This decl will be marked invalid if *any* members are invalid.
2150 ///
2151 class RecordDecl : public TagDecl {
2152   // FIXME: This can be packed into the bitfields in Decl.
2153   /// HasFlexibleArrayMember - This is true if this struct ends with a flexible
2154   /// array member (e.g. int X[]) or if this union contains a struct that does.
2155   /// If so, this cannot be contained in arrays or other structs as a member.
2156   bool HasFlexibleArrayMember : 1;
2157
2158   /// AnonymousStructOrUnion - Whether this is the type of an anonymous struct
2159   /// or union.
2160   bool AnonymousStructOrUnion : 1;
2161
2162   /// HasObjectMember - This is true if this struct has at least one member
2163   /// containing an object.
2164   bool HasObjectMember : 1;
2165
2166 protected:
2167   RecordDecl(Kind DK, TagKind TK, DeclContext *DC,
2168              SourceLocation L, IdentifierInfo *Id,
2169              RecordDecl *PrevDecl, SourceLocation TKL);
2170   virtual ~RecordDecl();
2171
2172 public:
2173   static RecordDecl *Create(ASTContext &C, TagKind TK, DeclContext *DC,
2174                             SourceLocation L, IdentifierInfo *Id,
2175                             SourceLocation TKL = SourceLocation(),
2176                             RecordDecl* PrevDecl = 0);
2177   static RecordDecl *Create(ASTContext &C, EmptyShell Empty);
2178
2179   const RecordDecl *getPreviousDeclaration() const {
2180     return cast_or_null<RecordDecl>(TagDecl::getPreviousDeclaration());
2181   }
2182   RecordDecl *getPreviousDeclaration() {
2183     return cast_or_null<RecordDecl>(TagDecl::getPreviousDeclaration());
2184   }
2185
2186   virtual void Destroy(ASTContext& C);
2187
2188   bool hasFlexibleArrayMember() const { return HasFlexibleArrayMember; }
2189   void setHasFlexibleArrayMember(bool V) { HasFlexibleArrayMember = V; }
2190
2191   /// isAnonymousStructOrUnion - Whether this is an anonymous struct
2192   /// or union. To be an anonymous struct or union, it must have been
2193   /// declared without a name and there must be no objects of this
2194   /// type declared, e.g.,
2195   /// @code
2196   ///   union { int i; float f; };
2197   /// @endcode
2198   /// is an anonymous union but neither of the following are:
2199   /// @code
2200   ///  union X { int i; float f; };
2201   ///  union { int i; float f; } obj;
2202   /// @endcode
2203   bool isAnonymousStructOrUnion() const { return AnonymousStructOrUnion; }
2204   void setAnonymousStructOrUnion(bool Anon) {
2205     AnonymousStructOrUnion = Anon;
2206   }
2207
2208   ValueDecl *getAnonymousStructOrUnionObject();
2209   const ValueDecl *getAnonymousStructOrUnionObject() const {
2210     return const_cast<RecordDecl*>(this)->getAnonymousStructOrUnionObject();
2211   }
2212
2213   bool hasObjectMember() const { return HasObjectMember; }
2214   void setHasObjectMember (bool val) { HasObjectMember = val; }
2215
2216   /// \brief Determines whether this declaration represents the
2217   /// injected class name.
2218   ///
2219   /// The injected class name in C++ is the name of the class that
2220   /// appears inside the class itself. For example:
2221   ///
2222   /// \code
2223   /// struct C {
2224   ///   // C is implicitly declared here as a synonym for the class name.
2225   /// };
2226   ///
2227   /// C::C c; // same as "C c;"
2228   /// \endcode
2229   bool isInjectedClassName() const;
2230
2231   /// getDefinition - Returns the RecordDecl that actually defines this
2232   ///  struct/union/class.  When determining whether or not a struct/union/class
2233   ///  is completely defined, one should use this method as opposed to
2234   ///  'isDefinition'.  'isDefinition' indicates whether or not a specific
2235   ///  RecordDecl is defining declaration, not whether or not the record
2236   ///  type is defined.  This method returns NULL if there is no RecordDecl
2237   ///  that defines the struct/union/tag.
2238   RecordDecl* getDefinition() const {
2239     return cast_or_null<RecordDecl>(TagDecl::getDefinition());
2240   }
2241
2242   // Iterator access to field members. The field iterator only visits
2243   // the non-static data members of this class, ignoring any static
2244   // data members, functions, constructors, destructors, etc.
2245   typedef specific_decl_iterator<FieldDecl> field_iterator;
2246
2247   field_iterator field_begin() const {
2248     return field_iterator(decls_begin());
2249   }
2250   field_iterator field_end() const {
2251     return field_iterator(decls_end());
2252   }
2253
2254   // field_empty - Whether there are any fields (non-static data
2255   // members) in this record.
2256   bool field_empty() const {
2257     return field_begin() == field_end();
2258   }
2259
2260   /// completeDefinition - Notes that the definition of this type is
2261   /// now complete.
2262   void completeDefinition();
2263
2264   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2265   static bool classof(const RecordDecl *D) { return true; }
2266   static bool classofKind(Kind K) {
2267     return K >= firstRecord && K <= lastRecord;
2268   }
2269 };
2270
2271 class FileScopeAsmDecl : public Decl {
2272   StringLiteral *AsmString;
2273   FileScopeAsmDecl(DeclContext *DC, SourceLocation L, StringLiteral *asmstring)
2274     : Decl(FileScopeAsm, DC, L), AsmString(asmstring) {}
2275 public:
2276   static FileScopeAsmDecl *Create(ASTContext &C, DeclContext *DC,
2277                                   SourceLocation L, StringLiteral *Str);
2278
2279   const StringLiteral *getAsmString() const { return AsmString; }
2280   StringLiteral *getAsmString() { return AsmString; }
2281   void setAsmString(StringLiteral *Asm) { AsmString = Asm; }
2282
2283   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2284   static bool classof(const FileScopeAsmDecl *D) { return true; }
2285   static bool classofKind(Kind K) { return K == FileScopeAsm; }
2286 };
2287
2288 /// BlockDecl - This represents a block literal declaration, which is like an
2289 /// unnamed FunctionDecl.  For example:
2290 /// ^{ statement-body }   or   ^(int arg1, float arg2){ statement-body }
2291 ///
2292 class BlockDecl : public Decl, public DeclContext {
2293   // FIXME: This can be packed into the bitfields in Decl.
2294   bool IsVariadic : 1;
2295   /// ParamInfo - new[]'d array of pointers to ParmVarDecls for the formal
2296   /// parameters of this function.  This is null if a prototype or if there are
2297   /// no formals.
2298   ParmVarDecl **ParamInfo;
2299   unsigned NumParams;
2300
2301   Stmt *Body;
2302   TypeSourceInfo *SignatureAsWritten;
2303
2304 protected:
2305   BlockDecl(DeclContext *DC, SourceLocation CaretLoc)
2306     : Decl(Block, DC, CaretLoc), DeclContext(Block),
2307       IsVariadic(false), ParamInfo(0), NumParams(0), Body(0),
2308       SignatureAsWritten(0) {}
2309
2310   virtual ~BlockDecl();
2311   virtual void Destroy(ASTContext& C);
2312
2313 public:
2314   static BlockDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L);
2315
2316   SourceLocation getCaretLocation() const { return getLocation(); }
2317
2318   bool isVariadic() const { return IsVariadic; }
2319   void setIsVariadic(bool value) { IsVariadic = value; }
2320
2321   CompoundStmt *getCompoundBody() const { return (CompoundStmt*) Body; }
2322   Stmt *getBody() const { return (Stmt*) Body; }
2323   void setBody(CompoundStmt *B) { Body = (Stmt*) B; }
2324
2325   void setSignatureAsWritten(TypeSourceInfo *Sig) { SignatureAsWritten = Sig; }
2326   TypeSourceInfo *getSignatureAsWritten() const { return SignatureAsWritten; }
2327
2328   // Iterator access to formal parameters.
2329   unsigned param_size() const { return getNumParams(); }
2330   typedef ParmVarDecl **param_iterator;
2331   typedef ParmVarDecl * const *param_const_iterator;
2332
2333   bool param_empty() const { return NumParams == 0; }
2334   param_iterator param_begin()  { return ParamInfo; }
2335   param_iterator param_end()   { return ParamInfo+param_size(); }
2336
2337   param_const_iterator param_begin() const { return ParamInfo; }
2338   param_const_iterator param_end() const   { return ParamInfo+param_size(); }
2339
2340   unsigned getNumParams() const;
2341   const ParmVarDecl *getParamDecl(unsigned i) const {
2342     assert(i < getNumParams() && "Illegal param #");
2343     return ParamInfo[i];
2344   }
2345   ParmVarDecl *getParamDecl(unsigned i) {
2346     assert(i < getNumParams() && "Illegal param #");
2347     return ParamInfo[i];
2348   }
2349   void setParams(ParmVarDecl **NewParamInfo, unsigned NumParams);
2350
2351   // Implement isa/cast/dyncast/etc.
2352   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2353   static bool classof(const BlockDecl *D) { return true; }
2354   static bool classofKind(Kind K) { return K == Block; }
2355   static DeclContext *castToDeclContext(const BlockDecl *D) {
2356     return static_cast<DeclContext *>(const_cast<BlockDecl*>(D));
2357   }
2358   static BlockDecl *castFromDeclContext(const DeclContext *DC) {
2359     return static_cast<BlockDecl *>(const_cast<DeclContext*>(DC));
2360   }
2361 };
2362
2363 /// Insertion operator for diagnostics.  This allows sending NamedDecl's
2364 /// into a diagnostic with <<.
2365 inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
2366                                            NamedDecl* ND) {
2367   DB.AddTaggedVal(reinterpret_cast<intptr_t>(ND), Diagnostic::ak_nameddecl);
2368   return DB;
2369 }
2370
2371 }  // end namespace clang
2372
2373 #endif