1193326Sed//===--- Decl.h - Classes for representing declarations ---------*- C++ -*-===// 2193326Sed// 3193326Sed// The LLVM Compiler Infrastructure 4193326Sed// 5193326Sed// This file is distributed under the University of Illinois Open Source 6193326Sed// License. See LICENSE.TXT for details. 7193326Sed// 8193326Sed//===----------------------------------------------------------------------===// 9193326Sed// 10193326Sed// This file defines the Decl subclasses. 11193326Sed// 12193326Sed//===----------------------------------------------------------------------===// 13193326Sed 14193326Sed#ifndef LLVM_CLANG_AST_DECL_H 15193326Sed#define LLVM_CLANG_AST_DECL_H 16193326Sed 17193326Sed#include "clang/AST/APValue.h" 18193326Sed#include "clang/AST/DeclBase.h" 19193326Sed#include "clang/AST/DeclarationName.h" 20193326Sed#include "clang/AST/ExternalASTSource.h" 21249423Sdim#include "clang/AST/Redeclarable.h" 22249423Sdim#include "clang/AST/Type.h" 23203955Srdivacky#include "clang/Basic/Linkage.h" 24226633Sdim#include "llvm/ADT/ArrayRef.h" 25221345Sdim#include "llvm/ADT/Optional.h" 26234353Sdim#include "llvm/Support/Compiler.h" 27193326Sed 28193326Sednamespace clang { 29249423Sdimstruct ASTTemplateArgumentListInfo; 30201361Srdivackyclass CXXTemporary; 31249423Sdimclass CompoundStmt; 32249423Sdimclass DependentFunctionTemplateSpecializationInfo; 33193326Sedclass Expr; 34193326Sedclass FunctionTemplateDecl; 35249423Sdimclass FunctionTemplateSpecializationInfo; 36249423Sdimclass LabelStmt; 37249423Sdimclass MemberSpecializationInfo; 38249423Sdimclass Module; 39249423Sdimclass NestedNameSpecifier; 40193326Sedclass Stmt; 41193326Sedclass StringLiteral; 42249423Sdimclass TemplateArgumentList; 43210299Sedclass TemplateParameterList; 44198092Srdivackyclass TypeLoc; 45207619Srdivackyclass UnresolvedSetImpl; 46249423Sdim 47198092Srdivacky/// \brief A container of type source information. 48198092Srdivacky/// 49198092Srdivacky/// A client can read the relevant info using TypeLoc wrappers, e.g: 50198092Srdivacky/// @code 51200583Srdivacky/// TypeLoc TL = TypeSourceInfo->getTypeLoc(); 52198092Srdivacky/// if (PointerLoc *PL = dyn_cast<PointerLoc>(&TL)) 53198092Srdivacky/// PL->getStarLoc().print(OS, SrcMgr); 54198092Srdivacky/// @endcode 55198092Srdivacky/// 56200583Srdivackyclass TypeSourceInfo { 57198092Srdivacky QualType Ty; 58198092Srdivacky // Contains a memory block after the class, used for type source information, 59198092Srdivacky // allocated by ASTContext. 60198092Srdivacky friend class ASTContext; 61200583Srdivacky TypeSourceInfo(QualType ty) : Ty(ty) { } 62198092Srdivackypublic: 63198398Srdivacky /// \brief Return the type wrapped by this type source info. 64198398Srdivacky QualType getType() const { return Ty; } 65198398Srdivacky 66198092Srdivacky /// \brief Return the TypeLoc wrapper for the type source info. 67208600Srdivacky TypeLoc getTypeLoc() const; // implemented in TypeLoc.h 68198092Srdivacky}; 69198092Srdivacky 70193326Sed/// TranslationUnitDecl - The top declaration context. 71193326Sedclass TranslationUnitDecl : public Decl, public DeclContext { 72234353Sdim virtual void anchor(); 73195341Sed ASTContext &Ctx; 74198092Srdivacky 75201361Srdivacky /// The (most recently entered) anonymous namespace for this 76201361Srdivacky /// translation unit, if one has been created. 77201361Srdivacky NamespaceDecl *AnonymousNamespace; 78201361Srdivacky 79195341Sed explicit TranslationUnitDecl(ASTContext &ctx) 80193326Sed : Decl(TranslationUnit, 0, SourceLocation()), 81195341Sed DeclContext(TranslationUnit), 82201361Srdivacky Ctx(ctx), AnonymousNamespace(0) {} 83193326Sedpublic: 84195341Sed ASTContext &getASTContext() const { return Ctx; } 85198092Srdivacky 86201361Srdivacky NamespaceDecl *getAnonymousNamespace() const { return AnonymousNamespace; } 87201361Srdivacky void setAnonymousNamespace(NamespaceDecl *D) { AnonymousNamespace = D; } 88201361Srdivacky 89193326Sed static TranslationUnitDecl *Create(ASTContext &C); 90193326Sed // Implement isa/cast/dyncast/etc. 91203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 92203955Srdivacky static bool classofKind(Kind K) { return K == TranslationUnit; } 93193326Sed static DeclContext *castToDeclContext(const TranslationUnitDecl *D) { 94193326Sed return static_cast<DeclContext *>(const_cast<TranslationUnitDecl*>(D)); 95193326Sed } 96193326Sed static TranslationUnitDecl *castFromDeclContext(const DeclContext *DC) { 97193326Sed return static_cast<TranslationUnitDecl *>(const_cast<DeclContext*>(DC)); 98193326Sed } 99193326Sed}; 100193326Sed 101193326Sed/// NamedDecl - This represents a decl with a name. Many decls have names such 102239462Sdim/// as ObjCMethodDecl, but not \@class, etc. 103193326Sedclass NamedDecl : public Decl { 104234353Sdim virtual void anchor(); 105193326Sed /// Name - The name of this declaration, which is typically a normal 106193326Sed /// identifier but may also be a special kind of name (C++ 107193326Sed /// constructor, Objective-C selector, etc.) 108193326Sed DeclarationName Name; 109193326Sed 110234353Sdimprivate: 111234353Sdim NamedDecl *getUnderlyingDeclImpl(); 112249423Sdim void verifyLinkage() const; 113234353Sdim 114193326Sedprotected: 115193326Sed NamedDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N) 116193326Sed : Decl(DK, DC, L), Name(N) { } 117193326Sed 118193326Sedpublic: 119193326Sed /// getIdentifier - Get the identifier that names this declaration, 120193326Sed /// if there is one. This will return NULL if this declaration has 121193326Sed /// no name (e.g., for an unnamed class) or if the name is a special 122193326Sed /// name (C++ constructor, Objective-C selector, etc.). 123193326Sed IdentifierInfo *getIdentifier() const { return Name.getAsIdentifierInfo(); } 124193326Sed 125198398Srdivacky /// getName - Get the name of identifier for this declaration as a StringRef. 126198398Srdivacky /// This requires that the declaration have a name and that it be a simple 127198398Srdivacky /// identifier. 128226633Sdim StringRef getName() const { 129198398Srdivacky assert(Name.isIdentifier() && "Name is not a simple identifier"); 130198398Srdivacky return getIdentifier() ? getIdentifier()->getName() : ""; 131198398Srdivacky } 132198398Srdivacky 133198398Srdivacky /// getNameAsString - Get a human-readable name for the declaration, even if 134198398Srdivacky /// it is one of the special kinds of names (C++ constructor, Objective-C 135198398Srdivacky /// selector, etc). Creating this name requires expensive string 136198398Srdivacky /// manipulation, so it should be called only when performance doesn't matter. 137198398Srdivacky /// For simple declarations, getNameAsCString() should suffice. 138198398Srdivacky // 139198398Srdivacky // FIXME: This function should be renamed to indicate that it is not just an 140198398Srdivacky // alternate form of getName(), and clients should move as appropriate. 141198398Srdivacky // 142198398Srdivacky // FIXME: Deprecated, move clients to getName(). 143198398Srdivacky std::string getNameAsString() const { return Name.getAsString(); } 144198398Srdivacky 145226633Sdim void printName(raw_ostream &os) const { return Name.printName(os); } 146208600Srdivacky 147193326Sed /// getDeclName - Get the actual, stored name of the declaration, 148193326Sed /// which may be a special name. 149193326Sed DeclarationName getDeclName() const { return Name; } 150193326Sed 151193326Sed /// \brief Set the name of this declaration. 152193326Sed void setDeclName(DeclarationName N) { Name = N; } 153193326Sed 154249423Sdim /// printQualifiedName - Returns human-readable qualified name for 155193326Sed /// declaration, like A::B::i, for i being member of namespace A::B. 156193326Sed /// If declaration is not member of context which can be named (record, 157249423Sdim /// namespace), it will return same result as printName(). 158193326Sed /// Creating this name is expensive, so it should be called only when 159193326Sed /// performance doesn't matter. 160249423Sdim void printQualifiedName(raw_ostream &OS) const; 161249423Sdim void printQualifiedName(raw_ostream &OS, const PrintingPolicy &Policy) const; 162249423Sdim 163249423Sdim // FIXME: Remove string versions. 164193326Sed std::string getQualifiedNameAsString() const; 165198092Srdivacky std::string getQualifiedNameAsString(const PrintingPolicy &Policy) const; 166193326Sed 167198092Srdivacky /// getNameForDiagnostic - Appends a human-readable name for this 168249423Sdim /// declaration into the given stream. 169198092Srdivacky /// 170198092Srdivacky /// This is the method invoked by Sema when displaying a NamedDecl 171198092Srdivacky /// in a diagnostic. It does not necessarily produce the same 172249423Sdim /// result as printName(); for example, class template 173198092Srdivacky /// specializations are printed with their template arguments. 174249423Sdim virtual void getNameForDiagnostic(raw_ostream &OS, 175198092Srdivacky const PrintingPolicy &Policy, 176249423Sdim bool Qualified) const; 177198092Srdivacky 178193326Sed /// declarationReplaces - Determine whether this declaration, if 179193326Sed /// known to be well-formed within its context, will replace the 180193326Sed /// declaration OldD if introduced into scope. A declaration will 181193326Sed /// replace another declaration if, for example, it is a 182193326Sed /// redeclaration of the same variable or function, but not if it is 183193326Sed /// a declaration of a different kind (function vs. class) or an 184193326Sed /// overloaded function. 185193326Sed bool declarationReplaces(NamedDecl *OldD) const; 186193326Sed 187193326Sed /// \brief Determine whether this declaration has linkage. 188193326Sed bool hasLinkage() const; 189193326Sed 190234353Sdim using Decl::isModulePrivate; 191234353Sdim using Decl::setModulePrivate; 192226633Sdim 193234353Sdim /// \brief Determine whether this declaration is hidden from name lookup. 194234353Sdim bool isHidden() const { return Hidden; } 195226633Sdim 196201361Srdivacky /// \brief Determine whether this declaration is a C++ class member. 197201361Srdivacky bool isCXXClassMember() const { 198201361Srdivacky const DeclContext *DC = getDeclContext(); 199201361Srdivacky 200201361Srdivacky // C++0x [class.mem]p1: 201201361Srdivacky // The enumerators of an unscoped enumeration defined in 202201361Srdivacky // the class are members of the class. 203201361Srdivacky // FIXME: support C++0x scoped enumerations. 204201361Srdivacky if (isa<EnumDecl>(DC)) 205201361Srdivacky DC = DC->getParent(); 206201361Srdivacky 207201361Srdivacky return DC->isRecord(); 208201361Srdivacky } 209201361Srdivacky 210234353Sdim /// \brief Determine whether the given declaration is an instance member of 211234353Sdim /// a C++ class. 212207619Srdivacky bool isCXXInstanceMember() const; 213207619Srdivacky 214249423Sdim /// \brief Determine what kind of linkage this entity has. 215249423Sdim Linkage getLinkage() const; 216218893Sdim 217249423Sdim /// \brief True if this decl has external linkage. 218249423Sdim bool hasExternalLinkage() const { 219249423Sdim return getLinkage() == ExternalLinkage; 220249423Sdim } 221218893Sdim 222218893Sdim /// \brief Determines the visibility of this entity. 223234353Sdim Visibility getVisibility() const { 224249423Sdim return getLinkageAndVisibility().getVisibility(); 225234353Sdim } 226218893Sdim 227218893Sdim /// \brief Determines the linkage and visibility of this entity. 228218893Sdim LinkageInfo getLinkageAndVisibility() const; 229218893Sdim 230249423Sdim /// Kinds of explicit visibility. 231249423Sdim enum ExplicitVisibilityKind { 232249423Sdim VisibilityForType, 233249423Sdim VisibilityForValue 234249423Sdim }; 235249423Sdim 236221345Sdim /// \brief If visibility was explicitly specified for this 237221345Sdim /// declaration, return that visibility. 238249423Sdim Optional<Visibility> 239249423Sdim getExplicitVisibility(ExplicitVisibilityKind kind) const; 240221345Sdim 241249423Sdim /// \brief True if the computed linkage is valid. Used for consistency 242249423Sdim /// checking. Should always return true. 243249423Sdim bool isLinkageValid() const; 244218893Sdim 245195099Sed /// \brief Looks through UsingDecls and ObjCCompatibleAliasDecls for 246195099Sed /// the underlying named decl. 247234353Sdim NamedDecl *getUnderlyingDecl() { 248234353Sdim // Fast-path the common case. 249234353Sdim if (this->getKind() != UsingShadow && 250234353Sdim this->getKind() != ObjCCompatibleAlias) 251234353Sdim return this; 252234353Sdim 253234353Sdim return getUnderlyingDeclImpl(); 254234353Sdim } 255195099Sed const NamedDecl *getUnderlyingDecl() const { 256195099Sed return const_cast<NamedDecl*>(this)->getUnderlyingDecl(); 257195099Sed } 258198092Srdivacky 259203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 260210299Sed static bool classofKind(Kind K) { return K >= firstNamed && K <= lastNamed; } 261193326Sed}; 262193326Sed 263226633Sdiminline raw_ostream &operator<<(raw_ostream &OS, const NamedDecl &ND) { 264226633Sdim ND.printName(OS); 265207619Srdivacky return OS; 266207619Srdivacky} 267207619Srdivacky 268218893Sdim/// LabelDecl - Represents the declaration of a label. Labels also have a 269218893Sdim/// corresponding LabelStmt, which indicates the position that the label was 270218893Sdim/// defined at. For normal labels, the location of the decl is the same as the 271218893Sdim/// location of the statement. For GNU local labels (__label__), the decl 272218893Sdim/// location is where the __label__ is. 273218893Sdimclass LabelDecl : public NamedDecl { 274234353Sdim virtual void anchor(); 275218893Sdim LabelStmt *TheStmt; 276221345Sdim /// LocStart - For normal labels, this is the same as the main declaration 277221345Sdim /// label, i.e., the location of the identifier; for GNU local labels, 278221345Sdim /// this is the location of the __label__ keyword. 279221345Sdim SourceLocation LocStart; 280221345Sdim 281221345Sdim LabelDecl(DeclContext *DC, SourceLocation IdentL, IdentifierInfo *II, 282221345Sdim LabelStmt *S, SourceLocation StartL) 283221345Sdim : NamedDecl(Label, DC, IdentL, II), TheStmt(S), LocStart(StartL) {} 284221345Sdim 285218893Sdimpublic: 286218893Sdim static LabelDecl *Create(ASTContext &C, DeclContext *DC, 287221345Sdim SourceLocation IdentL, IdentifierInfo *II); 288221345Sdim static LabelDecl *Create(ASTContext &C, DeclContext *DC, 289221345Sdim SourceLocation IdentL, IdentifierInfo *II, 290221345Sdim SourceLocation GnuLabelL); 291234353Sdim static LabelDecl *CreateDeserialized(ASTContext &C, unsigned ID); 292234353Sdim 293218893Sdim LabelStmt *getStmt() const { return TheStmt; } 294218893Sdim void setStmt(LabelStmt *T) { TheStmt = T; } 295221345Sdim 296221345Sdim bool isGnuLocal() const { return LocStart != getLocation(); } 297221345Sdim void setLocStart(SourceLocation L) { LocStart = L; } 298221345Sdim 299234353Sdim SourceRange getSourceRange() const LLVM_READONLY { 300221345Sdim return SourceRange(LocStart, getLocation()); 301221345Sdim } 302221345Sdim 303218893Sdim // Implement isa/cast/dyncast/etc. 304218893Sdim static bool classof(const Decl *D) { return classofKind(D->getKind()); } 305218893Sdim static bool classofKind(Kind K) { return K == Label; } 306218893Sdim}; 307234353Sdim 308193326Sed/// NamespaceDecl - Represent a C++ namespace. 309234353Sdimclass NamespaceDecl : public NamedDecl, public DeclContext, 310234353Sdim public Redeclarable<NamespaceDecl> 311234353Sdim{ 312234353Sdim virtual void anchor(); 313212904Sdim 314221345Sdim /// LocStart - The starting location of the source range, pointing 315221345Sdim /// to either the namespace or the inline keyword. 316221345Sdim SourceLocation LocStart; 317221345Sdim /// RBraceLoc - The ending location of the source range. 318221345Sdim SourceLocation RBraceLoc; 319198092Srdivacky 320234353Sdim /// \brief A pointer to either the anonymous namespace that lives just inside 321234353Sdim /// this namespace or to the first namespace in the chain (the latter case 322234353Sdim /// only when this is not the first in the chain), along with a 323234353Sdim /// boolean value indicating whether this is an inline namespace. 324234353Sdim llvm::PointerIntPair<NamespaceDecl *, 1, bool> AnonOrFirstNamespaceAndInline; 325198092Srdivacky 326234353Sdim NamespaceDecl(DeclContext *DC, bool Inline, SourceLocation StartLoc, 327234353Sdim SourceLocation IdLoc, IdentifierInfo *Id, 328234353Sdim NamespaceDecl *PrevDecl); 329234353Sdim 330234353Sdim typedef Redeclarable<NamespaceDecl> redeclarable_base; 331234353Sdim virtual NamespaceDecl *getNextRedeclaration() { 332234353Sdim return RedeclLink.getNext(); 333234353Sdim } 334234353Sdim virtual NamespaceDecl *getPreviousDeclImpl() { 335234353Sdim return getPreviousDecl(); 336234353Sdim } 337234353Sdim virtual NamespaceDecl *getMostRecentDeclImpl() { 338234353Sdim return getMostRecentDecl(); 339234353Sdim } 340234353Sdim 341193326Sedpublic: 342193326Sed static NamespaceDecl *Create(ASTContext &C, DeclContext *DC, 343234353Sdim bool Inline, SourceLocation StartLoc, 344234353Sdim SourceLocation IdLoc, IdentifierInfo *Id, 345234353Sdim NamespaceDecl *PrevDecl); 346198092Srdivacky 347234353Sdim static NamespaceDecl *CreateDeserialized(ASTContext &C, unsigned ID); 348234353Sdim 349234353Sdim typedef redeclarable_base::redecl_iterator redecl_iterator; 350234353Sdim using redeclarable_base::redecls_begin; 351234353Sdim using redeclarable_base::redecls_end; 352234353Sdim using redeclarable_base::getPreviousDecl; 353234353Sdim using redeclarable_base::getMostRecentDecl; 354234353Sdim 355212904Sdim /// \brief Returns true if this is an anonymous namespace declaration. 356212904Sdim /// 357212904Sdim /// For example: 358208600Srdivacky /// \code 359212904Sdim /// namespace { 360212904Sdim /// ... 361212904Sdim /// }; 362212904Sdim /// \endcode 363212904Sdim /// q.v. C++ [namespace.unnamed] 364198092Srdivacky bool isAnonymousNamespace() const { 365198092Srdivacky return !getIdentifier(); 366198092Srdivacky } 367198092Srdivacky 368212904Sdim /// \brief Returns true if this is an inline namespace declaration. 369212904Sdim bool isInline() const { 370234353Sdim return AnonOrFirstNamespaceAndInline.getInt(); 371212904Sdim } 372212904Sdim 373212904Sdim /// \brief Set whether this is an inline namespace declaration. 374212904Sdim void setInline(bool Inline) { 375234353Sdim AnonOrFirstNamespaceAndInline.setInt(Inline); 376212904Sdim } 377212904Sdim 378234353Sdim /// \brief Get the original (first) namespace declaration. 379234353Sdim NamespaceDecl *getOriginalNamespace() { 380234353Sdim if (isFirstDeclaration()) 381234353Sdim return this; 382234353Sdim 383234353Sdim return AnonOrFirstNamespaceAndInline.getPointer(); 384218893Sdim } 385208600Srdivacky 386208600Srdivacky /// \brief Get the original (first) namespace declaration. 387234353Sdim const NamespaceDecl *getOriginalNamespace() const { 388234353Sdim if (isFirstDeclaration()) 389234353Sdim return this; 390206084Srdivacky 391234353Sdim return AnonOrFirstNamespaceAndInline.getPointer(); 392193326Sed } 393198092Srdivacky 394208600Srdivacky /// \brief Return true if this declaration is an original (first) declaration 395208600Srdivacky /// of the namespace. This is false for non-original (subsequent) namespace 396208600Srdivacky /// declarations and anonymous namespaces. 397208600Srdivacky bool isOriginalNamespace() const { 398234353Sdim return isFirstDeclaration(); 399208600Srdivacky } 400208600Srdivacky 401234353Sdim /// \brief Retrieve the anonymous namespace nested inside this namespace, 402234353Sdim /// if any. 403201361Srdivacky NamespaceDecl *getAnonymousNamespace() const { 404234353Sdim return getOriginalNamespace()->AnonOrFirstNamespaceAndInline.getPointer(); 405201361Srdivacky } 406201361Srdivacky 407201361Srdivacky void setAnonymousNamespace(NamespaceDecl *D) { 408234353Sdim getOriginalNamespace()->AnonOrFirstNamespaceAndInline.setPointer(D); 409201361Srdivacky } 410201361Srdivacky 411234353Sdim /// Retrieves the canonical declaration of this namespace. 412234353Sdim NamespaceDecl *getCanonicalDecl() { 413234353Sdim return getOriginalNamespace(); 414206084Srdivacky } 415234353Sdim const NamespaceDecl *getCanonicalDecl() const { 416234353Sdim return getOriginalNamespace(); 417234353Sdim } 418234353Sdim 419234353Sdim virtual SourceRange getSourceRange() const LLVM_READONLY { 420221345Sdim return SourceRange(LocStart, RBraceLoc); 421193326Sed } 422193326Sed 423234353Sdim SourceLocation getLocStart() const LLVM_READONLY { return LocStart; } 424221345Sdim SourceLocation getRBraceLoc() const { return RBraceLoc; } 425221345Sdim void setLocStart(SourceLocation L) { LocStart = L; } 426221345Sdim void setRBraceLoc(SourceLocation L) { RBraceLoc = L; } 427221345Sdim 428193326Sed // Implement isa/cast/dyncast/etc. 429203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 430203955Srdivacky static bool classofKind(Kind K) { return K == Namespace; } 431193326Sed static DeclContext *castToDeclContext(const NamespaceDecl *D) { 432193326Sed return static_cast<DeclContext *>(const_cast<NamespaceDecl*>(D)); 433193326Sed } 434193326Sed static NamespaceDecl *castFromDeclContext(const DeclContext *DC) { 435193326Sed return static_cast<NamespaceDecl *>(const_cast<DeclContext*>(DC)); 436193326Sed } 437234353Sdim 438212904Sdim friend class ASTDeclReader; 439212904Sdim friend class ASTDeclWriter; 440193326Sed}; 441193326Sed 442198092Srdivacky/// ValueDecl - Represent the declaration of a variable (in which case it is 443193326Sed/// an lvalue) a function (in which case it is a function designator) or 444198092Srdivacky/// an enum constant. 445193326Sedclass ValueDecl : public NamedDecl { 446234353Sdim virtual void anchor(); 447193326Sed QualType DeclType; 448193326Sed 449193326Sedprotected: 450193326Sed ValueDecl(Kind DK, DeclContext *DC, SourceLocation L, 451198092Srdivacky DeclarationName N, QualType T) 452193326Sed : NamedDecl(DK, DC, L, N), DeclType(T) {} 453193326Sedpublic: 454193326Sed QualType getType() const { return DeclType; } 455193326Sed void setType(QualType newType) { DeclType = newType; } 456198092Srdivacky 457234353Sdim /// \brief Determine whether this symbol is weakly-imported, 458234353Sdim /// or declared with the weak or weak-ref attr. 459249423Sdim bool isWeak() const; 460234353Sdim 461193326Sed // Implement isa/cast/dyncast/etc. 462203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 463210299Sed static bool classofKind(Kind K) { return K >= firstValue && K <= lastValue; } 464193326Sed}; 465193326Sed 466210299Sed/// QualifierInfo - A struct with extended info about a syntactic 467210299Sed/// name qualifier, to be used for the case of out-of-line declarations. 468210299Sedstruct QualifierInfo { 469219077Sdim NestedNameSpecifierLoc QualifierLoc; 470221345Sdim 471221345Sdim /// NumTemplParamLists - The number of "outer" template parameter lists. 472221345Sdim /// The count includes all of the template parameter lists that were matched 473221345Sdim /// against the template-ids occurring into the NNS and possibly (in the 474221345Sdim /// case of an explicit specialization) a final "template <>". 475210299Sed unsigned NumTemplParamLists; 476221345Sdim 477210299Sed /// TemplParamLists - A new-allocated array of size NumTemplParamLists, 478221345Sdim /// containing pointers to the "outer" template parameter lists. 479221345Sdim /// It includes all of the template parameter lists that were matched 480221345Sdim /// against the template-ids occurring into the NNS and possibly (in the 481221345Sdim /// case of an explicit specialization) a final "template <>". 482210299Sed TemplateParameterList** TemplParamLists; 483210299Sed 484210299Sed /// Default constructor. 485219077Sdim QualifierInfo() : QualifierLoc(), NumTemplParamLists(0), TemplParamLists(0) {} 486221345Sdim 487221345Sdim /// setTemplateParameterListsInfo - Sets info about "outer" template 488210299Sed /// parameter lists. 489210299Sed void setTemplateParameterListsInfo(ASTContext &Context, 490210299Sed unsigned NumTPLists, 491210299Sed TemplateParameterList **TPLists); 492234353Sdim 493210299Sedprivate: 494210299Sed // Copy constructor and copy assignment are disabled. 495243830Sdim QualifierInfo(const QualifierInfo&) LLVM_DELETED_FUNCTION; 496243830Sdim QualifierInfo& operator=(const QualifierInfo&) LLVM_DELETED_FUNCTION; 497210299Sed}; 498210299Sed 499198092Srdivacky/// \brief Represents a ValueDecl that came out of a declarator. 500200583Srdivacky/// Contains type source information through TypeSourceInfo. 501198092Srdivackyclass DeclaratorDecl : public ValueDecl { 502205219Srdivacky // A struct representing both a TInfo and a syntactic qualifier, 503205219Srdivacky // to be used for the (uncommon) case of out-of-line declarations. 504210299Sed struct ExtInfo : public QualifierInfo { 505205219Srdivacky TypeSourceInfo *TInfo; 506205219Srdivacky }; 507198092Srdivacky 508205219Srdivacky llvm::PointerUnion<TypeSourceInfo*, ExtInfo*> DeclInfo; 509205219Srdivacky 510221345Sdim /// InnerLocStart - The start of the source range for this declaration, 511221345Sdim /// ignoring outer template declarations. 512221345Sdim SourceLocation InnerLocStart; 513221345Sdim 514205219Srdivacky bool hasExtInfo() const { return DeclInfo.is<ExtInfo*>(); } 515205219Srdivacky ExtInfo *getExtInfo() { return DeclInfo.get<ExtInfo*>(); } 516205219Srdivacky const ExtInfo *getExtInfo() const { return DeclInfo.get<ExtInfo*>(); } 517205219Srdivacky 518198092Srdivackyprotected: 519198092Srdivacky DeclaratorDecl(Kind DK, DeclContext *DC, SourceLocation L, 520221345Sdim DeclarationName N, QualType T, TypeSourceInfo *TInfo, 521221345Sdim SourceLocation StartL) 522221345Sdim : ValueDecl(DK, DC, L, N, T), DeclInfo(TInfo), InnerLocStart(StartL) { 523221345Sdim } 524198092Srdivacky 525198092Srdivackypublic: 526205219Srdivacky TypeSourceInfo *getTypeSourceInfo() const { 527205219Srdivacky return hasExtInfo() 528210299Sed ? getExtInfo()->TInfo 529205219Srdivacky : DeclInfo.get<TypeSourceInfo*>(); 530205219Srdivacky } 531205219Srdivacky void setTypeSourceInfo(TypeSourceInfo *TI) { 532205219Srdivacky if (hasExtInfo()) 533210299Sed getExtInfo()->TInfo = TI; 534205219Srdivacky else 535205219Srdivacky DeclInfo = TI; 536205219Srdivacky } 537205219Srdivacky 538210299Sed /// getInnerLocStart - Return SourceLocation representing start of source 539210299Sed /// range ignoring outer template declarations. 540221345Sdim SourceLocation getInnerLocStart() const { return InnerLocStart; } 541221345Sdim void setInnerLocStart(SourceLocation L) { InnerLocStart = L; } 542210299Sed 543210299Sed /// getOuterLocStart - Return SourceLocation representing start of source 544210299Sed /// range taking into account any outer template declarations. 545210299Sed SourceLocation getOuterLocStart() const; 546210299Sed 547234353Sdim virtual SourceRange getSourceRange() const LLVM_READONLY; 548234353Sdim SourceLocation getLocStart() const LLVM_READONLY { 549234353Sdim return getOuterLocStart(); 550234353Sdim } 551221345Sdim 552219077Sdim /// \brief Retrieve the nested-name-specifier that qualifies the name of this 553219077Sdim /// declaration, if it was present in the source. 554205219Srdivacky NestedNameSpecifier *getQualifier() const { 555219077Sdim return hasExtInfo() ? getExtInfo()->QualifierLoc.getNestedNameSpecifier() 556219077Sdim : 0; 557205219Srdivacky } 558234353Sdim 559234353Sdim /// \brief Retrieve the nested-name-specifier (with source-location 560234353Sdim /// information) that qualifies the name of this declaration, if it was 561219077Sdim /// present in the source. 562219077Sdim NestedNameSpecifierLoc getQualifierLoc() const { 563219077Sdim return hasExtInfo() ? getExtInfo()->QualifierLoc 564219077Sdim : NestedNameSpecifierLoc(); 565205219Srdivacky } 566234353Sdim 567219077Sdim void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc); 568205219Srdivacky 569210299Sed unsigned getNumTemplateParameterLists() const { 570210299Sed return hasExtInfo() ? getExtInfo()->NumTemplParamLists : 0; 571210299Sed } 572210299Sed TemplateParameterList *getTemplateParameterList(unsigned index) const { 573210299Sed assert(index < getNumTemplateParameterLists()); 574210299Sed return getExtInfo()->TemplParamLists[index]; 575210299Sed } 576210299Sed void setTemplateParameterListsInfo(ASTContext &Context, unsigned NumTPLists, 577221345Sdim TemplateParameterList **TPLists); 578210299Sed 579198092Srdivacky SourceLocation getTypeSpecStartLoc() const; 580198092Srdivacky 581198092Srdivacky // Implement isa/cast/dyncast/etc. 582203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 583203955Srdivacky static bool classofKind(Kind K) { 584210299Sed return K >= firstDeclarator && K <= lastDeclarator; 585198092Srdivacky } 586218893Sdim 587218893Sdim friend class ASTDeclReader; 588218893Sdim friend class ASTDeclWriter; 589198092Srdivacky}; 590198092Srdivacky 591193326Sed/// \brief Structure used to store a statement, the constant value to 592193326Sed/// which it was evaluated (if any), and whether or not the statement 593193326Sed/// is an integral constant expression (if known). 594193326Sedstruct EvaluatedStmt { 595200583Srdivacky EvaluatedStmt() : WasEvaluated(false), IsEvaluating(false), CheckedICE(false), 596200583Srdivacky CheckingICE(false), IsICE(false) { } 597193326Sed 598193326Sed /// \brief Whether this statement was already evaluated. 599193326Sed bool WasEvaluated : 1; 600193326Sed 601200583Srdivacky /// \brief Whether this statement is being evaluated. 602200583Srdivacky bool IsEvaluating : 1; 603200583Srdivacky 604193326Sed /// \brief Whether we already checked whether this statement was an 605193326Sed /// integral constant expression. 606193326Sed bool CheckedICE : 1; 607193326Sed 608200583Srdivacky /// \brief Whether we are checking whether this statement is an 609200583Srdivacky /// integral constant expression. 610200583Srdivacky bool CheckingICE : 1; 611200583Srdivacky 612234353Sdim /// \brief Whether this statement is an integral constant expression, 613234353Sdim /// or in C++11, whether the statement is a constant expression. Only 614234353Sdim /// valid if CheckedICE is true. 615193326Sed bool IsICE : 1; 616193326Sed 617193326Sed Stmt *Value; 618193326Sed APValue Evaluated; 619193326Sed}; 620193326Sed 621193326Sed/// VarDecl - An instance of this class is created to represent a variable 622193326Sed/// declaration or definition. 623198092Srdivackyclass VarDecl : public DeclaratorDecl, public Redeclarable<VarDecl> { 624193326Sedpublic: 625212904Sdim typedef clang::StorageClass StorageClass; 626193326Sed 627193326Sed /// getStorageClassSpecifierString - Return the string used to 628243830Sdim /// specify the storage class \p SC. 629193326Sed /// 630193326Sed /// It is illegal to call this function with SC == None. 631193326Sed static const char *getStorageClassSpecifierString(StorageClass SC); 632193326Sed 633234353Sdim /// \brief Initialization styles. 634234353Sdim enum InitializationStyle { 635234353Sdim CInit, ///< C-style initialization with assignment 636234353Sdim CallInit, ///< Call-style initialization (C++98) 637234353Sdim ListInit ///< Direct list-initialization (C++11) 638234353Sdim }; 639234353Sdim 640251662Sdim /// \brief Kinds of thread-local storage. 641251662Sdim enum TLSKind { 642251662Sdim TLS_None, ///< Not a TLS variable. 643251662Sdim TLS_Static, ///< TLS with a known-constant initializer. 644251662Sdim TLS_Dynamic ///< TLS with a dynamic initializer. 645251662Sdim }; 646251662Sdim 647198092Srdivackyprotected: 648198092Srdivacky /// \brief Placeholder type used in Init to denote an unparsed C++ default 649198092Srdivacky /// argument. 650198092Srdivacky struct UnparsedDefaultArgument; 651198092Srdivacky 652198092Srdivacky /// \brief Placeholder type used in Init to denote an uninstantiated C++ 653198092Srdivacky /// default argument. 654198092Srdivacky struct UninstantiatedDefaultArgument; 655198092Srdivacky 656198092Srdivacky typedef llvm::PointerUnion4<Stmt *, EvaluatedStmt *, 657198092Srdivacky UnparsedDefaultArgument *, 658198092Srdivacky UninstantiatedDefaultArgument *> InitType; 659198092Srdivacky 660198092Srdivacky /// \brief The initializer for this variable or, for a ParmVarDecl, the 661198092Srdivacky /// C++ default argument. 662198092Srdivacky mutable InitType Init; 663198092Srdivacky 664193326Sedprivate: 665221345Sdim class VarDeclBitfields { 666221345Sdim friend class VarDecl; 667221345Sdim friend class ASTDeclReader; 668193326Sed 669221345Sdim unsigned SClass : 3; 670251662Sdim unsigned TSCSpec : 2; 671234353Sdim unsigned InitStyle : 2; 672221345Sdim 673221345Sdim /// \brief Whether this variable is the exception variable in a C++ catch 674221345Sdim /// or an Objective-C @catch statement. 675221345Sdim unsigned ExceptionVar : 1; 676234353Sdim 677221345Sdim /// \brief Whether this local variable could be allocated in the return 678234353Sdim /// slot of its function, enabling the named return value optimization 679234353Sdim /// (NRVO). 680221345Sdim unsigned NRVOVariable : 1; 681218893Sdim 682221345Sdim /// \brief Whether this variable is the for-range-declaration in a C++0x 683221345Sdim /// for-range statement. 684221345Sdim unsigned CXXForRangeDecl : 1; 685224145Sdim 686224145Sdim /// \brief Whether this variable is an ARC pseudo-__strong 687224145Sdim /// variable; see isARCPseudoStrong() for details. 688224145Sdim unsigned ARCPseudoStrong : 1; 689226633Sdim 690226633Sdim /// \brief Whether this variable is (C++0x) constexpr. 691226633Sdim unsigned IsConstexpr : 1; 692221345Sdim }; 693251662Sdim enum { NumVarDeclBits = 12 }; 694221345Sdim 695221345Sdim friend class ASTDeclReader; 696193326Sed friend class StmtIteratorBase; 697234353Sdim 698193326Sedprotected: 699226633Sdim enum { NumParameterIndexBits = 8 }; 700234353Sdim 701221345Sdim class ParmVarDeclBitfields { 702221345Sdim friend class ParmVarDecl; 703221345Sdim friend class ASTDeclReader; 704221345Sdim 705221345Sdim unsigned : NumVarDeclBits; 706221345Sdim 707221345Sdim /// Whether this parameter inherits a default argument from a 708221345Sdim /// prior declaration. 709221345Sdim unsigned HasInheritedDefaultArg : 1; 710221345Sdim 711221345Sdim /// Whether this parameter undergoes K&R argument promotion. 712221345Sdim unsigned IsKNRPromoted : 1; 713221345Sdim 714221345Sdim /// Whether this parameter is an ObjC method parameter or not. 715221345Sdim unsigned IsObjCMethodParam : 1; 716221345Sdim 717221345Sdim /// If IsObjCMethodParam, a Decl::ObjCDeclQualifier. 718221345Sdim /// Otherwise, the number of function parameter scopes enclosing 719221345Sdim /// the function parameter scope in which this parameter was 720221345Sdim /// declared. 721234353Sdim unsigned ScopeDepthOrObjCQuals : 7; 722221345Sdim 723221345Sdim /// The number of parameters preceding this parameter in the 724221345Sdim /// function parameter scope in which it was declared. 725226633Sdim unsigned ParameterIndex : NumParameterIndexBits; 726221345Sdim }; 727221345Sdim 728221345Sdim union { 729221345Sdim unsigned AllBits; 730221345Sdim VarDeclBitfields VarDeclBits; 731221345Sdim ParmVarDeclBitfields ParmVarDeclBits; 732221345Sdim }; 733221345Sdim 734221345Sdim VarDecl(Kind DK, DeclContext *DC, SourceLocation StartLoc, 735221345Sdim SourceLocation IdLoc, IdentifierInfo *Id, 736249423Sdim QualType T, TypeSourceInfo *TInfo, StorageClass SC) 737221345Sdim : DeclaratorDecl(DK, DC, IdLoc, Id, T, TInfo, StartLoc), Init() { 738221345Sdim assert(sizeof(VarDeclBitfields) <= sizeof(unsigned)); 739221345Sdim assert(sizeof(ParmVarDeclBitfields) <= sizeof(unsigned)); 740221345Sdim AllBits = 0; 741221345Sdim VarDeclBits.SClass = SC; 742221345Sdim // Everything else is implicitly initialized to false. 743193326Sed } 744198092Srdivacky 745198092Srdivacky typedef Redeclarable<VarDecl> redeclarable_base; 746198092Srdivacky virtual VarDecl *getNextRedeclaration() { return RedeclLink.getNext(); } 747234353Sdim virtual VarDecl *getPreviousDeclImpl() { 748234353Sdim return getPreviousDecl(); 749234353Sdim } 750234353Sdim virtual VarDecl *getMostRecentDeclImpl() { 751234353Sdim return getMostRecentDecl(); 752234353Sdim } 753198092Srdivacky 754193326Sedpublic: 755198092Srdivacky typedef redeclarable_base::redecl_iterator redecl_iterator; 756234353Sdim using redeclarable_base::redecls_begin; 757234353Sdim using redeclarable_base::redecls_end; 758234353Sdim using redeclarable_base::getPreviousDecl; 759234353Sdim using redeclarable_base::getMostRecentDecl; 760198092Srdivacky 761193326Sed static VarDecl *Create(ASTContext &C, DeclContext *DC, 762221345Sdim SourceLocation StartLoc, SourceLocation IdLoc, 763221345Sdim IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, 764249423Sdim StorageClass S); 765193326Sed 766234353Sdim static VarDecl *CreateDeserialized(ASTContext &C, unsigned ID); 767234353Sdim 768234353Sdim virtual SourceRange getSourceRange() const LLVM_READONLY; 769203955Srdivacky 770249423Sdim /// \brief Returns the storage class as written in the source. For the 771249423Sdim /// computed linkage of symbol, see getLinkage. 772221345Sdim StorageClass getStorageClass() const { 773221345Sdim return (StorageClass) VarDeclBits.SClass; 774221345Sdim } 775218893Sdim void setStorageClass(StorageClass SC); 776198092Srdivacky 777251662Sdim void setTSCSpec(ThreadStorageClassSpecifier TSC) { 778251662Sdim VarDeclBits.TSCSpec = TSC; 779203955Srdivacky } 780251662Sdim ThreadStorageClassSpecifier getTSCSpec() const { 781251662Sdim return static_cast<ThreadStorageClassSpecifier>(VarDeclBits.TSCSpec); 782251662Sdim } 783251662Sdim TLSKind getTLSKind() const { 784251662Sdim switch (VarDeclBits.TSCSpec) { 785251662Sdim case TSCS_unspecified: 786251662Sdim return TLS_None; 787251662Sdim case TSCS___thread: // Fall through. 788251662Sdim case TSCS__Thread_local: 789251662Sdim return TLS_Static; 790251662Sdim case TSCS_thread_local: 791251662Sdim return TLS_Dynamic; 792251662Sdim } 793251662Sdim llvm_unreachable("Unknown thread storage class specifier!"); 794251662Sdim } 795193326Sed 796203955Srdivacky /// hasLocalStorage - Returns true if a variable with function scope 797203955Srdivacky /// is a non-static local variable. 798203955Srdivacky bool hasLocalStorage() const { 799212904Sdim if (getStorageClass() == SC_None) 800203955Srdivacky return !isFileVarDecl(); 801203955Srdivacky 802203955Srdivacky // Return true for: Auto, Register. 803226633Sdim // Return false for: Extern, Static, PrivateExtern, OpenCLWorkGroupLocal. 804203955Srdivacky 805212904Sdim return getStorageClass() >= SC_Auto; 806203955Srdivacky } 807203955Srdivacky 808234353Sdim /// isStaticLocal - Returns true if a variable with function scope is a 809207619Srdivacky /// static local variable. 810207619Srdivacky bool isStaticLocal() const { 811212904Sdim return getStorageClass() == SC_Static && !isFileVarDecl(); 812207619Srdivacky } 813234353Sdim 814249423Sdim /// \brief Returns true if a variable has extern or __private_extern__ 815249423Sdim /// storage. 816203955Srdivacky bool hasExternalStorage() const { 817212904Sdim return getStorageClass() == SC_Extern || 818212904Sdim getStorageClass() == SC_PrivateExtern; 819203955Srdivacky } 820203955Srdivacky 821203955Srdivacky /// hasGlobalStorage - Returns true for all variables that do not 822203955Srdivacky /// have local storage. This includs all global variables as well 823203955Srdivacky /// as static variables declared within a function. 824203955Srdivacky bool hasGlobalStorage() const { return !hasLocalStorage(); } 825203955Srdivacky 826249423Sdim /// Compute the language linkage. 827249423Sdim LanguageLinkage getLanguageLinkage() const; 828249423Sdim 829203955Srdivacky /// \brief Determines whether this variable is a variable with 830203955Srdivacky /// external, C linkage. 831203955Srdivacky bool isExternC() const; 832203955Srdivacky 833251662Sdim /// \brief Determines whether this variable's context is, or is nested within, 834251662Sdim /// a C++ extern "C" linkage spec. 835251662Sdim bool isInExternCContext() const; 836251662Sdim 837251662Sdim /// \brief Determines whether this variable's context is, or is nested within, 838251662Sdim /// a C++ extern "C++" linkage spec. 839251662Sdim bool isInExternCXXContext() const; 840251662Sdim 841218893Sdim /// isLocalVarDecl - Returns true for local variable declarations 842218893Sdim /// other than parameters. Note that this includes static variables 843218893Sdim /// inside of functions. It also includes variables inside blocks. 844203955Srdivacky /// 845203955Srdivacky /// void foo() { int x; static int y; extern int z; } 846203955Srdivacky /// 847218893Sdim bool isLocalVarDecl() const { 848203955Srdivacky if (getKind() != Decl::Var) 849203955Srdivacky return false; 850203955Srdivacky if (const DeclContext *DC = getDeclContext()) 851212904Sdim return DC->getRedeclContext()->isFunctionOrMethod(); 852203955Srdivacky return false; 853203955Srdivacky } 854203955Srdivacky 855218893Sdim /// isFunctionOrMethodVarDecl - Similar to isLocalVarDecl, but 856218893Sdim /// excludes variables declared in blocks. 857205219Srdivacky bool isFunctionOrMethodVarDecl() const { 858205219Srdivacky if (getKind() != Decl::Var) 859205219Srdivacky return false; 860212904Sdim const DeclContext *DC = getDeclContext()->getRedeclContext(); 861212904Sdim return DC->isFunctionOrMethod() && DC->getDeclKind() != Decl::Block; 862205219Srdivacky } 863205219Srdivacky 864203955Srdivacky /// \brief Determines whether this is a static data member. 865203955Srdivacky /// 866203955Srdivacky /// This will only be true in C++, and applies to, e.g., the 867203955Srdivacky /// variable 'x' in: 868203955Srdivacky /// \code 869203955Srdivacky /// struct S { 870203955Srdivacky /// static int x; 871203955Srdivacky /// }; 872203955Srdivacky /// \endcode 873203955Srdivacky bool isStaticDataMember() const { 874203955Srdivacky // If it wasn't static, it would be a FieldDecl. 875212904Sdim return getKind() != Decl::ParmVar && getDeclContext()->isRecord(); 876203955Srdivacky } 877203955Srdivacky 878203955Srdivacky virtual VarDecl *getCanonicalDecl(); 879203955Srdivacky const VarDecl *getCanonicalDecl() const { 880203955Srdivacky return const_cast<VarDecl*>(this)->getCanonicalDecl(); 881203955Srdivacky } 882203955Srdivacky 883203955Srdivacky enum DefinitionKind { 884203955Srdivacky DeclarationOnly, ///< This declaration is only a declaration. 885203955Srdivacky TentativeDefinition, ///< This declaration is a tentative definition. 886203955Srdivacky Definition ///< This declaration is definitely a definition. 887203955Srdivacky }; 888203955Srdivacky 889203955Srdivacky /// \brief Check whether this declaration is a definition. If this could be 890203955Srdivacky /// a tentative definition (in C), don't check whether there's an overriding 891203955Srdivacky /// definition. 892234353Sdim DefinitionKind isThisDeclarationADefinition(ASTContext &) const; 893234353Sdim DefinitionKind isThisDeclarationADefinition() const { 894234353Sdim return isThisDeclarationADefinition(getASTContext()); 895234353Sdim } 896203955Srdivacky 897218893Sdim /// \brief Check whether this variable is defined in this 898218893Sdim /// translation unit. 899234353Sdim DefinitionKind hasDefinition(ASTContext &) const; 900234353Sdim DefinitionKind hasDefinition() const { 901234353Sdim return hasDefinition(getASTContext()); 902234353Sdim } 903218893Sdim 904203955Srdivacky /// \brief Get the tentative definition that acts as the real definition in 905203955Srdivacky /// a TU. Returns null if there is a proper definition available. 906203955Srdivacky VarDecl *getActingDefinition(); 907203955Srdivacky const VarDecl *getActingDefinition() const { 908203955Srdivacky return const_cast<VarDecl*>(this)->getActingDefinition(); 909203955Srdivacky } 910203955Srdivacky 911203955Srdivacky /// \brief Determine whether this is a tentative definition of a 912203955Srdivacky /// variable in C. 913203955Srdivacky bool isTentativeDefinitionNow() const; 914203955Srdivacky 915203955Srdivacky /// \brief Get the real (not just tentative) definition for this declaration. 916234353Sdim VarDecl *getDefinition(ASTContext &); 917234353Sdim const VarDecl *getDefinition(ASTContext &C) const { 918234353Sdim return const_cast<VarDecl*>(this)->getDefinition(C); 919234353Sdim } 920234353Sdim VarDecl *getDefinition() { 921234353Sdim return getDefinition(getASTContext()); 922234353Sdim } 923203955Srdivacky const VarDecl *getDefinition() const { 924203955Srdivacky return const_cast<VarDecl*>(this)->getDefinition(); 925203955Srdivacky } 926203955Srdivacky 927234353Sdim /// \brief Determine whether this is or was instantiated from an out-of-line 928203955Srdivacky /// definition of a static data member. 929204643Srdivacky virtual bool isOutOfLine() const; 930203955Srdivacky 931203955Srdivacky /// \brief If this is a static data member, find its out-of-line definition. 932203955Srdivacky VarDecl *getOutOfLineDefinition(); 933234353Sdim 934203955Srdivacky /// isFileVarDecl - Returns true for file scoped variable declaration. 935203955Srdivacky bool isFileVarDecl() const { 936203955Srdivacky if (getKind() != Decl::Var) 937203955Srdivacky return false; 938234353Sdim 939212904Sdim if (getDeclContext()->getRedeclContext()->isFileContext()) 940212904Sdim return true; 941234353Sdim 942203955Srdivacky if (isStaticDataMember()) 943203955Srdivacky return true; 944203955Srdivacky 945203955Srdivacky return false; 946203955Srdivacky } 947203955Srdivacky 948203955Srdivacky /// getAnyInitializer - Get the initializer for this variable, no matter which 949203955Srdivacky /// declaration it is attached to. 950203955Srdivacky const Expr *getAnyInitializer() const { 951203955Srdivacky const VarDecl *D; 952203955Srdivacky return getAnyInitializer(D); 953203955Srdivacky } 954203955Srdivacky 955203955Srdivacky /// getAnyInitializer - Get the initializer for this variable, no matter which 956203955Srdivacky /// declaration it is attached to. Also get that declaration. 957203955Srdivacky const Expr *getAnyInitializer(const VarDecl *&D) const; 958203955Srdivacky 959203955Srdivacky bool hasInit() const { 960218893Sdim return !Init.isNull() && (Init.is<Stmt *>() || Init.is<EvaluatedStmt *>()); 961203955Srdivacky } 962198092Srdivacky const Expr *getInit() const { 963193326Sed if (Init.isNull()) 964193326Sed return 0; 965193326Sed 966193326Sed const Stmt *S = Init.dyn_cast<Stmt *>(); 967198092Srdivacky if (!S) { 968198092Srdivacky if (EvaluatedStmt *ES = Init.dyn_cast<EvaluatedStmt*>()) 969198092Srdivacky S = ES->Value; 970198092Srdivacky } 971198092Srdivacky return (const Expr*) S; 972193326Sed } 973198092Srdivacky Expr *getInit() { 974193326Sed if (Init.isNull()) 975193326Sed return 0; 976193326Sed 977193326Sed Stmt *S = Init.dyn_cast<Stmt *>(); 978198092Srdivacky if (!S) { 979198092Srdivacky if (EvaluatedStmt *ES = Init.dyn_cast<EvaluatedStmt*>()) 980198092Srdivacky S = ES->Value; 981198092Srdivacky } 982193326Sed 983198092Srdivacky return (Expr*) S; 984193326Sed } 985193326Sed 986193326Sed /// \brief Retrieve the address of the initializer expression. 987193326Sed Stmt **getInitAddress() { 988198092Srdivacky if (EvaluatedStmt *ES = Init.dyn_cast<EvaluatedStmt*>()) 989198092Srdivacky return &ES->Value; 990198092Srdivacky 991198092Srdivacky // This union hack tip-toes around strict-aliasing rules. 992198092Srdivacky union { 993198092Srdivacky InitType *InitPtr; 994198092Srdivacky Stmt **StmtPtr; 995198092Srdivacky }; 996198092Srdivacky 997198092Srdivacky InitPtr = &Init; 998198092Srdivacky return StmtPtr; 999193326Sed } 1000193326Sed 1001203955Srdivacky void setInit(Expr *I); 1002198092Srdivacky 1003224145Sdim /// \brief Determine whether this variable is a reference that 1004234353Sdim /// extends the lifetime of its temporary initializer. 1005224145Sdim /// 1006224145Sdim /// A reference extends the lifetime of its temporary initializer if 1007224145Sdim /// it's initializer is an rvalue that would normally go out of scope 1008224145Sdim /// at the end of the initializer (a full expression). In such cases, 1009224145Sdim /// the reference itself takes ownership of the temporary, which will 1010224145Sdim /// be destroyed when the reference goes out of scope. For example: 1011224145Sdim /// 1012224145Sdim /// \code 1013224145Sdim /// const int &r = 1.0; // creates a temporary of type 'int' 1014224145Sdim /// \endcode 1015224145Sdim bool extendsLifetimeOfTemporary() const; 1016224145Sdim 1017234353Sdim /// \brief Determine whether this variable's value can be used in a 1018234353Sdim /// constant expression, according to the relevant language standard. 1019234353Sdim /// This only checks properties of the declaration, and does not check 1020234353Sdim /// whether the initializer is in fact a constant expression. 1021234353Sdim bool isUsableInConstantExpressions(ASTContext &C) const; 1022193326Sed 1023234353Sdim EvaluatedStmt *ensureEvaluatedStmt() const; 1024200583Srdivacky 1025234353Sdim /// \brief Attempt to evaluate the value of the initializer attached to this 1026234353Sdim /// declaration, and produce notes explaining why it cannot be evaluated or is 1027234353Sdim /// not a constant expression. Returns a pointer to the value if evaluation 1028234353Sdim /// succeeded, 0 otherwise. 1029234353Sdim APValue *evaluateValue() const; 1030249423Sdim APValue *evaluateValue(SmallVectorImpl<PartialDiagnosticAt> &Notes) const; 1031200583Srdivacky 1032193326Sed /// \brief Return the already-evaluated value of this variable's 1033200583Srdivacky /// initializer, or NULL if the value is not yet known. Returns pointer 1034200583Srdivacky /// to untyped APValue if the value could not be evaluated. 1035193326Sed APValue *getEvaluatedValue() const { 1036193326Sed if (EvaluatedStmt *Eval = Init.dyn_cast<EvaluatedStmt *>()) 1037193326Sed if (Eval->WasEvaluated) 1038193326Sed return &Eval->Evaluated; 1039193326Sed 1040193326Sed return 0; 1041193326Sed } 1042193326Sed 1043193326Sed /// \brief Determines whether it is already known whether the 1044193326Sed /// initializer is an integral constant expression or not. 1045193326Sed bool isInitKnownICE() const { 1046193326Sed if (EvaluatedStmt *Eval = Init.dyn_cast<EvaluatedStmt *>()) 1047193326Sed return Eval->CheckedICE; 1048193326Sed 1049193326Sed return false; 1050193326Sed } 1051193326Sed 1052234353Sdim /// \brief Determines whether the initializer is an integral constant 1053234353Sdim /// expression, or in C++11, whether the initializer is a constant 1054234353Sdim /// expression. 1055193326Sed /// 1056193326Sed /// \pre isInitKnownICE() 1057193326Sed bool isInitICE() const { 1058198092Srdivacky assert(isInitKnownICE() && 1059193326Sed "Check whether we already know that the initializer is an ICE"); 1060193326Sed return Init.get<EvaluatedStmt *>()->IsICE; 1061193326Sed } 1062193326Sed 1063234353Sdim /// \brief Determine whether the value of the initializer attached to this 1064234353Sdim /// declaration is an integral constant expression. 1065234353Sdim bool checkInitIsICE() const; 1066200583Srdivacky 1067234353Sdim void setInitStyle(InitializationStyle Style) { 1068234353Sdim VarDeclBits.InitStyle = Style; 1069200583Srdivacky } 1070200583Srdivacky 1071234353Sdim /// \brief The style of initialization for this declaration. 1072234353Sdim /// 1073234353Sdim /// C-style initialization is "int x = 1;". Call-style initialization is 1074234353Sdim /// a C++98 direct-initializer, e.g. "int x(1);". The Init expression will be 1075234353Sdim /// the expression inside the parens or a "ClassType(a,b,c)" class constructor 1076234353Sdim /// expression for class types. List-style initialization is C++11 syntax, 1077234353Sdim /// e.g. "int x{1};". Clients can distinguish between different forms of 1078234353Sdim /// initialization by checking this value. In particular, "int x = {1};" is 1079234353Sdim /// C-style, "int x({1})" is call-style, and "int x{1};" is list-style; the 1080234353Sdim /// Init expression in all three cases is an InitListExpr. 1081234353Sdim InitializationStyle getInitStyle() const { 1082234353Sdim return static_cast<InitializationStyle>(VarDeclBits.InitStyle); 1083200583Srdivacky } 1084200583Srdivacky 1085234353Sdim /// \brief Whether the initializer is a direct-initializer (list or call). 1086234353Sdim bool isDirectInit() const { 1087234353Sdim return getInitStyle() != CInit; 1088193326Sed } 1089193326Sed 1090207619Srdivacky /// \brief Determine whether this variable is the exception variable in a 1091239462Sdim /// C++ catch statememt or an Objective-C \@catch statement. 1092207619Srdivacky bool isExceptionVariable() const { 1093221345Sdim return VarDeclBits.ExceptionVar; 1094207619Srdivacky } 1095221345Sdim void setExceptionVariable(bool EV) { VarDeclBits.ExceptionVar = EV; } 1096234353Sdim 1097208600Srdivacky /// \brief Determine whether this local variable can be used with the named 1098208600Srdivacky /// return value optimization (NRVO). 1099208600Srdivacky /// 1100208600Srdivacky /// The named return value optimization (NRVO) works by marking certain 1101208600Srdivacky /// non-volatile local variables of class type as NRVO objects. These 1102208600Srdivacky /// locals can be allocated within the return slot of their containing 1103208600Srdivacky /// function, in which case there is no need to copy the object to the 1104208600Srdivacky /// return slot when returning from the function. Within the function body, 1105208600Srdivacky /// each return that returns the NRVO object will have this variable as its 1106208600Srdivacky /// NRVO candidate. 1107221345Sdim bool isNRVOVariable() const { return VarDeclBits.NRVOVariable; } 1108221345Sdim void setNRVOVariable(bool NRVO) { VarDeclBits.NRVOVariable = NRVO; } 1109221345Sdim 1110221345Sdim /// \brief Determine whether this variable is the for-range-declaration in 1111221345Sdim /// a C++0x for-range statement. 1112221345Sdim bool isCXXForRangeDecl() const { return VarDeclBits.CXXForRangeDecl; } 1113221345Sdim void setCXXForRangeDecl(bool FRD) { VarDeclBits.CXXForRangeDecl = FRD; } 1114224145Sdim 1115224145Sdim /// \brief Determine whether this variable is an ARC pseudo-__strong 1116224145Sdim /// variable. A pseudo-__strong variable has a __strong-qualified 1117224145Sdim /// type but does not actually retain the object written into it. 1118224145Sdim /// Generally such variables are also 'const' for safety. 1119224145Sdim bool isARCPseudoStrong() const { return VarDeclBits.ARCPseudoStrong; } 1120224145Sdim void setARCPseudoStrong(bool ps) { VarDeclBits.ARCPseudoStrong = ps; } 1121234353Sdim 1122239462Sdim /// Whether this variable is (C++11) constexpr. 1123226633Sdim bool isConstexpr() const { return VarDeclBits.IsConstexpr; } 1124226633Sdim void setConstexpr(bool IC) { VarDeclBits.IsConstexpr = IC; } 1125226633Sdim 1126198092Srdivacky /// \brief If this variable is an instantiated static data member of a 1127198092Srdivacky /// class template specialization, returns the templated static data member 1128198092Srdivacky /// from which it was instantiated. 1129198112Srdivacky VarDecl *getInstantiatedFromStaticDataMember() const; 1130198092Srdivacky 1131234353Sdim /// \brief If this variable is a static data member, determine what kind of 1132198092Srdivacky /// template specialization or instantiation this is. 1133198112Srdivacky TemplateSpecializationKind getTemplateSpecializationKind() const; 1134234353Sdim 1135198092Srdivacky /// \brief If this variable is an instantiation of a static data member of a 1136198092Srdivacky /// class template specialization, retrieves the member specialization 1137198092Srdivacky /// information. 1138198112Srdivacky MemberSpecializationInfo *getMemberSpecializationInfo() const; 1139234353Sdim 1140198092Srdivacky /// \brief For a static data member that was instantiated from a static 1141198092Srdivacky /// data member of a class template, set the template specialiation kind. 1142198398Srdivacky void setTemplateSpecializationKind(TemplateSpecializationKind TSK, 1143198398Srdivacky SourceLocation PointOfInstantiation = SourceLocation()); 1144198092Srdivacky 1145193326Sed // Implement isa/cast/dyncast/etc. 1146203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1147210299Sed static bool classofKind(Kind K) { return K >= firstVar && K <= lastVar; } 1148193326Sed}; 1149193326Sed 1150193326Sedclass ImplicitParamDecl : public VarDecl { 1151234353Sdim virtual void anchor(); 1152193326Sedpublic: 1153193326Sed static ImplicitParamDecl *Create(ASTContext &C, DeclContext *DC, 1154221345Sdim SourceLocation IdLoc, IdentifierInfo *Id, 1155198092Srdivacky QualType T); 1156219077Sdim 1157234353Sdim static ImplicitParamDecl *CreateDeserialized(ASTContext &C, unsigned ID); 1158234353Sdim 1159221345Sdim ImplicitParamDecl(DeclContext *DC, SourceLocation IdLoc, 1160221345Sdim IdentifierInfo *Id, QualType Type) 1161221345Sdim : VarDecl(ImplicitParam, DC, IdLoc, IdLoc, Id, Type, 1162249423Sdim /*tinfo*/ 0, SC_None) { 1163219077Sdim setImplicit(); 1164219077Sdim } 1165219077Sdim 1166193326Sed // Implement isa/cast/dyncast/etc. 1167203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1168203955Srdivacky static bool classofKind(Kind K) { return K == ImplicitParam; } 1169193326Sed}; 1170193326Sed 1171221345Sdim/// ParmVarDecl - Represents a parameter to a function. 1172193326Sedclass ParmVarDecl : public VarDecl { 1173221345Sdimpublic: 1174221345Sdim enum { MaxFunctionScopeDepth = 255 }; 1175221345Sdim enum { MaxFunctionScopeIndex = 255 }; 1176198092Srdivacky 1177193326Sedprotected: 1178221345Sdim ParmVarDecl(Kind DK, DeclContext *DC, SourceLocation StartLoc, 1179221345Sdim SourceLocation IdLoc, IdentifierInfo *Id, 1180221345Sdim QualType T, TypeSourceInfo *TInfo, 1181249423Sdim StorageClass S, Expr *DefArg) 1182249423Sdim : VarDecl(DK, DC, StartLoc, IdLoc, Id, T, TInfo, S) { 1183221345Sdim assert(ParmVarDeclBits.HasInheritedDefaultArg == false); 1184221345Sdim assert(ParmVarDeclBits.IsKNRPromoted == false); 1185221345Sdim assert(ParmVarDeclBits.IsObjCMethodParam == false); 1186198092Srdivacky setDefaultArg(DefArg); 1187198092Srdivacky } 1188193326Sed 1189193326Sedpublic: 1190193326Sed static ParmVarDecl *Create(ASTContext &C, DeclContext *DC, 1191221345Sdim SourceLocation StartLoc, 1192221345Sdim SourceLocation IdLoc, IdentifierInfo *Id, 1193200583Srdivacky QualType T, TypeSourceInfo *TInfo, 1194249423Sdim StorageClass S, Expr *DefArg); 1195198092Srdivacky 1196234353Sdim static ParmVarDecl *CreateDeserialized(ASTContext &C, unsigned ID); 1197226633Sdim 1198234353Sdim virtual SourceRange getSourceRange() const LLVM_READONLY; 1199234353Sdim 1200221345Sdim void setObjCMethodScopeInfo(unsigned parameterIndex) { 1201221345Sdim ParmVarDeclBits.IsObjCMethodParam = true; 1202226633Sdim setParameterIndex(parameterIndex); 1203221345Sdim } 1204221345Sdim 1205221345Sdim void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex) { 1206221345Sdim assert(!ParmVarDeclBits.IsObjCMethodParam); 1207221345Sdim 1208221345Sdim ParmVarDeclBits.ScopeDepthOrObjCQuals = scopeDepth; 1209234353Sdim assert(ParmVarDeclBits.ScopeDepthOrObjCQuals == scopeDepth 1210234353Sdim && "truncation!"); 1211221345Sdim 1212226633Sdim setParameterIndex(parameterIndex); 1213221345Sdim } 1214221345Sdim 1215221345Sdim bool isObjCMethodParameter() const { 1216221345Sdim return ParmVarDeclBits.IsObjCMethodParam; 1217221345Sdim } 1218221345Sdim 1219221345Sdim unsigned getFunctionScopeDepth() const { 1220221345Sdim if (ParmVarDeclBits.IsObjCMethodParam) return 0; 1221221345Sdim return ParmVarDeclBits.ScopeDepthOrObjCQuals; 1222221345Sdim } 1223221345Sdim 1224221345Sdim /// Returns the index of this parameter in its prototype or method scope. 1225221345Sdim unsigned getFunctionScopeIndex() const { 1226226633Sdim return getParameterIndex(); 1227221345Sdim } 1228221345Sdim 1229193326Sed ObjCDeclQualifier getObjCDeclQualifier() const { 1230221345Sdim if (!ParmVarDeclBits.IsObjCMethodParam) return OBJC_TQ_None; 1231221345Sdim return ObjCDeclQualifier(ParmVarDeclBits.ScopeDepthOrObjCQuals); 1232193326Sed } 1233193326Sed void setObjCDeclQualifier(ObjCDeclQualifier QTVal) { 1234221345Sdim assert(ParmVarDeclBits.IsObjCMethodParam); 1235221345Sdim ParmVarDeclBits.ScopeDepthOrObjCQuals = QTVal; 1236193326Sed } 1237198092Srdivacky 1238221345Sdim /// True if the value passed to this parameter must undergo 1239221345Sdim /// K&R-style default argument promotion: 1240221345Sdim /// 1241221345Sdim /// C99 6.5.2.2. 1242221345Sdim /// If the expression that denotes the called function has a type 1243221345Sdim /// that does not include a prototype, the integer promotions are 1244221345Sdim /// performed on each argument, and arguments that have type float 1245221345Sdim /// are promoted to double. 1246221345Sdim bool isKNRPromoted() const { 1247221345Sdim return ParmVarDeclBits.IsKNRPromoted; 1248221345Sdim } 1249221345Sdim void setKNRPromoted(bool promoted) { 1250221345Sdim ParmVarDeclBits.IsKNRPromoted = promoted; 1251221345Sdim } 1252221345Sdim 1253201361Srdivacky Expr *getDefaultArg(); 1254198092Srdivacky const Expr *getDefaultArg() const { 1255201361Srdivacky return const_cast<ParmVarDecl *>(this)->getDefaultArg(); 1256193576Sed } 1257234353Sdim 1258198092Srdivacky void setDefaultArg(Expr *defarg) { 1259198092Srdivacky Init = reinterpret_cast<Stmt *>(defarg); 1260198092Srdivacky } 1261193326Sed 1262198092Srdivacky /// \brief Retrieve the source range that covers the entire default 1263198092Srdivacky /// argument. 1264234353Sdim SourceRange getDefaultArgRange() const; 1265198092Srdivacky void setUninstantiatedDefaultArg(Expr *arg) { 1266198092Srdivacky Init = reinterpret_cast<UninstantiatedDefaultArgument *>(arg); 1267198092Srdivacky } 1268198092Srdivacky Expr *getUninstantiatedDefaultArg() { 1269198092Srdivacky return (Expr *)Init.get<UninstantiatedDefaultArgument *>(); 1270198092Srdivacky } 1271198092Srdivacky const Expr *getUninstantiatedDefaultArg() const { 1272198092Srdivacky return (const Expr *)Init.get<UninstantiatedDefaultArgument *>(); 1273198092Srdivacky } 1274198092Srdivacky 1275193576Sed /// hasDefaultArg - Determines whether this parameter has a default argument, 1276193576Sed /// either parsed or not. 1277193576Sed bool hasDefaultArg() const { 1278198092Srdivacky return getInit() || hasUnparsedDefaultArg() || 1279198092Srdivacky hasUninstantiatedDefaultArg(); 1280193576Sed } 1281198092Srdivacky 1282193326Sed /// hasUnparsedDefaultArg - Determines whether this parameter has a 1283193326Sed /// default argument that has not yet been parsed. This will occur 1284193326Sed /// during the processing of a C++ class whose member functions have 1285193326Sed /// default arguments, e.g., 1286193326Sed /// @code 1287193326Sed /// class X { 1288193326Sed /// public: 1289193326Sed /// void f(int x = 17); // x has an unparsed default argument now 1290193326Sed /// }; // x has a regular default argument now 1291193326Sed /// @endcode 1292193326Sed bool hasUnparsedDefaultArg() const { 1293198092Srdivacky return Init.is<UnparsedDefaultArgument*>(); 1294193326Sed } 1295193326Sed 1296198092Srdivacky bool hasUninstantiatedDefaultArg() const { 1297198092Srdivacky return Init.is<UninstantiatedDefaultArgument*>(); 1298198092Srdivacky } 1299198092Srdivacky 1300193326Sed /// setUnparsedDefaultArg - Specify that this parameter has an 1301193326Sed /// unparsed default argument. The argument will be replaced with a 1302193326Sed /// real default argument via setDefaultArg when the class 1303193326Sed /// definition enclosing the function declaration that owns this 1304193326Sed /// default argument is completed. 1305198092Srdivacky void setUnparsedDefaultArg() { 1306198092Srdivacky Init = (UnparsedDefaultArgument *)0; 1307198092Srdivacky } 1308193326Sed 1309205219Srdivacky bool hasInheritedDefaultArg() const { 1310221345Sdim return ParmVarDeclBits.HasInheritedDefaultArg; 1311205219Srdivacky } 1312205219Srdivacky 1313205219Srdivacky void setHasInheritedDefaultArg(bool I = true) { 1314221345Sdim ParmVarDeclBits.HasInheritedDefaultArg = I; 1315205219Srdivacky } 1316205219Srdivacky 1317198893Srdivacky QualType getOriginalType() const { 1318200583Srdivacky if (getTypeSourceInfo()) 1319200583Srdivacky return getTypeSourceInfo()->getType(); 1320198893Srdivacky return getType(); 1321198893Srdivacky } 1322198092Srdivacky 1323218893Sdim /// \brief Determine whether this parameter is actually a function 1324218893Sdim /// parameter pack. 1325218893Sdim bool isParameterPack() const; 1326234353Sdim 1327193326Sed /// setOwningFunction - Sets the function declaration that owns this 1328193326Sed /// ParmVarDecl. Since ParmVarDecls are often created before the 1329193326Sed /// FunctionDecls that own them, this routine is required to update 1330193326Sed /// the DeclContext appropriately. 1331193326Sed void setOwningFunction(DeclContext *FD) { setDeclContext(FD); } 1332193326Sed 1333193326Sed // Implement isa/cast/dyncast/etc. 1334203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1335203955Srdivacky static bool classofKind(Kind K) { return K == ParmVar; } 1336234353Sdim 1337226633Sdimprivate: 1338226633Sdim enum { ParameterIndexSentinel = (1 << NumParameterIndexBits) - 1 }; 1339226633Sdim 1340226633Sdim void setParameterIndex(unsigned parameterIndex) { 1341226633Sdim if (parameterIndex >= ParameterIndexSentinel) { 1342226633Sdim setParameterIndexLarge(parameterIndex); 1343226633Sdim return; 1344226633Sdim } 1345234353Sdim 1346226633Sdim ParmVarDeclBits.ParameterIndex = parameterIndex; 1347226633Sdim assert(ParmVarDeclBits.ParameterIndex == parameterIndex && "truncation!"); 1348226633Sdim } 1349226633Sdim unsigned getParameterIndex() const { 1350226633Sdim unsigned d = ParmVarDeclBits.ParameterIndex; 1351226633Sdim return d == ParameterIndexSentinel ? getParameterIndexLarge() : d; 1352226633Sdim } 1353234353Sdim 1354226633Sdim void setParameterIndexLarge(unsigned parameterIndex); 1355226633Sdim unsigned getParameterIndexLarge() const; 1356193326Sed}; 1357193326Sed 1358193326Sed/// FunctionDecl - An instance of this class is created to represent a 1359198092Srdivacky/// function declaration or definition. 1360193326Sed/// 1361193326Sed/// Since a given function can be declared several times in a program, 1362193326Sed/// there may be several FunctionDecls that correspond to that 1363193326Sed/// function. Only one of those FunctionDecls will be found when 1364193326Sed/// traversing the list of declarations in the context of the 1365193326Sed/// FunctionDecl (e.g., the translation unit); this FunctionDecl 1366193326Sed/// contains all of the information known about the function. Other, 1367193326Sed/// previous declarations of the function are available via the 1368234353Sdim/// getPreviousDecl() chain. 1369198092Srdivackyclass FunctionDecl : public DeclaratorDecl, public DeclContext, 1370198092Srdivacky public Redeclarable<FunctionDecl> { 1371193326Sedpublic: 1372212904Sdim typedef clang::StorageClass StorageClass; 1373198092Srdivacky 1374210299Sed /// \brief The kind of templated function a FunctionDecl can be. 1375210299Sed enum TemplatedKind { 1376210299Sed TK_NonTemplate, 1377210299Sed TK_FunctionTemplate, 1378210299Sed TK_MemberSpecialization, 1379210299Sed TK_FunctionTemplateSpecialization, 1380210299Sed TK_DependentFunctionTemplateSpecialization 1381210299Sed }; 1382210299Sed 1383198092Srdivackyprivate: 1384193326Sed /// ParamInfo - new[]'d array of pointers to VarDecls for the formal 1385193326Sed /// parameters of this function. This is null if a prototype or if there are 1386195099Sed /// no formals. 1387193326Sed ParmVarDecl **ParamInfo; 1388198092Srdivacky 1389234353Sdim /// DeclsInPrototypeScope - Array of pointers to NamedDecls for 1390234353Sdim /// decls defined in the function prototype that are not parameters. E.g. 1391234353Sdim /// 'enum Y' in 'void f(enum Y {AA} x) {}'. 1392249423Sdim ArrayRef<NamedDecl *> DeclsInPrototypeScope; 1393234353Sdim 1394193326Sed LazyDeclStmtPtr Body; 1395193326Sed 1396193326Sed // FIXME: This can be packed into the bitfields in Decl. 1397193326Sed // NOTE: VC++ treats enums as signed, avoid using the StorageClass enum 1398193326Sed unsigned SClass : 2; 1399193326Sed bool IsInline : 1; 1400218893Sdim bool IsInlineSpecified : 1; 1401193326Sed bool IsVirtualAsWritten : 1; 1402193326Sed bool IsPure : 1; 1403193326Sed bool HasInheritedPrototype : 1; 1404193326Sed bool HasWrittenPrototype : 1; 1405193326Sed bool IsDeleted : 1; 1406198092Srdivacky bool IsTrivial : 1; // sunk from CXXMethodDecl 1407223017Sdim bool IsDefaulted : 1; // sunk from CXXMethoDecl 1408223017Sdim bool IsExplicitlyDefaulted : 1; //sunk from CXXMethodDecl 1409198092Srdivacky bool HasImplicitReturnZero : 1; 1410221345Sdim bool IsLateTemplateParsed : 1; 1411226633Sdim bool IsConstexpr : 1; 1412193326Sed 1413249423Sdim /// \brief Indicates if the function was a definition but its body was 1414249423Sdim /// skipped. 1415249423Sdim unsigned HasSkippedBody : 1; 1416249423Sdim 1417194711Sed /// \brief End part of this FunctionDecl's source range. 1418194711Sed /// 1419194711Sed /// We could compute the full range in getSourceRange(). However, when we're 1420194711Sed /// dealing with a function definition deserialized from a PCH/AST file, 1421194711Sed /// we can only compute the full range once the function body has been 1422194711Sed /// de-serialized, so it's far better to have the (sometimes-redundant) 1423194711Sed /// EndRangeLoc. 1424194613Sed SourceLocation EndRangeLoc; 1425193326Sed 1426193326Sed /// \brief The template or declaration that this declaration 1427193326Sed /// describes or was instantiated from, respectively. 1428198092Srdivacky /// 1429193326Sed /// For non-templates, this value will be NULL. For function 1430193326Sed /// declarations that describe a function template, this will be a 1431193326Sed /// pointer to a FunctionTemplateDecl. For member functions 1432198092Srdivacky /// of class template specializations, this will be a MemberSpecializationInfo 1433198092Srdivacky /// pointer containing information about the specialization. 1434198092Srdivacky /// For function template specializations, this will be a 1435195099Sed /// FunctionTemplateSpecializationInfo, which contains information about 1436198092Srdivacky /// the template being specialized and the template arguments involved in 1437195099Sed /// that specialization. 1438234353Sdim llvm::PointerUnion4<FunctionTemplateDecl *, 1439198092Srdivacky MemberSpecializationInfo *, 1440207619Srdivacky FunctionTemplateSpecializationInfo *, 1441207619Srdivacky DependentFunctionTemplateSpecializationInfo *> 1442195341Sed TemplateOrSpecialization; 1443193326Sed 1444212904Sdim /// DNLoc - Provides source/type location info for the 1445212904Sdim /// declaration name embedded in the DeclaratorDecl base class. 1446212904Sdim DeclarationNameLoc DNLoc; 1447212904Sdim 1448218893Sdim /// \brief Specify that this function declaration is actually a function 1449218893Sdim /// template specialization. 1450218893Sdim /// 1451218893Sdim /// \param C the ASTContext. 1452218893Sdim /// 1453218893Sdim /// \param Template the function template that this function template 1454218893Sdim /// specialization specializes. 1455218893Sdim /// 1456218893Sdim /// \param TemplateArgs the template arguments that produced this 1457218893Sdim /// function template specialization from the template. 1458218893Sdim /// 1459218893Sdim /// \param InsertPos If non-NULL, the position in the function template 1460218893Sdim /// specialization set where the function template specialization data will 1461218893Sdim /// be inserted. 1462218893Sdim /// 1463218893Sdim /// \param TSK the kind of template specialization this is. 1464218893Sdim /// 1465218893Sdim /// \param TemplateArgsAsWritten location info of template arguments. 1466218893Sdim /// 1467218893Sdim /// \param PointOfInstantiation point at which the function template 1468234353Sdim /// specialization was first instantiated. 1469218893Sdim void setFunctionTemplateSpecialization(ASTContext &C, 1470218893Sdim FunctionTemplateDecl *Template, 1471218893Sdim const TemplateArgumentList *TemplateArgs, 1472218893Sdim void *InsertPos, 1473218893Sdim TemplateSpecializationKind TSK, 1474218893Sdim const TemplateArgumentListInfo *TemplateArgsAsWritten, 1475218893Sdim SourceLocation PointOfInstantiation); 1476218893Sdim 1477218893Sdim /// \brief Specify that this record is an instantiation of the 1478218893Sdim /// member function FD. 1479218893Sdim void setInstantiationOfMemberFunction(ASTContext &C, FunctionDecl *FD, 1480218893Sdim TemplateSpecializationKind TSK); 1481218893Sdim 1482249423Sdim void setParams(ASTContext &C, ArrayRef<ParmVarDecl *> NewParamInfo); 1483218893Sdim 1484193326Sedprotected: 1485221345Sdim FunctionDecl(Kind DK, DeclContext *DC, SourceLocation StartLoc, 1486221345Sdim const DeclarationNameInfo &NameInfo, 1487212904Sdim QualType T, TypeSourceInfo *TInfo, 1488249423Sdim StorageClass S, bool isInlineSpecified, 1489226633Sdim bool isConstexprSpecified) 1490221345Sdim : DeclaratorDecl(DK, DC, NameInfo.getLoc(), NameInfo.getName(), T, TInfo, 1491221345Sdim StartLoc), 1492193326Sed DeclContext(DK), 1493198092Srdivacky ParamInfo(0), Body(), 1494249423Sdim SClass(S), 1495218893Sdim IsInline(isInlineSpecified), IsInlineSpecified(isInlineSpecified), 1496198092Srdivacky IsVirtualAsWritten(false), IsPure(false), HasInheritedPrototype(false), 1497198092Srdivacky HasWrittenPrototype(true), IsDeleted(false), IsTrivial(false), 1498223017Sdim IsDefaulted(false), IsExplicitlyDefaulted(false), 1499221345Sdim HasImplicitReturnZero(false), IsLateTemplateParsed(false), 1500249423Sdim IsConstexpr(isConstexprSpecified), HasSkippedBody(false), 1501249423Sdim EndRangeLoc(NameInfo.getEndLoc()), 1502212904Sdim TemplateOrSpecialization(), 1503212904Sdim DNLoc(NameInfo.getInfo()) {} 1504193326Sed 1505198092Srdivacky typedef Redeclarable<FunctionDecl> redeclarable_base; 1506198092Srdivacky virtual FunctionDecl *getNextRedeclaration() { return RedeclLink.getNext(); } 1507234353Sdim virtual FunctionDecl *getPreviousDeclImpl() { 1508234353Sdim return getPreviousDecl(); 1509234353Sdim } 1510234353Sdim virtual FunctionDecl *getMostRecentDeclImpl() { 1511234353Sdim return getMostRecentDecl(); 1512234353Sdim } 1513198092Srdivacky 1514193326Sedpublic: 1515198092Srdivacky typedef redeclarable_base::redecl_iterator redecl_iterator; 1516234353Sdim using redeclarable_base::redecls_begin; 1517234353Sdim using redeclarable_base::redecls_end; 1518234353Sdim using redeclarable_base::getPreviousDecl; 1519234353Sdim using redeclarable_base::getMostRecentDecl; 1520198092Srdivacky 1521221345Sdim static FunctionDecl *Create(ASTContext &C, DeclContext *DC, 1522221345Sdim SourceLocation StartLoc, SourceLocation NLoc, 1523198092Srdivacky DeclarationName N, QualType T, 1524200583Srdivacky TypeSourceInfo *TInfo, 1525249423Sdim StorageClass SC, 1526218893Sdim bool isInlineSpecified = false, 1527226633Sdim bool hasWrittenPrototype = true, 1528226633Sdim bool isConstexprSpecified = false) { 1529221345Sdim DeclarationNameInfo NameInfo(N, NLoc); 1530221345Sdim return FunctionDecl::Create(C, DC, StartLoc, NameInfo, T, TInfo, 1531249423Sdim SC, 1532226633Sdim isInlineSpecified, hasWrittenPrototype, 1533226633Sdim isConstexprSpecified); 1534212904Sdim } 1535212904Sdim 1536212904Sdim static FunctionDecl *Create(ASTContext &C, DeclContext *DC, 1537221345Sdim SourceLocation StartLoc, 1538212904Sdim const DeclarationNameInfo &NameInfo, 1539212904Sdim QualType T, TypeSourceInfo *TInfo, 1540249423Sdim StorageClass SC, 1541249423Sdim bool isInlineSpecified, 1542249423Sdim bool hasWrittenPrototype, 1543226633Sdim bool isConstexprSpecified = false); 1544194613Sed 1545234353Sdim static FunctionDecl *CreateDeserialized(ASTContext &C, unsigned ID); 1546234353Sdim 1547212904Sdim DeclarationNameInfo getNameInfo() const { 1548212904Sdim return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc); 1549212904Sdim } 1550212904Sdim 1551249423Sdim virtual void getNameForDiagnostic(raw_ostream &OS, 1552198092Srdivacky const PrintingPolicy &Policy, 1553198092Srdivacky bool Qualified) const; 1554198092Srdivacky 1555221345Sdim void setRangeEnd(SourceLocation E) { EndRangeLoc = E; } 1556193326Sed 1557234353Sdim virtual SourceRange getSourceRange() const LLVM_READONLY; 1558221345Sdim 1559210299Sed /// \brief Returns true if the function has a body (definition). The 1560210299Sed /// function body might be in any of the (re-)declarations of this 1561210299Sed /// function. The variant that accepts a FunctionDecl pointer will 1562210299Sed /// set that function declaration to the actual declaration 1563210299Sed /// containing the body (if there is one). 1564210299Sed bool hasBody(const FunctionDecl *&Definition) const; 1565210299Sed 1566210299Sed virtual bool hasBody() const { 1567210299Sed const FunctionDecl* Definition; 1568210299Sed return hasBody(Definition); 1569210299Sed } 1570210299Sed 1571223017Sdim /// hasTrivialBody - Returns whether the function has a trivial body that does 1572223017Sdim /// not require any specific codegen. 1573223017Sdim bool hasTrivialBody() const; 1574223017Sdim 1575223017Sdim /// isDefined - Returns true if the function is defined at all, including 1576223017Sdim /// a deleted definition. Except for the behavior when the function is 1577223017Sdim /// deleted, behaves like hasBody. 1578223017Sdim bool isDefined(const FunctionDecl *&Definition) const; 1579223017Sdim 1580223017Sdim virtual bool isDefined() const { 1581223017Sdim const FunctionDecl* Definition; 1582223017Sdim return isDefined(Definition); 1583223017Sdim } 1584223017Sdim 1585193326Sed /// getBody - Retrieve the body (definition) of the function. The 1586193326Sed /// function body might be in any of the (re-)declarations of this 1587193326Sed /// function. The variant that accepts a FunctionDecl pointer will 1588193326Sed /// set that function declaration to the actual declaration 1589193326Sed /// containing the body (if there is one). 1590210299Sed /// NOTE: For checking if there is a body, use hasBody() instead, to avoid 1591212904Sdim /// unnecessary AST de-serialization of the body. 1592195341Sed Stmt *getBody(const FunctionDecl *&Definition) const; 1593193326Sed 1594195341Sed virtual Stmt *getBody() const { 1595193326Sed const FunctionDecl* Definition; 1596195341Sed return getBody(Definition); 1597193326Sed } 1598193326Sed 1599193326Sed /// isThisDeclarationADefinition - Returns whether this specific 1600193326Sed /// declaration of the function is also a definition. This does not 1601193326Sed /// determine whether the function has been defined (e.g., in a 1602223017Sdim /// previous definition); for that information, use isDefined. Note 1603223017Sdim /// that this returns false for a defaulted function unless that function 1604223017Sdim /// has been implicitly defined (possibly as deleted). 1605221345Sdim bool isThisDeclarationADefinition() const { 1606223017Sdim return IsDeleted || Body || IsLateTemplateParsed; 1607223017Sdim } 1608223017Sdim 1609223017Sdim /// doesThisDeclarationHaveABody - Returns whether this specific 1610223017Sdim /// declaration of the function has a body - that is, if it is a non- 1611223017Sdim /// deleted definition. 1612223017Sdim bool doesThisDeclarationHaveABody() const { 1613221345Sdim return Body || IsLateTemplateParsed; 1614221345Sdim } 1615193326Sed 1616194613Sed void setBody(Stmt *B); 1617193326Sed void setLazyBody(uint64_t Offset) { Body = Offset; } 1618193326Sed 1619207619Srdivacky /// Whether this function is variadic. 1620207619Srdivacky bool isVariadic() const; 1621207619Srdivacky 1622193326Sed /// Whether this function is marked as virtual explicitly. 1623193326Sed bool isVirtualAsWritten() const { return IsVirtualAsWritten; } 1624193326Sed void setVirtualAsWritten(bool V) { IsVirtualAsWritten = V; } 1625193326Sed 1626193326Sed /// Whether this virtual function is pure, i.e. makes the containing class 1627193326Sed /// abstract. 1628193326Sed bool isPure() const { return IsPure; } 1629218893Sdim void setPure(bool P = true); 1630193326Sed 1631221345Sdim /// Whether this templated function will be late parsed. 1632221345Sdim bool isLateTemplateParsed() const { return IsLateTemplateParsed; } 1633221345Sdim void setLateTemplateParsed(bool ILT = true) { IsLateTemplateParsed = ILT; } 1634221345Sdim 1635198092Srdivacky /// Whether this function is "trivial" in some specialized C++ senses. 1636198092Srdivacky /// Can only be true for default constructors, copy constructors, 1637198092Srdivacky /// copy assignment operators, and destructors. Not meaningful until 1638198092Srdivacky /// the class has been fully built by Sema. 1639198092Srdivacky bool isTrivial() const { return IsTrivial; } 1640198092Srdivacky void setTrivial(bool IT) { IsTrivial = IT; } 1641198092Srdivacky 1642223017Sdim /// Whether this function is defaulted per C++0x. Only valid for 1643234353Sdim /// special member functions. 1644223017Sdim bool isDefaulted() const { return IsDefaulted; } 1645223017Sdim void setDefaulted(bool D = true) { IsDefaulted = D; } 1646223017Sdim 1647223017Sdim /// Whether this function is explicitly defaulted per C++0x. Only valid 1648223017Sdim /// for special member functions. 1649223017Sdim bool isExplicitlyDefaulted() const { return IsExplicitlyDefaulted; } 1650223017Sdim void setExplicitlyDefaulted(bool ED = true) { IsExplicitlyDefaulted = ED; } 1651223017Sdim 1652198092Srdivacky /// Whether falling off this function implicitly returns null/zero. 1653198092Srdivacky /// If a more specific implicit return value is required, front-ends 1654198092Srdivacky /// should synthesize the appropriate return statements. 1655198092Srdivacky bool hasImplicitReturnZero() const { return HasImplicitReturnZero; } 1656198092Srdivacky void setHasImplicitReturnZero(bool IRZ) { HasImplicitReturnZero = IRZ; } 1657198092Srdivacky 1658193326Sed /// \brief Whether this function has a prototype, either because one 1659193326Sed /// was explicitly written or because it was "inherited" by merging 1660193326Sed /// a declaration without a prototype with a declaration that has a 1661193326Sed /// prototype. 1662198092Srdivacky bool hasPrototype() const { 1663198092Srdivacky return HasWrittenPrototype || HasInheritedPrototype; 1664193326Sed } 1665198092Srdivacky 1666193326Sed bool hasWrittenPrototype() const { return HasWrittenPrototype; } 1667193326Sed 1668193326Sed /// \brief Whether this function inherited its prototype from a 1669193326Sed /// previous declaration. 1670193326Sed bool hasInheritedPrototype() const { return HasInheritedPrototype; } 1671193326Sed void setHasInheritedPrototype(bool P = true) { HasInheritedPrototype = P; } 1672193326Sed 1673239462Sdim /// Whether this is a (C++11) constexpr function or constexpr constructor. 1674226633Sdim bool isConstexpr() const { return IsConstexpr; } 1675249423Sdim void setConstexpr(bool IC) { IsConstexpr = IC; } 1676226633Sdim 1677193326Sed /// \brief Whether this function has been deleted. 1678193326Sed /// 1679193326Sed /// A function that is "deleted" (via the C++0x "= delete" syntax) 1680193326Sed /// acts like a normal function, except that it cannot actually be 1681193326Sed /// called or have its address taken. Deleted functions are 1682193326Sed /// typically used in C++ overload resolution to attract arguments 1683193326Sed /// whose type or lvalue/rvalue-ness would permit the use of a 1684193326Sed /// different overload that would behave incorrectly. For example, 1685193326Sed /// one might use deleted functions to ban implicit conversion from 1686193326Sed /// a floating-point number to an Integer type: 1687193326Sed /// 1688193326Sed /// @code 1689193326Sed /// struct Integer { 1690193326Sed /// Integer(long); // construct from a long 1691193326Sed /// Integer(double) = delete; // no construction from float or double 1692193326Sed /// Integer(long double) = delete; // no construction from long double 1693193326Sed /// }; 1694193326Sed /// @endcode 1695223017Sdim // If a function is deleted, its first declaration must be. 1696223017Sdim bool isDeleted() const { return getCanonicalDecl()->IsDeleted; } 1697223017Sdim bool isDeletedAsWritten() const { return IsDeleted && !IsDefaulted; } 1698223017Sdim void setDeletedAsWritten(bool D = true) { IsDeleted = D; } 1699193326Sed 1700223017Sdim /// \brief Determines whether this function is "main", which is the 1701223017Sdim /// entry point into an executable program. 1702193326Sed bool isMain() const; 1703193326Sed 1704223017Sdim /// \brief Determines whether this operator new or delete is one 1705223017Sdim /// of the reserved global placement operators: 1706223017Sdim /// void *operator new(size_t, void *); 1707223017Sdim /// void *operator new[](size_t, void *); 1708223017Sdim /// void operator delete(void *, void *); 1709223017Sdim /// void operator delete[](void *, void *); 1710223017Sdim /// These functions have special behavior under [new.delete.placement]: 1711223017Sdim /// These functions are reserved, a C++ program may not define 1712223017Sdim /// functions that displace the versions in the Standard C++ library. 1713223017Sdim /// The provisions of [basic.stc.dynamic] do not apply to these 1714223017Sdim /// reserved placement forms of operator new and operator delete. 1715223017Sdim /// 1716223017Sdim /// This function must be an allocation or deallocation function. 1717223017Sdim bool isReservedGlobalPlacementOperator() const; 1718223017Sdim 1719249423Sdim /// Compute the language linkage. 1720249423Sdim LanguageLinkage getLanguageLinkage() const; 1721249423Sdim 1722193326Sed /// \brief Determines whether this function is a function with 1723193326Sed /// external, C linkage. 1724198092Srdivacky bool isExternC() const; 1725193326Sed 1726251662Sdim /// \brief Determines whether this function's context is, or is nested within, 1727251662Sdim /// a C++ extern "C" linkage spec. 1728251662Sdim bool isInExternCContext() const; 1729251662Sdim 1730251662Sdim /// \brief Determines whether this function's context is, or is nested within, 1731251662Sdim /// a C++ extern "C++" linkage spec. 1732251662Sdim bool isInExternCXXContext() const; 1733251662Sdim 1734193326Sed /// \brief Determines whether this is a global function. 1735193326Sed bool isGlobal() const; 1736193326Sed 1737249423Sdim /// \brief Determines whether this function is known to be 'noreturn', through 1738249423Sdim /// an attribute on its declaration or its type. 1739249423Sdim bool isNoReturn() const; 1740249423Sdim 1741249423Sdim /// \brief True if the function was a definition but its body was skipped. 1742249423Sdim bool hasSkippedBody() const { return HasSkippedBody; } 1743249423Sdim void setHasSkippedBody(bool Skipped = true) { HasSkippedBody = Skipped; } 1744249423Sdim 1745195341Sed void setPreviousDeclaration(FunctionDecl * PrevDecl); 1746193326Sed 1747198092Srdivacky virtual const FunctionDecl *getCanonicalDecl() const; 1748198092Srdivacky virtual FunctionDecl *getCanonicalDecl(); 1749193326Sed 1750198092Srdivacky unsigned getBuiltinID() const; 1751198092Srdivacky 1752193326Sed // Iterator access to formal parameters. 1753193326Sed unsigned param_size() const { return getNumParams(); } 1754193326Sed typedef ParmVarDecl **param_iterator; 1755193326Sed typedef ParmVarDecl * const *param_const_iterator; 1756198092Srdivacky 1757193326Sed param_iterator param_begin() { return ParamInfo; } 1758193326Sed param_iterator param_end() { return ParamInfo+param_size(); } 1759198092Srdivacky 1760193326Sed param_const_iterator param_begin() const { return ParamInfo; } 1761193326Sed param_const_iterator param_end() const { return ParamInfo+param_size(); } 1762198092Srdivacky 1763193326Sed /// getNumParams - Return the number of parameters this function must have 1764203955Srdivacky /// based on its FunctionType. This is the length of the ParamInfo array 1765193326Sed /// after it has been created. 1766193326Sed unsigned getNumParams() const; 1767198092Srdivacky 1768193326Sed const ParmVarDecl *getParamDecl(unsigned i) const { 1769193326Sed assert(i < getNumParams() && "Illegal param #"); 1770193326Sed return ParamInfo[i]; 1771193326Sed } 1772193326Sed ParmVarDecl *getParamDecl(unsigned i) { 1773193326Sed assert(i < getNumParams() && "Illegal param #"); 1774193326Sed return ParamInfo[i]; 1775193326Sed } 1776249423Sdim void setParams(ArrayRef<ParmVarDecl *> NewParamInfo) { 1777226633Sdim setParams(getASTContext(), NewParamInfo); 1778218893Sdim } 1779193326Sed 1780249423Sdim const ArrayRef<NamedDecl *> &getDeclsInPrototypeScope() const { 1781234353Sdim return DeclsInPrototypeScope; 1782234353Sdim } 1783249423Sdim void setDeclsInPrototypeScope(ArrayRef<NamedDecl *> NewDecls); 1784234353Sdim 1785193326Sed /// getMinRequiredArguments - Returns the minimum number of arguments 1786193326Sed /// needed to call this function. This may be fewer than the number of 1787193326Sed /// function parameters, if some of the parameters have default 1788193326Sed /// arguments (in C++). 1789193326Sed unsigned getMinRequiredArguments() const; 1790193326Sed 1791198092Srdivacky QualType getResultType() const { 1792198092Srdivacky return getType()->getAs<FunctionType>()->getResultType(); 1793193326Sed } 1794234353Sdim 1795210299Sed /// \brief Determine the type of an expression that calls this function. 1796210299Sed QualType getCallResultType() const { 1797210299Sed return getType()->getAs<FunctionType>()->getCallResultType(getASTContext()); 1798210299Sed } 1799234353Sdim 1800249423Sdim /// \brief Returns the storage class as written in the source. For the 1801249423Sdim /// computed linkage of symbol, see getLinkage. 1802193326Sed StorageClass getStorageClass() const { return StorageClass(SClass); } 1803193326Sed 1804198893Srdivacky /// \brief Determine whether the "inline" keyword was specified for this 1805198893Srdivacky /// function. 1806218893Sdim bool isInlineSpecified() const { return IsInlineSpecified; } 1807234353Sdim 1808198893Srdivacky /// Set whether the "inline" keyword was specified for this function. 1809234353Sdim void setInlineSpecified(bool I) { 1810234353Sdim IsInlineSpecified = I; 1811218893Sdim IsInline = I; 1812218893Sdim } 1813193326Sed 1814218893Sdim /// Flag that this function is implicitly inline. 1815218893Sdim void setImplicitlyInline() { 1816218893Sdim IsInline = true; 1817218893Sdim } 1818218893Sdim 1819198893Srdivacky /// \brief Determine whether this function should be inlined, because it is 1820226633Sdim /// either marked "inline" or "constexpr" or is a member function of a class 1821226633Sdim /// that was defined in the class body. 1822249423Sdim bool isInlined() const { return IsInline; } 1823218893Sdim 1824198092Srdivacky bool isInlineDefinitionExternallyVisible() const; 1825226633Sdim 1826226633Sdim bool doesDeclarationForceExternallyVisibleDefinition() const; 1827234353Sdim 1828193326Sed /// isOverloadedOperator - Whether this function declaration 1829193326Sed /// represents an C++ overloaded operator, e.g., "operator+". 1830198092Srdivacky bool isOverloadedOperator() const { 1831193326Sed return getOverloadedOperator() != OO_None; 1832201361Srdivacky } 1833193326Sed 1834193326Sed OverloadedOperatorKind getOverloadedOperator() const; 1835193326Sed 1836202379Srdivacky const IdentifierInfo *getLiteralIdentifier() const; 1837202379Srdivacky 1838193326Sed /// \brief If this function is an instantiation of a member function 1839193326Sed /// of a class template specialization, retrieves the function from 1840193326Sed /// which it was instantiated. 1841193326Sed /// 1842193326Sed /// This routine will return non-NULL for (non-templated) member 1843193326Sed /// functions of class templates and for instantiations of function 1844193326Sed /// templates. For example, given: 1845193326Sed /// 1846193326Sed /// \code 1847193326Sed /// template<typename T> 1848193326Sed /// struct X { 1849193326Sed /// void f(T); 1850193326Sed /// }; 1851193326Sed /// \endcode 1852193326Sed /// 1853193326Sed /// The declaration for X<int>::f is a (non-templated) FunctionDecl 1854193326Sed /// whose parent is the class template specialization X<int>. For 1855193326Sed /// this declaration, getInstantiatedFromFunction() will return 1856193326Sed /// the FunctionDecl X<T>::A. When a complete definition of 1857193326Sed /// X<int>::A is required, it will be instantiated from the 1858193326Sed /// declaration returned by getInstantiatedFromMemberFunction(). 1859198092Srdivacky FunctionDecl *getInstantiatedFromMemberFunction() const; 1860234353Sdim 1861210299Sed /// \brief What kind of templated function this is. 1862210299Sed TemplatedKind getTemplatedKind() const; 1863193326Sed 1864198092Srdivacky /// \brief If this function is an instantiation of a member function of a 1865198092Srdivacky /// class template specialization, retrieves the member specialization 1866198092Srdivacky /// information. 1867249423Sdim MemberSpecializationInfo *getMemberSpecializationInfo() const { 1868249423Sdim return TemplateOrSpecialization.dyn_cast<MemberSpecializationInfo*>(); 1869249423Sdim } 1870234353Sdim 1871193326Sed /// \brief Specify that this record is an instantiation of the 1872198092Srdivacky /// member function FD. 1873198092Srdivacky void setInstantiationOfMemberFunction(FunctionDecl *FD, 1874218893Sdim TemplateSpecializationKind TSK) { 1875218893Sdim setInstantiationOfMemberFunction(getASTContext(), FD, TSK); 1876218893Sdim } 1877193326Sed 1878193326Sed /// \brief Retrieves the function template that is described by this 1879193326Sed /// function declaration. 1880193326Sed /// 1881193326Sed /// Every function template is represented as a FunctionTemplateDecl 1882193326Sed /// and a FunctionDecl (or something derived from FunctionDecl). The 1883193326Sed /// former contains template properties (such as the template 1884193326Sed /// parameter lists) while the latter contains the actual 1885193326Sed /// description of the template's 1886193326Sed /// contents. FunctionTemplateDecl::getTemplatedDecl() retrieves the 1887193326Sed /// FunctionDecl that describes the function template, 1888193326Sed /// getDescribedFunctionTemplate() retrieves the 1889193326Sed /// FunctionTemplateDecl from a FunctionDecl. 1890193326Sed FunctionTemplateDecl *getDescribedFunctionTemplate() const { 1891195099Sed return TemplateOrSpecialization.dyn_cast<FunctionTemplateDecl*>(); 1892193326Sed } 1893193326Sed 1894193326Sed void setDescribedFunctionTemplate(FunctionTemplateDecl *Template) { 1895195099Sed TemplateOrSpecialization = Template; 1896193326Sed } 1897193326Sed 1898234353Sdim /// \brief Determine whether this function is a function template 1899198092Srdivacky /// specialization. 1900198092Srdivacky bool isFunctionTemplateSpecialization() const { 1901198092Srdivacky return getPrimaryTemplate() != 0; 1902198092Srdivacky } 1903226633Sdim 1904226633Sdim /// \brief Retrieve the class scope template pattern that this function 1905226633Sdim /// template specialization is instantiated from. 1906226633Sdim FunctionDecl *getClassScopeSpecializationPattern() const; 1907226633Sdim 1908198092Srdivacky /// \brief If this function is actually a function template specialization, 1909234353Sdim /// retrieve information about this function template specialization. 1910198092Srdivacky /// Otherwise, returns NULL. 1911198092Srdivacky FunctionTemplateSpecializationInfo *getTemplateSpecializationInfo() const { 1912198092Srdivacky return TemplateOrSpecialization. 1913198092Srdivacky dyn_cast<FunctionTemplateSpecializationInfo*>(); 1914198092Srdivacky } 1915198893Srdivacky 1916198893Srdivacky /// \brief Determines whether this function is a function template 1917198893Srdivacky /// specialization or a member of a class template specialization that can 1918198893Srdivacky /// be implicitly instantiated. 1919198893Srdivacky bool isImplicitlyInstantiable() const; 1920234353Sdim 1921234353Sdim /// \brief Determines if the given function was instantiated from a 1922234353Sdim /// function template. 1923234353Sdim bool isTemplateInstantiation() const; 1924234353Sdim 1925198893Srdivacky /// \brief Retrieve the function declaration from which this function could 1926198893Srdivacky /// be instantiated, if it is an instantiation (rather than a non-template 1927198893Srdivacky /// or a specialization, for example). 1928198893Srdivacky FunctionDecl *getTemplateInstantiationPattern() const; 1929198893Srdivacky 1930195099Sed /// \brief Retrieve the primary template that this function template 1931195099Sed /// specialization either specializes or was instantiated from. 1932195099Sed /// 1933195099Sed /// If this function declaration is not a function template specialization, 1934195099Sed /// returns NULL. 1935195341Sed FunctionTemplateDecl *getPrimaryTemplate() const; 1936198092Srdivacky 1937195099Sed /// \brief Retrieve the template arguments used to produce this function 1938195099Sed /// template specialization from the primary template. 1939195099Sed /// 1940195099Sed /// If this function declaration is not a function template specialization, 1941195099Sed /// returns NULL. 1942198092Srdivacky const TemplateArgumentList *getTemplateSpecializationArgs() const; 1943198092Srdivacky 1944208600Srdivacky /// \brief Retrieve the template argument list as written in the sources, 1945208600Srdivacky /// if any. 1946208600Srdivacky /// 1947208600Srdivacky /// If this function declaration is not a function template specialization 1948208600Srdivacky /// or if it had no explicit template argument list, returns NULL. 1949208600Srdivacky /// Note that it an explicit template argument list may be written empty, 1950208600Srdivacky /// e.g., template<> void foo<>(char* s); 1951226633Sdim const ASTTemplateArgumentListInfo* 1952208600Srdivacky getTemplateSpecializationArgsAsWritten() const; 1953208600Srdivacky 1954195099Sed /// \brief Specify that this function declaration is actually a function 1955195099Sed /// template specialization. 1956195099Sed /// 1957195099Sed /// \param Template the function template that this function template 1958195099Sed /// specialization specializes. 1959195099Sed /// 1960195099Sed /// \param TemplateArgs the template arguments that produced this 1961195099Sed /// function template specialization from the template. 1962198092Srdivacky /// 1963198092Srdivacky /// \param InsertPos If non-NULL, the position in the function template 1964198092Srdivacky /// specialization set where the function template specialization data will 1965198092Srdivacky /// be inserted. 1966198092Srdivacky /// 1967198092Srdivacky /// \param TSK the kind of template specialization this is. 1968210299Sed /// 1969210299Sed /// \param TemplateArgsAsWritten location info of template arguments. 1970210299Sed /// 1971210299Sed /// \param PointOfInstantiation point at which the function template 1972234353Sdim /// specialization was first instantiated. 1973203955Srdivacky void setFunctionTemplateSpecialization(FunctionTemplateDecl *Template, 1974195341Sed const TemplateArgumentList *TemplateArgs, 1975198092Srdivacky void *InsertPos, 1976208600Srdivacky TemplateSpecializationKind TSK = TSK_ImplicitInstantiation, 1977210299Sed const TemplateArgumentListInfo *TemplateArgsAsWritten = 0, 1978218893Sdim SourceLocation PointOfInstantiation = SourceLocation()) { 1979218893Sdim setFunctionTemplateSpecialization(getASTContext(), Template, TemplateArgs, 1980218893Sdim InsertPos, TSK, TemplateArgsAsWritten, 1981218893Sdim PointOfInstantiation); 1982218893Sdim } 1983195341Sed 1984207619Srdivacky /// \brief Specifies that this function declaration is actually a 1985207619Srdivacky /// dependent function template specialization. 1986207619Srdivacky void setDependentTemplateSpecialization(ASTContext &Context, 1987207619Srdivacky const UnresolvedSetImpl &Templates, 1988207619Srdivacky const TemplateArgumentListInfo &TemplateArgs); 1989207619Srdivacky 1990207619Srdivacky DependentFunctionTemplateSpecializationInfo * 1991207619Srdivacky getDependentSpecializationInfo() const { 1992207619Srdivacky return TemplateOrSpecialization. 1993207619Srdivacky dyn_cast<DependentFunctionTemplateSpecializationInfo*>(); 1994207619Srdivacky } 1995207619Srdivacky 1996198092Srdivacky /// \brief Determine what kind of template instantiation this function 1997198092Srdivacky /// represents. 1998198092Srdivacky TemplateSpecializationKind getTemplateSpecializationKind() const; 1999195341Sed 2000198092Srdivacky /// \brief Determine what kind of template instantiation this function 2001198092Srdivacky /// represents. 2002198398Srdivacky void setTemplateSpecializationKind(TemplateSpecializationKind TSK, 2003198398Srdivacky SourceLocation PointOfInstantiation = SourceLocation()); 2004198092Srdivacky 2005198398Srdivacky /// \brief Retrieve the (first) point of instantiation of a function template 2006198398Srdivacky /// specialization or a member of a class template specialization. 2007198398Srdivacky /// 2008234353Sdim /// \returns the first point of instantiation, if this function was 2009234353Sdim /// instantiated from a template; otherwise, returns an invalid source 2010198398Srdivacky /// location. 2011198398Srdivacky SourceLocation getPointOfInstantiation() const; 2012234353Sdim 2013234353Sdim /// \brief Determine whether this is or was instantiated from an out-of-line 2014198092Srdivacky /// definition of a member function. 2015204643Srdivacky virtual bool isOutOfLine() const; 2016234353Sdim 2017234353Sdim /// \brief Identify a memory copying or setting function. 2018234353Sdim /// If the given function is a memory copy or setting function, returns 2019234353Sdim /// the corresponding Builtin ID. If the function is not a memory function, 2020234353Sdim /// returns 0. 2021234353Sdim unsigned getMemoryFunctionKind() const; 2022234353Sdim 2023193326Sed // Implement isa/cast/dyncast/etc. 2024203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2025203955Srdivacky static bool classofKind(Kind K) { 2026210299Sed return K >= firstFunction && K <= lastFunction; 2027193326Sed } 2028193326Sed static DeclContext *castToDeclContext(const FunctionDecl *D) { 2029193326Sed return static_cast<DeclContext *>(const_cast<FunctionDecl*>(D)); 2030193326Sed } 2031193326Sed static FunctionDecl *castFromDeclContext(const DeclContext *DC) { 2032193326Sed return static_cast<FunctionDecl *>(const_cast<DeclContext*>(DC)); 2033193326Sed } 2034210299Sed 2035212904Sdim friend class ASTDeclReader; 2036212904Sdim friend class ASTDeclWriter; 2037193326Sed}; 2038193326Sed 2039193326Sed 2040198092Srdivacky/// FieldDecl - An instance of this class is created by Sema::ActOnField to 2041193326Sed/// represent a member of a struct/union/class. 2042198092Srdivackyclass FieldDecl : public DeclaratorDecl { 2043193326Sed // FIXME: This can be packed into the bitfields in Decl. 2044193326Sed bool Mutable : 1; 2045218893Sdim mutable unsigned CachedFieldIndex : 31; 2046218893Sdim 2047239462Sdim /// \brief An InClassInitStyle value, and either a bit width expression (if 2048239462Sdim /// the InClassInitStyle value is ICIS_NoInit), or a pointer to the in-class 2049239462Sdim /// initializer for this field (otherwise). 2050223017Sdim /// 2051223017Sdim /// We can safely combine these two because in-class initializers are not 2052223017Sdim /// permitted for bit-fields. 2053223017Sdim /// 2054239462Sdim /// If the InClassInitStyle is not ICIS_NoInit and the initializer is null, 2055239462Sdim /// then this field has an in-class initializer which has not yet been parsed 2056239462Sdim /// and attached. 2057239462Sdim llvm::PointerIntPair<Expr *, 2, unsigned> InitializerOrBitWidth; 2058193326Sedprotected: 2059221345Sdim FieldDecl(Kind DK, DeclContext *DC, SourceLocation StartLoc, 2060221345Sdim SourceLocation IdLoc, IdentifierInfo *Id, 2061223017Sdim QualType T, TypeSourceInfo *TInfo, Expr *BW, bool Mutable, 2062239462Sdim InClassInitStyle InitStyle) 2063221345Sdim : DeclaratorDecl(DK, DC, IdLoc, Id, T, TInfo, StartLoc), 2064223017Sdim Mutable(Mutable), CachedFieldIndex(0), 2065239462Sdim InitializerOrBitWidth(BW, InitStyle) { 2066239462Sdim assert((!BW || InitStyle == ICIS_NoInit) && "got initializer for bitfield"); 2067198092Srdivacky } 2068193326Sed 2069193326Sedpublic: 2070218893Sdim static FieldDecl *Create(const ASTContext &C, DeclContext *DC, 2071221345Sdim SourceLocation StartLoc, SourceLocation IdLoc, 2072221345Sdim IdentifierInfo *Id, QualType T, 2073223017Sdim TypeSourceInfo *TInfo, Expr *BW, bool Mutable, 2074239462Sdim InClassInitStyle InitStyle); 2075193326Sed 2076234353Sdim static FieldDecl *CreateDeserialized(ASTContext &C, unsigned ID); 2077234353Sdim 2078218893Sdim /// getFieldIndex - Returns the index of this field within its record, 2079218893Sdim /// as appropriate for passing to ASTRecordLayout::getFieldOffset. 2080218893Sdim unsigned getFieldIndex() const; 2081218893Sdim 2082193326Sed /// isMutable - Determines whether this field is mutable (C++ only). 2083193326Sed bool isMutable() const { return Mutable; } 2084193326Sed 2085193326Sed /// isBitfield - Determines whether this field is a bitfield. 2086223017Sdim bool isBitField() const { 2087239462Sdim return getInClassInitStyle() == ICIS_NoInit && 2088239462Sdim InitializerOrBitWidth.getPointer(); 2089223017Sdim } 2090193326Sed 2091193326Sed /// @brief Determines whether this is an unnamed bitfield. 2092223017Sdim bool isUnnamedBitfield() const { return isBitField() && !getDeclName(); } 2093193326Sed 2094193326Sed /// isAnonymousStructOrUnion - Determines whether this field is a 2095193326Sed /// representative for an anonymous struct or union. Such fields are 2096193326Sed /// unnamed and are implicitly generated by the implementation to 2097193326Sed /// store the data for the anonymous union or struct. 2098193326Sed bool isAnonymousStructOrUnion() const; 2099193326Sed 2100223017Sdim Expr *getBitWidth() const { 2101223017Sdim return isBitField() ? InitializerOrBitWidth.getPointer() : 0; 2102223017Sdim } 2103226633Sdim unsigned getBitWidthValue(const ASTContext &Ctx) const; 2104239462Sdim 2105239462Sdim /// setBitWidth - Set the bit-field width for this member. 2106239462Sdim // Note: used by some clients (i.e., do not remove it). 2107239462Sdim void setBitWidth(Expr *Width); 2108239462Sdim /// removeBitWidth - Remove the bit-field width from this member. 2109239462Sdim // Note: used by some clients (i.e., do not remove it). 2110224145Sdim void removeBitWidth() { 2111239462Sdim assert(isBitField() && "no bitfield width to remove"); 2112224145Sdim InitializerOrBitWidth.setPointer(0); 2113224145Sdim } 2114193326Sed 2115239462Sdim /// getInClassInitStyle - Get the kind of (C++11) in-class initializer which 2116239462Sdim /// this field has. 2117239462Sdim InClassInitStyle getInClassInitStyle() const { 2118239462Sdim return static_cast<InClassInitStyle>(InitializerOrBitWidth.getInt()); 2119239462Sdim } 2120239462Sdim 2121239462Sdim /// hasInClassInitializer - Determine whether this member has a C++11 in-class 2122223017Sdim /// initializer. 2123223017Sdim bool hasInClassInitializer() const { 2124239462Sdim return getInClassInitStyle() != ICIS_NoInit; 2125223017Sdim } 2126239462Sdim /// getInClassInitializer - Get the C++11 in-class initializer for this 2127223017Sdim /// member, or null if one has not been set. If a valid declaration has an 2128223017Sdim /// in-class initializer, but this returns null, then we have not parsed and 2129223017Sdim /// attached it yet. 2130223017Sdim Expr *getInClassInitializer() const { 2131223017Sdim return hasInClassInitializer() ? InitializerOrBitWidth.getPointer() : 0; 2132223017Sdim } 2133239462Sdim /// setInClassInitializer - Set the C++11 in-class initializer for this 2134234353Sdim /// member. 2135223017Sdim void setInClassInitializer(Expr *Init); 2136239462Sdim /// removeInClassInitializer - Remove the C++11 in-class initializer from this 2137223017Sdim /// member. 2138223017Sdim void removeInClassInitializer() { 2139239462Sdim assert(hasInClassInitializer() && "no initializer to remove"); 2140223017Sdim InitializerOrBitWidth.setPointer(0); 2141239462Sdim InitializerOrBitWidth.setInt(ICIS_NoInit); 2142223017Sdim } 2143223017Sdim 2144203955Srdivacky /// getParent - Returns the parent of this field declaration, which 2145203955Srdivacky /// is the struct in which this method is defined. 2146203955Srdivacky const RecordDecl *getParent() const { 2147203955Srdivacky return cast<RecordDecl>(getDeclContext()); 2148203955Srdivacky } 2149203955Srdivacky 2150203955Srdivacky RecordDecl *getParent() { 2151203955Srdivacky return cast<RecordDecl>(getDeclContext()); 2152203955Srdivacky } 2153221345Sdim 2154234353Sdim SourceRange getSourceRange() const LLVM_READONLY; 2155221345Sdim 2156193326Sed // Implement isa/cast/dyncast/etc. 2157203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2158210299Sed static bool classofKind(Kind K) { return K >= firstField && K <= lastField; } 2159239462Sdim 2160239462Sdim friend class ASTDeclReader; 2161239462Sdim friend class ASTDeclWriter; 2162193326Sed}; 2163193326Sed 2164193326Sed/// EnumConstantDecl - An instance of this object exists for each enum constant 2165193326Sed/// that is defined. For example, in "enum X {a,b}", each of a/b are 2166193326Sed/// EnumConstantDecl's, X is an instance of EnumDecl, and the type of a/b is a 2167193326Sed/// TagType for the X EnumDecl. 2168193326Sedclass EnumConstantDecl : public ValueDecl { 2169193326Sed Stmt *Init; // an integer constant expression 2170193326Sed llvm::APSInt Val; // The value. 2171193326Sedprotected: 2172193326Sed EnumConstantDecl(DeclContext *DC, SourceLocation L, 2173193326Sed IdentifierInfo *Id, QualType T, Expr *E, 2174193326Sed const llvm::APSInt &V) 2175193326Sed : ValueDecl(EnumConstant, DC, L, Id, T), Init((Stmt*)E), Val(V) {} 2176193326Sed 2177193326Sedpublic: 2178193326Sed 2179193326Sed static EnumConstantDecl *Create(ASTContext &C, EnumDecl *DC, 2180193326Sed SourceLocation L, IdentifierInfo *Id, 2181193326Sed QualType T, Expr *E, 2182193326Sed const llvm::APSInt &V); 2183234353Sdim static EnumConstantDecl *CreateDeserialized(ASTContext &C, unsigned ID); 2184234353Sdim 2185193326Sed const Expr *getInitExpr() const { return (const Expr*) Init; } 2186193326Sed Expr *getInitExpr() { return (Expr*) Init; } 2187193326Sed const llvm::APSInt &getInitVal() const { return Val; } 2188193326Sed 2189193326Sed void setInitExpr(Expr *E) { Init = (Stmt*) E; } 2190193326Sed void setInitVal(const llvm::APSInt &V) { Val = V; } 2191198092Srdivacky 2192234353Sdim SourceRange getSourceRange() const LLVM_READONLY; 2193234353Sdim 2194193326Sed // Implement isa/cast/dyncast/etc. 2195203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2196203955Srdivacky static bool classofKind(Kind K) { return K == EnumConstant; } 2197198092Srdivacky 2198193326Sed friend class StmtIteratorBase; 2199193326Sed}; 2200193326Sed 2201218893Sdim/// IndirectFieldDecl - An instance of this class is created to represent a 2202218893Sdim/// field injected from an anonymous union/struct into the parent scope. 2203218893Sdim/// IndirectFieldDecl are always implicit. 2204218893Sdimclass IndirectFieldDecl : public ValueDecl { 2205234353Sdim virtual void anchor(); 2206218893Sdim NamedDecl **Chaining; 2207218893Sdim unsigned ChainingSize; 2208193326Sed 2209218893Sdim IndirectFieldDecl(DeclContext *DC, SourceLocation L, 2210218893Sdim DeclarationName N, QualType T, 2211218893Sdim NamedDecl **CH, unsigned CHS) 2212218893Sdim : ValueDecl(IndirectField, DC, L, N, T), Chaining(CH), ChainingSize(CHS) {} 2213218893Sdim 2214218893Sdimpublic: 2215218893Sdim static IndirectFieldDecl *Create(ASTContext &C, DeclContext *DC, 2216218893Sdim SourceLocation L, IdentifierInfo *Id, 2217218893Sdim QualType T, NamedDecl **CH, unsigned CHS); 2218234353Sdim 2219234353Sdim static IndirectFieldDecl *CreateDeserialized(ASTContext &C, unsigned ID); 2220218893Sdim 2221218893Sdim typedef NamedDecl * const *chain_iterator; 2222218893Sdim chain_iterator chain_begin() const { return Chaining; } 2223218893Sdim chain_iterator chain_end() const { return Chaining+ChainingSize; } 2224218893Sdim 2225218893Sdim unsigned getChainingSize() const { return ChainingSize; } 2226218893Sdim 2227218893Sdim FieldDecl *getAnonField() const { 2228218893Sdim assert(ChainingSize >= 2); 2229218893Sdim return cast<FieldDecl>(Chaining[ChainingSize - 1]); 2230218893Sdim } 2231218893Sdim 2232218893Sdim VarDecl *getVarDecl() const { 2233218893Sdim assert(ChainingSize >= 2); 2234218893Sdim return dyn_cast<VarDecl>(*chain_begin()); 2235218893Sdim } 2236218893Sdim 2237218893Sdim // Implement isa/cast/dyncast/etc. 2238218893Sdim static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2239218893Sdim static bool classofKind(Kind K) { return K == IndirectField; } 2240218893Sdim friend class ASTDeclReader; 2241218893Sdim}; 2242218893Sdim 2243193326Sed/// TypeDecl - Represents a declaration of a type. 2244193326Sed/// 2245193326Sedclass TypeDecl : public NamedDecl { 2246234353Sdim virtual void anchor(); 2247193326Sed /// TypeForDecl - This indicates the Type object that represents 2248193326Sed /// this TypeDecl. It is a cache maintained by 2249193326Sed /// ASTContext::getTypedefType, ASTContext::getTagDeclType, and 2250193326Sed /// ASTContext::getTemplateTypeParmType, and TemplateTypeParmDecl. 2251218893Sdim mutable const Type *TypeForDecl; 2252221345Sdim /// LocStart - The start of the source range for this declaration. 2253221345Sdim SourceLocation LocStart; 2254193326Sed friend class ASTContext; 2255193326Sed friend class DeclContext; 2256193326Sed friend class TagDecl; 2257193326Sed friend class TemplateTypeParmDecl; 2258193326Sed friend class TagType; 2259234353Sdim friend class ASTReader; 2260193326Sed 2261193326Sedprotected: 2262221345Sdim TypeDecl(Kind DK, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, 2263221345Sdim SourceLocation StartL = SourceLocation()) 2264221345Sdim : NamedDecl(DK, DC, L, Id), TypeForDecl(0), LocStart(StartL) {} 2265193326Sed 2266193326Sedpublic: 2267239462Sdim // Low-level accessor. If you just want the type defined by this node, 2268239462Sdim // check out ASTContext::getTypeDeclType or one of 2269239462Sdim // ASTContext::getTypedefType, ASTContext::getRecordType, etc. if you 2270239462Sdim // already know the specific kind of node this is. 2271218893Sdim const Type *getTypeForDecl() const { return TypeForDecl; } 2272218893Sdim void setTypeForDecl(const Type *TD) { TypeForDecl = TD; } 2273193326Sed 2274234353Sdim SourceLocation getLocStart() const LLVM_READONLY { return LocStart; } 2275221345Sdim void setLocStart(SourceLocation L) { LocStart = L; } 2276234353Sdim virtual SourceRange getSourceRange() const LLVM_READONLY { 2277221345Sdim if (LocStart.isValid()) 2278221345Sdim return SourceRange(LocStart, getLocation()); 2279221345Sdim else 2280221345Sdim return SourceRange(getLocation()); 2281221345Sdim } 2282221345Sdim 2283193326Sed // Implement isa/cast/dyncast/etc. 2284203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2285210299Sed static bool classofKind(Kind K) { return K >= firstType && K <= lastType; } 2286193326Sed}; 2287193326Sed 2288193326Sed 2289221345Sdim/// Base class for declarations which introduce a typedef-name. 2290221345Sdimclass TypedefNameDecl : public TypeDecl, public Redeclarable<TypedefNameDecl> { 2291234353Sdim virtual void anchor(); 2292193326Sed /// UnderlyingType - This is the type the typedef is set to. 2293200583Srdivacky TypeSourceInfo *TInfo; 2294198893Srdivacky 2295208600Srdivackyprotected: 2296221345Sdim TypedefNameDecl(Kind DK, DeclContext *DC, SourceLocation StartLoc, 2297221345Sdim SourceLocation IdLoc, IdentifierInfo *Id, 2298221345Sdim TypeSourceInfo *TInfo) 2299221345Sdim : TypeDecl(DK, DC, IdLoc, Id, StartLoc), TInfo(TInfo) {} 2300208600Srdivacky 2301221345Sdim typedef Redeclarable<TypedefNameDecl> redeclarable_base; 2302221345Sdim virtual TypedefNameDecl *getNextRedeclaration() { 2303221345Sdim return RedeclLink.getNext(); 2304221345Sdim } 2305234353Sdim virtual TypedefNameDecl *getPreviousDeclImpl() { 2306234353Sdim return getPreviousDecl(); 2307234353Sdim } 2308234353Sdim virtual TypedefNameDecl *getMostRecentDeclImpl() { 2309234353Sdim return getMostRecentDecl(); 2310234353Sdim } 2311221345Sdim 2312193326Sedpublic: 2313208600Srdivacky typedef redeclarable_base::redecl_iterator redecl_iterator; 2314234353Sdim using redeclarable_base::redecls_begin; 2315234353Sdim using redeclarable_base::redecls_end; 2316234353Sdim using redeclarable_base::getPreviousDecl; 2317234353Sdim using redeclarable_base::getMostRecentDecl; 2318198092Srdivacky 2319200583Srdivacky TypeSourceInfo *getTypeSourceInfo() const { 2320200583Srdivacky return TInfo; 2321198893Srdivacky } 2322193326Sed 2323221345Sdim /// Retrieves the canonical declaration of this typedef-name. 2324221345Sdim TypedefNameDecl *getCanonicalDecl() { 2325201361Srdivacky return getFirstDeclaration(); 2326201361Srdivacky } 2327221345Sdim const TypedefNameDecl *getCanonicalDecl() const { 2328201361Srdivacky return getFirstDeclaration(); 2329201361Srdivacky } 2330201361Srdivacky 2331198893Srdivacky QualType getUnderlyingType() const { 2332200583Srdivacky return TInfo->getType(); 2333198893Srdivacky } 2334200583Srdivacky void setTypeSourceInfo(TypeSourceInfo *newType) { 2335200583Srdivacky TInfo = newType; 2336198893Srdivacky } 2337198893Srdivacky 2338193326Sed // Implement isa/cast/dyncast/etc. 2339203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2340221345Sdim static bool classofKind(Kind K) { 2341221345Sdim return K >= firstTypedefName && K <= lastTypedefName; 2342221345Sdim } 2343221345Sdim}; 2344221345Sdim 2345221345Sdim/// TypedefDecl - Represents the declaration of a typedef-name via the 'typedef' 2346221345Sdim/// type specifier. 2347221345Sdimclass TypedefDecl : public TypedefNameDecl { 2348221345Sdim TypedefDecl(DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, 2349221345Sdim IdentifierInfo *Id, TypeSourceInfo *TInfo) 2350221345Sdim : TypedefNameDecl(Typedef, DC, StartLoc, IdLoc, Id, TInfo) {} 2351221345Sdim 2352221345Sdimpublic: 2353221345Sdim static TypedefDecl *Create(ASTContext &C, DeclContext *DC, 2354221345Sdim SourceLocation StartLoc, SourceLocation IdLoc, 2355221345Sdim IdentifierInfo *Id, TypeSourceInfo *TInfo); 2356234353Sdim static TypedefDecl *CreateDeserialized(ASTContext &C, unsigned ID); 2357234353Sdim 2358234353Sdim SourceRange getSourceRange() const LLVM_READONLY; 2359221345Sdim 2360221345Sdim // Implement isa/cast/dyncast/etc. 2361221345Sdim static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2362203955Srdivacky static bool classofKind(Kind K) { return K == Typedef; } 2363193326Sed}; 2364193326Sed 2365221345Sdim/// TypeAliasDecl - Represents the declaration of a typedef-name via a C++0x 2366221345Sdim/// alias-declaration. 2367221345Sdimclass TypeAliasDecl : public TypedefNameDecl { 2368221345Sdim TypeAliasDecl(DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, 2369221345Sdim IdentifierInfo *Id, TypeSourceInfo *TInfo) 2370221345Sdim : TypedefNameDecl(TypeAlias, DC, StartLoc, IdLoc, Id, TInfo) {} 2371198092Srdivacky 2372221345Sdimpublic: 2373221345Sdim static TypeAliasDecl *Create(ASTContext &C, DeclContext *DC, 2374221345Sdim SourceLocation StartLoc, SourceLocation IdLoc, 2375221345Sdim IdentifierInfo *Id, TypeSourceInfo *TInfo); 2376234353Sdim static TypeAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID); 2377221345Sdim 2378234353Sdim SourceRange getSourceRange() const LLVM_READONLY; 2379221345Sdim 2380221345Sdim // Implement isa/cast/dyncast/etc. 2381221345Sdim static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2382221345Sdim static bool classofKind(Kind K) { return K == TypeAlias; } 2383221345Sdim}; 2384221345Sdim 2385193326Sed/// TagDecl - Represents the declaration of a struct/union/class/enum. 2386198092Srdivackyclass TagDecl 2387198092Srdivacky : public TypeDecl, public DeclContext, public Redeclarable<TagDecl> { 2388193326Sedpublic: 2389198092Srdivacky // This is really ugly. 2390208600Srdivacky typedef TagTypeKind TagKind; 2391193326Sed 2392193326Sedprivate: 2393193326Sed // FIXME: This can be packed into the bitfields in Decl. 2394193326Sed /// TagDeclKind - The TagKind enum. 2395243830Sdim unsigned TagDeclKind : 3; 2396193326Sed 2397226633Sdim /// IsCompleteDefinition - True if this is a definition ("struct foo 2398226633Sdim /// {};"), false if it is a declaration ("struct foo;"). It is not 2399226633Sdim /// a definition until the definition has been fully processed. 2400226633Sdim bool IsCompleteDefinition : 1; 2401198092Srdivacky 2402234353Sdimprotected: 2403212904Sdim /// IsBeingDefined - True if this is currently being defined. 2404212904Sdim bool IsBeingDefined : 1; 2405212904Sdim 2406234353Sdimprivate: 2407203955Srdivacky /// IsEmbeddedInDeclarator - True if this tag declaration is 2408203955Srdivacky /// "embedded" (i.e., defined or declared for the very first time) 2409205219Srdivacky /// in the syntax of a declarator. 2410203955Srdivacky bool IsEmbeddedInDeclarator : 1; 2411203955Srdivacky 2412234353Sdim /// \brief True if this tag is free standing, e.g. "struct foo;". 2413226633Sdim bool IsFreeStanding : 1; 2414226633Sdim 2415208600Srdivackyprotected: 2416208600Srdivacky // These are used by (and only defined for) EnumDecl. 2417208600Srdivacky unsigned NumPositiveBits : 8; 2418208600Srdivacky unsigned NumNegativeBits : 8; 2419208600Srdivacky 2420218893Sdim /// IsScoped - True if this tag declaration is a scoped enumeration. Only 2421234353Sdim /// possible in C++11 mode. 2422218893Sdim bool IsScoped : 1; 2423218893Sdim /// IsScopedUsingClassTag - If this tag declaration is a scoped enum, 2424218893Sdim /// then this is true if the scoped enum was declared using the class 2425218893Sdim /// tag, false if it was declared with the struct tag. No meaning is 2426218893Sdim /// associated if this tag declaration is not a scoped enum. 2427218893Sdim bool IsScopedUsingClassTag : 1; 2428218893Sdim 2429218893Sdim /// IsFixed - True if this is an enumeration with fixed underlying type. Only 2430251662Sdim /// possible in C++11, Microsoft extensions, or Objective C mode. 2431218893Sdim bool IsFixed : 1; 2432218893Sdim 2433249423Sdim /// \brief Indicates whether it is possible for declarations of this kind 2434249423Sdim /// to have an out-of-date definition. 2435249423Sdim /// 2436249423Sdim /// This option is only enabled when modules are enabled. 2437249423Sdim bool MayHaveOutOfDateDef : 1; 2438249423Sdim 2439208600Srdivackyprivate: 2440198092Srdivacky SourceLocation RBraceLoc; 2441198092Srdivacky 2442205219Srdivacky // A struct representing syntactic qualifier info, 2443205219Srdivacky // to be used for the (uncommon) case of out-of-line declarations. 2444210299Sed typedef QualifierInfo ExtInfo; 2445205219Srdivacky 2446221345Sdim /// TypedefNameDeclOrQualifier - If the (out-of-line) tag declaration name 2447205219Srdivacky /// is qualified, it points to the qualifier info (nns and range); 2448205219Srdivacky /// otherwise, if the tag declaration is anonymous and it is part of 2449221345Sdim /// a typedef or alias, it points to the TypedefNameDecl (used for mangling); 2450221345Sdim /// otherwise, it is a null (TypedefNameDecl) pointer. 2451221345Sdim llvm::PointerUnion<TypedefNameDecl*, ExtInfo*> TypedefNameDeclOrQualifier; 2452205219Srdivacky 2453221345Sdim bool hasExtInfo() const { return TypedefNameDeclOrQualifier.is<ExtInfo*>(); } 2454221345Sdim ExtInfo *getExtInfo() { return TypedefNameDeclOrQualifier.get<ExtInfo*>(); } 2455205219Srdivacky const ExtInfo *getExtInfo() const { 2456221345Sdim return TypedefNameDeclOrQualifier.get<ExtInfo*>(); 2457205219Srdivacky } 2458205219Srdivacky 2459193326Sedprotected: 2460205219Srdivacky TagDecl(Kind DK, TagKind TK, DeclContext *DC, 2461205219Srdivacky SourceLocation L, IdentifierInfo *Id, 2462221345Sdim TagDecl *PrevDecl, SourceLocation StartL) 2463221345Sdim : TypeDecl(DK, DC, L, Id, StartL), DeclContext(DK), 2464221345Sdim TypedefNameDeclOrQualifier((TypedefNameDecl*) 0) { 2465208600Srdivacky assert((DK != Enum || TK == TTK_Enum) && 2466208600Srdivacky "EnumDecl not matched with TTK_Enum"); 2467193326Sed TagDeclKind = TK; 2468226633Sdim IsCompleteDefinition = false; 2469212904Sdim IsBeingDefined = false; 2470203955Srdivacky IsEmbeddedInDeclarator = false; 2471226633Sdim IsFreeStanding = false; 2472198092Srdivacky setPreviousDeclaration(PrevDecl); 2473193326Sed } 2474198092Srdivacky 2475198092Srdivacky typedef Redeclarable<TagDecl> redeclarable_base; 2476198092Srdivacky virtual TagDecl *getNextRedeclaration() { return RedeclLink.getNext(); } 2477234353Sdim virtual TagDecl *getPreviousDeclImpl() { 2478234353Sdim return getPreviousDecl(); 2479234353Sdim } 2480234353Sdim virtual TagDecl *getMostRecentDeclImpl() { 2481234353Sdim return getMostRecentDecl(); 2482234353Sdim } 2483198092Srdivacky 2484218893Sdim /// @brief Completes the definition of this tag declaration. 2485218893Sdim /// 2486218893Sdim /// This is a helper function for derived classes. 2487234353Sdim void completeDefinition(); 2488234353Sdim 2489193326Sedpublic: 2490198092Srdivacky typedef redeclarable_base::redecl_iterator redecl_iterator; 2491234353Sdim using redeclarable_base::redecls_begin; 2492234353Sdim using redeclarable_base::redecls_end; 2493234353Sdim using redeclarable_base::getPreviousDecl; 2494234353Sdim using redeclarable_base::getMostRecentDecl; 2495198092Srdivacky 2496198092Srdivacky SourceLocation getRBraceLoc() const { return RBraceLoc; } 2497198092Srdivacky void setRBraceLoc(SourceLocation L) { RBraceLoc = L; } 2498198092Srdivacky 2499210299Sed /// getInnerLocStart - Return SourceLocation representing start of source 2500210299Sed /// range ignoring outer template declarations. 2501221345Sdim SourceLocation getInnerLocStart() const { return getLocStart(); } 2502210299Sed 2503210299Sed /// getOuterLocStart - Return SourceLocation representing start of source 2504210299Sed /// range taking into account any outer template declarations. 2505210299Sed SourceLocation getOuterLocStart() const; 2506234353Sdim virtual SourceRange getSourceRange() const LLVM_READONLY; 2507198092Srdivacky 2508198092Srdivacky virtual TagDecl* getCanonicalDecl(); 2509199482Srdivacky const TagDecl* getCanonicalDecl() const { 2510199482Srdivacky return const_cast<TagDecl*>(this)->getCanonicalDecl(); 2511199482Srdivacky } 2512198092Srdivacky 2513212904Sdim /// isThisDeclarationADefinition() - Return true if this declaration 2514226633Sdim /// is a completion definintion of the type. Provided for consistency. 2515212904Sdim bool isThisDeclarationADefinition() const { 2516226633Sdim return isCompleteDefinition(); 2517212904Sdim } 2518212904Sdim 2519226633Sdim /// isCompleteDefinition - Return true if this decl has its body 2520226633Sdim /// fully specified. 2521226633Sdim bool isCompleteDefinition() const { 2522226633Sdim return IsCompleteDefinition; 2523193326Sed } 2524193326Sed 2525212904Sdim /// isBeingDefined - Return true if this decl is currently being defined. 2526212904Sdim bool isBeingDefined() const { 2527212904Sdim return IsBeingDefined; 2528212904Sdim } 2529212904Sdim 2530203955Srdivacky bool isEmbeddedInDeclarator() const { 2531203955Srdivacky return IsEmbeddedInDeclarator; 2532203955Srdivacky } 2533203955Srdivacky void setEmbeddedInDeclarator(bool isInDeclarator) { 2534203955Srdivacky IsEmbeddedInDeclarator = isInDeclarator; 2535203955Srdivacky } 2536203955Srdivacky 2537226633Sdim bool isFreeStanding() const { return IsFreeStanding; } 2538226633Sdim void setFreeStanding(bool isFreeStanding = true) { 2539226633Sdim IsFreeStanding = isFreeStanding; 2540226633Sdim } 2541226633Sdim 2542193326Sed /// \brief Whether this declaration declares a type that is 2543193326Sed /// dependent, i.e., a type that somehow depends on template 2544193326Sed /// parameters. 2545193326Sed bool isDependentType() const { return isDependentContext(); } 2546193326Sed 2547193326Sed /// @brief Starts the definition of this tag declaration. 2548198092Srdivacky /// 2549193326Sed /// This method should be invoked at the beginning of the definition 2550193326Sed /// of this tag declaration. It will set the tag type into a state 2551193326Sed /// where it is in the process of being defined. 2552193326Sed void startDefinition(); 2553193326Sed 2554198092Srdivacky /// getDefinition - Returns the TagDecl that actually defines this 2555193326Sed /// struct/union/class/enum. When determining whether or not a 2556226633Sdim /// struct/union/class/enum has a definition, one should use this 2557226633Sdim /// method as opposed to 'isDefinition'. 'isDefinition' indicates 2558226633Sdim /// whether or not a specific TagDecl is defining declaration, not 2559226633Sdim /// whether or not the struct/union/class/enum type is defined. 2560226633Sdim /// This method returns NULL if there is no TagDecl that defines 2561226633Sdim /// the struct/union/class/enum. 2562226633Sdim TagDecl *getDefinition() const; 2563198092Srdivacky 2564226633Sdim void setCompleteDefinition(bool V) { IsCompleteDefinition = V; } 2565203955Srdivacky 2566239462Sdim // FIXME: Return StringRef; 2567193326Sed const char *getKindName() const { 2568208600Srdivacky return TypeWithKeyword::getTagTypeKindName(getTagKind()); 2569193326Sed } 2570193326Sed 2571193326Sed TagKind getTagKind() const { 2572193326Sed return TagKind(TagDeclKind); 2573193326Sed } 2574193326Sed 2575193326Sed void setTagKind(TagKind TK) { TagDeclKind = TK; } 2576193326Sed 2577208600Srdivacky bool isStruct() const { return getTagKind() == TTK_Struct; } 2578243830Sdim bool isInterface() const { return getTagKind() == TTK_Interface; } 2579208600Srdivacky bool isClass() const { return getTagKind() == TTK_Class; } 2580208600Srdivacky bool isUnion() const { return getTagKind() == TTK_Union; } 2581208600Srdivacky bool isEnum() const { return getTagKind() == TTK_Enum; } 2582198092Srdivacky 2583249423Sdim /// Is this tag type named, either directly or via being defined in 2584249423Sdim /// a typedef of this type? 2585249423Sdim /// 2586249423Sdim /// C++11 [basic.link]p8: 2587249423Sdim /// A type is said to have linkage if and only if: 2588249423Sdim /// - it is a class or enumeration type that is named (or has a 2589249423Sdim /// name for linkage purposes) and the name has linkage; ... 2590249423Sdim /// C++11 [dcl.typedef]p9: 2591249423Sdim /// If the typedef declaration defines an unnamed class (or enum), 2592249423Sdim /// the first typedef-name declared by the declaration to be that 2593249423Sdim /// class type (or enum type) is used to denote the class type (or 2594249423Sdim /// enum type) for linkage purposes only. 2595249423Sdim /// 2596249423Sdim /// C does not have an analogous rule, but the same concept is 2597249423Sdim /// nonetheless useful in some places. 2598249423Sdim bool hasNameForLinkage() const { 2599249423Sdim return (getDeclName() || getTypedefNameForAnonDecl()); 2600249423Sdim } 2601249423Sdim 2602221345Sdim TypedefNameDecl *getTypedefNameForAnonDecl() const { 2603234353Sdim return hasExtInfo() ? 0 : 2604234353Sdim TypedefNameDeclOrQualifier.get<TypedefNameDecl*>(); 2605205219Srdivacky } 2606210299Sed 2607221345Sdim void setTypedefNameForAnonDecl(TypedefNameDecl *TDD); 2608210299Sed 2609219077Sdim /// \brief Retrieve the nested-name-specifier that qualifies the name of this 2610219077Sdim /// declaration, if it was present in the source. 2611205219Srdivacky NestedNameSpecifier *getQualifier() const { 2612219077Sdim return hasExtInfo() ? getExtInfo()->QualifierLoc.getNestedNameSpecifier() 2613219077Sdim : 0; 2614205219Srdivacky } 2615234353Sdim 2616234353Sdim /// \brief Retrieve the nested-name-specifier (with source-location 2617234353Sdim /// information) that qualifies the name of this declaration, if it was 2618219077Sdim /// present in the source. 2619219077Sdim NestedNameSpecifierLoc getQualifierLoc() const { 2620219077Sdim return hasExtInfo() ? getExtInfo()->QualifierLoc 2621219077Sdim : NestedNameSpecifierLoc(); 2622205219Srdivacky } 2623234353Sdim 2624219077Sdim void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc); 2625205219Srdivacky 2626210299Sed unsigned getNumTemplateParameterLists() const { 2627210299Sed return hasExtInfo() ? getExtInfo()->NumTemplParamLists : 0; 2628210299Sed } 2629210299Sed TemplateParameterList *getTemplateParameterList(unsigned i) const { 2630210299Sed assert(i < getNumTemplateParameterLists()); 2631210299Sed return getExtInfo()->TemplParamLists[i]; 2632210299Sed } 2633210299Sed void setTemplateParameterListsInfo(ASTContext &Context, unsigned NumTPLists, 2634221345Sdim TemplateParameterList **TPLists); 2635210299Sed 2636193326Sed // Implement isa/cast/dyncast/etc. 2637203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2638210299Sed static bool classofKind(Kind K) { return K >= firstTag && K <= lastTag; } 2639193326Sed 2640193326Sed static DeclContext *castToDeclContext(const TagDecl *D) { 2641193326Sed return static_cast<DeclContext *>(const_cast<TagDecl*>(D)); 2642193326Sed } 2643193326Sed static TagDecl *castFromDeclContext(const DeclContext *DC) { 2644193326Sed return static_cast<TagDecl *>(const_cast<DeclContext*>(DC)); 2645193326Sed } 2646210299Sed 2647212904Sdim friend class ASTDeclReader; 2648212904Sdim friend class ASTDeclWriter; 2649193326Sed}; 2650193326Sed 2651234353Sdim/// EnumDecl - Represents an enum. In C++11, enums can be forward-declared 2652234353Sdim/// with a fixed underlying type, and in C we allow them to be forward-declared 2653234353Sdim/// with no underlying type as an extension. 2654193326Sedclass EnumDecl : public TagDecl { 2655234353Sdim virtual void anchor(); 2656193326Sed /// IntegerType - This represent the integer type that the enum corresponds 2657193326Sed /// to for code generation purposes. Note that the enumerator constants may 2658193326Sed /// have a different type than this does. 2659218893Sdim /// 2660218893Sdim /// If the underlying integer type was explicitly stated in the source 2661218893Sdim /// code, this is a TypeSourceInfo* for that type. Otherwise this type 2662218893Sdim /// was automatically deduced somehow, and this is a Type*. 2663218893Sdim /// 2664218893Sdim /// Normally if IsFixed(), this would contain a TypeSourceInfo*, but in 2665218893Sdim /// some cases it won't. 2666218893Sdim /// 2667218893Sdim /// The underlying type of an enumeration never has any qualifiers, so 2668218893Sdim /// we can get away with just storing a raw Type*, and thus save an 2669218893Sdim /// extra pointer when TypeSourceInfo is needed. 2670193326Sed 2671218893Sdim llvm::PointerUnion<const Type*, TypeSourceInfo*> IntegerType; 2672218893Sdim 2673200583Srdivacky /// PromotionType - The integer type that values of this type should 2674200583Srdivacky /// promote to. In C, enumerators are generally of an integer type 2675200583Srdivacky /// directly, but gcc-style large enumerators (and all enumerators 2676200583Srdivacky /// in C++) are of the enum type instead. 2677200583Srdivacky QualType PromotionType; 2678200583Srdivacky 2679234353Sdim /// \brief If this enumeration is an instantiation of a member enumeration 2680234353Sdim /// of a class template specialization, this is the member specialization 2681234353Sdim /// information. 2682234353Sdim MemberSpecializationInfo *SpecializationInfo; 2683193326Sed 2684221345Sdim EnumDecl(DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, 2685221345Sdim IdentifierInfo *Id, EnumDecl *PrevDecl, 2686218893Sdim bool Scoped, bool ScopedUsingClassTag, bool Fixed) 2687221345Sdim : TagDecl(Enum, TTK_Enum, DC, IdLoc, Id, PrevDecl, StartLoc), 2688234353Sdim SpecializationInfo(0) { 2689221345Sdim assert(Scoped || !ScopedUsingClassTag); 2690221345Sdim IntegerType = (const Type*)0; 2691221345Sdim NumNegativeBits = 0; 2692221345Sdim NumPositiveBits = 0; 2693221345Sdim IsScoped = Scoped; 2694221345Sdim IsScopedUsingClassTag = ScopedUsingClassTag; 2695221345Sdim IsFixed = Fixed; 2696221345Sdim } 2697234353Sdim 2698234353Sdim void setInstantiationOfMemberEnum(ASTContext &C, EnumDecl *ED, 2699234353Sdim TemplateSpecializationKind TSK); 2700193326Sedpublic: 2701198092Srdivacky EnumDecl *getCanonicalDecl() { 2702198092Srdivacky return cast<EnumDecl>(TagDecl::getCanonicalDecl()); 2703198092Srdivacky } 2704199482Srdivacky const EnumDecl *getCanonicalDecl() const { 2705199482Srdivacky return cast<EnumDecl>(TagDecl::getCanonicalDecl()); 2706199482Srdivacky } 2707198092Srdivacky 2708234353Sdim const EnumDecl *getPreviousDecl() const { 2709234353Sdim return cast_or_null<EnumDecl>(TagDecl::getPreviousDecl()); 2710210299Sed } 2711234353Sdim EnumDecl *getPreviousDecl() { 2712234353Sdim return cast_or_null<EnumDecl>(TagDecl::getPreviousDecl()); 2713210299Sed } 2714210299Sed 2715234353Sdim const EnumDecl *getMostRecentDecl() const { 2716234353Sdim return cast<EnumDecl>(TagDecl::getMostRecentDecl()); 2717234353Sdim } 2718234353Sdim EnumDecl *getMostRecentDecl() { 2719234353Sdim return cast<EnumDecl>(TagDecl::getMostRecentDecl()); 2720234353Sdim } 2721234353Sdim 2722234353Sdim EnumDecl *getDefinition() const { 2723234353Sdim return cast_or_null<EnumDecl>(TagDecl::getDefinition()); 2724234353Sdim } 2725234353Sdim 2726193326Sed static EnumDecl *Create(ASTContext &C, DeclContext *DC, 2727221345Sdim SourceLocation StartLoc, SourceLocation IdLoc, 2728221345Sdim IdentifierInfo *Id, EnumDecl *PrevDecl, 2729218893Sdim bool IsScoped, bool IsScopedUsingClassTag, 2730218893Sdim bool IsFixed); 2731234353Sdim static EnumDecl *CreateDeserialized(ASTContext &C, unsigned ID); 2732198092Srdivacky 2733193326Sed /// completeDefinition - When created, the EnumDecl corresponds to a 2734193326Sed /// forward-declared enum. This method is used to mark the 2735193326Sed /// declaration as being defined; it's enumerators have already been 2736193326Sed /// added (via DeclContext::addDecl). NewType is the new underlying 2737193326Sed /// type of the enumeration type. 2738203955Srdivacky void completeDefinition(QualType NewType, 2739208600Srdivacky QualType PromotionType, 2740208600Srdivacky unsigned NumPositiveBits, 2741208600Srdivacky unsigned NumNegativeBits); 2742198092Srdivacky 2743193326Sed // enumerator_iterator - Iterates through the enumerators of this 2744193326Sed // enumeration. 2745193326Sed typedef specific_decl_iterator<EnumConstantDecl> enumerator_iterator; 2746193326Sed 2747198092Srdivacky enumerator_iterator enumerator_begin() const { 2748234353Sdim const EnumDecl *E = getDefinition(); 2749210299Sed if (!E) 2750210299Sed E = this; 2751210299Sed return enumerator_iterator(E->decls_begin()); 2752193326Sed } 2753193326Sed 2754198092Srdivacky enumerator_iterator enumerator_end() const { 2755234353Sdim const EnumDecl *E = getDefinition(); 2756210299Sed if (!E) 2757210299Sed E = this; 2758210299Sed return enumerator_iterator(E->decls_end()); 2759193326Sed } 2760193326Sed 2761200583Srdivacky /// getPromotionType - Return the integer type that enumerators 2762200583Srdivacky /// should promote to. 2763200583Srdivacky QualType getPromotionType() const { return PromotionType; } 2764200583Srdivacky 2765200583Srdivacky /// \brief Set the promotion type. 2766200583Srdivacky void setPromotionType(QualType T) { PromotionType = T; } 2767200583Srdivacky 2768193326Sed /// getIntegerType - Return the integer type this enum decl corresponds to. 2769193326Sed /// This returns a null qualtype for an enum forward definition. 2770218893Sdim QualType getIntegerType() const { 2771218893Sdim if (!IntegerType) 2772218893Sdim return QualType(); 2773218893Sdim if (const Type* T = IntegerType.dyn_cast<const Type*>()) 2774218893Sdim return QualType(T, 0); 2775218893Sdim return IntegerType.get<TypeSourceInfo*>()->getType(); 2776218893Sdim } 2777193326Sed 2778193326Sed /// \brief Set the underlying integer type. 2779218893Sdim void setIntegerType(QualType T) { IntegerType = T.getTypePtrOrNull(); } 2780193326Sed 2781218893Sdim /// \brief Set the underlying integer type source info. 2782218893Sdim void setIntegerTypeSourceInfo(TypeSourceInfo* TInfo) { IntegerType = TInfo; } 2783218893Sdim 2784218893Sdim /// \brief Return the type source info for the underlying integer type, 2785218893Sdim /// if no type source info exists, return 0. 2786218893Sdim TypeSourceInfo* getIntegerTypeSourceInfo() const { 2787218893Sdim return IntegerType.dyn_cast<TypeSourceInfo*>(); 2788218893Sdim } 2789218893Sdim 2790221345Sdim /// \brief Returns the width in bits required to store all the 2791208600Srdivacky /// non-negative enumerators of this enum. 2792208600Srdivacky unsigned getNumPositiveBits() const { 2793208600Srdivacky return NumPositiveBits; 2794208600Srdivacky } 2795208600Srdivacky void setNumPositiveBits(unsigned Num) { 2796208600Srdivacky NumPositiveBits = Num; 2797208600Srdivacky assert(NumPositiveBits == Num && "can't store this bitcount"); 2798208600Srdivacky } 2799208600Srdivacky 2800221345Sdim /// \brief Returns the width in bits required to store all the 2801208600Srdivacky /// negative enumerators of this enum. These widths include 2802208600Srdivacky /// the rightmost leading 1; that is: 2803234353Sdim /// 2804208600Srdivacky /// MOST NEGATIVE ENUMERATOR PATTERN NUM NEGATIVE BITS 2805208600Srdivacky /// ------------------------ ------- ----------------- 2806208600Srdivacky /// -1 1111111 1 2807208600Srdivacky /// -10 1110110 5 2808208600Srdivacky /// -101 1001011 8 2809208600Srdivacky unsigned getNumNegativeBits() const { 2810208600Srdivacky return NumNegativeBits; 2811208600Srdivacky } 2812208600Srdivacky void setNumNegativeBits(unsigned Num) { 2813208600Srdivacky NumNegativeBits = Num; 2814208600Srdivacky } 2815208600Srdivacky 2816251662Sdim /// \brief Returns true if this is a C++11 scoped enumeration. 2817218893Sdim bool isScoped() const { 2818218893Sdim return IsScoped; 2819218893Sdim } 2820218893Sdim 2821251662Sdim /// \brief Returns true if this is a C++11 scoped enumeration. 2822218893Sdim bool isScopedUsingClassTag() const { 2823218893Sdim return IsScopedUsingClassTag; 2824218893Sdim } 2825218893Sdim 2826251662Sdim /// \brief Returns true if this is an Objective-C, C++11, or 2827251662Sdim /// Microsoft-style enumeration with a fixed underlying type. 2828218893Sdim bool isFixed() const { 2829218893Sdim return IsFixed; 2830218893Sdim } 2831218893Sdim 2832218893Sdim /// \brief Returns true if this can be considered a complete type. 2833218893Sdim bool isComplete() const { 2834226633Sdim return isCompleteDefinition() || isFixed(); 2835218893Sdim } 2836218893Sdim 2837193326Sed /// \brief Returns the enumeration (declared within the template) 2838193326Sed /// from which this enumeration type was instantiated, or NULL if 2839193326Sed /// this enumeration was not instantiated from any template. 2840234353Sdim EnumDecl *getInstantiatedFromMemberEnum() const; 2841234353Sdim 2842234353Sdim /// \brief If this enumeration is a member of a specialization of a 2843234353Sdim /// templated class, determine what kind of template specialization 2844234353Sdim /// or instantiation this is. 2845234353Sdim TemplateSpecializationKind getTemplateSpecializationKind() const; 2846234353Sdim 2847234353Sdim /// \brief For an enumeration member that was instantiated from a member 2848234353Sdim /// enumeration of a templated class, set the template specialiation kind. 2849234353Sdim void setTemplateSpecializationKind(TemplateSpecializationKind TSK, 2850234353Sdim SourceLocation PointOfInstantiation = SourceLocation()); 2851234353Sdim 2852234353Sdim /// \brief If this enumeration is an instantiation of a member enumeration of 2853234353Sdim /// a class template specialization, retrieves the member specialization 2854234353Sdim /// information. 2855234353Sdim MemberSpecializationInfo *getMemberSpecializationInfo() const { 2856234353Sdim return SpecializationInfo; 2857193326Sed } 2858193326Sed 2859234353Sdim /// \brief Specify that this enumeration is an instantiation of the 2860234353Sdim /// member enumeration ED. 2861234353Sdim void setInstantiationOfMemberEnum(EnumDecl *ED, 2862234353Sdim TemplateSpecializationKind TSK) { 2863234353Sdim setInstantiationOfMemberEnum(getASTContext(), ED, TSK); 2864234353Sdim } 2865193326Sed 2866203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2867203955Srdivacky static bool classofKind(Kind K) { return K == Enum; } 2868218893Sdim 2869218893Sdim friend class ASTDeclReader; 2870193326Sed}; 2871193326Sed 2872193326Sed 2873193326Sed/// RecordDecl - Represents a struct/union/class. For example: 2874193326Sed/// struct X; // Forward declaration, no "body". 2875193326Sed/// union Y { int A, B; }; // Has body with members A and B (FieldDecls). 2876193326Sed/// This decl will be marked invalid if *any* members are invalid. 2877193326Sed/// 2878193326Sedclass RecordDecl : public TagDecl { 2879193326Sed // FIXME: This can be packed into the bitfields in Decl. 2880193326Sed /// HasFlexibleArrayMember - This is true if this struct ends with a flexible 2881193326Sed /// array member (e.g. int X[]) or if this union contains a struct that does. 2882193326Sed /// If so, this cannot be contained in arrays or other structs as a member. 2883193326Sed bool HasFlexibleArrayMember : 1; 2884193326Sed 2885206084Srdivacky /// AnonymousStructOrUnion - Whether this is the type of an anonymous struct 2886206084Srdivacky /// or union. 2887193326Sed bool AnonymousStructOrUnion : 1; 2888193326Sed 2889206084Srdivacky /// HasObjectMember - This is true if this struct has at least one member 2890234353Sdim /// containing an Objective-C object pointer type. 2891198092Srdivacky bool HasObjectMember : 1; 2892249423Sdim 2893249423Sdim /// HasVolatileMember - This is true if struct has at least one member of 2894249423Sdim /// 'volatile' type. 2895249423Sdim bool HasVolatileMember : 1; 2896198092Srdivacky 2897218893Sdim /// \brief Whether the field declarations of this record have been loaded 2898218893Sdim /// from external storage. To avoid unnecessary deserialization of 2899218893Sdim /// methods/nested types we allow deserialization of just the fields 2900218893Sdim /// when needed. 2901218893Sdim mutable bool LoadedFieldsFromExternalStorage : 1; 2902218893Sdim friend class DeclContext; 2903218893Sdim 2904193326Sedprotected: 2905193326Sed RecordDecl(Kind DK, TagKind TK, DeclContext *DC, 2906221345Sdim SourceLocation StartLoc, SourceLocation IdLoc, 2907221345Sdim IdentifierInfo *Id, RecordDecl *PrevDecl); 2908193326Sed 2909193326Sedpublic: 2910218893Sdim static RecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC, 2911221345Sdim SourceLocation StartLoc, SourceLocation IdLoc, 2912221345Sdim IdentifierInfo *Id, RecordDecl* PrevDecl = 0); 2913234353Sdim static RecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID); 2914193326Sed 2915234353Sdim const RecordDecl *getPreviousDecl() const { 2916234353Sdim return cast_or_null<RecordDecl>(TagDecl::getPreviousDecl()); 2917210299Sed } 2918234353Sdim RecordDecl *getPreviousDecl() { 2919234353Sdim return cast_or_null<RecordDecl>(TagDecl::getPreviousDecl()); 2920210299Sed } 2921210299Sed 2922234353Sdim const RecordDecl *getMostRecentDecl() const { 2923234353Sdim return cast<RecordDecl>(TagDecl::getMostRecentDecl()); 2924234353Sdim } 2925234353Sdim RecordDecl *getMostRecentDecl() { 2926234353Sdim return cast<RecordDecl>(TagDecl::getMostRecentDecl()); 2927234353Sdim } 2928234353Sdim 2929193326Sed bool hasFlexibleArrayMember() const { return HasFlexibleArrayMember; } 2930193326Sed void setHasFlexibleArrayMember(bool V) { HasFlexibleArrayMember = V; } 2931193326Sed 2932193326Sed /// isAnonymousStructOrUnion - Whether this is an anonymous struct 2933193326Sed /// or union. To be an anonymous struct or union, it must have been 2934193326Sed /// declared without a name and there must be no objects of this 2935193326Sed /// type declared, e.g., 2936193326Sed /// @code 2937193326Sed /// union { int i; float f; }; 2938198092Srdivacky /// @endcode 2939193326Sed /// is an anonymous union but neither of the following are: 2940193326Sed /// @code 2941193326Sed /// union X { int i; float f; }; 2942193326Sed /// union { int i; float f; } obj; 2943193326Sed /// @endcode 2944193326Sed bool isAnonymousStructOrUnion() const { return AnonymousStructOrUnion; } 2945193326Sed void setAnonymousStructOrUnion(bool Anon) { 2946193326Sed AnonymousStructOrUnion = Anon; 2947193326Sed } 2948193326Sed 2949198092Srdivacky bool hasObjectMember() const { return HasObjectMember; } 2950198092Srdivacky void setHasObjectMember (bool val) { HasObjectMember = val; } 2951198092Srdivacky 2952249423Sdim bool hasVolatileMember() const { return HasVolatileMember; } 2953249423Sdim void setHasVolatileMember (bool val) { HasVolatileMember = val; } 2954249423Sdim 2955193326Sed /// \brief Determines whether this declaration represents the 2956193326Sed /// injected class name. 2957193326Sed /// 2958193326Sed /// The injected class name in C++ is the name of the class that 2959193326Sed /// appears inside the class itself. For example: 2960193326Sed /// 2961193326Sed /// \code 2962193326Sed /// struct C { 2963193326Sed /// // C is implicitly declared here as a synonym for the class name. 2964193326Sed /// }; 2965193326Sed /// 2966193326Sed /// C::C c; // same as "C c;" 2967193326Sed /// \endcode 2968193326Sed bool isInjectedClassName() const; 2969193326Sed 2970226633Sdim /// getDefinition - Returns the RecordDecl that actually defines 2971226633Sdim /// this struct/union/class. When determining whether or not a 2972226633Sdim /// struct/union/class is completely defined, one should use this 2973226633Sdim /// method as opposed to 'isCompleteDefinition'. 2974226633Sdim /// 'isCompleteDefinition' indicates whether or not a specific 2975226633Sdim /// RecordDecl is a completed definition, not whether or not the 2976226633Sdim /// record type is defined. This method returns NULL if there is 2977226633Sdim /// no RecordDecl that defines the struct/union/tag. 2978226633Sdim RecordDecl *getDefinition() const { 2979203955Srdivacky return cast_or_null<RecordDecl>(TagDecl::getDefinition()); 2980193326Sed } 2981198092Srdivacky 2982193326Sed // Iterator access to field members. The field iterator only visits 2983193326Sed // the non-static data members of this class, ignoring any static 2984193326Sed // data members, functions, constructors, destructors, etc. 2985193326Sed typedef specific_decl_iterator<FieldDecl> field_iterator; 2986193326Sed 2987218893Sdim field_iterator field_begin() const; 2988218893Sdim 2989195341Sed field_iterator field_end() const { 2990218893Sdim return field_iterator(decl_iterator()); 2991193326Sed } 2992193326Sed 2993193326Sed // field_empty - Whether there are any fields (non-static data 2994193326Sed // members) in this record. 2995198092Srdivacky bool field_empty() const { 2996195341Sed return field_begin() == field_end(); 2997193326Sed } 2998193326Sed 2999193326Sed /// completeDefinition - Notes that the definition of this type is 3000193326Sed /// now complete. 3001218893Sdim virtual void completeDefinition(); 3002193326Sed 3003203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 3004203955Srdivacky static bool classofKind(Kind K) { 3005210299Sed return K >= firstRecord && K <= lastRecord; 3006193326Sed } 3007218893Sdim 3008243830Sdim /// isMsStrust - Get whether or not this is an ms_struct which can 3009243830Sdim /// be turned on with an attribute, pragma, or -mms-bitfields 3010243830Sdim /// commandline option. 3011243830Sdim bool isMsStruct(const ASTContext &C) const; 3012243830Sdim 3013218893Sdimprivate: 3014218893Sdim /// \brief Deserialize just the fields. 3015218893Sdim void LoadFieldsFromExternalStorage() const; 3016193326Sed}; 3017193326Sed 3018193326Sedclass FileScopeAsmDecl : public Decl { 3019234353Sdim virtual void anchor(); 3020193326Sed StringLiteral *AsmString; 3021221345Sdim SourceLocation RParenLoc; 3022221345Sdim FileScopeAsmDecl(DeclContext *DC, StringLiteral *asmstring, 3023221345Sdim SourceLocation StartL, SourceLocation EndL) 3024221345Sdim : Decl(FileScopeAsm, DC, StartL), AsmString(asmstring), RParenLoc(EndL) {} 3025193326Sedpublic: 3026193326Sed static FileScopeAsmDecl *Create(ASTContext &C, DeclContext *DC, 3027221345Sdim StringLiteral *Str, SourceLocation AsmLoc, 3028221345Sdim SourceLocation RParenLoc); 3029193326Sed 3030234353Sdim static FileScopeAsmDecl *CreateDeserialized(ASTContext &C, unsigned ID); 3031234353Sdim 3032221345Sdim SourceLocation getAsmLoc() const { return getLocation(); } 3033221345Sdim SourceLocation getRParenLoc() const { return RParenLoc; } 3034221345Sdim void setRParenLoc(SourceLocation L) { RParenLoc = L; } 3035234353Sdim SourceRange getSourceRange() const LLVM_READONLY { 3036221345Sdim return SourceRange(getAsmLoc(), getRParenLoc()); 3037221345Sdim } 3038221345Sdim 3039193326Sed const StringLiteral *getAsmString() const { return AsmString; } 3040193326Sed StringLiteral *getAsmString() { return AsmString; } 3041193326Sed void setAsmString(StringLiteral *Asm) { AsmString = Asm; } 3042193326Sed 3043203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 3044203955Srdivacky static bool classofKind(Kind K) { return K == FileScopeAsm; } 3045193326Sed}; 3046193326Sed 3047193326Sed/// BlockDecl - This represents a block literal declaration, which is like an 3048193326Sed/// unnamed FunctionDecl. For example: 3049193326Sed/// ^{ statement-body } or ^(int arg1, float arg2){ statement-body } 3050193326Sed/// 3051193326Sedclass BlockDecl : public Decl, public DeclContext { 3052218893Sdimpublic: 3053218893Sdim /// A class which contains all the information about a particular 3054218893Sdim /// captured value. 3055218893Sdim class Capture { 3056218893Sdim enum { 3057218893Sdim flag_isByRef = 0x1, 3058218893Sdim flag_isNested = 0x2 3059218893Sdim }; 3060218893Sdim 3061218893Sdim /// The variable being captured. 3062218893Sdim llvm::PointerIntPair<VarDecl*, 2> VariableAndFlags; 3063218893Sdim 3064218893Sdim /// The copy expression, expressed in terms of a DeclRef (or 3065218893Sdim /// BlockDeclRef) to the captured variable. Only required if the 3066218893Sdim /// variable has a C++ class type. 3067218893Sdim Expr *CopyExpr; 3068218893Sdim 3069218893Sdim public: 3070218893Sdim Capture(VarDecl *variable, bool byRef, bool nested, Expr *copy) 3071218893Sdim : VariableAndFlags(variable, 3072218893Sdim (byRef ? flag_isByRef : 0) | (nested ? flag_isNested : 0)), 3073218893Sdim CopyExpr(copy) {} 3074218893Sdim 3075218893Sdim /// The variable being captured. 3076218893Sdim VarDecl *getVariable() const { return VariableAndFlags.getPointer(); } 3077218893Sdim 3078218893Sdim /// Whether this is a "by ref" capture, i.e. a capture of a __block 3079218893Sdim /// variable. 3080218893Sdim bool isByRef() const { return VariableAndFlags.getInt() & flag_isByRef; } 3081218893Sdim 3082218893Sdim /// Whether this is a nested capture, i.e. the variable captured 3083218893Sdim /// is not from outside the immediately enclosing function/block. 3084218893Sdim bool isNested() const { return VariableAndFlags.getInt() & flag_isNested; } 3085218893Sdim 3086218893Sdim bool hasCopyExpr() const { return CopyExpr != 0; } 3087218893Sdim Expr *getCopyExpr() const { return CopyExpr; } 3088218893Sdim void setCopyExpr(Expr *e) { CopyExpr = e; } 3089218893Sdim }; 3090218893Sdim 3091218893Sdimprivate: 3092193326Sed // FIXME: This can be packed into the bitfields in Decl. 3093207619Srdivacky bool IsVariadic : 1; 3094218893Sdim bool CapturesCXXThis : 1; 3095234353Sdim bool BlockMissingReturnType : 1; 3096234353Sdim bool IsConversionFromLambda : 1; 3097193326Sed /// ParamInfo - new[]'d array of pointers to ParmVarDecls for the formal 3098193326Sed /// parameters of this function. This is null if a prototype or if there are 3099193326Sed /// no formals. 3100193326Sed ParmVarDecl **ParamInfo; 3101193326Sed unsigned NumParams; 3102198092Srdivacky 3103193326Sed Stmt *Body; 3104210299Sed TypeSourceInfo *SignatureAsWritten; 3105198092Srdivacky 3106218893Sdim Capture *Captures; 3107218893Sdim unsigned NumCaptures; 3108218893Sdim 3109193326Sedprotected: 3110193326Sed BlockDecl(DeclContext *DC, SourceLocation CaretLoc) 3111198092Srdivacky : Decl(Block, DC, CaretLoc), DeclContext(Block), 3112218893Sdim IsVariadic(false), CapturesCXXThis(false), 3113234353Sdim BlockMissingReturnType(true), IsConversionFromLambda(false), 3114218893Sdim ParamInfo(0), NumParams(0), Body(0), 3115218893Sdim SignatureAsWritten(0), Captures(0), NumCaptures(0) {} 3116193326Sed 3117193326Sedpublic: 3118234353Sdim static BlockDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L); 3119234353Sdim static BlockDecl *CreateDeserialized(ASTContext &C, unsigned ID); 3120234353Sdim 3121193326Sed SourceLocation getCaretLocation() const { return getLocation(); } 3122193326Sed 3123207619Srdivacky bool isVariadic() const { return IsVariadic; } 3124207619Srdivacky void setIsVariadic(bool value) { IsVariadic = value; } 3125198092Srdivacky 3126195341Sed CompoundStmt *getCompoundBody() const { return (CompoundStmt*) Body; } 3127195341Sed Stmt *getBody() const { return (Stmt*) Body; } 3128193326Sed void setBody(CompoundStmt *B) { Body = (Stmt*) B; } 3129193326Sed 3130210299Sed void setSignatureAsWritten(TypeSourceInfo *Sig) { SignatureAsWritten = Sig; } 3131210299Sed TypeSourceInfo *getSignatureAsWritten() const { return SignatureAsWritten; } 3132210299Sed 3133193326Sed // Iterator access to formal parameters. 3134193326Sed unsigned param_size() const { return getNumParams(); } 3135193326Sed typedef ParmVarDecl **param_iterator; 3136193326Sed typedef ParmVarDecl * const *param_const_iterator; 3137198092Srdivacky 3138193326Sed bool param_empty() const { return NumParams == 0; } 3139193326Sed param_iterator param_begin() { return ParamInfo; } 3140193326Sed param_iterator param_end() { return ParamInfo+param_size(); } 3141198092Srdivacky 3142193326Sed param_const_iterator param_begin() const { return ParamInfo; } 3143193326Sed param_const_iterator param_end() const { return ParamInfo+param_size(); } 3144198092Srdivacky 3145218893Sdim unsigned getNumParams() const { return NumParams; } 3146193326Sed const ParmVarDecl *getParamDecl(unsigned i) const { 3147193326Sed assert(i < getNumParams() && "Illegal param #"); 3148193326Sed return ParamInfo[i]; 3149193326Sed } 3150193326Sed ParmVarDecl *getParamDecl(unsigned i) { 3151193326Sed assert(i < getNumParams() && "Illegal param #"); 3152193326Sed return ParamInfo[i]; 3153193326Sed } 3154249423Sdim void setParams(ArrayRef<ParmVarDecl *> NewParamInfo); 3155198092Srdivacky 3156218893Sdim /// hasCaptures - True if this block (or its nested blocks) captures 3157218893Sdim /// anything of local storage from its enclosing scopes. 3158218893Sdim bool hasCaptures() const { return NumCaptures != 0 || CapturesCXXThis; } 3159218893Sdim 3160218893Sdim /// getNumCaptures - Returns the number of captured variables. 3161218893Sdim /// Does not include an entry for 'this'. 3162218893Sdim unsigned getNumCaptures() const { return NumCaptures; } 3163218893Sdim 3164218893Sdim typedef const Capture *capture_iterator; 3165218893Sdim typedef const Capture *capture_const_iterator; 3166218893Sdim capture_iterator capture_begin() { return Captures; } 3167218893Sdim capture_iterator capture_end() { return Captures + NumCaptures; } 3168218893Sdim capture_const_iterator capture_begin() const { return Captures; } 3169218893Sdim capture_const_iterator capture_end() const { return Captures + NumCaptures; } 3170218893Sdim 3171218893Sdim bool capturesCXXThis() const { return CapturesCXXThis; } 3172234353Sdim bool blockMissingReturnType() const { return BlockMissingReturnType; } 3173234353Sdim void setBlockMissingReturnType(bool val) { BlockMissingReturnType = val; } 3174218893Sdim 3175234353Sdim bool isConversionFromLambda() const { return IsConversionFromLambda; } 3176234353Sdim void setIsConversionFromLambda(bool val) { IsConversionFromLambda = val; } 3177234353Sdim 3178224145Sdim bool capturesVariable(const VarDecl *var) const; 3179224145Sdim 3180218893Sdim void setCaptures(ASTContext &Context, 3181218893Sdim const Capture *begin, 3182218893Sdim const Capture *end, 3183218893Sdim bool capturesCXXThis); 3184218893Sdim 3185234353Sdim virtual SourceRange getSourceRange() const LLVM_READONLY; 3186234353Sdim 3187193326Sed // Implement isa/cast/dyncast/etc. 3188203955Srdivacky static bool classof(const Decl *D) { return classofKind(D->getKind()); } 3189203955Srdivacky static bool classofKind(Kind K) { return K == Block; } 3190193326Sed static DeclContext *castToDeclContext(const BlockDecl *D) { 3191193326Sed return static_cast<DeclContext *>(const_cast<BlockDecl*>(D)); 3192193326Sed } 3193193326Sed static BlockDecl *castFromDeclContext(const DeclContext *DC) { 3194193326Sed return static_cast<BlockDecl *>(const_cast<DeclContext*>(DC)); 3195193326Sed } 3196193326Sed}; 3197193326Sed 3198251662Sdim/// \brief This represents the body of a CapturedStmt, and serves as its 3199251662Sdim/// DeclContext. 3200251662Sdimclass CapturedDecl : public Decl, public DeclContext { 3201251662Sdimprivate: 3202251662Sdim /// \brief The number of parameters to the outlined function. 3203251662Sdim unsigned NumParams; 3204251662Sdim /// \brief The body of the outlined function. 3205251662Sdim Stmt *Body; 3206251662Sdim 3207251662Sdim explicit CapturedDecl(DeclContext *DC, unsigned NumParams) 3208251662Sdim : Decl(Captured, DC, SourceLocation()), DeclContext(Captured), 3209251662Sdim NumParams(NumParams), Body(0) { } 3210251662Sdim 3211251662Sdim ImplicitParamDecl **getParams() const { 3212251662Sdim return reinterpret_cast<ImplicitParamDecl **>( 3213251662Sdim const_cast<CapturedDecl *>(this) + 1); 3214251662Sdim } 3215251662Sdim 3216251662Sdimpublic: 3217251662Sdim static CapturedDecl *Create(ASTContext &C, DeclContext *DC, unsigned NumParams); 3218251662Sdim static CapturedDecl *CreateDeserialized(ASTContext &C, unsigned ID, 3219251662Sdim unsigned NumParams); 3220251662Sdim 3221251662Sdim Stmt *getBody() const { return Body; } 3222251662Sdim void setBody(Stmt *B) { Body = B; } 3223251662Sdim 3224251662Sdim unsigned getNumParams() const { return NumParams; } 3225251662Sdim 3226251662Sdim ImplicitParamDecl *getParam(unsigned i) const { 3227251662Sdim assert(i < NumParams); 3228251662Sdim return getParams()[i]; 3229251662Sdim } 3230251662Sdim void setParam(unsigned i, ImplicitParamDecl *P) { 3231251662Sdim assert(i < NumParams); 3232251662Sdim getParams()[i] = P; 3233251662Sdim } 3234251662Sdim 3235251662Sdim /// \brief Retrieve the parameter containing captured variables. 3236251662Sdim ImplicitParamDecl *getContextParam() const { return getParam(0); } 3237251662Sdim void setContextParam(ImplicitParamDecl *P) { setParam(0, P); } 3238251662Sdim 3239251662Sdim typedef ImplicitParamDecl **param_iterator; 3240251662Sdim /// \brief Retrieve an iterator pointing to the first parameter decl. 3241251662Sdim param_iterator param_begin() const { return getParams(); } 3242251662Sdim /// \brief Retrieve an iterator one past the last parameter decl. 3243251662Sdim param_iterator param_end() const { return getParams() + NumParams; } 3244251662Sdim 3245251662Sdim // Implement isa/cast/dyncast/etc. 3246251662Sdim static bool classof(const Decl *D) { return classofKind(D->getKind()); } 3247251662Sdim static bool classofKind(Kind K) { return K == Captured; } 3248251662Sdim static DeclContext *castToDeclContext(const CapturedDecl *D) { 3249251662Sdim return static_cast<DeclContext *>(const_cast<CapturedDecl *>(D)); 3250251662Sdim } 3251251662Sdim static CapturedDecl *castFromDeclContext(const DeclContext *DC) { 3252251662Sdim return static_cast<CapturedDecl *>(const_cast<DeclContext *>(DC)); 3253251662Sdim } 3254251662Sdim 3255251662Sdim friend class ASTDeclReader; 3256251662Sdim friend class ASTDeclWriter; 3257251662Sdim}; 3258251662Sdim 3259234353Sdim/// \brief Describes a module import declaration, which makes the contents 3260234353Sdim/// of the named module visible in the current translation unit. 3261234353Sdim/// 3262234353Sdim/// An import declaration imports the named module (or submodule). For example: 3263234353Sdim/// \code 3264249423Sdim/// @import std.vector; 3265234353Sdim/// \endcode 3266234353Sdim/// 3267239462Sdim/// Import declarations can also be implicitly generated from 3268239462Sdim/// \#include/\#import directives. 3269234353Sdimclass ImportDecl : public Decl { 3270234353Sdim /// \brief The imported module, along with a bit that indicates whether 3271234353Sdim /// we have source-location information for each identifier in the module 3272234353Sdim /// name. 3273234353Sdim /// 3274234353Sdim /// When the bit is false, we only have a single source location for the 3275234353Sdim /// end of the import declaration. 3276234353Sdim llvm::PointerIntPair<Module *, 1, bool> ImportedAndComplete; 3277234353Sdim 3278234353Sdim /// \brief The next import in the list of imports local to the translation 3279234353Sdim /// unit being parsed (not loaded from an AST file). 3280234353Sdim ImportDecl *NextLocalImport; 3281234353Sdim 3282234353Sdim friend class ASTReader; 3283234353Sdim friend class ASTDeclReader; 3284234353Sdim friend class ASTContext; 3285234353Sdim 3286234353Sdim ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported, 3287234353Sdim ArrayRef<SourceLocation> IdentifierLocs); 3288234353Sdim 3289234353Sdim ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported, 3290234353Sdim SourceLocation EndLoc); 3291234353Sdim 3292234353Sdim ImportDecl(EmptyShell Empty) : Decl(Import, Empty), NextLocalImport() { } 3293234353Sdim 3294234353Sdimpublic: 3295234353Sdim /// \brief Create a new module import declaration. 3296234353Sdim static ImportDecl *Create(ASTContext &C, DeclContext *DC, 3297234353Sdim SourceLocation StartLoc, Module *Imported, 3298234353Sdim ArrayRef<SourceLocation> IdentifierLocs); 3299234353Sdim 3300234353Sdim /// \brief Create a new module import declaration for an implicitly-generated 3301234353Sdim /// import. 3302234353Sdim static ImportDecl *CreateImplicit(ASTContext &C, DeclContext *DC, 3303234353Sdim SourceLocation StartLoc, Module *Imported, 3304234353Sdim SourceLocation EndLoc); 3305234353Sdim 3306234353Sdim /// \brief Create a new, deserialized module import declaration. 3307234353Sdim static ImportDecl *CreateDeserialized(ASTContext &C, unsigned ID, 3308234353Sdim unsigned NumLocations); 3309234353Sdim 3310234353Sdim /// \brief Retrieve the module that was imported by the import declaration. 3311234353Sdim Module *getImportedModule() const { return ImportedAndComplete.getPointer(); } 3312234353Sdim 3313234353Sdim /// \brief Retrieves the locations of each of the identifiers that make up 3314234353Sdim /// the complete module name in the import declaration. 3315234353Sdim /// 3316234353Sdim /// This will return an empty array if the locations of the individual 3317234353Sdim /// identifiers aren't available. 3318234353Sdim ArrayRef<SourceLocation> getIdentifierLocs() const; 3319234353Sdim 3320234353Sdim virtual SourceRange getSourceRange() const LLVM_READONLY; 3321234353Sdim 3322234353Sdim static bool classof(const Decl *D) { return classofKind(D->getKind()); } 3323234353Sdim static bool classofKind(Kind K) { return K == Import; } 3324234353Sdim}; 3325234353Sdim 3326249423Sdim/// \brief Represents an empty-declaration. 3327249423Sdimclass EmptyDecl : public Decl { 3328249423Sdim virtual void anchor(); 3329249423Sdim EmptyDecl(DeclContext *DC, SourceLocation L) 3330249423Sdim : Decl(Empty, DC, L) { } 3331249423Sdim 3332249423Sdimpublic: 3333249423Sdim static EmptyDecl *Create(ASTContext &C, DeclContext *DC, 3334249423Sdim SourceLocation L); 3335249423Sdim static EmptyDecl *CreateDeserialized(ASTContext &C, unsigned ID); 3336249423Sdim 3337249423Sdim static bool classof(const Decl *D) { return classofKind(D->getKind()); } 3338249423Sdim static bool classofKind(Kind K) { return K == Empty; } 3339249423Sdim}; 3340249423Sdim 3341193326Sed/// Insertion operator for diagnostics. This allows sending NamedDecl's 3342193326Sed/// into a diagnostic with <<. 3343193326Sedinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 3344226633Sdim const NamedDecl* ND) { 3345226633Sdim DB.AddTaggedVal(reinterpret_cast<intptr_t>(ND), 3346226633Sdim DiagnosticsEngine::ak_nameddecl); 3347193326Sed return DB; 3348193326Sed} 3349234353Sdiminline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD, 3350234353Sdim const NamedDecl* ND) { 3351234353Sdim PD.AddTaggedVal(reinterpret_cast<intptr_t>(ND), 3352234353Sdim DiagnosticsEngine::ak_nameddecl); 3353234353Sdim return PD; 3354234353Sdim} 3355193326Sed 3356218893Sdimtemplate<typename decl_type> 3357218893Sdimvoid Redeclarable<decl_type>::setPreviousDeclaration(decl_type *PrevDecl) { 3358218893Sdim // Note: This routine is implemented here because we need both NamedDecl 3359218893Sdim // and Redeclarable to be defined. 3360218893Sdim 3361218893Sdim decl_type *First; 3362234353Sdim 3363218893Sdim if (PrevDecl) { 3364218893Sdim // Point to previous. Make sure that this is actually the most recent 3365218893Sdim // redeclaration, or we can build invalid chains. If the most recent 3366218893Sdim // redeclaration is invalid, it won't be PrevDecl, but we want it anyway. 3367218893Sdim First = PrevDecl->getFirstDeclaration(); 3368218893Sdim assert(First->RedeclLink.NextIsLatest() && "Expected first"); 3369249423Sdim decl_type *MostRecent = First->RedeclLink.getNext(); 3370249423Sdim RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent)); 3371218893Sdim } else { 3372218893Sdim // Make this first. 3373218893Sdim First = static_cast<decl_type*>(this); 3374218893Sdim } 3375234353Sdim 3376218893Sdim // First one will point to this one as latest. 3377218893Sdim First->RedeclLink = LatestDeclLink(static_cast<decl_type*>(this)); 3378249423Sdim assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) || 3379249423Sdim cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid()); 3380218893Sdim} 3381218893Sdim 3382234353Sdim// Inline function definitions. 3383234353Sdim 3384234353Sdim/// \brief Check if the given decl is complete. 3385234353Sdim/// 3386234353Sdim/// We use this function to break a cycle between the inline definitions in 3387234353Sdim/// Type.h and Decl.h. 3388234353Sdiminline bool IsEnumDeclComplete(EnumDecl *ED) { 3389234353Sdim return ED->isComplete(); 3390234353Sdim} 3391234353Sdim 3392234353Sdim/// \brief Check if the given decl is scoped. 3393234353Sdim/// 3394234353Sdim/// We use this function to break a cycle between the inline definitions in 3395234353Sdim/// Type.h and Decl.h. 3396234353Sdiminline bool IsEnumDeclScoped(EnumDecl *ED) { 3397234353Sdim return ED->isScoped(); 3398234353Sdim} 3399234353Sdim 3400193326Sed} // end namespace clang 3401193326Sed 3402193326Sed#endif 3403