clang API Documentation

Decl.h
Go to the documentation of this file.
00001 //===--- Decl.h - Classes for representing declarations ---------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 //  This file defines the Decl subclasses.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_CLANG_AST_DECL_H
00015 #define LLVM_CLANG_AST_DECL_H
00016 
00017 #include "clang/AST/APValue.h"
00018 #include "clang/AST/DeclBase.h"
00019 #include "clang/AST/Redeclarable.h"
00020 #include "clang/AST/DeclarationName.h"
00021 #include "clang/AST/ExternalASTSource.h"
00022 #include "clang/Basic/Linkage.h"
00023 #include "llvm/ADT/ArrayRef.h"
00024 #include "llvm/ADT/Optional.h"
00025 #include "llvm/Support/Compiler.h"
00026 
00027 namespace clang {
00028 class CXXTemporary;
00029 class Expr;
00030 class FunctionTemplateDecl;
00031 class Stmt;
00032 class CompoundStmt;
00033 class StringLiteral;
00034 class NestedNameSpecifier;
00035 class TemplateParameterList;
00036 class TemplateArgumentList;
00037 struct ASTTemplateArgumentListInfo;
00038 class MemberSpecializationInfo;
00039 class FunctionTemplateSpecializationInfo;
00040 class DependentFunctionTemplateSpecializationInfo;
00041 class TypeLoc;
00042 class UnresolvedSetImpl;
00043 class LabelStmt;
00044 class Module;
00045   
00046 /// \brief A container of type source information.
00047 ///
00048 /// A client can read the relevant info using TypeLoc wrappers, e.g:
00049 /// @code
00050 /// TypeLoc TL = TypeSourceInfo->getTypeLoc();
00051 /// if (PointerLoc *PL = dyn_cast<PointerLoc>(&TL))
00052 ///   PL->getStarLoc().print(OS, SrcMgr);
00053 /// @endcode
00054 ///
00055 class TypeSourceInfo {
00056   QualType Ty;
00057   // Contains a memory block after the class, used for type source information,
00058   // allocated by ASTContext.
00059   friend class ASTContext;
00060   TypeSourceInfo(QualType ty) : Ty(ty) { }
00061 public:
00062   /// \brief Return the type wrapped by this type source info.
00063   QualType getType() const { return Ty; }
00064 
00065   /// \brief Return the TypeLoc wrapper for the type source info.
00066   TypeLoc getTypeLoc() const; // implemented in TypeLoc.h
00067 };
00068 
00069 /// TranslationUnitDecl - The top declaration context.
00070 class TranslationUnitDecl : public Decl, public DeclContext {
00071   virtual void anchor();
00072   ASTContext &Ctx;
00073 
00074   /// The (most recently entered) anonymous namespace for this
00075   /// translation unit, if one has been created.
00076   NamespaceDecl *AnonymousNamespace;
00077 
00078   explicit TranslationUnitDecl(ASTContext &ctx)
00079     : Decl(TranslationUnit, 0, SourceLocation()),
00080       DeclContext(TranslationUnit),
00081       Ctx(ctx), AnonymousNamespace(0) {}
00082 public:
00083   ASTContext &getASTContext() const { return Ctx; }
00084 
00085   NamespaceDecl *getAnonymousNamespace() const { return AnonymousNamespace; }
00086   void setAnonymousNamespace(NamespaceDecl *D) { AnonymousNamespace = D; }
00087 
00088   static TranslationUnitDecl *Create(ASTContext &C);
00089   // Implement isa/cast/dyncast/etc.
00090   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
00091   static bool classof(const TranslationUnitDecl *D) { return true; }
00092   static bool classofKind(Kind K) { return K == TranslationUnit; }
00093   static DeclContext *castToDeclContext(const TranslationUnitDecl *D) {
00094     return static_cast<DeclContext *>(const_cast<TranslationUnitDecl*>(D));
00095   }
00096   static TranslationUnitDecl *castFromDeclContext(const DeclContext *DC) {
00097     return static_cast<TranslationUnitDecl *>(const_cast<DeclContext*>(DC));
00098   }
00099 };
00100 
00101 /// NamedDecl - This represents a decl with a name.  Many decls have names such
00102 /// as ObjCMethodDecl, but not @class, etc.
00103 class NamedDecl : public Decl {
00104   virtual void anchor();
00105   /// Name - The name of this declaration, which is typically a normal
00106   /// identifier but may also be a special kind of name (C++
00107   /// constructor, Objective-C selector, etc.)
00108   DeclarationName Name;
00109 
00110 private:
00111   NamedDecl *getUnderlyingDeclImpl();
00112 
00113 protected:
00114   NamedDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N)
00115     : Decl(DK, DC, L), Name(N) { }
00116 
00117 public:
00118   /// getIdentifier - Get the identifier that names this declaration,
00119   /// if there is one. This will return NULL if this declaration has
00120   /// no name (e.g., for an unnamed class) or if the name is a special
00121   /// name (C++ constructor, Objective-C selector, etc.).
00122   IdentifierInfo *getIdentifier() const { return Name.getAsIdentifierInfo(); }
00123 
00124   /// getName - Get the name of identifier for this declaration as a StringRef.
00125   /// This requires that the declaration have a name and that it be a simple
00126   /// identifier.
00127   StringRef getName() const {
00128     assert(Name.isIdentifier() && "Name is not a simple identifier");
00129     return getIdentifier() ? getIdentifier()->getName() : "";
00130   }
00131 
00132   /// getNameAsString - Get a human-readable name for the declaration, even if
00133   /// it is one of the special kinds of names (C++ constructor, Objective-C
00134   /// selector, etc).  Creating this name requires expensive string
00135   /// manipulation, so it should be called only when performance doesn't matter.
00136   /// For simple declarations, getNameAsCString() should suffice.
00137   //
00138   // FIXME: This function should be renamed to indicate that it is not just an
00139   // alternate form of getName(), and clients should move as appropriate.
00140   //
00141   // FIXME: Deprecated, move clients to getName().
00142   std::string getNameAsString() const { return Name.getAsString(); }
00143 
00144   void printName(raw_ostream &os) const { return Name.printName(os); }
00145 
00146   /// getDeclName - Get the actual, stored name of the declaration,
00147   /// which may be a special name.
00148   DeclarationName getDeclName() const { return Name; }
00149 
00150   /// \brief Set the name of this declaration.
00151   void setDeclName(DeclarationName N) { Name = N; }
00152 
00153   /// getQualifiedNameAsString - Returns human-readable qualified name for
00154   /// declaration, like A::B::i, for i being member of namespace A::B.
00155   /// If declaration is not member of context which can be named (record,
00156   /// namespace), it will return same result as getNameAsString().
00157   /// Creating this name is expensive, so it should be called only when
00158   /// performance doesn't matter.
00159   std::string getQualifiedNameAsString() const;
00160   std::string getQualifiedNameAsString(const PrintingPolicy &Policy) const;
00161 
00162   /// getNameForDiagnostic - Appends a human-readable name for this
00163   /// declaration into the given string.
00164   ///
00165   /// This is the method invoked by Sema when displaying a NamedDecl
00166   /// in a diagnostic.  It does not necessarily produce the same
00167   /// result as getNameAsString(); for example, class template
00168   /// specializations are printed with their template arguments.
00169   ///
00170   /// TODO: use an API that doesn't require so many temporary strings
00171   virtual void getNameForDiagnostic(std::string &S,
00172                                     const PrintingPolicy &Policy,
00173                                     bool Qualified) const {
00174     if (Qualified)
00175       S += getQualifiedNameAsString(Policy);
00176     else
00177       S += getNameAsString();
00178   }
00179 
00180   /// declarationReplaces - Determine whether this declaration, if
00181   /// known to be well-formed within its context, will replace the
00182   /// declaration OldD if introduced into scope. A declaration will
00183   /// replace another declaration if, for example, it is a
00184   /// redeclaration of the same variable or function, but not if it is
00185   /// a declaration of a different kind (function vs. class) or an
00186   /// overloaded function.
00187   bool declarationReplaces(NamedDecl *OldD) const;
00188 
00189   /// \brief Determine whether this declaration has linkage.
00190   bool hasLinkage() const;
00191 
00192   using Decl::isModulePrivate;
00193   using Decl::setModulePrivate;
00194   
00195   /// \brief Determine whether this declaration is hidden from name lookup.
00196   bool isHidden() const { return Hidden; }
00197   
00198   /// \brief Determine whether this declaration is a C++ class member.
00199   bool isCXXClassMember() const {
00200     const DeclContext *DC = getDeclContext();
00201 
00202     // C++0x [class.mem]p1:
00203     //   The enumerators of an unscoped enumeration defined in
00204     //   the class are members of the class.
00205     // FIXME: support C++0x scoped enumerations.
00206     if (isa<EnumDecl>(DC))
00207       DC = DC->getParent();
00208 
00209     return DC->isRecord();
00210   }
00211 
00212   /// \brief Determine whether the given declaration is an instance member of
00213   /// a C++ class.
00214   bool isCXXInstanceMember() const;
00215 
00216   class LinkageInfo {
00217     Linkage linkage_;
00218     Visibility visibility_;
00219     bool explicit_;
00220 
00221     void setVisibility(Visibility V, bool E) { visibility_ = V; explicit_ = E; }
00222   public:
00223     LinkageInfo() : linkage_(ExternalLinkage), visibility_(DefaultVisibility),
00224                     explicit_(false) {}
00225     LinkageInfo(Linkage L, Visibility V, bool E)
00226       : linkage_(L), visibility_(V), explicit_(E) {}
00227 
00228     static LinkageInfo external() {
00229       return LinkageInfo();
00230     }
00231     static LinkageInfo internal() {
00232       return LinkageInfo(InternalLinkage, DefaultVisibility, false);
00233     }
00234     static LinkageInfo uniqueExternal() {
00235       return LinkageInfo(UniqueExternalLinkage, DefaultVisibility, false);
00236     }
00237     static LinkageInfo none() {
00238       return LinkageInfo(NoLinkage, DefaultVisibility, false);
00239     }
00240 
00241     Linkage linkage() const { return linkage_; }
00242     Visibility visibility() const { return visibility_; }
00243     bool visibilityExplicit() const { return explicit_; }
00244 
00245     void setLinkage(Linkage L) { linkage_ = L; }
00246     void mergeLinkage(Linkage L) {
00247       setLinkage(minLinkage(linkage(), L));
00248     }
00249     void mergeLinkage(LinkageInfo Other) {
00250       mergeLinkage(Other.linkage());
00251     }
00252 
00253     // Merge the visibility V giving preference to explicit ones.
00254     // This is used, for example, when merging the visibility of a class
00255     // down to one of its members. If the member has no explicit visibility,
00256     // the class visibility wins.
00257     void mergeVisibility(Visibility V, bool E = false) {
00258       // Never increase the visibility
00259       if (visibility() < V)
00260         return;
00261 
00262       // If we have an explicit visibility, keep it
00263       if (visibilityExplicit())
00264         return;
00265 
00266       setVisibility(V, E);
00267     }
00268     // Merge the visibility V, keeping the most restrictive one.
00269     // This is used for cases like merging the visibility of a template
00270     // argument to an instantiation. If we already have a hidden class,
00271     // no argument should give it default visibility.
00272     void mergeVisibilityWithMin(Visibility V, bool E = false) {
00273       // Never increase the visibility
00274       if (visibility() < V)
00275         return;
00276 
00277       // FIXME: this
00278       // If this visibility is explicit, keep it.
00279       if (visibilityExplicit() && !E)
00280         return;
00281 
00282       // should be replaced with this
00283       // Don't lose the explicit bit for nothing
00284       //      if (visibility() == V && visibilityExplicit())
00285       //        return;
00286 
00287       setVisibility(V, E);
00288     }
00289     void mergeVisibility(LinkageInfo Other) {
00290       mergeVisibility(Other.visibility(), Other.visibilityExplicit());
00291     }
00292     void mergeVisibilityWithMin(LinkageInfo Other) {
00293       mergeVisibilityWithMin(Other.visibility(), Other.visibilityExplicit());
00294     }
00295 
00296     void merge(LinkageInfo Other) {
00297       mergeLinkage(Other);
00298       mergeVisibility(Other);
00299     }
00300     void mergeWithMin(LinkageInfo Other) {
00301       mergeLinkage(Other);
00302       mergeVisibilityWithMin(Other);
00303     }
00304   };
00305 
00306   /// \brief Determine what kind of linkage this entity has.
00307   Linkage getLinkage() const;
00308 
00309   /// \brief Determines the visibility of this entity.
00310   Visibility getVisibility() const {
00311     return getLinkageAndVisibility().visibility();
00312   }
00313 
00314   /// \brief Determines the linkage and visibility of this entity.
00315   LinkageInfo getLinkageAndVisibility() const;
00316 
00317   /// \brief If visibility was explicitly specified for this
00318   /// declaration, return that visibility.
00319   llvm::Optional<Visibility> getExplicitVisibility() const;
00320 
00321   /// \brief Clear the linkage cache in response to a change
00322   /// to the declaration.
00323   void ClearLinkageCache();
00324 
00325   /// \brief Looks through UsingDecls and ObjCCompatibleAliasDecls for
00326   /// the underlying named decl.
00327   NamedDecl *getUnderlyingDecl() {
00328     // Fast-path the common case.
00329     if (this->getKind() != UsingShadow &&
00330         this->getKind() != ObjCCompatibleAlias)
00331       return this;
00332 
00333     return getUnderlyingDeclImpl();
00334   }
00335   const NamedDecl *getUnderlyingDecl() const {
00336     return const_cast<NamedDecl*>(this)->getUnderlyingDecl();
00337   }
00338 
00339   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
00340   static bool classof(const NamedDecl *D) { return true; }
00341   static bool classofKind(Kind K) { return K >= firstNamed && K <= lastNamed; }
00342 };
00343 
00344 inline raw_ostream &operator<<(raw_ostream &OS, const NamedDecl &ND) {
00345   ND.printName(OS);
00346   return OS;
00347 }
00348 
00349 /// LabelDecl - Represents the declaration of a label.  Labels also have a
00350 /// corresponding LabelStmt, which indicates the position that the label was
00351 /// defined at.  For normal labels, the location of the decl is the same as the
00352 /// location of the statement.  For GNU local labels (__label__), the decl
00353 /// location is where the __label__ is.
00354 class LabelDecl : public NamedDecl {
00355   virtual void anchor();
00356   LabelStmt *TheStmt;
00357   /// LocStart - For normal labels, this is the same as the main declaration
00358   /// label, i.e., the location of the identifier; for GNU local labels,
00359   /// this is the location of the __label__ keyword.
00360   SourceLocation LocStart;
00361 
00362   LabelDecl(DeclContext *DC, SourceLocation IdentL, IdentifierInfo *II,
00363             LabelStmt *S, SourceLocation StartL)
00364     : NamedDecl(Label, DC, IdentL, II), TheStmt(S), LocStart(StartL) {}
00365 
00366 public:
00367   static LabelDecl *Create(ASTContext &C, DeclContext *DC,
00368                            SourceLocation IdentL, IdentifierInfo *II);
00369   static LabelDecl *Create(ASTContext &C, DeclContext *DC,
00370                            SourceLocation IdentL, IdentifierInfo *II,
00371                            SourceLocation GnuLabelL);
00372   static LabelDecl *CreateDeserialized(ASTContext &C, unsigned ID);
00373   
00374   LabelStmt *getStmt() const { return TheStmt; }
00375   void setStmt(LabelStmt *T) { TheStmt = T; }
00376 
00377   bool isGnuLocal() const { return LocStart != getLocation(); }
00378   void setLocStart(SourceLocation L) { LocStart = L; }
00379 
00380   SourceRange getSourceRange() const LLVM_READONLY {
00381     return SourceRange(LocStart, getLocation());
00382   }
00383 
00384   // Implement isa/cast/dyncast/etc.
00385   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
00386   static bool classof(const LabelDecl *D) { return true; }
00387   static bool classofKind(Kind K) { return K == Label; }
00388 };
00389 
00390 /// NamespaceDecl - Represent a C++ namespace.
00391 class NamespaceDecl : public NamedDecl, public DeclContext, 
00392                       public Redeclarable<NamespaceDecl> 
00393 {
00394   virtual void anchor();
00395 
00396   /// LocStart - The starting location of the source range, pointing
00397   /// to either the namespace or the inline keyword.
00398   SourceLocation LocStart;
00399   /// RBraceLoc - The ending location of the source range.
00400   SourceLocation RBraceLoc;
00401 
00402   /// \brief A pointer to either the anonymous namespace that lives just inside
00403   /// this namespace or to the first namespace in the chain (the latter case
00404   /// only when this is not the first in the chain), along with a 
00405   /// boolean value indicating whether this is an inline namespace.
00406   llvm::PointerIntPair<NamespaceDecl *, 1, bool> AnonOrFirstNamespaceAndInline;
00407 
00408   NamespaceDecl(DeclContext *DC, bool Inline, SourceLocation StartLoc,
00409                 SourceLocation IdLoc, IdentifierInfo *Id,
00410                 NamespaceDecl *PrevDecl);
00411   
00412   typedef Redeclarable<NamespaceDecl> redeclarable_base;
00413   virtual NamespaceDecl *getNextRedeclaration() {
00414     return RedeclLink.getNext();
00415   }
00416   virtual NamespaceDecl *getPreviousDeclImpl() {
00417     return getPreviousDecl();
00418   }
00419   virtual NamespaceDecl *getMostRecentDeclImpl() {
00420     return getMostRecentDecl();
00421   }
00422   
00423 public:
00424   static NamespaceDecl *Create(ASTContext &C, DeclContext *DC,
00425                                bool Inline, SourceLocation StartLoc,
00426                                SourceLocation IdLoc, IdentifierInfo *Id,
00427                                NamespaceDecl *PrevDecl);
00428 
00429   static NamespaceDecl *CreateDeserialized(ASTContext &C, unsigned ID);
00430 
00431   typedef redeclarable_base::redecl_iterator redecl_iterator;
00432   using redeclarable_base::redecls_begin;
00433   using redeclarable_base::redecls_end;
00434   using redeclarable_base::getPreviousDecl;
00435   using redeclarable_base::getMostRecentDecl;
00436 
00437   /// \brief Returns true if this is an anonymous namespace declaration.
00438   ///
00439   /// For example:
00440   /// \code
00441   ///   namespace {
00442   ///     ...
00443   ///   };
00444   /// \endcode
00445   /// q.v. C++ [namespace.unnamed]
00446   bool isAnonymousNamespace() const {
00447     return !getIdentifier();
00448   }
00449 
00450   /// \brief Returns true if this is an inline namespace declaration.
00451   bool isInline() const {
00452     return AnonOrFirstNamespaceAndInline.getInt();
00453   }
00454 
00455   /// \brief Set whether this is an inline namespace declaration.
00456   void setInline(bool Inline) {
00457     AnonOrFirstNamespaceAndInline.setInt(Inline);
00458   }
00459 
00460   /// \brief Get the original (first) namespace declaration.
00461   NamespaceDecl *getOriginalNamespace() {
00462     if (isFirstDeclaration())
00463       return this;
00464 
00465     return AnonOrFirstNamespaceAndInline.getPointer();
00466   }
00467 
00468   /// \brief Get the original (first) namespace declaration.
00469   const NamespaceDecl *getOriginalNamespace() const {
00470     if (isFirstDeclaration())
00471       return this;
00472 
00473     return AnonOrFirstNamespaceAndInline.getPointer();
00474   }
00475 
00476   /// \brief Return true if this declaration is an original (first) declaration
00477   /// of the namespace. This is false for non-original (subsequent) namespace
00478   /// declarations and anonymous namespaces.
00479   bool isOriginalNamespace() const {
00480     return isFirstDeclaration();
00481   }
00482 
00483   /// \brief Retrieve the anonymous namespace nested inside this namespace,
00484   /// if any.
00485   NamespaceDecl *getAnonymousNamespace() const {
00486     return getOriginalNamespace()->AnonOrFirstNamespaceAndInline.getPointer();
00487   }
00488 
00489   void setAnonymousNamespace(NamespaceDecl *D) {
00490     getOriginalNamespace()->AnonOrFirstNamespaceAndInline.setPointer(D);
00491   }
00492 
00493   /// Retrieves the canonical declaration of this namespace.
00494   NamespaceDecl *getCanonicalDecl() {
00495     return getOriginalNamespace();
00496   }
00497   const NamespaceDecl *getCanonicalDecl() const {
00498     return getOriginalNamespace();
00499   }
00500   
00501   virtual SourceRange getSourceRange() const LLVM_READONLY {
00502     return SourceRange(LocStart, RBraceLoc);
00503   }
00504 
00505   SourceLocation getLocStart() const LLVM_READONLY { return LocStart; }
00506   SourceLocation getRBraceLoc() const { return RBraceLoc; }
00507   void setLocStart(SourceLocation L) { LocStart = L; }
00508   void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
00509 
00510   // Implement isa/cast/dyncast/etc.
00511   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
00512   static bool classof(const NamespaceDecl *D) { return true; }
00513   static bool classofKind(Kind K) { return K == Namespace; }
00514   static DeclContext *castToDeclContext(const NamespaceDecl *D) {
00515     return static_cast<DeclContext *>(const_cast<NamespaceDecl*>(D));
00516   }
00517   static NamespaceDecl *castFromDeclContext(const DeclContext *DC) {
00518     return static_cast<NamespaceDecl *>(const_cast<DeclContext*>(DC));
00519   }
00520 
00521   friend class ASTDeclReader;
00522   friend class ASTDeclWriter;
00523 };
00524 
00525 /// ValueDecl - Represent the declaration of a variable (in which case it is
00526 /// an lvalue) a function (in which case it is a function designator) or
00527 /// an enum constant.
00528 class ValueDecl : public NamedDecl {
00529   virtual void anchor();
00530   QualType DeclType;
00531 
00532 protected:
00533   ValueDecl(Kind DK, DeclContext *DC, SourceLocation L,
00534             DeclarationName N, QualType T)
00535     : NamedDecl(DK, DC, L, N), DeclType(T) {}
00536 public:
00537   QualType getType() const { return DeclType; }
00538   void setType(QualType newType) { DeclType = newType; }
00539 
00540   /// \brief Determine whether this symbol is weakly-imported,
00541   ///        or declared with the weak or weak-ref attr.
00542   bool isWeak() const {
00543     return hasAttr<WeakAttr>() || hasAttr<WeakRefAttr>() || isWeakImported();
00544   }
00545 
00546   // Implement isa/cast/dyncast/etc.
00547   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
00548   static bool classof(const ValueDecl *D) { return true; }
00549   static bool classofKind(Kind K) { return K >= firstValue && K <= lastValue; }
00550 };
00551 
00552 /// QualifierInfo - A struct with extended info about a syntactic
00553 /// name qualifier, to be used for the case of out-of-line declarations.
00554 struct QualifierInfo {
00555   NestedNameSpecifierLoc QualifierLoc;
00556 
00557   /// NumTemplParamLists - The number of "outer" template parameter lists.
00558   /// The count includes all of the template parameter lists that were matched
00559   /// against the template-ids occurring into the NNS and possibly (in the
00560   /// case of an explicit specialization) a final "template <>".
00561   unsigned NumTemplParamLists;
00562 
00563   /// TemplParamLists - A new-allocated array of size NumTemplParamLists,
00564   /// containing pointers to the "outer" template parameter lists.
00565   /// It includes all of the template parameter lists that were matched
00566   /// against the template-ids occurring into the NNS and possibly (in the
00567   /// case of an explicit specialization) a final "template <>".
00568   TemplateParameterList** TemplParamLists;
00569 
00570   /// Default constructor.
00571   QualifierInfo() : QualifierLoc(), NumTemplParamLists(0), TemplParamLists(0) {}
00572 
00573   /// setTemplateParameterListsInfo - Sets info about "outer" template
00574   /// parameter lists.
00575   void setTemplateParameterListsInfo(ASTContext &Context,
00576                                      unsigned NumTPLists,
00577                                      TemplateParameterList **TPLists);
00578 
00579 private:
00580   // Copy constructor and copy assignment are disabled.
00581   QualifierInfo(const QualifierInfo&);
00582   QualifierInfo& operator=(const QualifierInfo&);
00583 };
00584 
00585 /// \brief Represents a ValueDecl that came out of a declarator.
00586 /// Contains type source information through TypeSourceInfo.
00587 class DeclaratorDecl : public ValueDecl {
00588   // A struct representing both a TInfo and a syntactic qualifier,
00589   // to be used for the (uncommon) case of out-of-line declarations.
00590   struct ExtInfo : public QualifierInfo {
00591     TypeSourceInfo *TInfo;
00592   };
00593 
00594   llvm::PointerUnion<TypeSourceInfo*, ExtInfo*> DeclInfo;
00595 
00596   /// InnerLocStart - The start of the source range for this declaration,
00597   /// ignoring outer template declarations.
00598   SourceLocation InnerLocStart;
00599 
00600   bool hasExtInfo() const { return DeclInfo.is<ExtInfo*>(); }
00601   ExtInfo *getExtInfo() { return DeclInfo.get<ExtInfo*>(); }
00602   const ExtInfo *getExtInfo() const { return DeclInfo.get<ExtInfo*>(); }
00603 
00604 protected:
00605   DeclaratorDecl(Kind DK, DeclContext *DC, SourceLocation L,
00606                  DeclarationName N, QualType T, TypeSourceInfo *TInfo,
00607                  SourceLocation StartL)
00608     : ValueDecl(DK, DC, L, N, T), DeclInfo(TInfo), InnerLocStart(StartL) {
00609   }
00610 
00611 public:
00612   TypeSourceInfo *getTypeSourceInfo() const {
00613     return hasExtInfo()
00614       ? getExtInfo()->TInfo
00615       : DeclInfo.get<TypeSourceInfo*>();
00616   }
00617   void setTypeSourceInfo(TypeSourceInfo *TI) {
00618     if (hasExtInfo())
00619       getExtInfo()->TInfo = TI;
00620     else
00621       DeclInfo = TI;
00622   }
00623 
00624   /// getInnerLocStart - Return SourceLocation representing start of source
00625   /// range ignoring outer template declarations.
00626   SourceLocation getInnerLocStart() const { return InnerLocStart; }
00627   void setInnerLocStart(SourceLocation L) { InnerLocStart = L; }
00628 
00629   /// getOuterLocStart - Return SourceLocation representing start of source
00630   /// range taking into account any outer template declarations.
00631   SourceLocation getOuterLocStart() const;
00632 
00633   virtual SourceRange getSourceRange() const LLVM_READONLY;
00634   SourceLocation getLocStart() const LLVM_READONLY {
00635     return getOuterLocStart();
00636   }
00637 
00638   /// \brief Retrieve the nested-name-specifier that qualifies the name of this
00639   /// declaration, if it was present in the source.
00640   NestedNameSpecifier *getQualifier() const {
00641     return hasExtInfo() ? getExtInfo()->QualifierLoc.getNestedNameSpecifier()
00642                         : 0;
00643   }
00644 
00645   /// \brief Retrieve the nested-name-specifier (with source-location
00646   /// information) that qualifies the name of this declaration, if it was
00647   /// present in the source.
00648   NestedNameSpecifierLoc getQualifierLoc() const {
00649     return hasExtInfo() ? getExtInfo()->QualifierLoc
00650                         : NestedNameSpecifierLoc();
00651   }
00652 
00653   void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc);
00654 
00655   unsigned getNumTemplateParameterLists() const {
00656     return hasExtInfo() ? getExtInfo()->NumTemplParamLists : 0;
00657   }
00658   TemplateParameterList *getTemplateParameterList(unsigned index) const {
00659     assert(index < getNumTemplateParameterLists());
00660     return getExtInfo()->TemplParamLists[index];
00661   }
00662   void setTemplateParameterListsInfo(ASTContext &Context, unsigned NumTPLists,
00663                                      TemplateParameterList **TPLists);
00664 
00665   SourceLocation getTypeSpecStartLoc() const;
00666 
00667   // Implement isa/cast/dyncast/etc.
00668   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
00669   static bool classof(const DeclaratorDecl *D) { return true; }
00670   static bool classofKind(Kind K) {
00671     return K >= firstDeclarator && K <= lastDeclarator;
00672   }
00673 
00674   friend class ASTDeclReader;
00675   friend class ASTDeclWriter;
00676 };
00677 
00678 /// \brief Structure used to store a statement, the constant value to
00679 /// which it was evaluated (if any), and whether or not the statement
00680 /// is an integral constant expression (if known).
00681 struct EvaluatedStmt {
00682   EvaluatedStmt() : WasEvaluated(false), IsEvaluating(false), CheckedICE(false),
00683                     CheckingICE(false), IsICE(false) { }
00684 
00685   /// \brief Whether this statement was already evaluated.
00686   bool WasEvaluated : 1;
00687 
00688   /// \brief Whether this statement is being evaluated.
00689   bool IsEvaluating : 1;
00690 
00691   /// \brief Whether we already checked whether this statement was an
00692   /// integral constant expression.
00693   bool CheckedICE : 1;
00694 
00695   /// \brief Whether we are checking whether this statement is an
00696   /// integral constant expression.
00697   bool CheckingICE : 1;
00698 
00699   /// \brief Whether this statement is an integral constant expression,
00700   /// or in C++11, whether the statement is a constant expression. Only
00701   /// valid if CheckedICE is true.
00702   bool IsICE : 1;
00703 
00704   Stmt *Value;
00705   APValue Evaluated;
00706 };
00707 
00708 /// VarDecl - An instance of this class is created to represent a variable
00709 /// declaration or definition.
00710 class VarDecl : public DeclaratorDecl, public Redeclarable<VarDecl> {
00711 public:
00712   typedef clang::StorageClass StorageClass;
00713 
00714   /// getStorageClassSpecifierString - Return the string used to
00715   /// specify the storage class \arg SC.
00716   ///
00717   /// It is illegal to call this function with SC == None.
00718   static const char *getStorageClassSpecifierString(StorageClass SC);
00719 
00720   /// \brief Initialization styles.
00721   enum InitializationStyle {
00722     CInit,    ///< C-style initialization with assignment
00723     CallInit, ///< Call-style initialization (C++98)
00724     ListInit  ///< Direct list-initialization (C++11)
00725   };
00726 
00727 protected:
00728   /// \brief Placeholder type used in Init to denote an unparsed C++ default
00729   /// argument.
00730   struct UnparsedDefaultArgument;
00731 
00732   /// \brief Placeholder type used in Init to denote an uninstantiated C++
00733   /// default argument.
00734   struct UninstantiatedDefaultArgument;
00735 
00736   typedef llvm::PointerUnion4<Stmt *, EvaluatedStmt *,
00737                               UnparsedDefaultArgument *,
00738                               UninstantiatedDefaultArgument *> InitType;
00739 
00740   /// \brief The initializer for this variable or, for a ParmVarDecl, the
00741   /// C++ default argument.
00742   mutable InitType Init;
00743 
00744 private:
00745   class VarDeclBitfields {
00746     friend class VarDecl;
00747     friend class ASTDeclReader;
00748 
00749     unsigned SClass : 3;
00750     unsigned SClassAsWritten : 3;
00751     unsigned ThreadSpecified : 1;
00752     unsigned InitStyle : 2;
00753 
00754     /// \brief Whether this variable is the exception variable in a C++ catch
00755     /// or an Objective-C @catch statement.
00756     unsigned ExceptionVar : 1;
00757 
00758     /// \brief Whether this local variable could be allocated in the return
00759     /// slot of its function, enabling the named return value optimization
00760     /// (NRVO).
00761     unsigned NRVOVariable : 1;
00762 
00763     /// \brief Whether this variable is the for-range-declaration in a C++0x
00764     /// for-range statement.
00765     unsigned CXXForRangeDecl : 1;
00766 
00767     /// \brief Whether this variable is an ARC pseudo-__strong
00768     /// variable;  see isARCPseudoStrong() for details.
00769     unsigned ARCPseudoStrong : 1;
00770 
00771     /// \brief Whether this variable is (C++0x) constexpr.
00772     unsigned IsConstexpr : 1;
00773   };
00774   enum { NumVarDeclBits = 14 };
00775 
00776   friend class ASTDeclReader;
00777   friend class StmtIteratorBase;
00778 
00779 protected:
00780   enum { NumParameterIndexBits = 8 };
00781 
00782   class ParmVarDeclBitfields {
00783     friend class ParmVarDecl;
00784     friend class ASTDeclReader;
00785 
00786     unsigned : NumVarDeclBits;
00787 
00788     /// Whether this parameter inherits a default argument from a
00789     /// prior declaration.
00790     unsigned HasInheritedDefaultArg : 1;
00791 
00792     /// Whether this parameter undergoes K&R argument promotion.
00793     unsigned IsKNRPromoted : 1;
00794 
00795     /// Whether this parameter is an ObjC method parameter or not.
00796     unsigned IsObjCMethodParam : 1;
00797 
00798     /// If IsObjCMethodParam, a Decl::ObjCDeclQualifier.
00799     /// Otherwise, the number of function parameter scopes enclosing
00800     /// the function parameter scope in which this parameter was
00801     /// declared.
00802     unsigned ScopeDepthOrObjCQuals : 7;
00803 
00804     /// The number of parameters preceding this parameter in the
00805     /// function parameter scope in which it was declared.
00806     unsigned ParameterIndex : NumParameterIndexBits;
00807   };
00808 
00809   union {
00810     unsigned AllBits;
00811     VarDeclBitfields VarDeclBits;
00812     ParmVarDeclBitfields ParmVarDeclBits;
00813   };
00814 
00815   VarDecl(Kind DK, DeclContext *DC, SourceLocation StartLoc,
00816           SourceLocation IdLoc, IdentifierInfo *Id,
00817           QualType T, TypeSourceInfo *TInfo, StorageClass SC,
00818           StorageClass SCAsWritten)
00819     : DeclaratorDecl(DK, DC, IdLoc, Id, T, TInfo, StartLoc), Init() {
00820     assert(sizeof(VarDeclBitfields) <= sizeof(unsigned));
00821     assert(sizeof(ParmVarDeclBitfields) <= sizeof(unsigned));
00822     AllBits = 0;
00823     VarDeclBits.SClass = SC;
00824     VarDeclBits.SClassAsWritten = SCAsWritten;
00825     // Everything else is implicitly initialized to false.
00826   }
00827 
00828   typedef Redeclarable<VarDecl> redeclarable_base;
00829   virtual VarDecl *getNextRedeclaration() { return RedeclLink.getNext(); }
00830   virtual VarDecl *getPreviousDeclImpl() {
00831     return getPreviousDecl();
00832   }
00833   virtual VarDecl *getMostRecentDeclImpl() {
00834     return getMostRecentDecl();
00835   }
00836 
00837 public:
00838   typedef redeclarable_base::redecl_iterator redecl_iterator;
00839   using redeclarable_base::redecls_begin;
00840   using redeclarable_base::redecls_end;
00841   using redeclarable_base::getPreviousDecl;
00842   using redeclarable_base::getMostRecentDecl;
00843 
00844   static VarDecl *Create(ASTContext &C, DeclContext *DC,
00845                          SourceLocation StartLoc, SourceLocation IdLoc,
00846                          IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo,
00847                          StorageClass S, StorageClass SCAsWritten);
00848 
00849   static VarDecl *CreateDeserialized(ASTContext &C, unsigned ID);
00850   
00851   virtual SourceRange getSourceRange() const LLVM_READONLY;
00852 
00853   StorageClass getStorageClass() const {
00854     return (StorageClass) VarDeclBits.SClass;
00855   }
00856   StorageClass getStorageClassAsWritten() const {
00857     return (StorageClass) VarDeclBits.SClassAsWritten;
00858   }
00859   void setStorageClass(StorageClass SC);
00860   void setStorageClassAsWritten(StorageClass SC) {
00861     assert(isLegalForVariable(SC));
00862     VarDeclBits.SClassAsWritten = SC;
00863   }
00864 
00865   void setThreadSpecified(bool T) { VarDeclBits.ThreadSpecified = T; }
00866   bool isThreadSpecified() const {
00867     return VarDeclBits.ThreadSpecified;
00868   }
00869 
00870   /// hasLocalStorage - Returns true if a variable with function scope
00871   ///  is a non-static local variable.
00872   bool hasLocalStorage() const {
00873     if (getStorageClass() == SC_None)
00874       return !isFileVarDecl();
00875 
00876     // Return true for:  Auto, Register.
00877     // Return false for: Extern, Static, PrivateExtern, OpenCLWorkGroupLocal.
00878 
00879     return getStorageClass() >= SC_Auto;
00880   }
00881 
00882   /// isStaticLocal - Returns true if a variable with function scope is a
00883   /// static local variable.
00884   bool isStaticLocal() const {
00885     return getStorageClass() == SC_Static && !isFileVarDecl();
00886   }
00887 
00888   /// hasExternStorage - Returns true if a variable has extern or
00889   /// __private_extern__ storage.
00890   bool hasExternalStorage() const {
00891     return getStorageClass() == SC_Extern ||
00892            getStorageClass() == SC_PrivateExtern;
00893   }
00894 
00895   /// hasGlobalStorage - Returns true for all variables that do not
00896   ///  have local storage.  This includs all global variables as well
00897   ///  as static variables declared within a function.
00898   bool hasGlobalStorage() const { return !hasLocalStorage(); }
00899 
00900   /// \brief Determines whether this variable is a variable with
00901   /// external, C linkage.
00902   bool isExternC() const;
00903 
00904   /// isLocalVarDecl - Returns true for local variable declarations
00905   /// other than parameters.  Note that this includes static variables
00906   /// inside of functions. It also includes variables inside blocks.
00907   ///
00908   ///   void foo() { int x; static int y; extern int z; }
00909   ///
00910   bool isLocalVarDecl() const {
00911     if (getKind() != Decl::Var)
00912       return false;
00913     if (const DeclContext *DC = getDeclContext())
00914       return DC->getRedeclContext()->isFunctionOrMethod();
00915     return false;
00916   }
00917 
00918   /// isFunctionOrMethodVarDecl - Similar to isLocalVarDecl, but
00919   /// excludes variables declared in blocks.
00920   bool isFunctionOrMethodVarDecl() const {
00921     if (getKind() != Decl::Var)
00922       return false;
00923     const DeclContext *DC = getDeclContext()->getRedeclContext();
00924     return DC->isFunctionOrMethod() && DC->getDeclKind() != Decl::Block;
00925   }
00926 
00927   /// \brief Determines whether this is a static data member.
00928   ///
00929   /// This will only be true in C++, and applies to, e.g., the
00930   /// variable 'x' in:
00931   /// \code
00932   /// struct S {
00933   ///   static int x;
00934   /// };
00935   /// \endcode
00936   bool isStaticDataMember() const {
00937     // If it wasn't static, it would be a FieldDecl.
00938     return getKind() != Decl::ParmVar && getDeclContext()->isRecord();
00939   }
00940 
00941   virtual VarDecl *getCanonicalDecl();
00942   const VarDecl *getCanonicalDecl() const {
00943     return const_cast<VarDecl*>(this)->getCanonicalDecl();
00944   }
00945 
00946   enum DefinitionKind {
00947     DeclarationOnly,      ///< This declaration is only a declaration.
00948     TentativeDefinition,  ///< This declaration is a tentative definition.
00949     Definition            ///< This declaration is definitely a definition.
00950   };
00951 
00952   /// \brief Check whether this declaration is a definition. If this could be
00953   /// a tentative definition (in C), don't check whether there's an overriding
00954   /// definition.
00955   DefinitionKind isThisDeclarationADefinition(ASTContext &) const;
00956   DefinitionKind isThisDeclarationADefinition() const {
00957     return isThisDeclarationADefinition(getASTContext());
00958   }
00959 
00960   /// \brief Check whether this variable is defined in this
00961   /// translation unit.
00962   DefinitionKind hasDefinition(ASTContext &) const;
00963   DefinitionKind hasDefinition() const {
00964     return hasDefinition(getASTContext());
00965   }
00966 
00967   /// \brief Get the tentative definition that acts as the real definition in
00968   /// a TU. Returns null if there is a proper definition available.
00969   VarDecl *getActingDefinition();
00970   const VarDecl *getActingDefinition() const {
00971     return const_cast<VarDecl*>(this)->getActingDefinition();
00972   }
00973 
00974   /// \brief Determine whether this is a tentative definition of a
00975   /// variable in C.
00976   bool isTentativeDefinitionNow() const;
00977 
00978   /// \brief Get the real (not just tentative) definition for this declaration.
00979   VarDecl *getDefinition(ASTContext &);
00980   const VarDecl *getDefinition(ASTContext &C) const {
00981     return const_cast<VarDecl*>(this)->getDefinition(C);
00982   }
00983   VarDecl *getDefinition() {
00984     return getDefinition(getASTContext());
00985   }
00986   const VarDecl *getDefinition() const {
00987     return const_cast<VarDecl*>(this)->getDefinition();
00988   }
00989 
00990   /// \brief Determine whether this is or was instantiated from an out-of-line
00991   /// definition of a static data member.
00992   virtual bool isOutOfLine() const;
00993 
00994   /// \brief If this is a static data member, find its out-of-line definition.
00995   VarDecl *getOutOfLineDefinition();
00996 
00997   /// isFileVarDecl - Returns true for file scoped variable declaration.
00998   bool isFileVarDecl() const {
00999     if (getKind() != Decl::Var)
01000       return false;
01001 
01002     if (getDeclContext()->getRedeclContext()->isFileContext())
01003       return true;
01004 
01005     if (isStaticDataMember())
01006       return true;
01007 
01008     return false;
01009   }
01010 
01011   /// getAnyInitializer - Get the initializer for this variable, no matter which
01012   /// declaration it is attached to.
01013   const Expr *getAnyInitializer() const {
01014     const VarDecl *D;
01015     return getAnyInitializer(D);
01016   }
01017 
01018   /// getAnyInitializer - Get the initializer for this variable, no matter which
01019   /// declaration it is attached to. Also get that declaration.
01020   const Expr *getAnyInitializer(const VarDecl *&D) const;
01021 
01022   bool hasInit() const {
01023     return !Init.isNull() && (Init.is<Stmt *>() || Init.is<EvaluatedStmt *>());
01024   }
01025   const Expr *getInit() const {
01026     if (Init.isNull())
01027       return 0;
01028 
01029     const Stmt *S = Init.dyn_cast<Stmt *>();
01030     if (!S) {
01031       if (EvaluatedStmt *ES = Init.dyn_cast<EvaluatedStmt*>())
01032         S = ES->Value;
01033     }
01034     return (const Expr*) S;
01035   }
01036   Expr *getInit() {
01037     if (Init.isNull())
01038       return 0;
01039 
01040     Stmt *S = Init.dyn_cast<Stmt *>();
01041     if (!S) {
01042       if (EvaluatedStmt *ES = Init.dyn_cast<EvaluatedStmt*>())
01043         S = ES->Value;
01044     }
01045 
01046     return (Expr*) S;
01047   }
01048 
01049   /// \brief Retrieve the address of the initializer expression.
01050   Stmt **getInitAddress() {
01051     if (EvaluatedStmt *ES = Init.dyn_cast<EvaluatedStmt*>())
01052       return &ES->Value;
01053 
01054     // This union hack tip-toes around strict-aliasing rules.
01055     union {
01056       InitType *InitPtr;
01057       Stmt **StmtPtr;
01058     };
01059 
01060     InitPtr = &Init;
01061     return StmtPtr;
01062   }
01063 
01064   void setInit(Expr *I);
01065 
01066   /// \brief Determine whether this variable is a reference that
01067   /// extends the lifetime of its temporary initializer.
01068   ///
01069   /// A reference extends the lifetime of its temporary initializer if
01070   /// it's initializer is an rvalue that would normally go out of scope
01071   /// at the end of the initializer (a full expression). In such cases,
01072   /// the reference itself takes ownership of the temporary, which will
01073   /// be destroyed when the reference goes out of scope. For example:
01074   ///
01075   /// \code
01076   /// const int &r = 1.0; // creates a temporary of type 'int'
01077   /// \endcode
01078   bool extendsLifetimeOfTemporary() const;
01079 
01080   /// \brief Determine whether this variable's value can be used in a
01081   /// constant expression, according to the relevant language standard.
01082   /// This only checks properties of the declaration, and does not check
01083   /// whether the initializer is in fact a constant expression.
01084   bool isUsableInConstantExpressions(ASTContext &C) const;
01085 
01086   EvaluatedStmt *ensureEvaluatedStmt() const;
01087 
01088   /// \brief Attempt to evaluate the value of the initializer attached to this
01089   /// declaration, and produce notes explaining why it cannot be evaluated or is
01090   /// not a constant expression. Returns a pointer to the value if evaluation
01091   /// succeeded, 0 otherwise.
01092   APValue *evaluateValue() const;
01093   APValue *evaluateValue(
01094     llvm::SmallVectorImpl<PartialDiagnosticAt> &Notes) const;
01095 
01096   /// \brief Return the already-evaluated value of this variable's
01097   /// initializer, or NULL if the value is not yet known. Returns pointer
01098   /// to untyped APValue if the value could not be evaluated.
01099   APValue *getEvaluatedValue() const {
01100     if (EvaluatedStmt *Eval = Init.dyn_cast<EvaluatedStmt *>())
01101       if (Eval->WasEvaluated)
01102         return &Eval->Evaluated;
01103 
01104     return 0;
01105   }
01106 
01107   /// \brief Determines whether it is already known whether the
01108   /// initializer is an integral constant expression or not.
01109   bool isInitKnownICE() const {
01110     if (EvaluatedStmt *Eval = Init.dyn_cast<EvaluatedStmt *>())
01111       return Eval->CheckedICE;
01112 
01113     return false;
01114   }
01115 
01116   /// \brief Determines whether the initializer is an integral constant
01117   /// expression, or in C++11, whether the initializer is a constant
01118   /// expression.
01119   ///
01120   /// \pre isInitKnownICE()
01121   bool isInitICE() const {
01122     assert(isInitKnownICE() &&
01123            "Check whether we already know that the initializer is an ICE");
01124     return Init.get<EvaluatedStmt *>()->IsICE;
01125   }
01126 
01127   /// \brief Determine whether the value of the initializer attached to this
01128   /// declaration is an integral constant expression.
01129   bool checkInitIsICE() const;
01130 
01131   void setInitStyle(InitializationStyle Style) {
01132     VarDeclBits.InitStyle = Style;
01133   }
01134 
01135   /// \brief The style of initialization for this declaration.
01136   ///
01137   /// C-style initialization is "int x = 1;". Call-style initialization is
01138   /// a C++98 direct-initializer, e.g. "int x(1);". The Init expression will be
01139   /// the expression inside the parens or a "ClassType(a,b,c)" class constructor
01140   /// expression for class types. List-style initialization is C++11 syntax,
01141   /// e.g. "int x{1};". Clients can distinguish between different forms of
01142   /// initialization by checking this value. In particular, "int x = {1};" is
01143   /// C-style, "int x({1})" is call-style, and "int x{1};" is list-style; the
01144   /// Init expression in all three cases is an InitListExpr.
01145   InitializationStyle getInitStyle() const {
01146     return static_cast<InitializationStyle>(VarDeclBits.InitStyle);
01147   }
01148 
01149   /// \brief Whether the initializer is a direct-initializer (list or call).
01150   bool isDirectInit() const {
01151     return getInitStyle() != CInit;
01152   }
01153 
01154   /// \brief Determine whether this variable is the exception variable in a
01155   /// C++ catch statememt or an Objective-C @catch statement.
01156   bool isExceptionVariable() const {
01157     return VarDeclBits.ExceptionVar;
01158   }
01159   void setExceptionVariable(bool EV) { VarDeclBits.ExceptionVar = EV; }
01160 
01161   /// \brief Determine whether this local variable can be used with the named
01162   /// return value optimization (NRVO).
01163   ///
01164   /// The named return value optimization (NRVO) works by marking certain
01165   /// non-volatile local variables of class type as NRVO objects. These
01166   /// locals can be allocated within the return slot of their containing
01167   /// function, in which case there is no need to copy the object to the
01168   /// return slot when returning from the function. Within the function body,
01169   /// each return that returns the NRVO object will have this variable as its
01170   /// NRVO candidate.
01171   bool isNRVOVariable() const { return VarDeclBits.NRVOVariable; }
01172   void setNRVOVariable(bool NRVO) { VarDeclBits.NRVOVariable = NRVO; }
01173 
01174   /// \brief Determine whether this variable is the for-range-declaration in
01175   /// a C++0x for-range statement.
01176   bool isCXXForRangeDecl() const { return VarDeclBits.CXXForRangeDecl; }
01177   void setCXXForRangeDecl(bool FRD) { VarDeclBits.CXXForRangeDecl = FRD; }
01178 
01179   /// \brief Determine whether this variable is an ARC pseudo-__strong
01180   /// variable.  A pseudo-__strong variable has a __strong-qualified
01181   /// type but does not actually retain the object written into it.
01182   /// Generally such variables are also 'const' for safety.
01183   bool isARCPseudoStrong() const { return VarDeclBits.ARCPseudoStrong; }
01184   void setARCPseudoStrong(bool ps) { VarDeclBits.ARCPseudoStrong = ps; }
01185 
01186   /// Whether this variable is (C++0x) constexpr.
01187   bool isConstexpr() const { return VarDeclBits.IsConstexpr; }
01188   void setConstexpr(bool IC) { VarDeclBits.IsConstexpr = IC; }
01189 
01190   /// \brief If this variable is an instantiated static data member of a
01191   /// class template specialization, returns the templated static data member
01192   /// from which it was instantiated.
01193   VarDecl *getInstantiatedFromStaticDataMember() const;
01194 
01195   /// \brief If this variable is a static data member, determine what kind of
01196   /// template specialization or instantiation this is.
01197   TemplateSpecializationKind getTemplateSpecializationKind() const;
01198 
01199   /// \brief If this variable is an instantiation of a static data member of a
01200   /// class template specialization, retrieves the member specialization
01201   /// information.
01202   MemberSpecializationInfo *getMemberSpecializationInfo() const;
01203 
01204   /// \brief For a static data member that was instantiated from a static
01205   /// data member of a class template, set the template specialiation kind.
01206   void setTemplateSpecializationKind(TemplateSpecializationKind TSK,
01207                         SourceLocation PointOfInstantiation = SourceLocation());
01208 
01209   // Implement isa/cast/dyncast/etc.
01210   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
01211   static bool classof(const VarDecl *D) { return true; }
01212   static bool classofKind(Kind K) { return K >= firstVar && K <= lastVar; }
01213 };
01214 
01215 class ImplicitParamDecl : public VarDecl {
01216   virtual void anchor();
01217 public:
01218   static ImplicitParamDecl *Create(ASTContext &C, DeclContext *DC,
01219                                    SourceLocation IdLoc, IdentifierInfo *Id,
01220                                    QualType T);
01221 
01222   static ImplicitParamDecl *CreateDeserialized(ASTContext &C, unsigned ID);
01223   
01224   ImplicitParamDecl(DeclContext *DC, SourceLocation IdLoc,
01225                     IdentifierInfo *Id, QualType Type)
01226     : VarDecl(ImplicitParam, DC, IdLoc, IdLoc, Id, Type,
01227               /*tinfo*/ 0, SC_None, SC_None) {
01228     setImplicit();
01229   }
01230 
01231   // Implement isa/cast/dyncast/etc.
01232   static bool classof(const ImplicitParamDecl *D) { return true; }
01233   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
01234   static bool classofKind(Kind K) { return K == ImplicitParam; }
01235 };
01236 
01237 /// ParmVarDecl - Represents a parameter to a function.
01238 class ParmVarDecl : public VarDecl {
01239 public:
01240   enum { MaxFunctionScopeDepth = 255 };
01241   enum { MaxFunctionScopeIndex = 255 };
01242 
01243 protected:
01244   ParmVarDecl(Kind DK, DeclContext *DC, SourceLocation StartLoc,
01245               SourceLocation IdLoc, IdentifierInfo *Id,
01246               QualType T, TypeSourceInfo *TInfo,
01247               StorageClass S, StorageClass SCAsWritten, Expr *DefArg)
01248     : VarDecl(DK, DC, StartLoc, IdLoc, Id, T, TInfo, S, SCAsWritten) {
01249     assert(ParmVarDeclBits.HasInheritedDefaultArg == false);
01250     assert(ParmVarDeclBits.IsKNRPromoted == false);
01251     assert(ParmVarDeclBits.IsObjCMethodParam == false);
01252     setDefaultArg(DefArg);
01253   }
01254 
01255 public:
01256   static ParmVarDecl *Create(ASTContext &C, DeclContext *DC,
01257                              SourceLocation StartLoc,
01258                              SourceLocation IdLoc, IdentifierInfo *Id,
01259                              QualType T, TypeSourceInfo *TInfo,
01260                              StorageClass S, StorageClass SCAsWritten,
01261                              Expr *DefArg);
01262 
01263   static ParmVarDecl *CreateDeserialized(ASTContext &C, unsigned ID);
01264   
01265   virtual SourceRange getSourceRange() const LLVM_READONLY;
01266 
01267   void setObjCMethodScopeInfo(unsigned parameterIndex) {
01268     ParmVarDeclBits.IsObjCMethodParam = true;
01269     setParameterIndex(parameterIndex);
01270   }
01271 
01272   void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex) {
01273     assert(!ParmVarDeclBits.IsObjCMethodParam);
01274 
01275     ParmVarDeclBits.ScopeDepthOrObjCQuals = scopeDepth;
01276     assert(ParmVarDeclBits.ScopeDepthOrObjCQuals == scopeDepth
01277            && "truncation!");
01278 
01279     setParameterIndex(parameterIndex);
01280   }
01281 
01282   bool isObjCMethodParameter() const {
01283     return ParmVarDeclBits.IsObjCMethodParam;
01284   }
01285 
01286   unsigned getFunctionScopeDepth() const {
01287     if (ParmVarDeclBits.IsObjCMethodParam) return 0;
01288     return ParmVarDeclBits.ScopeDepthOrObjCQuals;
01289   }
01290 
01291   /// Returns the index of this parameter in its prototype or method scope.
01292   unsigned getFunctionScopeIndex() const {
01293     return getParameterIndex();
01294   }
01295 
01296   ObjCDeclQualifier getObjCDeclQualifier() const {
01297     if (!ParmVarDeclBits.IsObjCMethodParam) return OBJC_TQ_None;
01298     return ObjCDeclQualifier(ParmVarDeclBits.ScopeDepthOrObjCQuals);
01299   }
01300   void setObjCDeclQualifier(ObjCDeclQualifier QTVal) {
01301     assert(ParmVarDeclBits.IsObjCMethodParam);
01302     ParmVarDeclBits.ScopeDepthOrObjCQuals = QTVal;
01303   }
01304 
01305   /// True if the value passed to this parameter must undergo
01306   /// K&R-style default argument promotion:
01307   ///
01308   /// C99 6.5.2.2.
01309   ///   If the expression that denotes the called function has a type
01310   ///   that does not include a prototype, the integer promotions are
01311   ///   performed on each argument, and arguments that have type float
01312   ///   are promoted to double.
01313   bool isKNRPromoted() const {
01314     return ParmVarDeclBits.IsKNRPromoted;
01315   }
01316   void setKNRPromoted(bool promoted) {
01317     ParmVarDeclBits.IsKNRPromoted = promoted;
01318   }
01319 
01320   Expr *getDefaultArg();
01321   const Expr *getDefaultArg() const {
01322     return const_cast<ParmVarDecl *>(this)->getDefaultArg();
01323   }
01324 
01325   void setDefaultArg(Expr *defarg) {
01326     Init = reinterpret_cast<Stmt *>(defarg);
01327   }
01328 
01329   /// \brief Retrieve the source range that covers the entire default
01330   /// argument.
01331   SourceRange getDefaultArgRange() const;
01332   void setUninstantiatedDefaultArg(Expr *arg) {
01333     Init = reinterpret_cast<UninstantiatedDefaultArgument *>(arg);
01334   }
01335   Expr *getUninstantiatedDefaultArg() {
01336     return (Expr *)Init.get<UninstantiatedDefaultArgument *>();
01337   }
01338   const Expr *getUninstantiatedDefaultArg() const {
01339     return (const Expr *)Init.get<UninstantiatedDefaultArgument *>();
01340   }
01341 
01342   /// hasDefaultArg - Determines whether this parameter has a default argument,
01343   /// either parsed or not.
01344   bool hasDefaultArg() const {
01345     return getInit() || hasUnparsedDefaultArg() ||
01346       hasUninstantiatedDefaultArg();
01347   }
01348 
01349   /// hasUnparsedDefaultArg - Determines whether this parameter has a
01350   /// default argument that has not yet been parsed. This will occur
01351   /// during the processing of a C++ class whose member functions have
01352   /// default arguments, e.g.,
01353   /// @code
01354   ///   class X {
01355   ///   public:
01356   ///     void f(int x = 17); // x has an unparsed default argument now
01357   ///   }; // x has a regular default argument now
01358   /// @endcode
01359   bool hasUnparsedDefaultArg() const {
01360     return Init.is<UnparsedDefaultArgument*>();
01361   }
01362 
01363   bool hasUninstantiatedDefaultArg() const {
01364     return Init.is<UninstantiatedDefaultArgument*>();
01365   }
01366 
01367   /// setUnparsedDefaultArg - Specify that this parameter has an
01368   /// unparsed default argument. The argument will be replaced with a
01369   /// real default argument via setDefaultArg when the class
01370   /// definition enclosing the function declaration that owns this
01371   /// default argument is completed.
01372   void setUnparsedDefaultArg() {
01373     Init = (UnparsedDefaultArgument *)0;
01374   }
01375 
01376   bool hasInheritedDefaultArg() const {
01377     return ParmVarDeclBits.HasInheritedDefaultArg;
01378   }
01379 
01380   void setHasInheritedDefaultArg(bool I = true) {
01381     ParmVarDeclBits.HasInheritedDefaultArg = I;
01382   }
01383 
01384   QualType getOriginalType() const {
01385     if (getTypeSourceInfo())
01386       return getTypeSourceInfo()->getType();
01387     return getType();
01388   }
01389 
01390   /// \brief Determine whether this parameter is actually a function
01391   /// parameter pack.
01392   bool isParameterPack() const;
01393 
01394   /// setOwningFunction - Sets the function declaration that owns this
01395   /// ParmVarDecl. Since ParmVarDecls are often created before the
01396   /// FunctionDecls that own them, this routine is required to update
01397   /// the DeclContext appropriately.
01398   void setOwningFunction(DeclContext *FD) { setDeclContext(FD); }
01399 
01400   // Implement isa/cast/dyncast/etc.
01401   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
01402   static bool classof(const ParmVarDecl *D) { return true; }
01403   static bool classofKind(Kind K) { return K == ParmVar; }
01404 
01405 private:
01406   enum { ParameterIndexSentinel = (1 << NumParameterIndexBits) - 1 };
01407 
01408   void setParameterIndex(unsigned parameterIndex) {
01409     if (parameterIndex >= ParameterIndexSentinel) {
01410       setParameterIndexLarge(parameterIndex);
01411       return;
01412     }
01413 
01414     ParmVarDeclBits.ParameterIndex = parameterIndex;
01415     assert(ParmVarDeclBits.ParameterIndex == parameterIndex && "truncation!");
01416   }
01417   unsigned getParameterIndex() const {
01418     unsigned d = ParmVarDeclBits.ParameterIndex;
01419     return d == ParameterIndexSentinel ? getParameterIndexLarge() : d;
01420   }
01421 
01422   void setParameterIndexLarge(unsigned parameterIndex);
01423   unsigned getParameterIndexLarge() const;
01424 };
01425 
01426 /// FunctionDecl - An instance of this class is created to represent a
01427 /// function declaration or definition.
01428 ///
01429 /// Since a given function can be declared several times in a program,
01430 /// there may be several FunctionDecls that correspond to that
01431 /// function. Only one of those FunctionDecls will be found when
01432 /// traversing the list of declarations in the context of the
01433 /// FunctionDecl (e.g., the translation unit); this FunctionDecl
01434 /// contains all of the information known about the function. Other,
01435 /// previous declarations of the function are available via the
01436 /// getPreviousDecl() chain.
01437 class FunctionDecl : public DeclaratorDecl, public DeclContext,
01438                      public Redeclarable<FunctionDecl> {
01439 public:
01440   typedef clang::StorageClass StorageClass;
01441 
01442   /// \brief The kind of templated function a FunctionDecl can be.
01443   enum TemplatedKind {
01444     TK_NonTemplate,
01445     TK_FunctionTemplate,
01446     TK_MemberSpecialization,
01447     TK_FunctionTemplateSpecialization,
01448     TK_DependentFunctionTemplateSpecialization
01449   };
01450 
01451 private:
01452   /// ParamInfo - new[]'d array of pointers to VarDecls for the formal
01453   /// parameters of this function.  This is null if a prototype or if there are
01454   /// no formals.
01455   ParmVarDecl **ParamInfo;
01456 
01457   /// DeclsInPrototypeScope - Array of pointers to NamedDecls for
01458   /// decls defined in the function prototype that are not parameters. E.g.
01459   /// 'enum Y' in 'void f(enum Y {AA} x) {}'.
01460   llvm::ArrayRef<NamedDecl*> DeclsInPrototypeScope;
01461 
01462   LazyDeclStmtPtr Body;
01463 
01464   // FIXME: This can be packed into the bitfields in Decl.
01465   // NOTE: VC++ treats enums as signed, avoid using the StorageClass enum
01466   unsigned SClass : 2;
01467   unsigned SClassAsWritten : 2;
01468   bool IsInline : 1;
01469   bool IsInlineSpecified : 1;
01470   bool IsVirtualAsWritten : 1;
01471   bool IsPure : 1;
01472   bool HasInheritedPrototype : 1;
01473   bool HasWrittenPrototype : 1;
01474   bool IsDeleted : 1;
01475   bool IsTrivial : 1; // sunk from CXXMethodDecl
01476   bool IsDefaulted : 1; // sunk from CXXMethoDecl
01477   bool IsExplicitlyDefaulted : 1; //sunk from CXXMethodDecl
01478   bool HasImplicitReturnZero : 1;
01479   bool IsLateTemplateParsed : 1;
01480   bool IsConstexpr : 1;
01481 
01482   /// \brief End part of this FunctionDecl's source range.
01483   ///
01484   /// We could compute the full range in getSourceRange(). However, when we're
01485   /// dealing with a function definition deserialized from a PCH/AST file,
01486   /// we can only compute the full range once the function body has been
01487   /// de-serialized, so it's far better to have the (sometimes-redundant)
01488   /// EndRangeLoc.
01489   SourceLocation EndRangeLoc;
01490 
01491   /// \brief The template or declaration that this declaration
01492   /// describes or was instantiated from, respectively.
01493   ///
01494   /// For non-templates, this value will be NULL. For function
01495   /// declarations that describe a function template, this will be a
01496   /// pointer to a FunctionTemplateDecl. For member functions
01497   /// of class template specializations, this will be a MemberSpecializationInfo
01498   /// pointer containing information about the specialization.
01499   /// For function template specializations, this will be a
01500   /// FunctionTemplateSpecializationInfo, which contains information about
01501   /// the template being specialized and the template arguments involved in
01502   /// that specialization.
01503   llvm::PointerUnion4<FunctionTemplateDecl *,
01504                       MemberSpecializationInfo *,
01505                       FunctionTemplateSpecializationInfo *,
01506                       DependentFunctionTemplateSpecializationInfo *>
01507     TemplateOrSpecialization;
01508 
01509   /// DNLoc - Provides source/type location info for the
01510   /// declaration name embedded in the DeclaratorDecl base class.
01511   DeclarationNameLoc DNLoc;
01512 
01513   /// \brief Specify that this function declaration is actually a function
01514   /// template specialization.
01515   ///
01516   /// \param C the ASTContext.
01517   ///
01518   /// \param Template the function template that this function template
01519   /// specialization specializes.
01520   ///
01521   /// \param TemplateArgs the template arguments that produced this
01522   /// function template specialization from the template.
01523   ///
01524   /// \param InsertPos If non-NULL, the position in the function template
01525   /// specialization set where the function template specialization data will
01526   /// be inserted.
01527   ///
01528   /// \param TSK the kind of template specialization this is.
01529   ///
01530   /// \param TemplateArgsAsWritten location info of template arguments.
01531   ///
01532   /// \param PointOfInstantiation point at which the function template
01533   /// specialization was first instantiated.
01534   void setFunctionTemplateSpecialization(ASTContext &C,
01535                                          FunctionTemplateDecl *Template,
01536                                        const TemplateArgumentList *TemplateArgs,
01537                                          void *InsertPos,
01538                                          TemplateSpecializationKind TSK,
01539                           const TemplateArgumentListInfo *TemplateArgsAsWritten,
01540                                          SourceLocation PointOfInstantiation);
01541 
01542   /// \brief Specify that this record is an instantiation of the
01543   /// member function FD.
01544   void setInstantiationOfMemberFunction(ASTContext &C, FunctionDecl *FD,
01545                                         TemplateSpecializationKind TSK);
01546 
01547   void setParams(ASTContext &C, llvm::ArrayRef<ParmVarDecl *> NewParamInfo);
01548 
01549 protected:
01550   FunctionDecl(Kind DK, DeclContext *DC, SourceLocation StartLoc,
01551                const DeclarationNameInfo &NameInfo,
01552                QualType T, TypeSourceInfo *TInfo,
01553                StorageClass S, StorageClass SCAsWritten, bool isInlineSpecified,
01554                bool isConstexprSpecified)
01555     : DeclaratorDecl(DK, DC, NameInfo.getLoc(), NameInfo.getName(), T, TInfo,
01556                      StartLoc),
01557       DeclContext(DK),
01558       ParamInfo(0), Body(),
01559       SClass(S), SClassAsWritten(SCAsWritten),
01560       IsInline(isInlineSpecified), IsInlineSpecified(isInlineSpecified),
01561       IsVirtualAsWritten(false), IsPure(false), HasInheritedPrototype(false),
01562       HasWrittenPrototype(true), IsDeleted(false), IsTrivial(false),
01563       IsDefaulted(false), IsExplicitlyDefaulted(false),
01564       HasImplicitReturnZero(false), IsLateTemplateParsed(false),
01565       IsConstexpr(isConstexprSpecified), EndRangeLoc(NameInfo.getEndLoc()),
01566       TemplateOrSpecialization(),
01567       DNLoc(NameInfo.getInfo()) {}
01568 
01569   typedef Redeclarable<FunctionDecl> redeclarable_base;
01570   virtual FunctionDecl *getNextRedeclaration() { return RedeclLink.getNext(); }
01571   virtual FunctionDecl *getPreviousDeclImpl() {
01572     return getPreviousDecl();
01573   }
01574   virtual FunctionDecl *getMostRecentDeclImpl() {
01575     return getMostRecentDecl();
01576   }
01577 
01578 public:
01579   typedef redeclarable_base::redecl_iterator redecl_iterator;
01580   using redeclarable_base::redecls_begin;
01581   using redeclarable_base::redecls_end;
01582   using redeclarable_base::getPreviousDecl;
01583   using redeclarable_base::getMostRecentDecl;
01584 
01585   static FunctionDecl *Create(ASTContext &C, DeclContext *DC,
01586                               SourceLocation StartLoc, SourceLocation NLoc,
01587                               DeclarationName N, QualType T,
01588                               TypeSourceInfo *TInfo,
01589                               StorageClass SC = SC_None,
01590                               StorageClass SCAsWritten = SC_None,
01591                               bool isInlineSpecified = false,
01592                               bool hasWrittenPrototype = true,
01593                               bool isConstexprSpecified = false) {
01594     DeclarationNameInfo NameInfo(N, NLoc);
01595     return FunctionDecl::Create(C, DC, StartLoc, NameInfo, T, TInfo,
01596                                 SC, SCAsWritten,
01597                                 isInlineSpecified, hasWrittenPrototype,
01598                                 isConstexprSpecified);
01599   }
01600 
01601   static FunctionDecl *Create(ASTContext &C, DeclContext *DC,
01602                               SourceLocation StartLoc,
01603                               const DeclarationNameInfo &NameInfo,
01604                               QualType T, TypeSourceInfo *TInfo,
01605                               StorageClass SC = SC_None,
01606                               StorageClass SCAsWritten = SC_None,
01607                               bool isInlineSpecified = false,
01608                               bool hasWrittenPrototype = true,
01609                               bool isConstexprSpecified = false);
01610 
01611   static FunctionDecl *CreateDeserialized(ASTContext &C, unsigned ID);
01612                        
01613   DeclarationNameInfo getNameInfo() const {
01614     return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
01615   }
01616 
01617   virtual void getNameForDiagnostic(std::string &S,
01618                                     const PrintingPolicy &Policy,
01619                                     bool Qualified) const;
01620 
01621   void setRangeEnd(SourceLocation E) { EndRangeLoc = E; }
01622 
01623   virtual SourceRange getSourceRange() const LLVM_READONLY;
01624 
01625   /// \brief Returns true if the function has a body (definition). The
01626   /// function body might be in any of the (re-)declarations of this
01627   /// function. The variant that accepts a FunctionDecl pointer will
01628   /// set that function declaration to the actual declaration
01629   /// containing the body (if there is one).
01630   bool hasBody(const FunctionDecl *&Definition) const;
01631 
01632   virtual bool hasBody() const {
01633     const FunctionDecl* Definition;
01634     return hasBody(Definition);
01635   }
01636 
01637   /// hasTrivialBody - Returns whether the function has a trivial body that does
01638   /// not require any specific codegen.
01639   bool hasTrivialBody() const;
01640 
01641   /// isDefined - Returns true if the function is defined at all, including
01642   /// a deleted definition. Except for the behavior when the function is
01643   /// deleted, behaves like hasBody.
01644   bool isDefined(const FunctionDecl *&Definition) const;
01645 
01646   virtual bool isDefined() const {
01647     const FunctionDecl* Definition;
01648     return isDefined(Definition);
01649   }
01650 
01651   /// getBody - Retrieve the body (definition) of the function. The
01652   /// function body might be in any of the (re-)declarations of this
01653   /// function. The variant that accepts a FunctionDecl pointer will
01654   /// set that function declaration to the actual declaration
01655   /// containing the body (if there is one).
01656   /// NOTE: For checking if there is a body, use hasBody() instead, to avoid
01657   /// unnecessary AST de-serialization of the body.
01658   Stmt *getBody(const FunctionDecl *&Definition) const;
01659 
01660   virtual Stmt *getBody() const {
01661     const FunctionDecl* Definition;
01662     return getBody(Definition);
01663   }
01664 
01665   /// isThisDeclarationADefinition - Returns whether this specific
01666   /// declaration of the function is also a definition. This does not
01667   /// determine whether the function has been defined (e.g., in a
01668   /// previous definition); for that information, use isDefined. Note
01669   /// that this returns false for a defaulted function unless that function
01670   /// has been implicitly defined (possibly as deleted).
01671   bool isThisDeclarationADefinition() const {
01672     return IsDeleted || Body || IsLateTemplateParsed;
01673   }
01674 
01675   /// doesThisDeclarationHaveABody - Returns whether this specific
01676   /// declaration of the function has a body - that is, if it is a non-
01677   /// deleted definition.
01678   bool doesThisDeclarationHaveABody() const {
01679     return Body || IsLateTemplateParsed;
01680   }
01681 
01682   void setBody(Stmt *B);
01683   void setLazyBody(uint64_t Offset) { Body = Offset; }
01684 
01685   /// Whether this function is variadic.
01686   bool isVariadic() const;
01687 
01688   /// Whether this function is marked as virtual explicitly.
01689   bool isVirtualAsWritten() const { return IsVirtualAsWritten; }
01690   void setVirtualAsWritten(bool V) { IsVirtualAsWritten = V; }
01691 
01692   /// Whether this virtual function is pure, i.e. makes the containing class
01693   /// abstract.
01694   bool isPure() const { return IsPure; }
01695   void setPure(bool P = true);
01696 
01697   /// Whether this templated function will be late parsed.
01698   bool isLateTemplateParsed() const { return IsLateTemplateParsed; }
01699   void setLateTemplateParsed(bool ILT = true) { IsLateTemplateParsed = ILT; }
01700 
01701   /// Whether this function is "trivial" in some specialized C++ senses.
01702   /// Can only be true for default constructors, copy constructors,
01703   /// copy assignment operators, and destructors.  Not meaningful until
01704   /// the class has been fully built by Sema.
01705   bool isTrivial() const { return IsTrivial; }
01706   void setTrivial(bool IT) { IsTrivial = IT; }
01707 
01708   /// Whether this function is defaulted per C++0x. Only valid for
01709   /// special member functions.
01710   bool isDefaulted() const { return IsDefaulted; }
01711   void setDefaulted(bool D = true) { IsDefaulted = D; }
01712 
01713   /// Whether this function is explicitly defaulted per C++0x. Only valid
01714   /// for special member functions.
01715   bool isExplicitlyDefaulted() const { return IsExplicitlyDefaulted; }
01716   void setExplicitlyDefaulted(bool ED = true) { IsExplicitlyDefaulted = ED; }
01717 
01718   /// Whether falling off this function implicitly returns null/zero.
01719   /// If a more specific implicit return value is required, front-ends
01720   /// should synthesize the appropriate return statements.
01721   bool hasImplicitReturnZero() const { return HasImplicitReturnZero; }
01722   void setHasImplicitReturnZero(bool IRZ) { HasImplicitReturnZero = IRZ; }
01723 
01724   /// \brief Whether this function has a prototype, either because one
01725   /// was explicitly written or because it was "inherited" by merging
01726   /// a declaration without a prototype with a declaration that has a
01727   /// prototype.
01728   bool hasPrototype() const {
01729     return HasWrittenPrototype || HasInheritedPrototype;
01730   }
01731 
01732   bool hasWrittenPrototype() const { return HasWrittenPrototype; }
01733 
01734   /// \brief Whether this function inherited its prototype from a
01735   /// previous declaration.
01736   bool hasInheritedPrototype() const { return HasInheritedPrototype; }
01737   void setHasInheritedPrototype(bool P = true) { HasInheritedPrototype = P; }
01738 
01739   /// Whether this is a (C++0x) constexpr function or constexpr constructor.
01740   bool isConstexpr() const { return IsConstexpr; }
01741   void setConstexpr(bool IC) { IsConstexpr = IC; }
01742 
01743   /// \brief Whether this function has been deleted.
01744   ///
01745   /// A function that is "deleted" (via the C++0x "= delete" syntax)
01746   /// acts like a normal function, except that it cannot actually be
01747   /// called or have its address taken. Deleted functions are
01748   /// typically used in C++ overload resolution to attract arguments
01749   /// whose type or lvalue/rvalue-ness would permit the use of a
01750   /// different overload that would behave incorrectly. For example,
01751   /// one might use deleted functions to ban implicit conversion from
01752   /// a floating-point number to an Integer type:
01753   ///
01754   /// @code
01755   /// struct Integer {
01756   ///   Integer(long); // construct from a long
01757   ///   Integer(double) = delete; // no construction from float or double
01758   ///   Integer(long double) = delete; // no construction from long double
01759   /// };
01760   /// @endcode
01761   // If a function is deleted, its first declaration must be.
01762   bool isDeleted() const { return getCanonicalDecl()->IsDeleted; }
01763   bool isDeletedAsWritten() const { return IsDeleted && !IsDefaulted; }
01764   void setDeletedAsWritten(bool D = true) { IsDeleted = D; }
01765 
01766   /// \brief Determines whether this function is "main", which is the
01767   /// entry point into an executable program.
01768   bool isMain() const;
01769 
01770   /// \brief Determines whether this operator new or delete is one
01771   /// of the reserved global placement operators:
01772   ///    void *operator new(size_t, void *);
01773   ///    void *operator new[](size_t, void *);
01774   ///    void operator delete(void *, void *);
01775   ///    void operator delete[](void *, void *);
01776   /// These functions have special behavior under [new.delete.placement]:
01777   ///    These functions are reserved, a C++ program may not define
01778   ///    functions that displace the versions in the Standard C++ library.
01779   ///    The provisions of [basic.stc.dynamic] do not apply to these
01780   ///    reserved placement forms of operator new and operator delete.
01781   ///
01782   /// This function must be an allocation or deallocation function.
01783   bool isReservedGlobalPlacementOperator() const;
01784 
01785   /// \brief Determines whether this function is a function with
01786   /// external, C linkage.
01787   bool isExternC() const;
01788 
01789   /// \brief Determines whether this is a global function.
01790   bool isGlobal() const;
01791 
01792   void setPreviousDeclaration(FunctionDecl * PrevDecl);
01793 
01794   virtual const FunctionDecl *getCanonicalDecl() const;
01795   virtual FunctionDecl *getCanonicalDecl();
01796 
01797   unsigned getBuiltinID() const;
01798 
01799   // Iterator access to formal parameters.
01800   unsigned param_size() const { return getNumParams(); }
01801   typedef ParmVarDecl **param_iterator;
01802   typedef ParmVarDecl * const *param_const_iterator;
01803 
01804   param_iterator param_begin() { return ParamInfo; }
01805   param_iterator param_end()   { return ParamInfo+param_size(); }
01806 
01807   param_const_iterator param_begin() const { return ParamInfo; }
01808   param_const_iterator param_end() const   { return ParamInfo+param_size(); }
01809 
01810   /// getNumParams - Return the number of parameters this function must have
01811   /// based on its FunctionType.  This is the length of the ParamInfo array
01812   /// after it has been created.
01813   unsigned getNumParams() const;
01814 
01815   const ParmVarDecl *getParamDecl(unsigned i) const {
01816     assert(i < getNumParams() && "Illegal param #");
01817     return ParamInfo[i];
01818   }
01819   ParmVarDecl *getParamDecl(unsigned i) {
01820     assert(i < getNumParams() && "Illegal param #");
01821     return ParamInfo[i];
01822   }
01823   void setParams(llvm::ArrayRef<ParmVarDecl *> NewParamInfo) {
01824     setParams(getASTContext(), NewParamInfo);
01825   }
01826 
01827   const llvm::ArrayRef<NamedDecl*> &getDeclsInPrototypeScope() const {
01828     return DeclsInPrototypeScope;
01829   }
01830   void setDeclsInPrototypeScope(llvm::ArrayRef<NamedDecl *> NewDecls);
01831 
01832   /// getMinRequiredArguments - Returns the minimum number of arguments
01833   /// needed to call this function. This may be fewer than the number of
01834   /// function parameters, if some of the parameters have default
01835   /// arguments (in C++).
01836   unsigned getMinRequiredArguments() const;
01837 
01838   QualType getResultType() const {
01839     return getType()->getAs<FunctionType>()->getResultType();
01840   }
01841 
01842   /// \brief Determine the type of an expression that calls this function.
01843   QualType getCallResultType() const {
01844     return getType()->getAs<FunctionType>()->getCallResultType(getASTContext());
01845   }
01846 
01847   StorageClass getStorageClass() const { return StorageClass(SClass); }
01848   void setStorageClass(StorageClass SC);
01849 
01850   StorageClass getStorageClassAsWritten() const {
01851     return StorageClass(SClassAsWritten);
01852   }
01853 
01854   /// \brief Determine whether the "inline" keyword was specified for this
01855   /// function.
01856   bool isInlineSpecified() const { return IsInlineSpecified; }
01857 
01858   /// Set whether the "inline" keyword was specified for this function.
01859   void setInlineSpecified(bool I) {
01860     IsInlineSpecified = I;
01861     IsInline = I;
01862   }
01863 
01864   /// Flag that this function is implicitly inline.
01865   void setImplicitlyInline() {
01866     IsInline = true;
01867   }
01868 
01869   /// \brief Determine whether this function should be inlined, because it is
01870   /// either marked "inline" or "constexpr" or is a member function of a class
01871   /// that was defined in the class body.
01872   bool isInlined() const;
01873 
01874   bool isInlineDefinitionExternallyVisible() const;
01875 
01876   bool doesDeclarationForceExternallyVisibleDefinition() const;
01877 
01878   /// isOverloadedOperator - Whether this function declaration
01879   /// represents an C++ overloaded operator, e.g., "operator+".
01880   bool isOverloadedOperator() const {
01881     return getOverloadedOperator() != OO_None;
01882   }
01883 
01884   OverloadedOperatorKind getOverloadedOperator() const;
01885 
01886   const IdentifierInfo *getLiteralIdentifier() const;
01887 
01888   /// \brief If this function is an instantiation of a member function
01889   /// of a class template specialization, retrieves the function from
01890   /// which it was instantiated.
01891   ///
01892   /// This routine will return non-NULL for (non-templated) member
01893   /// functions of class templates and for instantiations of function
01894   /// templates. For example, given:
01895   ///
01896   /// \code
01897   /// template<typename T>
01898   /// struct X {
01899   ///   void f(T);
01900   /// };
01901   /// \endcode
01902   ///
01903   /// The declaration for X<int>::f is a (non-templated) FunctionDecl
01904   /// whose parent is the class template specialization X<int>. For
01905   /// this declaration, getInstantiatedFromFunction() will return
01906   /// the FunctionDecl X<T>::A. When a complete definition of
01907   /// X<int>::A is required, it will be instantiated from the
01908   /// declaration returned by getInstantiatedFromMemberFunction().
01909   FunctionDecl *getInstantiatedFromMemberFunction() const;
01910 
01911   /// \brief What kind of templated function this is.
01912   TemplatedKind getTemplatedKind() const;
01913 
01914   /// \brief If this function is an instantiation of a member function of a
01915   /// class template specialization, retrieves the member specialization
01916   /// information.
01917   MemberSpecializationInfo *getMemberSpecializationInfo() const;
01918 
01919   /// \brief Specify that this record is an instantiation of the
01920   /// member function FD.
01921   void setInstantiationOfMemberFunction(FunctionDecl *FD,
01922                                         TemplateSpecializationKind TSK) {
01923     setInstantiationOfMemberFunction(getASTContext(), FD, TSK);
01924   }
01925 
01926   /// \brief Retrieves the function template that is described by this
01927   /// function declaration.
01928   ///
01929   /// Every function template is represented as a FunctionTemplateDecl
01930   /// and a FunctionDecl (or something derived from FunctionDecl). The
01931   /// former contains template properties (such as the template
01932   /// parameter lists) while the latter contains the actual
01933   /// description of the template's
01934   /// contents. FunctionTemplateDecl::getTemplatedDecl() retrieves the
01935   /// FunctionDecl that describes the function template,
01936   /// getDescribedFunctionTemplate() retrieves the
01937   /// FunctionTemplateDecl from a FunctionDecl.
01938   FunctionTemplateDecl *getDescribedFunctionTemplate() const {
01939     return TemplateOrSpecialization.dyn_cast<FunctionTemplateDecl*>();
01940   }
01941 
01942   void setDescribedFunctionTemplate(FunctionTemplateDecl *Template) {
01943     TemplateOrSpecialization = Template;
01944   }
01945 
01946   /// \brief Determine whether this function is a function template
01947   /// specialization.
01948   bool isFunctionTemplateSpecialization() const {
01949     return getPrimaryTemplate() != 0;
01950   }
01951 
01952   /// \brief Retrieve the class scope template pattern that this function
01953   ///  template specialization is instantiated from.
01954   FunctionDecl *getClassScopeSpecializationPattern() const;
01955 
01956   /// \brief If this function is actually a function template specialization,
01957   /// retrieve information about this function template specialization.
01958   /// Otherwise, returns NULL.
01959   FunctionTemplateSpecializationInfo *getTemplateSpecializationInfo() const {
01960     return TemplateOrSpecialization.
01961              dyn_cast<FunctionTemplateSpecializationInfo*>();
01962   }
01963 
01964   /// \brief Determines whether this function is a function template
01965   /// specialization or a member of a class template specialization that can
01966   /// be implicitly instantiated.
01967   bool isImplicitlyInstantiable() const;
01968 
01969   /// \brief Determines if the given function was instantiated from a
01970   /// function template.
01971   bool isTemplateInstantiation() const;
01972 
01973   /// \brief Retrieve the function declaration from which this function could
01974   /// be instantiated, if it is an instantiation (rather than a non-template
01975   /// or a specialization, for example).
01976   FunctionDecl *getTemplateInstantiationPattern() const;
01977 
01978   /// \brief Retrieve the primary template that this function template
01979   /// specialization either specializes or was instantiated from.
01980   ///
01981   /// If this function declaration is not a function template specialization,
01982   /// returns NULL.
01983   FunctionTemplateDecl *getPrimaryTemplate() const;
01984 
01985   /// \brief Retrieve the template arguments used to produce this function
01986   /// template specialization from the primary template.
01987   ///
01988   /// If this function declaration is not a function template specialization,
01989   /// returns NULL.
01990   const TemplateArgumentList *getTemplateSpecializationArgs() const;
01991 
01992   /// \brief Retrieve the template argument list as written in the sources,
01993   /// if any.
01994   ///
01995   /// If this function declaration is not a function template specialization
01996   /// or if it had no explicit template argument list, returns NULL.
01997   /// Note that it an explicit template argument list may be written empty,
01998   /// e.g., template<> void foo<>(char* s);
01999   const ASTTemplateArgumentListInfo*
02000   getTemplateSpecializationArgsAsWritten() const;
02001 
02002   /// \brief Specify that this function declaration is actually a function
02003   /// template specialization.
02004   ///
02005   /// \param Template the function template that this function template
02006   /// specialization specializes.
02007   ///
02008   /// \param TemplateArgs the template arguments that produced this
02009   /// function template specialization from the template.
02010   ///
02011   /// \param InsertPos If non-NULL, the position in the function template
02012   /// specialization set where the function template specialization data will
02013   /// be inserted.
02014   ///
02015   /// \param TSK the kind of template specialization this is.
02016   ///
02017   /// \param TemplateArgsAsWritten location info of template arguments.
02018   ///
02019   /// \param PointOfInstantiation point at which the function template
02020   /// specialization was first instantiated.
02021   void setFunctionTemplateSpecialization(FunctionTemplateDecl *Template,
02022                                       const TemplateArgumentList *TemplateArgs,
02023                                          void *InsertPos,
02024                     TemplateSpecializationKind TSK = TSK_ImplicitInstantiation,
02025                     const TemplateArgumentListInfo *TemplateArgsAsWritten = 0,
02026                     SourceLocation PointOfInstantiation = SourceLocation()) {
02027     setFunctionTemplateSpecialization(getASTContext(), Template, TemplateArgs,
02028                                       InsertPos, TSK, TemplateArgsAsWritten,
02029                                       PointOfInstantiation);
02030   }
02031 
02032   /// \brief Specifies that this function declaration is actually a
02033   /// dependent function template specialization.
02034   void setDependentTemplateSpecialization(ASTContext &Context,
02035                              const UnresolvedSetImpl &Templates,
02036                       const TemplateArgumentListInfo &TemplateArgs);
02037 
02038   DependentFunctionTemplateSpecializationInfo *
02039   getDependentSpecializationInfo() const {
02040     return TemplateOrSpecialization.
02041              dyn_cast<DependentFunctionTemplateSpecializationInfo*>();
02042   }
02043 
02044   /// \brief Determine what kind of template instantiation this function
02045   /// represents.
02046   TemplateSpecializationKind getTemplateSpecializationKind() const;
02047 
02048   /// \brief Determine what kind of template instantiation this function
02049   /// represents.
02050   void setTemplateSpecializationKind(TemplateSpecializationKind TSK,
02051                         SourceLocation PointOfInstantiation = SourceLocation());
02052 
02053   /// \brief Retrieve the (first) point of instantiation of a function template
02054   /// specialization or a member of a class template specialization.
02055   ///
02056   /// \returns the first point of instantiation, if this function was
02057   /// instantiated from a template; otherwise, returns an invalid source
02058   /// location.
02059   SourceLocation getPointOfInstantiation() const;
02060 
02061   /// \brief Determine whether this is or was instantiated from an out-of-line
02062   /// definition of a member function.
02063   virtual bool isOutOfLine() const;
02064 
02065   /// \brief Identify a memory copying or setting function.
02066   /// If the given function is a memory copy or setting function, returns
02067   /// the corresponding Builtin ID. If the function is not a memory function,
02068   /// returns 0.
02069   unsigned getMemoryFunctionKind() const;
02070 
02071   // Implement isa/cast/dyncast/etc.
02072   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
02073   static bool classof(const FunctionDecl *D) { return true; }
02074   static bool classofKind(Kind K) {
02075     return K >= firstFunction && K <= lastFunction;
02076   }
02077   static DeclContext *castToDeclContext(const FunctionDecl *D) {
02078     return static_cast<DeclContext *>(const_cast<FunctionDecl*>(D));
02079   }
02080   static FunctionDecl *castFromDeclContext(const DeclContext *DC) {
02081     return static_cast<FunctionDecl *>(const_cast<DeclContext*>(DC));
02082   }
02083 
02084   friend class ASTDeclReader;
02085   friend class ASTDeclWriter;
02086 };
02087 
02088 
02089 /// FieldDecl - An instance of this class is created by Sema::ActOnField to
02090 /// represent a member of a struct/union/class.
02091 class FieldDecl : public DeclaratorDecl {
02092   // FIXME: This can be packed into the bitfields in Decl.
02093   bool Mutable : 1;
02094   mutable unsigned CachedFieldIndex : 31;
02095 
02096   /// \brief A pointer to either the in-class initializer for this field (if
02097   /// the boolean value is false), or the bit width expression for this bit
02098   /// field (if the boolean value is true).
02099   ///
02100   /// We can safely combine these two because in-class initializers are not
02101   /// permitted for bit-fields.
02102   ///
02103   /// If the boolean is false and the initializer is null, then this field has
02104   /// an in-class initializer which has not yet been parsed and attached.
02105   llvm::PointerIntPair<Expr *, 1, bool> InitializerOrBitWidth;
02106 protected:
02107   FieldDecl(Kind DK, DeclContext *DC, SourceLocation StartLoc,
02108             SourceLocation IdLoc, IdentifierInfo *Id,
02109             QualType T, TypeSourceInfo *TInfo, Expr *BW, bool Mutable,
02110             bool HasInit)
02111     : DeclaratorDecl(DK, DC, IdLoc, Id, T, TInfo, StartLoc),
02112       Mutable(Mutable), CachedFieldIndex(0),
02113       InitializerOrBitWidth(BW, !HasInit) {
02114     assert(!(BW && HasInit) && "got initializer for bitfield");
02115   }
02116 
02117 public:
02118   static FieldDecl *Create(const ASTContext &C, DeclContext *DC,
02119                            SourceLocation StartLoc, SourceLocation IdLoc,
02120                            IdentifierInfo *Id, QualType T,
02121                            TypeSourceInfo *TInfo, Expr *BW, bool Mutable,
02122                            bool HasInit);
02123 
02124   static FieldDecl *CreateDeserialized(ASTContext &C, unsigned ID);
02125   
02126   /// getFieldIndex - Returns the index of this field within its record,
02127   /// as appropriate for passing to ASTRecordLayout::getFieldOffset.
02128   unsigned getFieldIndex() const;
02129 
02130   /// isMutable - Determines whether this field is mutable (C++ only).
02131   bool isMutable() const { return Mutable; }
02132 
02133   /// \brief Set whether this field is mutable (C++ only).
02134   void setMutable(bool M) { Mutable = M; }
02135 
02136   /// isBitfield - Determines whether this field is a bitfield.
02137   bool isBitField() const {
02138     return InitializerOrBitWidth.getInt() && InitializerOrBitWidth.getPointer();
02139   }
02140 
02141   /// @brief Determines whether this is an unnamed bitfield.
02142   bool isUnnamedBitfield() const { return isBitField() && !getDeclName(); }
02143 
02144   /// isAnonymousStructOrUnion - Determines whether this field is a
02145   /// representative for an anonymous struct or union. Such fields are
02146   /// unnamed and are implicitly generated by the implementation to
02147   /// store the data for the anonymous union or struct.
02148   bool isAnonymousStructOrUnion() const;
02149 
02150   Expr *getBitWidth() const {
02151     return isBitField() ? InitializerOrBitWidth.getPointer() : 0;
02152   }
02153   unsigned getBitWidthValue(const ASTContext &Ctx) const;
02154   void setBitWidth(Expr *BW) {
02155     assert(!InitializerOrBitWidth.getPointer() &&
02156            "bit width or initializer already set");
02157     InitializerOrBitWidth.setPointer(BW);
02158     InitializerOrBitWidth.setInt(1);
02159   }
02160   /// removeBitWidth - Remove the bitfield width from this member.
02161   void removeBitWidth() {
02162     assert(isBitField() && "no bit width to remove");
02163     InitializerOrBitWidth.setPointer(0);
02164   }
02165 
02166   /// hasInClassInitializer - Determine whether this member has a C++0x in-class
02167   /// initializer.
02168   bool hasInClassInitializer() const {
02169     return !InitializerOrBitWidth.getInt();
02170   }
02171   /// getInClassInitializer - Get the C++0x in-class initializer for this
02172   /// member, or null if one has not been set. If a valid declaration has an
02173   /// in-class initializer, but this returns null, then we have not parsed and
02174   /// attached it yet.
02175   Expr *getInClassInitializer() const {
02176     return hasInClassInitializer() ? InitializerOrBitWidth.getPointer() : 0;
02177   }
02178   /// setInClassInitializer - Set the C++0x in-class initializer for this
02179   /// member.
02180   void setInClassInitializer(Expr *Init);
02181   /// removeInClassInitializer - Remove the C++0x in-class initializer from this
02182   /// member.
02183   void removeInClassInitializer() {
02184     assert(!InitializerOrBitWidth.getInt() && "no initializer to remove");
02185     InitializerOrBitWidth.setPointer(0);
02186     InitializerOrBitWidth.setInt(1);
02187   }
02188 
02189   /// getParent - Returns the parent of this field declaration, which
02190   /// is the struct in which this method is defined.
02191   const RecordDecl *getParent() const {
02192     return cast<RecordDecl>(getDeclContext());
02193   }
02194 
02195   RecordDecl *getParent() {
02196     return cast<RecordDecl>(getDeclContext());
02197   }
02198 
02199   SourceRange getSourceRange() const LLVM_READONLY;
02200 
02201   // Implement isa/cast/dyncast/etc.
02202   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
02203   static bool classof(const FieldDecl *D) { return true; }
02204   static bool classofKind(Kind K) { return K >= firstField && K <= lastField; }
02205 };
02206 
02207 /// EnumConstantDecl - An instance of this object exists for each enum constant
02208 /// that is defined.  For example, in "enum X {a,b}", each of a/b are
02209 /// EnumConstantDecl's, X is an instance of EnumDecl, and the type of a/b is a
02210 /// TagType for the X EnumDecl.
02211 class EnumConstantDecl : public ValueDecl {
02212   Stmt *Init; // an integer constant expression
02213   llvm::APSInt Val; // The value.
02214 protected:
02215   EnumConstantDecl(DeclContext *DC, SourceLocation L,
02216                    IdentifierInfo *Id, QualType T, Expr *E,
02217                    const llvm::APSInt &V)
02218     : ValueDecl(EnumConstant, DC, L, Id, T), Init((Stmt*)E), Val(V) {}
02219 
02220 public:
02221 
02222   static EnumConstantDecl *Create(ASTContext &C, EnumDecl *DC,
02223                                   SourceLocation L, IdentifierInfo *Id,
02224                                   QualType T, Expr *E,
02225                                   const llvm::APSInt &V);
02226   static EnumConstantDecl *CreateDeserialized(ASTContext &C, unsigned ID);
02227   
02228   const Expr *getInitExpr() const { return (const Expr*) Init; }
02229   Expr *getInitExpr() { return (Expr*) Init; }
02230   const llvm::APSInt &getInitVal() const { return Val; }
02231 
02232   void setInitExpr(Expr *E) { Init = (Stmt*) E; }
02233   void setInitVal(const llvm::APSInt &V) { Val = V; }
02234 
02235   SourceRange getSourceRange() const LLVM_READONLY;
02236 
02237   // Implement isa/cast/dyncast/etc.
02238   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
02239   static bool classof(const EnumConstantDecl *D) { return true; }
02240   static bool classofKind(Kind K) { return K == EnumConstant; }
02241 
02242   friend class StmtIteratorBase;
02243 };
02244 
02245 /// IndirectFieldDecl - An instance of this class is created to represent a
02246 /// field injected from an anonymous union/struct into the parent scope.
02247 /// IndirectFieldDecl are always implicit.
02248 class IndirectFieldDecl : public ValueDecl {
02249   virtual void anchor();
02250   NamedDecl **Chaining;
02251   unsigned ChainingSize;
02252 
02253   IndirectFieldDecl(DeclContext *DC, SourceLocation L,
02254                     DeclarationName N, QualType T,
02255                     NamedDecl **CH, unsigned CHS)
02256     : ValueDecl(IndirectField, DC, L, N, T), Chaining(CH), ChainingSize(CHS) {}
02257 
02258 public:
02259   static IndirectFieldDecl *Create(ASTContext &C, DeclContext *DC,
02260                                    SourceLocation L, IdentifierInfo *Id,
02261                                    QualType T, NamedDecl **CH, unsigned CHS);
02262 
02263   static IndirectFieldDecl *CreateDeserialized(ASTContext &C, unsigned ID);
02264   
02265   typedef NamedDecl * const *chain_iterator;
02266   chain_iterator chain_begin() const { return Chaining; }
02267   chain_iterator chain_end() const  { return Chaining+ChainingSize; }
02268 
02269   unsigned getChainingSize() const { return ChainingSize; }
02270 
02271   FieldDecl *getAnonField() const {
02272     assert(ChainingSize >= 2);
02273     return cast<FieldDecl>(Chaining[ChainingSize - 1]);
02274   }
02275 
02276   VarDecl *getVarDecl() const {
02277     assert(ChainingSize >= 2);
02278     return dyn_cast<VarDecl>(*chain_begin());
02279   }
02280 
02281   // Implement isa/cast/dyncast/etc.
02282   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
02283   static bool classof(const IndirectFieldDecl *D) { return true; }
02284   static bool classofKind(Kind K) { return K == IndirectField; }
02285   friend class ASTDeclReader;
02286 };
02287 
02288 /// TypeDecl - Represents a declaration of a type.
02289 ///
02290 class TypeDecl : public NamedDecl {
02291   virtual void anchor();
02292   /// TypeForDecl - This indicates the Type object that represents
02293   /// this TypeDecl.  It is a cache maintained by
02294   /// ASTContext::getTypedefType, ASTContext::getTagDeclType, and
02295   /// ASTContext::getTemplateTypeParmType, and TemplateTypeParmDecl.
02296   mutable const Type *TypeForDecl;
02297   /// LocStart - The start of the source range for this declaration.
02298   SourceLocation LocStart;
02299   friend class ASTContext;
02300   friend class DeclContext;
02301   friend class TagDecl;
02302   friend class TemplateTypeParmDecl;
02303   friend class TagType;
02304   friend class ASTReader;
02305 
02306 protected:
02307   TypeDecl(Kind DK, DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
02308            SourceLocation StartL = SourceLocation())
02309     : NamedDecl(DK, DC, L, Id), TypeForDecl(0), LocStart(StartL) {}
02310 
02311 public:
02312   // Low-level accessor
02313   const Type *getTypeForDecl() const { return TypeForDecl; }
02314   void setTypeForDecl(const Type *TD) { TypeForDecl = TD; }
02315 
02316   SourceLocation getLocStart() const LLVM_READONLY { return LocStart; }
02317   void setLocStart(SourceLocation L) { LocStart = L; }
02318   virtual SourceRange getSourceRange() const LLVM_READONLY {
02319     if (LocStart.isValid())
02320       return SourceRange(LocStart, getLocation());
02321     else
02322       return SourceRange(getLocation());
02323   }
02324 
02325   // Implement isa/cast/dyncast/etc.
02326   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
02327   static bool classof(const TypeDecl *D) { return true; }
02328   static bool classofKind(Kind K) { return K >= firstType && K <= lastType; }
02329 };
02330 
02331 
02332 /// Base class for declarations which introduce a typedef-name.
02333 class TypedefNameDecl : public TypeDecl, public Redeclarable<TypedefNameDecl> {
02334   virtual void anchor();
02335   /// UnderlyingType - This is the type the typedef is set to.
02336   TypeSourceInfo *TInfo;
02337 
02338 protected:
02339   TypedefNameDecl(Kind DK, DeclContext *DC, SourceLocation StartLoc,
02340                   SourceLocation IdLoc, IdentifierInfo *Id,
02341                   TypeSourceInfo *TInfo)
02342     : TypeDecl(DK, DC, IdLoc, Id, StartLoc), TInfo(TInfo) {}
02343 
02344   typedef Redeclarable<TypedefNameDecl> redeclarable_base;
02345   virtual TypedefNameDecl *getNextRedeclaration() {
02346     return RedeclLink.getNext();
02347   }
02348   virtual TypedefNameDecl *getPreviousDeclImpl() {
02349     return getPreviousDecl();
02350   }
02351   virtual TypedefNameDecl *getMostRecentDeclImpl() {
02352     return getMostRecentDecl();
02353   }
02354 
02355 public:
02356   typedef redeclarable_base::redecl_iterator redecl_iterator;
02357   using redeclarable_base::redecls_begin;
02358   using redeclarable_base::redecls_end;
02359   using redeclarable_base::getPreviousDecl;
02360   using redeclarable_base::getMostRecentDecl;
02361 
02362   TypeSourceInfo *getTypeSourceInfo() const {
02363     return TInfo;
02364   }
02365 
02366   /// Retrieves the canonical declaration of this typedef-name.
02367   TypedefNameDecl *getCanonicalDecl() {
02368     return getFirstDeclaration();
02369   }
02370   const TypedefNameDecl *getCanonicalDecl() const {
02371     return getFirstDeclaration();
02372   }
02373 
02374   QualType getUnderlyingType() const {
02375     return TInfo->getType();
02376   }
02377   void setTypeSourceInfo(TypeSourceInfo *newType) {
02378     TInfo = newType;
02379   }
02380 
02381   // Implement isa/cast/dyncast/etc.
02382   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
02383   static bool classof(const TypedefNameDecl *D) { return true; }
02384   static bool classofKind(Kind K) {
02385     return K >= firstTypedefName && K <= lastTypedefName;
02386   }
02387 };
02388 
02389 /// TypedefDecl - Represents the declaration of a typedef-name via the 'typedef'
02390 /// type specifier.
02391 class TypedefDecl : public TypedefNameDecl {
02392   TypedefDecl(DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc,
02393               IdentifierInfo *Id, TypeSourceInfo *TInfo)
02394     : TypedefNameDecl(Typedef, DC, StartLoc, IdLoc, Id, TInfo) {}
02395 
02396 public:
02397   static TypedefDecl *Create(ASTContext &C, DeclContext *DC,
02398                              SourceLocation StartLoc, SourceLocation IdLoc,
02399                              IdentifierInfo *Id, TypeSourceInfo *TInfo);
02400   static TypedefDecl *CreateDeserialized(ASTContext &C, unsigned ID);
02401   
02402   SourceRange getSourceRange() const LLVM_READONLY;
02403 
02404   // Implement isa/cast/dyncast/etc.
02405   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
02406   static bool classof(const TypedefDecl *D) { return true; }
02407   static bool classofKind(Kind K) { return K == Typedef; }
02408 };
02409 
02410 /// TypeAliasDecl - Represents the declaration of a typedef-name via a C++0x
02411 /// alias-declaration.
02412 class TypeAliasDecl : public TypedefNameDecl {
02413   TypeAliasDecl(DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc,
02414                 IdentifierInfo *Id, TypeSourceInfo *TInfo)
02415     : TypedefNameDecl(TypeAlias, DC, StartLoc, IdLoc, Id, TInfo) {}
02416 
02417 public:
02418   static TypeAliasDecl *Create(ASTContext &C, DeclContext *DC,
02419                                SourceLocation StartLoc, SourceLocation IdLoc,
02420                                IdentifierInfo *Id, TypeSourceInfo *TInfo);
02421   static TypeAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID);
02422 
02423   SourceRange getSourceRange() const LLVM_READONLY;
02424 
02425   // Implement isa/cast/dyncast/etc.
02426   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
02427   static bool classof(const TypeAliasDecl *D) { return true; }
02428   static bool classofKind(Kind K) { return K == TypeAlias; }
02429 };
02430 
02431 /// TagDecl - Represents the declaration of a struct/union/class/enum.
02432 class TagDecl
02433   : public TypeDecl, public DeclContext, public Redeclarable<TagDecl> {
02434 public:
02435   // This is really ugly.
02436   typedef TagTypeKind TagKind;
02437 
02438 private:
02439   // FIXME: This can be packed into the bitfields in Decl.
02440   /// TagDeclKind - The TagKind enum.
02441   unsigned TagDeclKind : 2;
02442 
02443   /// IsCompleteDefinition - True if this is a definition ("struct foo
02444   /// {};"), false if it is a declaration ("struct foo;").  It is not
02445   /// a definition until the definition has been fully processed.
02446   bool IsCompleteDefinition : 1;
02447 
02448 protected:
02449   /// IsBeingDefined - True if this is currently being defined.
02450   bool IsBeingDefined : 1;
02451 
02452 private:
02453   /// IsEmbeddedInDeclarator - True if this tag declaration is
02454   /// "embedded" (i.e., defined or declared for the very first time)
02455   /// in the syntax of a declarator.
02456   bool IsEmbeddedInDeclarator : 1;
02457 
02458   /// \brief True if this tag is free standing, e.g. "struct foo;".
02459   bool IsFreeStanding : 1;
02460 
02461 protected:
02462   // These are used by (and only defined for) EnumDecl.
02463   unsigned NumPositiveBits : 8;
02464   unsigned NumNegativeBits : 8;
02465 
02466   /// IsScoped - True if this tag declaration is a scoped enumeration. Only
02467   /// possible in C++11 mode.
02468   bool IsScoped : 1;
02469   /// IsScopedUsingClassTag - If this tag declaration is a scoped enum,
02470   /// then this is true if the scoped enum was declared using the class
02471   /// tag, false if it was declared with the struct tag. No meaning is
02472   /// associated if this tag declaration is not a scoped enum.
02473   bool IsScopedUsingClassTag : 1;
02474 
02475   /// IsFixed - True if this is an enumeration with fixed underlying type. Only
02476   /// possible in C++11 or Microsoft extensions mode.
02477   bool IsFixed : 1;
02478 
02479 private:
02480   SourceLocation RBraceLoc;
02481 
02482   // A struct representing syntactic qualifier info,
02483   // to be used for the (uncommon) case of out-of-line declarations.
02484   typedef QualifierInfo ExtInfo;
02485 
02486   /// TypedefNameDeclOrQualifier - If the (out-of-line) tag declaration name
02487   /// is qualified, it points to the qualifier info (nns and range);
02488   /// otherwise, if the tag declaration is anonymous and it is part of
02489   /// a typedef or alias, it points to the TypedefNameDecl (used for mangling);
02490   /// otherwise, it is a null (TypedefNameDecl) pointer.
02491   llvm::PointerUnion<TypedefNameDecl*, ExtInfo*> TypedefNameDeclOrQualifier;
02492 
02493   bool hasExtInfo() const { return TypedefNameDeclOrQualifier.is<ExtInfo*>(); }
02494   ExtInfo *getExtInfo() { return TypedefNameDeclOrQualifier.get<ExtInfo*>(); }
02495   const ExtInfo *getExtInfo() const {
02496     return TypedefNameDeclOrQualifier.get<ExtInfo*>();
02497   }
02498 
02499 protected:
02500   TagDecl(Kind DK, TagKind TK, DeclContext *DC,
02501           SourceLocation L, IdentifierInfo *Id,
02502           TagDecl *PrevDecl, SourceLocation StartL)
02503     : TypeDecl(DK, DC, L, Id, StartL), DeclContext(DK),
02504       TypedefNameDeclOrQualifier((TypedefNameDecl*) 0) {
02505     assert((DK != Enum || TK == TTK_Enum) &&
02506            "EnumDecl not matched with TTK_Enum");
02507     TagDeclKind = TK;
02508     IsCompleteDefinition = false;
02509     IsBeingDefined = false;
02510     IsEmbeddedInDeclarator = false;
02511     IsFreeStanding = false;
02512     setPreviousDeclaration(PrevDecl);
02513   }
02514 
02515   typedef Redeclarable<TagDecl> redeclarable_base;
02516   virtual TagDecl *getNextRedeclaration() { return RedeclLink.getNext(); }
02517   virtual TagDecl *getPreviousDeclImpl() {
02518     return getPreviousDecl();
02519   }
02520   virtual TagDecl *getMostRecentDeclImpl() {
02521     return getMostRecentDecl();
02522   }
02523 
02524   /// @brief Completes the definition of this tag declaration.
02525   ///
02526   /// This is a helper function for derived classes.
02527   void completeDefinition();
02528 
02529 public:
02530   typedef redeclarable_base::redecl_iterator redecl_iterator;
02531   using redeclarable_base::redecls_begin;
02532   using redeclarable_base::redecls_end;
02533   using redeclarable_base::getPreviousDecl;
02534   using redeclarable_base::getMostRecentDecl;
02535 
02536   SourceLocation getRBraceLoc() const { return RBraceLoc; }
02537   void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
02538 
02539   /// getInnerLocStart - Return SourceLocation representing start of source
02540   /// range ignoring outer template declarations.
02541   SourceLocation getInnerLocStart() const { return getLocStart(); }
02542 
02543   /// getOuterLocStart - Return SourceLocation representing start of source
02544   /// range taking into account any outer template declarations.
02545   SourceLocation getOuterLocStart() const;
02546   virtual SourceRange getSourceRange() const LLVM_READONLY;
02547 
02548   virtual TagDecl* getCanonicalDecl();
02549   const TagDecl* getCanonicalDecl() const {
02550     return const_cast<TagDecl*>(this)->getCanonicalDecl();
02551   }
02552 
02553   /// isThisDeclarationADefinition() - Return true if this declaration
02554   /// is a completion definintion of the type.  Provided for consistency.
02555   bool isThisDeclarationADefinition() const {
02556     return isCompleteDefinition();
02557   }
02558 
02559   /// isCompleteDefinition - Return true if this decl has its body
02560   /// fully specified.
02561   bool isCompleteDefinition() const {
02562     return IsCompleteDefinition;
02563   }
02564 
02565   /// isBeingDefined - Return true if this decl is currently being defined.
02566   bool isBeingDefined() const {
02567     return IsBeingDefined;
02568   }
02569 
02570   bool isEmbeddedInDeclarator() const {
02571     return IsEmbeddedInDeclarator;
02572   }
02573   void setEmbeddedInDeclarator(bool isInDeclarator) {
02574     IsEmbeddedInDeclarator = isInDeclarator;
02575   }
02576 
02577   bool isFreeStanding() const { return IsFreeStanding; }
02578   void setFreeStanding(bool isFreeStanding = true) {
02579     IsFreeStanding = isFreeStanding;
02580   }
02581 
02582   /// \brief Whether this declaration declares a type that is
02583   /// dependent, i.e., a type that somehow depends on template
02584   /// parameters.
02585   bool isDependentType() const { return isDependentContext(); }
02586 
02587   /// @brief Starts the definition of this tag declaration.
02588   ///
02589   /// This method should be invoked at the beginning of the definition
02590   /// of this tag declaration. It will set the tag type into a state
02591   /// where it is in the process of being defined.
02592   void startDefinition();
02593 
02594   /// getDefinition - Returns the TagDecl that actually defines this
02595   ///  struct/union/class/enum.  When determining whether or not a
02596   ///  struct/union/class/enum has a definition, one should use this
02597   ///  method as opposed to 'isDefinition'.  'isDefinition' indicates
02598   ///  whether or not a specific TagDecl is defining declaration, not
02599   ///  whether or not the struct/union/class/enum type is defined.
02600   ///  This method returns NULL if there is no TagDecl that defines
02601   ///  the struct/union/class/enum.
02602   TagDecl *getDefinition() const;
02603 
02604   void setCompleteDefinition(bool V) { IsCompleteDefinition = V; }
02605 
02606   // FIXME: Return StringRef;
02607   const char *getKindName() const {
02608     return TypeWithKeyword::getTagTypeKindName(getTagKind());
02609   }
02610 
02611   TagKind getTagKind() const {
02612     return TagKind(TagDeclKind);
02613   }
02614 
02615   void setTagKind(TagKind TK) { TagDeclKind = TK; }
02616 
02617   bool isStruct() const { return getTagKind() == TTK_Struct; }
02618   bool isClass()  const { return getTagKind() == TTK_Class; }
02619   bool isUnion()  const { return getTagKind() == TTK_Union; }
02620   bool isEnum()   const { return getTagKind() == TTK_Enum; }
02621 
02622   TypedefNameDecl *getTypedefNameForAnonDecl() const {
02623     return hasExtInfo() ? 0 :
02624            TypedefNameDeclOrQualifier.get<TypedefNameDecl*>();
02625   }
02626 
02627   void setTypedefNameForAnonDecl(TypedefNameDecl *TDD);
02628 
02629   /// \brief Retrieve the nested-name-specifier that qualifies the name of this
02630   /// declaration, if it was present in the source.
02631   NestedNameSpecifier *getQualifier() const {
02632     return hasExtInfo() ? getExtInfo()->QualifierLoc.getNestedNameSpecifier()
02633                         : 0;
02634   }
02635 
02636   /// \brief Retrieve the nested-name-specifier (with source-location
02637   /// information) that qualifies the name of this declaration, if it was
02638   /// present in the source.
02639   NestedNameSpecifierLoc getQualifierLoc() const {
02640     return hasExtInfo() ? getExtInfo()->QualifierLoc
02641                         : NestedNameSpecifierLoc();
02642   }
02643 
02644   void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc);
02645 
02646   unsigned getNumTemplateParameterLists() const {
02647     return hasExtInfo() ? getExtInfo()->NumTemplParamLists : 0;
02648   }
02649   TemplateParameterList *getTemplateParameterList(unsigned i) const {
02650     assert(i < getNumTemplateParameterLists());
02651     return getExtInfo()->TemplParamLists[i];
02652   }
02653   void setTemplateParameterListsInfo(ASTContext &Context, unsigned NumTPLists,
02654                                      TemplateParameterList **TPLists);
02655 
02656   // Implement isa/cast/dyncast/etc.
02657   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
02658   static bool classof(const TagDecl *D) { return true; }
02659   static bool classofKind(Kind K) { return K >= firstTag && K <= lastTag; }
02660 
02661   static DeclContext *castToDeclContext(const TagDecl *D) {
02662     return static_cast<DeclContext *>(const_cast<TagDecl*>(D));
02663   }
02664   static TagDecl *castFromDeclContext(const DeclContext *DC) {
02665     return static_cast<TagDecl *>(const_cast<DeclContext*>(DC));
02666   }
02667 
02668   friend class ASTDeclReader;
02669   friend class ASTDeclWriter;
02670 };
02671 
02672 /// EnumDecl - Represents an enum.  In C++11, enums can be forward-declared
02673 /// with a fixed underlying type, and in C we allow them to be forward-declared
02674 /// with no underlying type as an extension.
02675 class EnumDecl : public TagDecl {
02676   virtual void anchor();
02677   /// IntegerType - This represent the integer type that the enum corresponds
02678   /// to for code generation purposes.  Note that the enumerator constants may
02679   /// have a different type than this does.
02680   ///
02681   /// If the underlying integer type was explicitly stated in the source
02682   /// code, this is a TypeSourceInfo* for that type. Otherwise this type
02683   /// was automatically deduced somehow, and this is a Type*.
02684   ///
02685   /// Normally if IsFixed(), this would contain a TypeSourceInfo*, but in
02686   /// some cases it won't.
02687   ///
02688   /// The underlying type of an enumeration never has any qualifiers, so
02689   /// we can get away with just storing a raw Type*, and thus save an
02690   /// extra pointer when TypeSourceInfo is needed.
02691 
02692   llvm::PointerUnion<const Type*, TypeSourceInfo*> IntegerType;
02693 
02694   /// PromotionType - The integer type that values of this type should
02695   /// promote to.  In C, enumerators are generally of an integer type
02696   /// directly, but gcc-style large enumerators (and all enumerators
02697   /// in C++) are of the enum type instead.
02698   QualType PromotionType;
02699 
02700   /// \brief If this enumeration is an instantiation of a member enumeration
02701   /// of a class template specialization, this is the member specialization
02702   /// information.
02703   MemberSpecializationInfo *SpecializationInfo;
02704 
02705   EnumDecl(DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc,
02706            IdentifierInfo *Id, EnumDecl *PrevDecl,
02707            bool Scoped, bool ScopedUsingClassTag, bool Fixed)
02708     : TagDecl(Enum, TTK_Enum, DC, IdLoc, Id, PrevDecl, StartLoc),
02709       SpecializationInfo(0) {
02710     assert(Scoped || !ScopedUsingClassTag);
02711     IntegerType = (const Type*)0;
02712     NumNegativeBits = 0;
02713     NumPositiveBits = 0;
02714     IsScoped = Scoped;
02715     IsScopedUsingClassTag = ScopedUsingClassTag;
02716     IsFixed = Fixed;
02717   }
02718 
02719   void setInstantiationOfMemberEnum(ASTContext &C, EnumDecl *ED,
02720                                     TemplateSpecializationKind TSK);
02721 public:
02722   EnumDecl *getCanonicalDecl() {
02723     return cast<EnumDecl>(TagDecl::getCanonicalDecl());
02724   }
02725   const EnumDecl *getCanonicalDecl() const {
02726     return cast<EnumDecl>(TagDecl::getCanonicalDecl());
02727   }
02728 
02729   const EnumDecl *getPreviousDecl() const {
02730     return cast_or_null<EnumDecl>(TagDecl::getPreviousDecl());
02731   }
02732   EnumDecl *getPreviousDecl() {
02733     return cast_or_null<EnumDecl>(TagDecl::getPreviousDecl());
02734   }
02735 
02736   const EnumDecl *getMostRecentDecl() const {
02737     return cast<EnumDecl>(TagDecl::getMostRecentDecl());
02738   }
02739   EnumDecl *getMostRecentDecl() {
02740     return cast<EnumDecl>(TagDecl::getMostRecentDecl());
02741   }
02742 
02743   EnumDecl *getDefinition() const {
02744     return cast_or_null<EnumDecl>(TagDecl::getDefinition());
02745   }
02746 
02747   static EnumDecl *Create(ASTContext &C, DeclContext *DC,
02748                           SourceLocation StartLoc, SourceLocation IdLoc,
02749                           IdentifierInfo *Id, EnumDecl *PrevDecl,
02750                           bool IsScoped, bool IsScopedUsingClassTag,
02751                           bool IsFixed);
02752   static EnumDecl *CreateDeserialized(ASTContext &C, unsigned ID);
02753 
02754   /// completeDefinition - When created, the EnumDecl corresponds to a
02755   /// forward-declared enum. This method is used to mark the
02756   /// declaration as being defined; it's enumerators have already been
02757   /// added (via DeclContext::addDecl). NewType is the new underlying
02758   /// type of the enumeration type.
02759   void completeDefinition(QualType NewType,
02760                           QualType PromotionType,
02761                           unsigned NumPositiveBits,
02762                           unsigned NumNegativeBits);
02763 
02764   // enumerator_iterator - Iterates through the enumerators of this
02765   // enumeration.
02766   typedef specific_decl_iterator<EnumConstantDecl> enumerator_iterator;
02767 
02768   enumerator_iterator enumerator_begin() const {
02769     const EnumDecl *E = getDefinition();
02770     if (!E)
02771       E = this;
02772     return enumerator_iterator(E->decls_begin());
02773   }
02774 
02775   enumerator_iterator enumerator_end() const {
02776     const EnumDecl *E = getDefinition();
02777     if (!E)
02778       E = this;
02779     return enumerator_iterator(E->decls_end());
02780   }
02781 
02782   /// getPromotionType - Return the integer type that enumerators
02783   /// should promote to.
02784   QualType getPromotionType() const { return PromotionType; }
02785 
02786   /// \brief Set the promotion type.
02787   void setPromotionType(QualType T) { PromotionType = T; }
02788 
02789   /// getIntegerType - Return the integer type this enum decl corresponds to.
02790   /// This returns a null qualtype for an enum forward definition.
02791   QualType getIntegerType() const {
02792     if (!IntegerType)
02793       return QualType();
02794     if (const Type* T = IntegerType.dyn_cast<const Type*>())
02795       return QualType(T, 0);
02796     return IntegerType.get<TypeSourceInfo*>()->getType();
02797   }
02798 
02799   /// \brief Set the underlying integer type.
02800   void setIntegerType(QualType T) { IntegerType = T.getTypePtrOrNull(); }
02801 
02802   /// \brief Set the underlying integer type source info.
02803   void setIntegerTypeSourceInfo(TypeSourceInfo* TInfo) { IntegerType = TInfo; }
02804 
02805   /// \brief Return the type source info for the underlying integer type,
02806   /// if no type source info exists, return 0.
02807   TypeSourceInfo* getIntegerTypeSourceInfo() const {
02808     return IntegerType.dyn_cast<TypeSourceInfo*>();
02809   }
02810 
02811   /// \brief Returns the width in bits required to store all the
02812   /// non-negative enumerators of this enum.
02813   unsigned getNumPositiveBits() const {
02814     return NumPositiveBits;
02815   }
02816   void setNumPositiveBits(unsigned Num) {
02817     NumPositiveBits = Num;
02818     assert(NumPositiveBits == Num && "can't store this bitcount");
02819   }
02820 
02821   /// \brief Returns the width in bits required to store all the
02822   /// negative enumerators of this enum.  These widths include
02823   /// the rightmost leading 1;  that is:
02824   ///
02825   /// MOST NEGATIVE ENUMERATOR     PATTERN     NUM NEGATIVE BITS
02826   /// ------------------------     -------     -----------------
02827   ///                       -1     1111111                     1
02828   ///                      -10     1110110                     5
02829   ///                     -101     1001011                     8
02830   unsigned getNumNegativeBits() const {
02831     return NumNegativeBits;
02832   }
02833   void setNumNegativeBits(unsigned Num) {
02834     NumNegativeBits = Num;
02835   }
02836 
02837   /// \brief Returns true if this is a C++0x scoped enumeration.
02838   bool isScoped() const {
02839     return IsScoped;
02840   }
02841 
02842   /// \brief Returns true if this is a C++0x scoped enumeration.
02843   bool isScopedUsingClassTag() const {
02844     return IsScopedUsingClassTag;
02845   }
02846 
02847   /// \brief Returns true if this is a C++0x enumeration with fixed underlying
02848   /// type.
02849   bool isFixed() const {
02850     return IsFixed;
02851   }
02852 
02853   /// \brief Returns true if this can be considered a complete type.
02854   bool isComplete() const {
02855     return isCompleteDefinition() || isFixed();
02856   }
02857 
02858   /// \brief Returns the enumeration (declared within the template)
02859   /// from which this enumeration type was instantiated, or NULL if
02860   /// this enumeration was not instantiated from any template.
02861   EnumDecl *getInstantiatedFromMemberEnum() const;
02862 
02863   /// \brief If this enumeration is a member of a specialization of a
02864   /// templated class, determine what kind of template specialization
02865   /// or instantiation this is.
02866   TemplateSpecializationKind getTemplateSpecializationKind() const;
02867 
02868   /// \brief For an enumeration member that was instantiated from a member
02869   /// enumeration of a templated class, set the template specialiation kind.
02870   void setTemplateSpecializationKind(TemplateSpecializationKind TSK,
02871                         SourceLocation PointOfInstantiation = SourceLocation());
02872 
02873   /// \brief If this enumeration is an instantiation of a member enumeration of
02874   /// a class template specialization, retrieves the member specialization
02875   /// information.
02876   MemberSpecializationInfo *getMemberSpecializationInfo() const {
02877     return SpecializationInfo;
02878   }
02879 
02880   /// \brief Specify that this enumeration is an instantiation of the
02881   /// member enumeration ED.
02882   void setInstantiationOfMemberEnum(EnumDecl *ED,
02883                                     TemplateSpecializationKind TSK) {
02884     setInstantiationOfMemberEnum(getASTContext(), ED, TSK);
02885   }
02886 
02887   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
02888   static bool classof(const EnumDecl *D) { return true; }
02889   static bool classofKind(Kind K) { return K == Enum; }
02890 
02891   friend class ASTDeclReader;
02892 };
02893 
02894 
02895 /// RecordDecl - Represents a struct/union/class.  For example:
02896 ///   struct X;                  // Forward declaration, no "body".
02897 ///   union Y { int A, B; };     // Has body with members A and B (FieldDecls).
02898 /// This decl will be marked invalid if *any* members are invalid.
02899 ///
02900 class RecordDecl : public TagDecl {
02901   // FIXME: This can be packed into the bitfields in Decl.
02902   /// HasFlexibleArrayMember - This is true if this struct ends with a flexible
02903   /// array member (e.g. int X[]) or if this union contains a struct that does.
02904   /// If so, this cannot be contained in arrays or other structs as a member.
02905   bool HasFlexibleArrayMember : 1;
02906 
02907   /// AnonymousStructOrUnion - Whether this is the type of an anonymous struct
02908   /// or union.
02909   bool AnonymousStructOrUnion : 1;
02910 
02911   /// HasObjectMember - This is true if this struct has at least one member
02912   /// containing an Objective-C object pointer type.
02913   bool HasObjectMember : 1;
02914 
02915   /// \brief Whether the field declarations of this record have been loaded
02916   /// from external storage. To avoid unnecessary deserialization of
02917   /// methods/nested types we allow deserialization of just the fields
02918   /// when needed.
02919   mutable bool LoadedFieldsFromExternalStorage : 1;
02920   friend class DeclContext;
02921 
02922 protected:
02923   RecordDecl(Kind DK, TagKind TK, DeclContext *DC,
02924              SourceLocation StartLoc, SourceLocation IdLoc,
02925              IdentifierInfo *Id, RecordDecl *PrevDecl);
02926 
02927 public:
02928   static RecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC,
02929                             SourceLocation StartLoc, SourceLocation IdLoc,
02930                             IdentifierInfo *Id, RecordDecl* PrevDecl = 0);
02931   static RecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID);
02932 
02933   const RecordDecl *getPreviousDecl() const {
02934     return cast_or_null<RecordDecl>(TagDecl::getPreviousDecl());
02935   }
02936   RecordDecl *getPreviousDecl() {
02937     return cast_or_null<RecordDecl>(TagDecl::getPreviousDecl());
02938   }
02939 
02940   const RecordDecl *getMostRecentDecl() const {
02941     return cast<RecordDecl>(TagDecl::getMostRecentDecl());
02942   }
02943   RecordDecl *getMostRecentDecl() {
02944     return cast<RecordDecl>(TagDecl::getMostRecentDecl());
02945   }
02946 
02947   bool hasFlexibleArrayMember() const { return HasFlexibleArrayMember; }
02948   void setHasFlexibleArrayMember(bool V) { HasFlexibleArrayMember = V; }
02949 
02950   /// isAnonymousStructOrUnion - Whether this is an anonymous struct
02951   /// or union. To be an anonymous struct or union, it must have been
02952   /// declared without a name and there must be no objects of this
02953   /// type declared, e.g.,
02954   /// @code
02955   ///   union { int i; float f; };
02956   /// @endcode
02957   /// is an anonymous union but neither of the following are:
02958   /// @code
02959   ///  union X { int i; float f; };
02960   ///  union { int i; float f; } obj;
02961   /// @endcode
02962   bool isAnonymousStructOrUnion() const { return AnonymousStructOrUnion; }
02963   void setAnonymousStructOrUnion(bool Anon) {
02964     AnonymousStructOrUnion = Anon;
02965   }
02966 
02967   bool hasObjectMember() const { return HasObjectMember; }
02968   void setHasObjectMember (bool val) { HasObjectMember = val; }
02969 
02970   /// \brief Determines whether this declaration represents the
02971   /// injected class name.
02972   ///
02973   /// The injected class name in C++ is the name of the class that
02974   /// appears inside the class itself. For example:
02975   ///
02976   /// \code
02977   /// struct C {
02978   ///   // C is implicitly declared here as a synonym for the class name.
02979   /// };
02980   ///
02981   /// C::C c; // same as "C c;"
02982   /// \endcode
02983   bool isInjectedClassName() const;
02984 
02985   /// getDefinition - Returns the RecordDecl that actually defines
02986   ///  this struct/union/class.  When determining whether or not a
02987   ///  struct/union/class is completely defined, one should use this
02988   ///  method as opposed to 'isCompleteDefinition'.
02989   ///  'isCompleteDefinition' indicates whether or not a specific
02990   ///  RecordDecl is a completed definition, not whether or not the
02991   ///  record type is defined.  This method returns NULL if there is
02992   ///  no RecordDecl that defines the struct/union/tag.
02993   RecordDecl *getDefinition() const {
02994     return cast_or_null<RecordDecl>(TagDecl::getDefinition());
02995   }
02996 
02997   // Iterator access to field members. The field iterator only visits
02998   // the non-static data members of this class, ignoring any static
02999   // data members, functions, constructors, destructors, etc.
03000   typedef specific_decl_iterator<FieldDecl> field_iterator;
03001 
03002   field_iterator field_begin() const;
03003 
03004   field_iterator field_end() const {
03005     return field_iterator(decl_iterator());
03006   }
03007 
03008   // field_empty - Whether there are any fields (non-static data
03009   // members) in this record.
03010   bool field_empty() const {
03011     return field_begin() == field_end();
03012   }
03013 
03014   /// completeDefinition - Notes that the definition of this type is
03015   /// now complete.
03016   virtual void completeDefinition();
03017 
03018   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
03019   static bool classof(const RecordDecl *D) { return true; }
03020   static bool classofKind(Kind K) {
03021     return K >= firstRecord && K <= lastRecord;
03022   }
03023 
03024 private:
03025   /// \brief Deserialize just the fields.
03026   void LoadFieldsFromExternalStorage() const;
03027 };
03028 
03029 class FileScopeAsmDecl : public Decl {
03030   virtual void anchor();
03031   StringLiteral *AsmString;
03032   SourceLocation RParenLoc;
03033   FileScopeAsmDecl(DeclContext *DC, StringLiteral *asmstring,
03034                    SourceLocation StartL, SourceLocation EndL)
03035     : Decl(FileScopeAsm, DC, StartL), AsmString(asmstring), RParenLoc(EndL) {}
03036 public:
03037   static FileScopeAsmDecl *Create(ASTContext &C, DeclContext *DC,
03038                                   StringLiteral *Str, SourceLocation AsmLoc,
03039                                   SourceLocation RParenLoc);
03040 
03041   static FileScopeAsmDecl *CreateDeserialized(ASTContext &C, unsigned ID);
03042   
03043   SourceLocation getAsmLoc() const { return getLocation(); }
03044   SourceLocation getRParenLoc() const { return RParenLoc; }
03045   void setRParenLoc(SourceLocation L) { RParenLoc = L; }
03046   SourceRange getSourceRange() const LLVM_READONLY {
03047     return SourceRange(getAsmLoc(), getRParenLoc());
03048   }
03049 
03050   const StringLiteral *getAsmString() const { return AsmString; }
03051   StringLiteral *getAsmString() { return AsmString; }
03052   void setAsmString(StringLiteral *Asm) { AsmString = Asm; }
03053 
03054   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
03055   static bool classof(const FileScopeAsmDecl *D) { return true; }
03056   static bool classofKind(Kind K) { return K == FileScopeAsm; }
03057 };
03058 
03059 /// BlockDecl - This represents a block literal declaration, which is like an
03060 /// unnamed FunctionDecl.  For example:
03061 /// ^{ statement-body }   or   ^(int arg1, float arg2){ statement-body }
03062 ///
03063 class BlockDecl : public Decl, public DeclContext {
03064 public:
03065   /// A class which contains all the information about a particular
03066   /// captured value.
03067   class Capture {
03068     enum {
03069       flag_isByRef = 0x1,
03070       flag_isNested = 0x2
03071     };
03072 
03073     /// The variable being captured.
03074     llvm::PointerIntPair<VarDecl*, 2> VariableAndFlags;
03075 
03076     /// The copy expression, expressed in terms of a DeclRef (or
03077     /// BlockDeclRef) to the captured variable.  Only required if the
03078     /// variable has a C++ class type.
03079     Expr *CopyExpr;
03080 
03081   public:
03082     Capture(VarDecl *variable, bool byRef, bool nested, Expr *copy)
03083       : VariableAndFlags(variable,
03084                   (byRef ? flag_isByRef : 0) | (nested ? flag_isNested : 0)),
03085         CopyExpr(copy) {}
03086 
03087     /// The variable being captured.
03088     VarDecl *getVariable() const { return VariableAndFlags.getPointer(); }
03089 
03090     /// Whether this is a "by ref" capture, i.e. a capture of a __block
03091     /// variable.
03092     bool isByRef() const { return VariableAndFlags.getInt() & flag_isByRef; }
03093 
03094     /// Whether this is a nested capture, i.e. the variable captured
03095     /// is not from outside the immediately enclosing function/block.
03096     bool isNested() const { return VariableAndFlags.getInt() & flag_isNested; }
03097 
03098     bool hasCopyExpr() const { return CopyExpr != 0; }
03099     Expr *getCopyExpr() const { return CopyExpr; }
03100     void setCopyExpr(Expr *e) { CopyExpr = e; }
03101   };
03102 
03103 private:
03104   // FIXME: This can be packed into the bitfields in Decl.
03105   bool IsVariadic : 1;
03106   bool CapturesCXXThis : 1;
03107   bool BlockMissingReturnType : 1;
03108   bool IsConversionFromLambda : 1;
03109   /// ParamInfo - new[]'d array of pointers to ParmVarDecls for the formal
03110   /// parameters of this function.  This is null if a prototype or if there are
03111   /// no formals.
03112   ParmVarDecl **ParamInfo;
03113   unsigned NumParams;
03114 
03115   Stmt *Body;
03116   TypeSourceInfo *SignatureAsWritten;
03117 
03118   Capture *Captures;
03119   unsigned NumCaptures;
03120 
03121 protected:
03122   BlockDecl(DeclContext *DC, SourceLocation CaretLoc)
03123     : Decl(Block, DC, CaretLoc), DeclContext(Block),
03124       IsVariadic(false), CapturesCXXThis(false),
03125       BlockMissingReturnType(true), IsConversionFromLambda(false),
03126       ParamInfo(0), NumParams(0), Body(0),
03127       SignatureAsWritten(0), Captures(0), NumCaptures(0) {}
03128 
03129 public:
03130   static BlockDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L); 
03131   static BlockDecl *CreateDeserialized(ASTContext &C, unsigned ID);
03132   
03133   SourceLocation getCaretLocation() const { return getLocation(); }
03134 
03135   bool isVariadic() const { return IsVariadic; }
03136   void setIsVariadic(bool value) { IsVariadic = value; }
03137 
03138   CompoundStmt *getCompoundBody() const { return (CompoundStmt*) Body; }
03139   Stmt *getBody() const { return (Stmt*) Body; }
03140   void setBody(CompoundStmt *B) { Body = (Stmt*) B; }
03141 
03142   void setSignatureAsWritten(TypeSourceInfo *Sig) { SignatureAsWritten = Sig; }
03143   TypeSourceInfo *getSignatureAsWritten() const { return SignatureAsWritten; }
03144 
03145   // Iterator access to formal parameters.
03146   unsigned param_size() const { return getNumParams(); }
03147   typedef ParmVarDecl **param_iterator;
03148   typedef ParmVarDecl * const *param_const_iterator;
03149 
03150   bool param_empty() const { return NumParams == 0; }
03151   param_iterator param_begin()  { return ParamInfo; }
03152   param_iterator param_end()   { return ParamInfo+param_size(); }
03153 
03154   param_const_iterator param_begin() const { return ParamInfo; }
03155   param_const_iterator param_end() const   { return ParamInfo+param_size(); }
03156 
03157   unsigned getNumParams() const { return NumParams; }
03158   const ParmVarDecl *getParamDecl(unsigned i) const {
03159     assert(i < getNumParams() && "Illegal param #");
03160     return ParamInfo[i];
03161   }
03162   ParmVarDecl *getParamDecl(unsigned i) {
03163     assert(i < getNumParams() && "Illegal param #");
03164     return ParamInfo[i];
03165   }
03166   void setParams(llvm::ArrayRef<ParmVarDecl *> NewParamInfo);
03167 
03168   /// hasCaptures - True if this block (or its nested blocks) captures
03169   /// anything of local storage from its enclosing scopes.
03170   bool hasCaptures() const { return NumCaptures != 0 || CapturesCXXThis; }
03171 
03172   /// getNumCaptures - Returns the number of captured variables.
03173   /// Does not include an entry for 'this'.
03174   unsigned getNumCaptures() const { return NumCaptures; }
03175 
03176   typedef const Capture *capture_iterator;
03177   typedef const Capture *capture_const_iterator;
03178   capture_iterator capture_begin() { return Captures; }
03179   capture_iterator capture_end() { return Captures + NumCaptures; }
03180   capture_const_iterator capture_begin() const { return Captures; }
03181   capture_const_iterator capture_end() const { return Captures + NumCaptures; }
03182 
03183   bool capturesCXXThis() const { return CapturesCXXThis; }
03184   bool blockMissingReturnType() const { return BlockMissingReturnType; }
03185   void setBlockMissingReturnType(bool val) { BlockMissingReturnType = val; }
03186 
03187   bool isConversionFromLambda() const { return IsConversionFromLambda; }
03188   void setIsConversionFromLambda(bool val) { IsConversionFromLambda = val; }
03189 
03190   bool capturesVariable(const VarDecl *var) const;
03191 
03192   void setCaptures(ASTContext &Context,
03193                    const Capture *begin,
03194                    const Capture *end,
03195                    bool capturesCXXThis);
03196 
03197   virtual SourceRange getSourceRange() const LLVM_READONLY;
03198 
03199   // Implement isa/cast/dyncast/etc.
03200   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
03201   static bool classof(const BlockDecl *D) { return true; }
03202   static bool classofKind(Kind K) { return K == Block; }
03203   static DeclContext *castToDeclContext(const BlockDecl *D) {
03204     return static_cast<DeclContext *>(const_cast<BlockDecl*>(D));
03205   }
03206   static BlockDecl *castFromDeclContext(const DeclContext *DC) {
03207     return static_cast<BlockDecl *>(const_cast<DeclContext*>(DC));
03208   }
03209 };
03210 
03211 /// \brief Describes a module import declaration, which makes the contents
03212 /// of the named module visible in the current translation unit.
03213 ///
03214 /// An import declaration imports the named module (or submodule). For example:
03215 /// \code
03216 ///   @__experimental_modules_import std.vector;
03217 /// \endcode
03218 ///
03219 /// Import declarations can also be implicitly generated from #include/#import 
03220 /// directives.
03221 class ImportDecl : public Decl {
03222   /// \brief The imported module, along with a bit that indicates whether
03223   /// we have source-location information for each identifier in the module
03224   /// name. 
03225   ///
03226   /// When the bit is false, we only have a single source location for the
03227   /// end of the import declaration.
03228   llvm::PointerIntPair<Module *, 1, bool> ImportedAndComplete;
03229   
03230   /// \brief The next import in the list of imports local to the translation
03231   /// unit being parsed (not loaded from an AST file).
03232   ImportDecl *NextLocalImport;
03233   
03234   friend class ASTReader;
03235   friend class ASTDeclReader;
03236   friend class ASTContext;
03237   
03238   ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported,
03239              ArrayRef<SourceLocation> IdentifierLocs);
03240 
03241   ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported,
03242              SourceLocation EndLoc);
03243 
03244   ImportDecl(EmptyShell Empty) : Decl(Import, Empty), NextLocalImport() { }
03245   
03246 public:
03247   /// \brief Create a new module import declaration.
03248   static ImportDecl *Create(ASTContext &C, DeclContext *DC, 
03249                             SourceLocation StartLoc, Module *Imported,
03250                             ArrayRef<SourceLocation> IdentifierLocs);
03251   
03252   /// \brief Create a new module import declaration for an implicitly-generated
03253   /// import.
03254   static ImportDecl *CreateImplicit(ASTContext &C, DeclContext *DC, 
03255                                     SourceLocation StartLoc, Module *Imported, 
03256                                     SourceLocation EndLoc);
03257   
03258   /// \brief Create a new, deserialized module import declaration.
03259   static ImportDecl *CreateDeserialized(ASTContext &C, unsigned ID, 
03260                                         unsigned NumLocations);
03261   
03262   /// \brief Retrieve the module that was imported by the import declaration.
03263   Module *getImportedModule() const { return ImportedAndComplete.getPointer(); }
03264   
03265   /// \brief Retrieves the locations of each of the identifiers that make up
03266   /// the complete module name in the import declaration.
03267   ///
03268   /// This will return an empty array if the locations of the individual
03269   /// identifiers aren't available.
03270   ArrayRef<SourceLocation> getIdentifierLocs() const;
03271   
03272   virtual SourceRange getSourceRange() const LLVM_READONLY;
03273   
03274   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
03275   static bool classof(const ImportDecl *D) { return true; }
03276   static bool classofKind(Kind K) { return K == Import; }
03277 };
03278   
03279 
03280 /// Insertion operator for diagnostics.  This allows sending NamedDecl's
03281 /// into a diagnostic with <<.
03282 inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
03283                                            const NamedDecl* ND) {
03284   DB.AddTaggedVal(reinterpret_cast<intptr_t>(ND),
03285                   DiagnosticsEngine::ak_nameddecl);
03286   return DB;
03287 }
03288 inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
03289                                            const NamedDecl* ND) {
03290   PD.AddTaggedVal(reinterpret_cast<intptr_t>(ND),
03291                   DiagnosticsEngine::ak_nameddecl);
03292   return PD;
03293 }
03294 
03295 template<typename decl_type>
03296 void Redeclarable<decl_type>::setPreviousDeclaration(decl_type *PrevDecl) {
03297   // Note: This routine is implemented here because we need both NamedDecl
03298   // and Redeclarable to be defined.
03299 
03300   decl_type *First;
03301 
03302   if (PrevDecl) {
03303     // Point to previous. Make sure that this is actually the most recent
03304     // redeclaration, or we can build invalid chains. If the most recent
03305     // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
03306     RedeclLink = PreviousDeclLink(
03307                    llvm::cast<decl_type>(PrevDecl->getMostRecentDecl()));
03308     First = PrevDecl->getFirstDeclaration();
03309     assert(First->RedeclLink.NextIsLatest() && "Expected first");
03310   } else {
03311     // Make this first.
03312     First = static_cast<decl_type*>(this);
03313   }
03314 
03315   // First one will point to this one as latest.
03316   First->RedeclLink = LatestDeclLink(static_cast<decl_type*>(this));
03317   if (NamedDecl *ND = dyn_cast<NamedDecl>(static_cast<decl_type*>(this)))
03318     ND->ClearLinkageCache();
03319 }
03320 
03321 // Inline function definitions.
03322 
03323 /// \brief Check if the given decl is complete.
03324 ///
03325 /// We use this function to break a cycle between the inline definitions in
03326 /// Type.h and Decl.h.
03327 inline bool IsEnumDeclComplete(EnumDecl *ED) {
03328   return ED->isComplete();
03329 }
03330 
03331 /// \brief Check if the given decl is scoped.
03332 ///
03333 /// We use this function to break a cycle between the inline definitions in
03334 /// Type.h and Decl.h.
03335 inline bool IsEnumDeclScoped(EnumDecl *ED) {
03336   return ED->isScoped();
03337 }
03338 
03339 }  // end namespace clang
03340 
03341 #endif