Decl.h revision 1f7fd68131872707a297335e6bc71beef47f9d73
1//===--- Decl.h - Classes for representing declarations ---------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file defines the Decl subclasses. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef LLVM_CLANG_AST_DECL_H 15#define LLVM_CLANG_AST_DECL_H 16 17#include "clang/AST/APValue.h" 18#include "clang/AST/DeclBase.h" 19#include "clang/AST/DeclarationName.h" 20#include "clang/AST/ExternalASTSource.h" 21#include "clang/AST/Redeclarable.h" 22#include "clang/AST/Type.h" 23#include "clang/Basic/Linkage.h" 24#include "llvm/ADT/ArrayRef.h" 25#include "llvm/ADT/Optional.h" 26#include "llvm/Support/Compiler.h" 27#include "llvm/Support/raw_ostream.h" 28 29namespace clang { 30struct ASTTemplateArgumentListInfo; 31class CXXTemporary; 32class CompoundStmt; 33class DependentFunctionTemplateSpecializationInfo; 34class Expr; 35class FunctionTemplateDecl; 36class FunctionTemplateSpecializationInfo; 37class LabelStmt; 38class MemberSpecializationInfo; 39class Module; 40class NestedNameSpecifier; 41class Stmt; 42class StringLiteral; 43class TemplateArgumentList; 44class TemplateParameterList; 45class TypeLoc; 46class UnresolvedSetImpl; 47class VarTemplateDecl; 48 49/// \brief A container of type source information. 50/// 51/// A client can read the relevant info using TypeLoc wrappers, e.g: 52/// @code 53/// TypeLoc TL = TypeSourceInfo->getTypeLoc(); 54/// if (PointerLoc *PL = dyn_cast<PointerLoc>(&TL)) 55/// PL->getStarLoc().print(OS, SrcMgr); 56/// @endcode 57/// 58class TypeSourceInfo { 59 QualType Ty; 60 // Contains a memory block after the class, used for type source information, 61 // allocated by ASTContext. 62 friend class ASTContext; 63 TypeSourceInfo(QualType ty) : Ty(ty) { } 64public: 65 /// \brief Return the type wrapped by this type source info. 66 QualType getType() const { return Ty; } 67 68 /// \brief Return the TypeLoc wrapper for the type source info. 69 TypeLoc getTypeLoc() const; // implemented in TypeLoc.h 70}; 71 72/// TranslationUnitDecl - The top declaration context. 73class TranslationUnitDecl : public Decl, public DeclContext { 74 virtual void anchor(); 75 ASTContext &Ctx; 76 77 /// The (most recently entered) anonymous namespace for this 78 /// translation unit, if one has been created. 79 NamespaceDecl *AnonymousNamespace; 80 81 explicit TranslationUnitDecl(ASTContext &ctx) 82 : Decl(TranslationUnit, 0, SourceLocation()), 83 DeclContext(TranslationUnit), 84 Ctx(ctx), AnonymousNamespace(0) {} 85public: 86 ASTContext &getASTContext() const { return Ctx; } 87 88 NamespaceDecl *getAnonymousNamespace() const { return AnonymousNamespace; } 89 void setAnonymousNamespace(NamespaceDecl *D) { AnonymousNamespace = D; } 90 91 static TranslationUnitDecl *Create(ASTContext &C); 92 // Implement isa/cast/dyncast/etc. 93 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 94 static bool classofKind(Kind K) { return K == TranslationUnit; } 95 static DeclContext *castToDeclContext(const TranslationUnitDecl *D) { 96 return static_cast<DeclContext *>(const_cast<TranslationUnitDecl*>(D)); 97 } 98 static TranslationUnitDecl *castFromDeclContext(const DeclContext *DC) { 99 return static_cast<TranslationUnitDecl *>(const_cast<DeclContext*>(DC)); 100 } 101}; 102 103/// NamedDecl - This represents a decl with a name. Many decls have names such 104/// as ObjCMethodDecl, but not \@class, etc. 105class NamedDecl : public Decl { 106 virtual void anchor(); 107 /// Name - The name of this declaration, which is typically a normal 108 /// identifier but may also be a special kind of name (C++ 109 /// constructor, Objective-C selector, etc.) 110 DeclarationName Name; 111 112private: 113 NamedDecl *getUnderlyingDeclImpl(); 114 115protected: 116 NamedDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N) 117 : Decl(DK, DC, L), Name(N) { } 118 119public: 120 /// getIdentifier - Get the identifier that names this declaration, 121 /// if there is one. This will return NULL if this declaration has 122 /// no name (e.g., for an unnamed class) or if the name is a special 123 /// name (C++ constructor, Objective-C selector, etc.). 124 IdentifierInfo *getIdentifier() const { return Name.getAsIdentifierInfo(); } 125 126 /// getName - Get the name of identifier for this declaration as a StringRef. 127 /// This requires that the declaration have a name and that it be a simple 128 /// identifier. 129 StringRef getName() const { 130 assert(Name.isIdentifier() && "Name is not a simple identifier"); 131 return getIdentifier() ? getIdentifier()->getName() : ""; 132 } 133 134 /// getNameAsString - Get a human-readable name for the declaration, even if 135 /// it is one of the special kinds of names (C++ constructor, Objective-C 136 /// selector, etc). Creating this name requires expensive string 137 /// manipulation, so it should be called only when performance doesn't matter. 138 /// For simple declarations, getNameAsCString() should suffice. 139 // 140 // FIXME: This function should be renamed to indicate that it is not just an 141 // alternate form of getName(), and clients should move as appropriate. 142 // 143 // FIXME: Deprecated, move clients to getName(). 144 std::string getNameAsString() const { return Name.getAsString(); } 145 146 void printName(raw_ostream &os) const { os << Name; } 147 148 /// getDeclName - Get the actual, stored name of the declaration, 149 /// which may be a special name. 150 DeclarationName getDeclName() const { return Name; } 151 152 /// \brief Set the name of this declaration. 153 void setDeclName(DeclarationName N) { Name = N; } 154 155 /// printQualifiedName - Returns human-readable qualified name for 156 /// declaration, like A::B::i, for i being member of namespace A::B. 157 /// If declaration is not member of context which can be named (record, 158 /// namespace), it will return same result as printName(). 159 /// Creating this name is expensive, so it should be called only when 160 /// performance doesn't matter. 161 void printQualifiedName(raw_ostream &OS) const; 162 void printQualifiedName(raw_ostream &OS, const PrintingPolicy &Policy) const; 163 164 // FIXME: Remove string versions. 165 std::string getQualifiedNameAsString() const; 166 std::string getQualifiedNameAsString(const PrintingPolicy &Policy) const; 167 168 /// getNameForDiagnostic - Appends a human-readable name for this 169 /// declaration into the given stream. 170 /// 171 /// This is the method invoked by Sema when displaying a NamedDecl 172 /// in a diagnostic. It does not necessarily produce the same 173 /// result as printName(); for example, class template 174 /// specializations are printed with their template arguments. 175 virtual void getNameForDiagnostic(raw_ostream &OS, 176 const PrintingPolicy &Policy, 177 bool Qualified) const; 178 179 /// declarationReplaces - Determine whether this declaration, if 180 /// known to be well-formed within its context, will replace the 181 /// declaration OldD if introduced into scope. A declaration will 182 /// replace another declaration if, for example, it is a 183 /// redeclaration of the same variable or function, but not if it is 184 /// a declaration of a different kind (function vs. class) or an 185 /// overloaded function. 186 bool declarationReplaces(NamedDecl *OldD) const; 187 188 /// \brief Determine whether this declaration has linkage. 189 bool hasLinkage() const; 190 191 using Decl::isModulePrivate; 192 using Decl::setModulePrivate; 193 194 /// \brief Determine whether this declaration is hidden from name lookup. 195 bool isHidden() const { return Hidden; } 196 197 /// \brief Set whether this declaration is hidden from name lookup. 198 void setHidden(bool Hide) { Hidden = Hide; } 199 200 /// \brief Determine whether this declaration is a C++ class member. 201 bool isCXXClassMember() const { 202 const DeclContext *DC = getDeclContext(); 203 204 // C++0x [class.mem]p1: 205 // The enumerators of an unscoped enumeration defined in 206 // the class are members of the class. 207 // FIXME: support C++0x scoped enumerations. 208 if (isa<EnumDecl>(DC)) 209 DC = DC->getParent(); 210 211 return DC->isRecord(); 212 } 213 214 /// \brief Determine whether the given declaration is an instance member of 215 /// a C++ class. 216 bool isCXXInstanceMember() const; 217 218 /// \brief Determine what kind of linkage this entity has. 219 /// This is not the linkage as defined by the standard or the codegen notion 220 /// of linkage. It is just an implementation detail that is used to compute 221 /// those. 222 Linkage getLinkageInternal() const; 223 224 /// \brief Get the linkage from a semantic point of view. Entities in 225 /// anonymous namespaces are external (in c++98). 226 Linkage getFormalLinkage() const { 227 return clang::getFormalLinkage(getLinkageInternal()); 228 } 229 230 /// \brief True if this decl has external linkage. 231 bool hasExternalFormalLinkage() const { 232 return isExternalFormalLinkage(getLinkageInternal()); 233 } 234 235 bool isExternallyVisible() const { 236 return clang::isExternallyVisible(getLinkageInternal()); 237 } 238 239 /// \brief Determines the visibility of this entity. 240 Visibility getVisibility() const { 241 return getLinkageAndVisibility().getVisibility(); 242 } 243 244 /// \brief Determines the linkage and visibility of this entity. 245 LinkageInfo getLinkageAndVisibility() const; 246 247 /// Kinds of explicit visibility. 248 enum ExplicitVisibilityKind { 249 VisibilityForType, 250 VisibilityForValue 251 }; 252 253 /// \brief If visibility was explicitly specified for this 254 /// declaration, return that visibility. 255 Optional<Visibility> 256 getExplicitVisibility(ExplicitVisibilityKind kind) const; 257 258 /// \brief True if the computed linkage is valid. Used for consistency 259 /// checking. Should always return true. 260 bool isLinkageValid() const; 261 262 /// \brief Looks through UsingDecls and ObjCCompatibleAliasDecls for 263 /// the underlying named decl. 264 NamedDecl *getUnderlyingDecl() { 265 // Fast-path the common case. 266 if (this->getKind() != UsingShadow && 267 this->getKind() != ObjCCompatibleAlias) 268 return this; 269 270 return getUnderlyingDeclImpl(); 271 } 272 const NamedDecl *getUnderlyingDecl() const { 273 return const_cast<NamedDecl*>(this)->getUnderlyingDecl(); 274 } 275 276 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 277 static bool classofKind(Kind K) { return K >= firstNamed && K <= lastNamed; } 278}; 279 280inline raw_ostream &operator<<(raw_ostream &OS, const NamedDecl &ND) { 281 ND.printName(OS); 282 return OS; 283} 284 285/// LabelDecl - Represents the declaration of a label. Labels also have a 286/// corresponding LabelStmt, which indicates the position that the label was 287/// defined at. For normal labels, the location of the decl is the same as the 288/// location of the statement. For GNU local labels (__label__), the decl 289/// location is where the __label__ is. 290class LabelDecl : public NamedDecl { 291 virtual void anchor(); 292 LabelStmt *TheStmt; 293 /// LocStart - For normal labels, this is the same as the main declaration 294 /// label, i.e., the location of the identifier; for GNU local labels, 295 /// this is the location of the __label__ keyword. 296 SourceLocation LocStart; 297 298 LabelDecl(DeclContext *DC, SourceLocation IdentL, IdentifierInfo *II, 299 LabelStmt *S, SourceLocation StartL) 300 : NamedDecl(Label, DC, IdentL, II), TheStmt(S), LocStart(StartL) {} 301 302public: 303 static LabelDecl *Create(ASTContext &C, DeclContext *DC, 304 SourceLocation IdentL, IdentifierInfo *II); 305 static LabelDecl *Create(ASTContext &C, DeclContext *DC, 306 SourceLocation IdentL, IdentifierInfo *II, 307 SourceLocation GnuLabelL); 308 static LabelDecl *CreateDeserialized(ASTContext &C, unsigned ID); 309 310 LabelStmt *getStmt() const { return TheStmt; } 311 void setStmt(LabelStmt *T) { TheStmt = T; } 312 313 bool isGnuLocal() const { return LocStart != getLocation(); } 314 void setLocStart(SourceLocation L) { LocStart = L; } 315 316 SourceRange getSourceRange() const LLVM_READONLY { 317 return SourceRange(LocStart, getLocation()); 318 } 319 320 // Implement isa/cast/dyncast/etc. 321 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 322 static bool classofKind(Kind K) { return K == Label; } 323}; 324 325/// NamespaceDecl - Represent a C++ namespace. 326class NamespaceDecl : public NamedDecl, public DeclContext, 327 public Redeclarable<NamespaceDecl> 328{ 329 virtual void anchor(); 330 331 /// LocStart - The starting location of the source range, pointing 332 /// to either the namespace or the inline keyword. 333 SourceLocation LocStart; 334 /// RBraceLoc - The ending location of the source range. 335 SourceLocation RBraceLoc; 336 337 /// \brief A pointer to either the anonymous namespace that lives just inside 338 /// this namespace or to the first namespace in the chain (the latter case 339 /// only when this is not the first in the chain), along with a 340 /// boolean value indicating whether this is an inline namespace. 341 llvm::PointerIntPair<NamespaceDecl *, 1, bool> AnonOrFirstNamespaceAndInline; 342 343 NamespaceDecl(DeclContext *DC, bool Inline, SourceLocation StartLoc, 344 SourceLocation IdLoc, IdentifierInfo *Id, 345 NamespaceDecl *PrevDecl); 346 347 typedef Redeclarable<NamespaceDecl> redeclarable_base; 348 virtual NamespaceDecl *getNextRedeclaration() { 349 return RedeclLink.getNext(); 350 } 351 virtual NamespaceDecl *getPreviousDeclImpl() { 352 return getPreviousDecl(); 353 } 354 virtual NamespaceDecl *getMostRecentDeclImpl() { 355 return getMostRecentDecl(); 356 } 357 358public: 359 static NamespaceDecl *Create(ASTContext &C, DeclContext *DC, 360 bool Inline, SourceLocation StartLoc, 361 SourceLocation IdLoc, IdentifierInfo *Id, 362 NamespaceDecl *PrevDecl); 363 364 static NamespaceDecl *CreateDeserialized(ASTContext &C, unsigned ID); 365 366 typedef redeclarable_base::redecl_iterator redecl_iterator; 367 using redeclarable_base::redecls_begin; 368 using redeclarable_base::redecls_end; 369 using redeclarable_base::getPreviousDecl; 370 using redeclarable_base::getMostRecentDecl; 371 372 /// \brief Returns true if this is an anonymous namespace declaration. 373 /// 374 /// For example: 375 /// \code 376 /// namespace { 377 /// ... 378 /// }; 379 /// \endcode 380 /// q.v. C++ [namespace.unnamed] 381 bool isAnonymousNamespace() const { 382 return !getIdentifier(); 383 } 384 385 /// \brief Returns true if this is an inline namespace declaration. 386 bool isInline() const { 387 return AnonOrFirstNamespaceAndInline.getInt(); 388 } 389 390 /// \brief Set whether this is an inline namespace declaration. 391 void setInline(bool Inline) { 392 AnonOrFirstNamespaceAndInline.setInt(Inline); 393 } 394 395 /// \brief Get the original (first) namespace declaration. 396 NamespaceDecl *getOriginalNamespace() { 397 if (isFirstDeclaration()) 398 return this; 399 400 return AnonOrFirstNamespaceAndInline.getPointer(); 401 } 402 403 /// \brief Get the original (first) namespace declaration. 404 const NamespaceDecl *getOriginalNamespace() const { 405 if (isFirstDeclaration()) 406 return this; 407 408 return AnonOrFirstNamespaceAndInline.getPointer(); 409 } 410 411 /// \brief Return true if this declaration is an original (first) declaration 412 /// of the namespace. This is false for non-original (subsequent) namespace 413 /// declarations and anonymous namespaces. 414 bool isOriginalNamespace() const { 415 return isFirstDeclaration(); 416 } 417 418 /// \brief Retrieve the anonymous namespace nested inside this namespace, 419 /// if any. 420 NamespaceDecl *getAnonymousNamespace() const { 421 return getOriginalNamespace()->AnonOrFirstNamespaceAndInline.getPointer(); 422 } 423 424 void setAnonymousNamespace(NamespaceDecl *D) { 425 getOriginalNamespace()->AnonOrFirstNamespaceAndInline.setPointer(D); 426 } 427 428 /// Retrieves the canonical declaration of this namespace. 429 NamespaceDecl *getCanonicalDecl() { 430 return getOriginalNamespace(); 431 } 432 const NamespaceDecl *getCanonicalDecl() const { 433 return getOriginalNamespace(); 434 } 435 436 virtual SourceRange getSourceRange() const LLVM_READONLY { 437 return SourceRange(LocStart, RBraceLoc); 438 } 439 440 SourceLocation getLocStart() const LLVM_READONLY { return LocStart; } 441 SourceLocation getRBraceLoc() const { return RBraceLoc; } 442 void setLocStart(SourceLocation L) { LocStart = L; } 443 void setRBraceLoc(SourceLocation L) { RBraceLoc = L; } 444 445 // Implement isa/cast/dyncast/etc. 446 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 447 static bool classofKind(Kind K) { return K == Namespace; } 448 static DeclContext *castToDeclContext(const NamespaceDecl *D) { 449 return static_cast<DeclContext *>(const_cast<NamespaceDecl*>(D)); 450 } 451 static NamespaceDecl *castFromDeclContext(const DeclContext *DC) { 452 return static_cast<NamespaceDecl *>(const_cast<DeclContext*>(DC)); 453 } 454 455 friend class ASTDeclReader; 456 friend class ASTDeclWriter; 457}; 458 459/// ValueDecl - Represent the declaration of a variable (in which case it is 460/// an lvalue) a function (in which case it is a function designator) or 461/// an enum constant. 462class ValueDecl : public NamedDecl { 463 virtual void anchor(); 464 QualType DeclType; 465 466protected: 467 ValueDecl(Kind DK, DeclContext *DC, SourceLocation L, 468 DeclarationName N, QualType T) 469 : NamedDecl(DK, DC, L, N), DeclType(T) {} 470public: 471 QualType getType() const { return DeclType; } 472 void setType(QualType newType) { DeclType = newType; } 473 474 /// \brief Determine whether this symbol is weakly-imported, 475 /// or declared with the weak or weak-ref attr. 476 bool isWeak() const; 477 478 // Implement isa/cast/dyncast/etc. 479 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 480 static bool classofKind(Kind K) { return K >= firstValue && K <= lastValue; } 481}; 482 483/// QualifierInfo - A struct with extended info about a syntactic 484/// name qualifier, to be used for the case of out-of-line declarations. 485struct QualifierInfo { 486 NestedNameSpecifierLoc QualifierLoc; 487 488 /// NumTemplParamLists - The number of "outer" template parameter lists. 489 /// The count includes all of the template parameter lists that were matched 490 /// against the template-ids occurring into the NNS and possibly (in the 491 /// case of an explicit specialization) a final "template <>". 492 unsigned NumTemplParamLists; 493 494 /// TemplParamLists - A new-allocated array of size NumTemplParamLists, 495 /// containing pointers to the "outer" template parameter lists. 496 /// It includes all of the template parameter lists that were matched 497 /// against the template-ids occurring into the NNS and possibly (in the 498 /// case of an explicit specialization) a final "template <>". 499 TemplateParameterList** TemplParamLists; 500 501 /// Default constructor. 502 QualifierInfo() : QualifierLoc(), NumTemplParamLists(0), TemplParamLists(0) {} 503 504 /// setTemplateParameterListsInfo - Sets info about "outer" template 505 /// parameter lists. 506 void setTemplateParameterListsInfo(ASTContext &Context, 507 unsigned NumTPLists, 508 TemplateParameterList **TPLists); 509 510private: 511 // Copy constructor and copy assignment are disabled. 512 QualifierInfo(const QualifierInfo&) LLVM_DELETED_FUNCTION; 513 QualifierInfo& operator=(const QualifierInfo&) LLVM_DELETED_FUNCTION; 514}; 515 516/// \brief Represents a ValueDecl that came out of a declarator. 517/// Contains type source information through TypeSourceInfo. 518class DeclaratorDecl : public ValueDecl { 519 // A struct representing both a TInfo and a syntactic qualifier, 520 // to be used for the (uncommon) case of out-of-line declarations. 521 struct ExtInfo : public QualifierInfo { 522 TypeSourceInfo *TInfo; 523 }; 524 525 llvm::PointerUnion<TypeSourceInfo*, ExtInfo*> DeclInfo; 526 527 /// InnerLocStart - The start of the source range for this declaration, 528 /// ignoring outer template declarations. 529 SourceLocation InnerLocStart; 530 531 bool hasExtInfo() const { return DeclInfo.is<ExtInfo*>(); } 532 ExtInfo *getExtInfo() { return DeclInfo.get<ExtInfo*>(); } 533 const ExtInfo *getExtInfo() const { return DeclInfo.get<ExtInfo*>(); } 534 535protected: 536 DeclaratorDecl(Kind DK, DeclContext *DC, SourceLocation L, 537 DeclarationName N, QualType T, TypeSourceInfo *TInfo, 538 SourceLocation StartL) 539 : ValueDecl(DK, DC, L, N, T), DeclInfo(TInfo), InnerLocStart(StartL) { 540 } 541 542public: 543 TypeSourceInfo *getTypeSourceInfo() const { 544 return hasExtInfo() 545 ? getExtInfo()->TInfo 546 : DeclInfo.get<TypeSourceInfo*>(); 547 } 548 void setTypeSourceInfo(TypeSourceInfo *TI) { 549 if (hasExtInfo()) 550 getExtInfo()->TInfo = TI; 551 else 552 DeclInfo = TI; 553 } 554 555 /// getInnerLocStart - Return SourceLocation representing start of source 556 /// range ignoring outer template declarations. 557 SourceLocation getInnerLocStart() const { return InnerLocStart; } 558 void setInnerLocStart(SourceLocation L) { InnerLocStart = L; } 559 560 /// getOuterLocStart - Return SourceLocation representing start of source 561 /// range taking into account any outer template declarations. 562 SourceLocation getOuterLocStart() const; 563 564 virtual SourceRange getSourceRange() const LLVM_READONLY; 565 SourceLocation getLocStart() const LLVM_READONLY { 566 return getOuterLocStart(); 567 } 568 569 /// \brief Retrieve the nested-name-specifier that qualifies the name of this 570 /// declaration, if it was present in the source. 571 NestedNameSpecifier *getQualifier() const { 572 return hasExtInfo() ? getExtInfo()->QualifierLoc.getNestedNameSpecifier() 573 : 0; 574 } 575 576 /// \brief Retrieve the nested-name-specifier (with source-location 577 /// information) that qualifies the name of this declaration, if it was 578 /// present in the source. 579 NestedNameSpecifierLoc getQualifierLoc() const { 580 return hasExtInfo() ? getExtInfo()->QualifierLoc 581 : NestedNameSpecifierLoc(); 582 } 583 584 void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc); 585 586 unsigned getNumTemplateParameterLists() const { 587 return hasExtInfo() ? getExtInfo()->NumTemplParamLists : 0; 588 } 589 TemplateParameterList *getTemplateParameterList(unsigned index) const { 590 assert(index < getNumTemplateParameterLists()); 591 return getExtInfo()->TemplParamLists[index]; 592 } 593 void setTemplateParameterListsInfo(ASTContext &Context, unsigned NumTPLists, 594 TemplateParameterList **TPLists); 595 596 SourceLocation getTypeSpecStartLoc() const; 597 598 // Implement isa/cast/dyncast/etc. 599 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 600 static bool classofKind(Kind K) { 601 return K >= firstDeclarator && K <= lastDeclarator; 602 } 603 604 friend class ASTDeclReader; 605 friend class ASTDeclWriter; 606}; 607 608/// \brief Structure used to store a statement, the constant value to 609/// which it was evaluated (if any), and whether or not the statement 610/// is an integral constant expression (if known). 611struct EvaluatedStmt { 612 EvaluatedStmt() : WasEvaluated(false), IsEvaluating(false), CheckedICE(false), 613 CheckingICE(false), IsICE(false) { } 614 615 /// \brief Whether this statement was already evaluated. 616 bool WasEvaluated : 1; 617 618 /// \brief Whether this statement is being evaluated. 619 bool IsEvaluating : 1; 620 621 /// \brief Whether we already checked whether this statement was an 622 /// integral constant expression. 623 bool CheckedICE : 1; 624 625 /// \brief Whether we are checking whether this statement is an 626 /// integral constant expression. 627 bool CheckingICE : 1; 628 629 /// \brief Whether this statement is an integral constant expression, 630 /// or in C++11, whether the statement is a constant expression. Only 631 /// valid if CheckedICE is true. 632 bool IsICE : 1; 633 634 Stmt *Value; 635 APValue Evaluated; 636}; 637 638/// VarDecl - An instance of this class is created to represent a variable 639/// declaration or definition. 640class VarDecl : public DeclaratorDecl, public Redeclarable<VarDecl> { 641public: 642 typedef clang::StorageClass StorageClass; 643 644 /// getStorageClassSpecifierString - Return the string used to 645 /// specify the storage class \p SC. 646 /// 647 /// It is illegal to call this function with SC == None. 648 static const char *getStorageClassSpecifierString(StorageClass SC); 649 650 /// \brief Initialization styles. 651 enum InitializationStyle { 652 CInit, ///< C-style initialization with assignment 653 CallInit, ///< Call-style initialization (C++98) 654 ListInit ///< Direct list-initialization (C++11) 655 }; 656 657 /// \brief Kinds of thread-local storage. 658 enum TLSKind { 659 TLS_None, ///< Not a TLS variable. 660 TLS_Static, ///< TLS with a known-constant initializer. 661 TLS_Dynamic ///< TLS with a dynamic initializer. 662 }; 663 664protected: 665 /// \brief Placeholder type used in Init to denote an unparsed C++ default 666 /// argument. 667 struct UnparsedDefaultArgument; 668 669 /// \brief Placeholder type used in Init to denote an uninstantiated C++ 670 /// default argument. 671 struct UninstantiatedDefaultArgument; 672 673 typedef llvm::PointerUnion4<Stmt *, EvaluatedStmt *, 674 UnparsedDefaultArgument *, 675 UninstantiatedDefaultArgument *> InitType; 676 677 /// \brief The initializer for this variable or, for a ParmVarDecl, the 678 /// C++ default argument. 679 mutable InitType Init; 680 681private: 682 class VarDeclBitfields { 683 friend class VarDecl; 684 friend class ASTDeclReader; 685 686 unsigned SClass : 3; 687 unsigned TSCSpec : 2; 688 unsigned InitStyle : 2; 689 690 /// \brief Whether this variable is the exception variable in a C++ catch 691 /// or an Objective-C @catch statement. 692 unsigned ExceptionVar : 1; 693 694 /// \brief Whether this local variable could be allocated in the return 695 /// slot of its function, enabling the named return value optimization 696 /// (NRVO). 697 unsigned NRVOVariable : 1; 698 699 /// \brief Whether this variable is the for-range-declaration in a C++0x 700 /// for-range statement. 701 unsigned CXXForRangeDecl : 1; 702 703 /// \brief Whether this variable is an ARC pseudo-__strong 704 /// variable; see isARCPseudoStrong() for details. 705 unsigned ARCPseudoStrong : 1; 706 707 /// \brief Whether this variable is (C++0x) constexpr. 708 unsigned IsConstexpr : 1; 709 710 /// \brief Whether this local extern variable's previous declaration was 711 /// declared in the same block scope. This controls whether we should merge 712 /// the type of this declaration with its previous declaration. 713 unsigned PreviousDeclInSameBlockScope : 1; 714 }; 715 enum { NumVarDeclBits = 13 }; 716 717 friend class ASTDeclReader; 718 friend class StmtIteratorBase; 719 friend class ASTNodeImporter; 720 721protected: 722 enum { NumParameterIndexBits = 8 }; 723 724 class ParmVarDeclBitfields { 725 friend class ParmVarDecl; 726 friend class ASTDeclReader; 727 728 unsigned : NumVarDeclBits; 729 730 /// Whether this parameter inherits a default argument from a 731 /// prior declaration. 732 unsigned HasInheritedDefaultArg : 1; 733 734 /// Whether this parameter undergoes K&R argument promotion. 735 unsigned IsKNRPromoted : 1; 736 737 /// Whether this parameter is an ObjC method parameter or not. 738 unsigned IsObjCMethodParam : 1; 739 740 /// If IsObjCMethodParam, a Decl::ObjCDeclQualifier. 741 /// Otherwise, the number of function parameter scopes enclosing 742 /// the function parameter scope in which this parameter was 743 /// declared. 744 unsigned ScopeDepthOrObjCQuals : 7; 745 746 /// The number of parameters preceding this parameter in the 747 /// function parameter scope in which it was declared. 748 unsigned ParameterIndex : NumParameterIndexBits; 749 }; 750 751 union { 752 unsigned AllBits; 753 VarDeclBitfields VarDeclBits; 754 ParmVarDeclBitfields ParmVarDeclBits; 755 }; 756 757 VarDecl(Kind DK, DeclContext *DC, SourceLocation StartLoc, 758 SourceLocation IdLoc, IdentifierInfo *Id, QualType T, 759 TypeSourceInfo *TInfo, StorageClass SC); 760 761 typedef Redeclarable<VarDecl> redeclarable_base; 762 virtual VarDecl *getNextRedeclaration() { return RedeclLink.getNext(); } 763 virtual VarDecl *getPreviousDeclImpl() { 764 return getPreviousDecl(); 765 } 766 virtual VarDecl *getMostRecentDeclImpl() { 767 return getMostRecentDecl(); 768 } 769 770public: 771 typedef redeclarable_base::redecl_iterator redecl_iterator; 772 using redeclarable_base::redecls_begin; 773 using redeclarable_base::redecls_end; 774 using redeclarable_base::getPreviousDecl; 775 using redeclarable_base::getMostRecentDecl; 776 777 static VarDecl *Create(ASTContext &C, DeclContext *DC, 778 SourceLocation StartLoc, SourceLocation IdLoc, 779 IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, 780 StorageClass S); 781 782 static VarDecl *CreateDeserialized(ASTContext &C, unsigned ID); 783 784 virtual SourceRange getSourceRange() const LLVM_READONLY; 785 786 /// \brief Returns the storage class as written in the source. For the 787 /// computed linkage of symbol, see getLinkage. 788 StorageClass getStorageClass() const { 789 return (StorageClass) VarDeclBits.SClass; 790 } 791 void setStorageClass(StorageClass SC); 792 793 void setTSCSpec(ThreadStorageClassSpecifier TSC) { 794 VarDeclBits.TSCSpec = TSC; 795 } 796 ThreadStorageClassSpecifier getTSCSpec() const { 797 return static_cast<ThreadStorageClassSpecifier>(VarDeclBits.TSCSpec); 798 } 799 TLSKind getTLSKind() const { 800 switch (VarDeclBits.TSCSpec) { 801 case TSCS_unspecified: 802 return TLS_None; 803 case TSCS___thread: // Fall through. 804 case TSCS__Thread_local: 805 return TLS_Static; 806 case TSCS_thread_local: 807 return TLS_Dynamic; 808 } 809 llvm_unreachable("Unknown thread storage class specifier!"); 810 } 811 812 /// hasLocalStorage - Returns true if a variable with function scope 813 /// is a non-static local variable. 814 bool hasLocalStorage() const { 815 if (getStorageClass() == SC_None) 816 // Second check is for C++11 [dcl.stc]p4. 817 return !isFileVarDecl() && getTSCSpec() == TSCS_unspecified; 818 819 // Return true for: Auto, Register. 820 // Return false for: Extern, Static, PrivateExtern, OpenCLWorkGroupLocal. 821 822 return getStorageClass() >= SC_Auto; 823 } 824 825 /// isStaticLocal - Returns true if a variable with function scope is a 826 /// static local variable. 827 bool isStaticLocal() const { 828 return (getStorageClass() == SC_Static || 829 // C++11 [dcl.stc]p4 830 (getStorageClass() == SC_None && getTSCSpec() == TSCS_thread_local)) 831 && !isFileVarDecl(); 832 } 833 834 /// \brief Returns true if a variable has extern or __private_extern__ 835 /// storage. 836 bool hasExternalStorage() const { 837 return getStorageClass() == SC_Extern || 838 getStorageClass() == SC_PrivateExtern; 839 } 840 841 /// hasGlobalStorage - Returns true for all variables that do not 842 /// have local storage. This includs all global variables as well 843 /// as static variables declared within a function. 844 bool hasGlobalStorage() const { return !hasLocalStorage(); } 845 846 /// \brief Get the storage duration of this variable, per C++ [basid.stc]. 847 StorageDuration getStorageDuration() const { 848 return hasLocalStorage() ? SD_Automatic : 849 getTSCSpec() ? SD_Thread : SD_Static; 850 } 851 852 /// Compute the language linkage. 853 LanguageLinkage getLanguageLinkage() const; 854 855 /// \brief Determines whether this variable is a variable with 856 /// external, C linkage. 857 bool isExternC() const; 858 859 /// \brief Determines whether this variable's context is, or is nested within, 860 /// a C++ extern "C" linkage spec. 861 bool isInExternCContext() const; 862 863 /// \brief Determines whether this variable's context is, or is nested within, 864 /// a C++ extern "C++" linkage spec. 865 bool isInExternCXXContext() const; 866 867 /// isLocalVarDecl - Returns true for local variable declarations 868 /// other than parameters. Note that this includes static variables 869 /// inside of functions. It also includes variables inside blocks. 870 /// 871 /// void foo() { int x; static int y; extern int z; } 872 /// 873 bool isLocalVarDecl() const { 874 if (getKind() != Decl::Var) 875 return false; 876 if (const DeclContext *DC = getDeclContext()) 877 return DC->getRedeclContext()->isFunctionOrMethod(); 878 return false; 879 } 880 881 /// isFunctionOrMethodVarDecl - Similar to isLocalVarDecl, but 882 /// excludes variables declared in blocks. 883 bool isFunctionOrMethodVarDecl() const { 884 if (getKind() != Decl::Var) 885 return false; 886 const DeclContext *DC = getDeclContext()->getRedeclContext(); 887 return DC->isFunctionOrMethod() && DC->getDeclKind() != Decl::Block; 888 } 889 890 /// \brief Determines whether this is a static data member. 891 /// 892 /// This will only be true in C++, and applies to, e.g., the 893 /// variable 'x' in: 894 /// \code 895 /// struct S { 896 /// static int x; 897 /// }; 898 /// \endcode 899 bool isStaticDataMember() const { 900 // If it wasn't static, it would be a FieldDecl. 901 return getKind() != Decl::ParmVar && getDeclContext()->isRecord(); 902 } 903 904 virtual VarDecl *getCanonicalDecl(); 905 const VarDecl *getCanonicalDecl() const { 906 return const_cast<VarDecl*>(this)->getCanonicalDecl(); 907 } 908 909 enum DefinitionKind { 910 DeclarationOnly, ///< This declaration is only a declaration. 911 TentativeDefinition, ///< This declaration is a tentative definition. 912 Definition ///< This declaration is definitely a definition. 913 }; 914 915 /// \brief Check whether this declaration is a definition. If this could be 916 /// a tentative definition (in C), don't check whether there's an overriding 917 /// definition. 918 DefinitionKind isThisDeclarationADefinition(ASTContext &) const; 919 DefinitionKind isThisDeclarationADefinition() const { 920 return isThisDeclarationADefinition(getASTContext()); 921 } 922 923 /// \brief Check whether this variable is defined in this 924 /// translation unit. 925 DefinitionKind hasDefinition(ASTContext &) const; 926 DefinitionKind hasDefinition() const { 927 return hasDefinition(getASTContext()); 928 } 929 930 /// \brief Get the tentative definition that acts as the real definition in 931 /// a TU. Returns null if there is a proper definition available. 932 VarDecl *getActingDefinition(); 933 const VarDecl *getActingDefinition() const { 934 return const_cast<VarDecl*>(this)->getActingDefinition(); 935 } 936 937 /// \brief Get the real (not just tentative) definition for this declaration. 938 VarDecl *getDefinition(ASTContext &); 939 const VarDecl *getDefinition(ASTContext &C) const { 940 return const_cast<VarDecl*>(this)->getDefinition(C); 941 } 942 VarDecl *getDefinition() { 943 return getDefinition(getASTContext()); 944 } 945 const VarDecl *getDefinition() const { 946 return const_cast<VarDecl*>(this)->getDefinition(); 947 } 948 949 /// \brief Determine whether this is or was instantiated from an out-of-line 950 /// definition of a static data member. 951 virtual bool isOutOfLine() const; 952 953 /// \brief If this is a static data member, find its out-of-line definition. 954 VarDecl *getOutOfLineDefinition(); 955 956 /// isFileVarDecl - Returns true for file scoped variable declaration. 957 bool isFileVarDecl() const { 958 Kind K = getKind(); 959 if (K == ParmVar || K == ImplicitParam) 960 return false; 961 962 if (getDeclContext()->getRedeclContext()->isFileContext()) 963 return true; 964 965 if (isStaticDataMember()) 966 return true; 967 968 return false; 969 } 970 971 /// getAnyInitializer - Get the initializer for this variable, no matter which 972 /// declaration it is attached to. 973 const Expr *getAnyInitializer() const { 974 const VarDecl *D; 975 return getAnyInitializer(D); 976 } 977 978 /// getAnyInitializer - Get the initializer for this variable, no matter which 979 /// declaration it is attached to. Also get that declaration. 980 const Expr *getAnyInitializer(const VarDecl *&D) const; 981 982 bool hasInit() const { 983 return !Init.isNull() && (Init.is<Stmt *>() || Init.is<EvaluatedStmt *>()); 984 } 985 const Expr *getInit() const { 986 if (Init.isNull()) 987 return 0; 988 989 const Stmt *S = Init.dyn_cast<Stmt *>(); 990 if (!S) { 991 if (EvaluatedStmt *ES = Init.dyn_cast<EvaluatedStmt*>()) 992 S = ES->Value; 993 } 994 return (const Expr*) S; 995 } 996 Expr *getInit() { 997 if (Init.isNull()) 998 return 0; 999 1000 Stmt *S = Init.dyn_cast<Stmt *>(); 1001 if (!S) { 1002 if (EvaluatedStmt *ES = Init.dyn_cast<EvaluatedStmt*>()) 1003 S = ES->Value; 1004 } 1005 1006 return (Expr*) S; 1007 } 1008 1009 /// \brief Retrieve the address of the initializer expression. 1010 Stmt **getInitAddress() { 1011 if (EvaluatedStmt *ES = Init.dyn_cast<EvaluatedStmt*>()) 1012 return &ES->Value; 1013 1014 // This union hack tip-toes around strict-aliasing rules. 1015 union { 1016 InitType *InitPtr; 1017 Stmt **StmtPtr; 1018 }; 1019 1020 InitPtr = &Init; 1021 return StmtPtr; 1022 } 1023 1024 void setInit(Expr *I); 1025 1026 /// \brief Determine whether this variable's value can be used in a 1027 /// constant expression, according to the relevant language standard. 1028 /// This only checks properties of the declaration, and does not check 1029 /// whether the initializer is in fact a constant expression. 1030 bool isUsableInConstantExpressions(ASTContext &C) const; 1031 1032 EvaluatedStmt *ensureEvaluatedStmt() const; 1033 1034 /// \brief Attempt to evaluate the value of the initializer attached to this 1035 /// declaration, and produce notes explaining why it cannot be evaluated or is 1036 /// not a constant expression. Returns a pointer to the value if evaluation 1037 /// succeeded, 0 otherwise. 1038 APValue *evaluateValue() const; 1039 APValue *evaluateValue(SmallVectorImpl<PartialDiagnosticAt> &Notes) const; 1040 1041 /// \brief Return the already-evaluated value of this variable's 1042 /// initializer, or NULL if the value is not yet known. Returns pointer 1043 /// to untyped APValue if the value could not be evaluated. 1044 APValue *getEvaluatedValue() const { 1045 if (EvaluatedStmt *Eval = Init.dyn_cast<EvaluatedStmt *>()) 1046 if (Eval->WasEvaluated) 1047 return &Eval->Evaluated; 1048 1049 return 0; 1050 } 1051 1052 /// \brief Determines whether it is already known whether the 1053 /// initializer is an integral constant expression or not. 1054 bool isInitKnownICE() const { 1055 if (EvaluatedStmt *Eval = Init.dyn_cast<EvaluatedStmt *>()) 1056 return Eval->CheckedICE; 1057 1058 return false; 1059 } 1060 1061 /// \brief Determines whether the initializer is an integral constant 1062 /// expression, or in C++11, whether the initializer is a constant 1063 /// expression. 1064 /// 1065 /// \pre isInitKnownICE() 1066 bool isInitICE() const { 1067 assert(isInitKnownICE() && 1068 "Check whether we already know that the initializer is an ICE"); 1069 return Init.get<EvaluatedStmt *>()->IsICE; 1070 } 1071 1072 /// \brief Determine whether the value of the initializer attached to this 1073 /// declaration is an integral constant expression. 1074 bool checkInitIsICE() const; 1075 1076 void setInitStyle(InitializationStyle Style) { 1077 VarDeclBits.InitStyle = Style; 1078 } 1079 1080 /// \brief The style of initialization for this declaration. 1081 /// 1082 /// C-style initialization is "int x = 1;". Call-style initialization is 1083 /// a C++98 direct-initializer, e.g. "int x(1);". The Init expression will be 1084 /// the expression inside the parens or a "ClassType(a,b,c)" class constructor 1085 /// expression for class types. List-style initialization is C++11 syntax, 1086 /// e.g. "int x{1};". Clients can distinguish between different forms of 1087 /// initialization by checking this value. In particular, "int x = {1};" is 1088 /// C-style, "int x({1})" is call-style, and "int x{1};" is list-style; the 1089 /// Init expression in all three cases is an InitListExpr. 1090 InitializationStyle getInitStyle() const { 1091 return static_cast<InitializationStyle>(VarDeclBits.InitStyle); 1092 } 1093 1094 /// \brief Whether the initializer is a direct-initializer (list or call). 1095 bool isDirectInit() const { 1096 return getInitStyle() != CInit; 1097 } 1098 1099 /// \brief Determine whether this variable is the exception variable in a 1100 /// C++ catch statememt or an Objective-C \@catch statement. 1101 bool isExceptionVariable() const { 1102 return VarDeclBits.ExceptionVar; 1103 } 1104 void setExceptionVariable(bool EV) { VarDeclBits.ExceptionVar = EV; } 1105 1106 /// \brief Determine whether this local variable can be used with the named 1107 /// return value optimization (NRVO). 1108 /// 1109 /// The named return value optimization (NRVO) works by marking certain 1110 /// non-volatile local variables of class type as NRVO objects. These 1111 /// locals can be allocated within the return slot of their containing 1112 /// function, in which case there is no need to copy the object to the 1113 /// return slot when returning from the function. Within the function body, 1114 /// each return that returns the NRVO object will have this variable as its 1115 /// NRVO candidate. 1116 bool isNRVOVariable() const { return VarDeclBits.NRVOVariable; } 1117 void setNRVOVariable(bool NRVO) { VarDeclBits.NRVOVariable = NRVO; } 1118 1119 /// \brief Determine whether this variable is the for-range-declaration in 1120 /// a C++0x for-range statement. 1121 bool isCXXForRangeDecl() const { return VarDeclBits.CXXForRangeDecl; } 1122 void setCXXForRangeDecl(bool FRD) { VarDeclBits.CXXForRangeDecl = FRD; } 1123 1124 /// \brief Determine whether this variable is an ARC pseudo-__strong 1125 /// variable. A pseudo-__strong variable has a __strong-qualified 1126 /// type but does not actually retain the object written into it. 1127 /// Generally such variables are also 'const' for safety. 1128 bool isARCPseudoStrong() const { return VarDeclBits.ARCPseudoStrong; } 1129 void setARCPseudoStrong(bool ps) { VarDeclBits.ARCPseudoStrong = ps; } 1130 1131 /// Whether this variable is (C++11) constexpr. 1132 bool isConstexpr() const { return VarDeclBits.IsConstexpr; } 1133 void setConstexpr(bool IC) { VarDeclBits.IsConstexpr = IC; } 1134 1135 /// Whether this local extern variable declaration's previous declaration 1136 /// was declared in the same block scope. Only correct in C++. 1137 bool isPreviousDeclInSameBlockScope() const { 1138 return VarDeclBits.PreviousDeclInSameBlockScope; 1139 } 1140 void setPreviousDeclInSameBlockScope(bool Same) { 1141 VarDeclBits.PreviousDeclInSameBlockScope = Same; 1142 } 1143 1144 /// \brief If this variable is an instantiated static data member of a 1145 /// class template specialization, returns the templated static data member 1146 /// from which it was instantiated. 1147 VarDecl *getInstantiatedFromStaticDataMember() const; 1148 1149 /// \brief If this variable is a static data member, determine what kind of 1150 /// template specialization or instantiation this is. 1151 TemplateSpecializationKind getTemplateSpecializationKind() const; 1152 1153 /// \brief If this variable is an instantiation of a static data member of a 1154 /// class template specialization, retrieves the member specialization 1155 /// information. 1156 MemberSpecializationInfo *getMemberSpecializationInfo() const; 1157 1158 /// \brief For a static data member that was instantiated from a static 1159 /// data member of a class template, set the template specialiation kind. 1160 void setTemplateSpecializationKind(TemplateSpecializationKind TSK, 1161 SourceLocation PointOfInstantiation = SourceLocation()); 1162 1163 /// \brief Specify that this variable is an instantiation of the 1164 /// static data member VD. 1165 void setInstantiationOfStaticDataMember(VarDecl *VD, 1166 TemplateSpecializationKind TSK); 1167 1168 /// \brief Retrieves the variable template that is described by this 1169 /// variable declaration. 1170 /// 1171 /// Every variable template is represented as a VarTemplateDecl and a 1172 /// VarDecl. The former contains template properties (such as 1173 /// the template parameter lists) while the latter contains the 1174 /// actual description of the template's 1175 /// contents. VarTemplateDecl::getTemplatedDecl() retrieves the 1176 /// VarDecl that from a VarTemplateDecl, while 1177 /// getDescribedVarTemplate() retrieves the VarTemplateDecl from 1178 /// a VarDecl. 1179 VarTemplateDecl *getDescribedVarTemplate() const; 1180 1181 void setDescribedVarTemplate(VarTemplateDecl *Template); 1182 1183 // Implement isa/cast/dyncast/etc. 1184 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1185 static bool classofKind(Kind K) { return K >= firstVar && K <= lastVar; } 1186}; 1187 1188class ImplicitParamDecl : public VarDecl { 1189 virtual void anchor(); 1190public: 1191 static ImplicitParamDecl *Create(ASTContext &C, DeclContext *DC, 1192 SourceLocation IdLoc, IdentifierInfo *Id, 1193 QualType T); 1194 1195 static ImplicitParamDecl *CreateDeserialized(ASTContext &C, unsigned ID); 1196 1197 ImplicitParamDecl(DeclContext *DC, SourceLocation IdLoc, 1198 IdentifierInfo *Id, QualType Type) 1199 : VarDecl(ImplicitParam, DC, IdLoc, IdLoc, Id, Type, 1200 /*tinfo*/ 0, SC_None) { 1201 setImplicit(); 1202 } 1203 1204 // Implement isa/cast/dyncast/etc. 1205 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1206 static bool classofKind(Kind K) { return K == ImplicitParam; } 1207}; 1208 1209/// ParmVarDecl - Represents a parameter to a function. 1210class ParmVarDecl : public VarDecl { 1211public: 1212 enum { MaxFunctionScopeDepth = 255 }; 1213 enum { MaxFunctionScopeIndex = 255 }; 1214 1215protected: 1216 ParmVarDecl(Kind DK, DeclContext *DC, SourceLocation StartLoc, 1217 SourceLocation IdLoc, IdentifierInfo *Id, 1218 QualType T, TypeSourceInfo *TInfo, 1219 StorageClass S, Expr *DefArg) 1220 : VarDecl(DK, DC, StartLoc, IdLoc, Id, T, TInfo, S) { 1221 assert(ParmVarDeclBits.HasInheritedDefaultArg == false); 1222 assert(ParmVarDeclBits.IsKNRPromoted == false); 1223 assert(ParmVarDeclBits.IsObjCMethodParam == false); 1224 setDefaultArg(DefArg); 1225 } 1226 1227public: 1228 static ParmVarDecl *Create(ASTContext &C, DeclContext *DC, 1229 SourceLocation StartLoc, 1230 SourceLocation IdLoc, IdentifierInfo *Id, 1231 QualType T, TypeSourceInfo *TInfo, 1232 StorageClass S, Expr *DefArg); 1233 1234 static ParmVarDecl *CreateDeserialized(ASTContext &C, unsigned ID); 1235 1236 virtual SourceRange getSourceRange() const LLVM_READONLY; 1237 1238 void setObjCMethodScopeInfo(unsigned parameterIndex) { 1239 ParmVarDeclBits.IsObjCMethodParam = true; 1240 setParameterIndex(parameterIndex); 1241 } 1242 1243 void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex) { 1244 assert(!ParmVarDeclBits.IsObjCMethodParam); 1245 1246 ParmVarDeclBits.ScopeDepthOrObjCQuals = scopeDepth; 1247 assert(ParmVarDeclBits.ScopeDepthOrObjCQuals == scopeDepth 1248 && "truncation!"); 1249 1250 setParameterIndex(parameterIndex); 1251 } 1252 1253 bool isObjCMethodParameter() const { 1254 return ParmVarDeclBits.IsObjCMethodParam; 1255 } 1256 1257 unsigned getFunctionScopeDepth() const { 1258 if (ParmVarDeclBits.IsObjCMethodParam) return 0; 1259 return ParmVarDeclBits.ScopeDepthOrObjCQuals; 1260 } 1261 1262 /// Returns the index of this parameter in its prototype or method scope. 1263 unsigned getFunctionScopeIndex() const { 1264 return getParameterIndex(); 1265 } 1266 1267 ObjCDeclQualifier getObjCDeclQualifier() const { 1268 if (!ParmVarDeclBits.IsObjCMethodParam) return OBJC_TQ_None; 1269 return ObjCDeclQualifier(ParmVarDeclBits.ScopeDepthOrObjCQuals); 1270 } 1271 void setObjCDeclQualifier(ObjCDeclQualifier QTVal) { 1272 assert(ParmVarDeclBits.IsObjCMethodParam); 1273 ParmVarDeclBits.ScopeDepthOrObjCQuals = QTVal; 1274 } 1275 1276 /// True if the value passed to this parameter must undergo 1277 /// K&R-style default argument promotion: 1278 /// 1279 /// C99 6.5.2.2. 1280 /// If the expression that denotes the called function has a type 1281 /// that does not include a prototype, the integer promotions are 1282 /// performed on each argument, and arguments that have type float 1283 /// are promoted to double. 1284 bool isKNRPromoted() const { 1285 return ParmVarDeclBits.IsKNRPromoted; 1286 } 1287 void setKNRPromoted(bool promoted) { 1288 ParmVarDeclBits.IsKNRPromoted = promoted; 1289 } 1290 1291 Expr *getDefaultArg(); 1292 const Expr *getDefaultArg() const { 1293 return const_cast<ParmVarDecl *>(this)->getDefaultArg(); 1294 } 1295 1296 void setDefaultArg(Expr *defarg) { 1297 Init = reinterpret_cast<Stmt *>(defarg); 1298 } 1299 1300 /// \brief Retrieve the source range that covers the entire default 1301 /// argument. 1302 SourceRange getDefaultArgRange() const; 1303 void setUninstantiatedDefaultArg(Expr *arg) { 1304 Init = reinterpret_cast<UninstantiatedDefaultArgument *>(arg); 1305 } 1306 Expr *getUninstantiatedDefaultArg() { 1307 return (Expr *)Init.get<UninstantiatedDefaultArgument *>(); 1308 } 1309 const Expr *getUninstantiatedDefaultArg() const { 1310 return (const Expr *)Init.get<UninstantiatedDefaultArgument *>(); 1311 } 1312 1313 /// hasDefaultArg - Determines whether this parameter has a default argument, 1314 /// either parsed or not. 1315 bool hasDefaultArg() const { 1316 return getInit() || hasUnparsedDefaultArg() || 1317 hasUninstantiatedDefaultArg(); 1318 } 1319 1320 /// hasUnparsedDefaultArg - Determines whether this parameter has a 1321 /// default argument that has not yet been parsed. This will occur 1322 /// during the processing of a C++ class whose member functions have 1323 /// default arguments, e.g., 1324 /// @code 1325 /// class X { 1326 /// public: 1327 /// void f(int x = 17); // x has an unparsed default argument now 1328 /// }; // x has a regular default argument now 1329 /// @endcode 1330 bool hasUnparsedDefaultArg() const { 1331 return Init.is<UnparsedDefaultArgument*>(); 1332 } 1333 1334 bool hasUninstantiatedDefaultArg() const { 1335 return Init.is<UninstantiatedDefaultArgument*>(); 1336 } 1337 1338 /// setUnparsedDefaultArg - Specify that this parameter has an 1339 /// unparsed default argument. The argument will be replaced with a 1340 /// real default argument via setDefaultArg when the class 1341 /// definition enclosing the function declaration that owns this 1342 /// default argument is completed. 1343 void setUnparsedDefaultArg() { 1344 Init = (UnparsedDefaultArgument *)0; 1345 } 1346 1347 bool hasInheritedDefaultArg() const { 1348 return ParmVarDeclBits.HasInheritedDefaultArg; 1349 } 1350 1351 void setHasInheritedDefaultArg(bool I = true) { 1352 ParmVarDeclBits.HasInheritedDefaultArg = I; 1353 } 1354 1355 QualType getOriginalType() const; 1356 1357 /// \brief Determine whether this parameter is actually a function 1358 /// parameter pack. 1359 bool isParameterPack() const; 1360 1361 /// setOwningFunction - Sets the function declaration that owns this 1362 /// ParmVarDecl. Since ParmVarDecls are often created before the 1363 /// FunctionDecls that own them, this routine is required to update 1364 /// the DeclContext appropriately. 1365 void setOwningFunction(DeclContext *FD) { setDeclContext(FD); } 1366 1367 // Implement isa/cast/dyncast/etc. 1368 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 1369 static bool classofKind(Kind K) { return K == ParmVar; } 1370 1371private: 1372 enum { ParameterIndexSentinel = (1 << NumParameterIndexBits) - 1 }; 1373 1374 void setParameterIndex(unsigned parameterIndex) { 1375 if (parameterIndex >= ParameterIndexSentinel) { 1376 setParameterIndexLarge(parameterIndex); 1377 return; 1378 } 1379 1380 ParmVarDeclBits.ParameterIndex = parameterIndex; 1381 assert(ParmVarDeclBits.ParameterIndex == parameterIndex && "truncation!"); 1382 } 1383 unsigned getParameterIndex() const { 1384 unsigned d = ParmVarDeclBits.ParameterIndex; 1385 return d == ParameterIndexSentinel ? getParameterIndexLarge() : d; 1386 } 1387 1388 void setParameterIndexLarge(unsigned parameterIndex); 1389 unsigned getParameterIndexLarge() const; 1390}; 1391 1392/// FunctionDecl - An instance of this class is created to represent a 1393/// function declaration or definition. 1394/// 1395/// Since a given function can be declared several times in a program, 1396/// there may be several FunctionDecls that correspond to that 1397/// function. Only one of those FunctionDecls will be found when 1398/// traversing the list of declarations in the context of the 1399/// FunctionDecl (e.g., the translation unit); this FunctionDecl 1400/// contains all of the information known about the function. Other, 1401/// previous declarations of the function are available via the 1402/// getPreviousDecl() chain. 1403class FunctionDecl : public DeclaratorDecl, public DeclContext, 1404 public Redeclarable<FunctionDecl> { 1405public: 1406 typedef clang::StorageClass StorageClass; 1407 1408 /// \brief The kind of templated function a FunctionDecl can be. 1409 enum TemplatedKind { 1410 TK_NonTemplate, 1411 TK_FunctionTemplate, 1412 TK_MemberSpecialization, 1413 TK_FunctionTemplateSpecialization, 1414 TK_DependentFunctionTemplateSpecialization 1415 }; 1416 1417private: 1418 /// ParamInfo - new[]'d array of pointers to VarDecls for the formal 1419 /// parameters of this function. This is null if a prototype or if there are 1420 /// no formals. 1421 ParmVarDecl **ParamInfo; 1422 1423 /// DeclsInPrototypeScope - Array of pointers to NamedDecls for 1424 /// decls defined in the function prototype that are not parameters. E.g. 1425 /// 'enum Y' in 'void f(enum Y {AA} x) {}'. 1426 ArrayRef<NamedDecl *> DeclsInPrototypeScope; 1427 1428 LazyDeclStmtPtr Body; 1429 1430 // FIXME: This can be packed into the bitfields in Decl. 1431 // NOTE: VC++ treats enums as signed, avoid using the StorageClass enum 1432 unsigned SClass : 2; 1433 bool IsInline : 1; 1434 bool IsInlineSpecified : 1; 1435 bool IsVirtualAsWritten : 1; 1436 bool IsPure : 1; 1437 bool HasInheritedPrototype : 1; 1438 bool HasWrittenPrototype : 1; 1439 bool IsDeleted : 1; 1440 bool IsTrivial : 1; // sunk from CXXMethodDecl 1441 bool IsDefaulted : 1; // sunk from CXXMethoDecl 1442 bool IsExplicitlyDefaulted : 1; //sunk from CXXMethodDecl 1443 bool HasImplicitReturnZero : 1; 1444 bool IsLateTemplateParsed : 1; 1445 bool IsConstexpr : 1; 1446 1447 /// \brief Indicates if the function was a definition but its body was 1448 /// skipped. 1449 unsigned HasSkippedBody : 1; 1450 1451 /// \brief End part of this FunctionDecl's source range. 1452 /// 1453 /// We could compute the full range in getSourceRange(). However, when we're 1454 /// dealing with a function definition deserialized from a PCH/AST file, 1455 /// we can only compute the full range once the function body has been 1456 /// de-serialized, so it's far better to have the (sometimes-redundant) 1457 /// EndRangeLoc. 1458 SourceLocation EndRangeLoc; 1459 1460 /// \brief The template or declaration that this declaration 1461 /// describes or was instantiated from, respectively. 1462 /// 1463 /// For non-templates, this value will be NULL. For function 1464 /// declarations that describe a function template, this will be a 1465 /// pointer to a FunctionTemplateDecl. For member functions 1466 /// of class template specializations, this will be a MemberSpecializationInfo 1467 /// pointer containing information about the specialization. 1468 /// For function template specializations, this will be a 1469 /// FunctionTemplateSpecializationInfo, which contains information about 1470 /// the template being specialized and the template arguments involved in 1471 /// that specialization. 1472 llvm::PointerUnion4<FunctionTemplateDecl *, 1473 MemberSpecializationInfo *, 1474 FunctionTemplateSpecializationInfo *, 1475 DependentFunctionTemplateSpecializationInfo *> 1476 TemplateOrSpecialization; 1477 1478 /// DNLoc - Provides source/type location info for the 1479 /// declaration name embedded in the DeclaratorDecl base class. 1480 DeclarationNameLoc DNLoc; 1481 1482 /// \brief Specify that this function declaration is actually a function 1483 /// template specialization. 1484 /// 1485 /// \param C the ASTContext. 1486 /// 1487 /// \param Template the function template that this function template 1488 /// specialization specializes. 1489 /// 1490 /// \param TemplateArgs the template arguments that produced this 1491 /// function template specialization from the template. 1492 /// 1493 /// \param InsertPos If non-NULL, the position in the function template 1494 /// specialization set where the function template specialization data will 1495 /// be inserted. 1496 /// 1497 /// \param TSK the kind of template specialization this is. 1498 /// 1499 /// \param TemplateArgsAsWritten location info of template arguments. 1500 /// 1501 /// \param PointOfInstantiation point at which the function template 1502 /// specialization was first instantiated. 1503 void setFunctionTemplateSpecialization(ASTContext &C, 1504 FunctionTemplateDecl *Template, 1505 const TemplateArgumentList *TemplateArgs, 1506 void *InsertPos, 1507 TemplateSpecializationKind TSK, 1508 const TemplateArgumentListInfo *TemplateArgsAsWritten, 1509 SourceLocation PointOfInstantiation); 1510 1511 /// \brief Specify that this record is an instantiation of the 1512 /// member function FD. 1513 void setInstantiationOfMemberFunction(ASTContext &C, FunctionDecl *FD, 1514 TemplateSpecializationKind TSK); 1515 1516 void setParams(ASTContext &C, ArrayRef<ParmVarDecl *> NewParamInfo); 1517 1518protected: 1519 FunctionDecl(Kind DK, DeclContext *DC, SourceLocation StartLoc, 1520 const DeclarationNameInfo &NameInfo, 1521 QualType T, TypeSourceInfo *TInfo, 1522 StorageClass S, bool isInlineSpecified, 1523 bool isConstexprSpecified) 1524 : DeclaratorDecl(DK, DC, NameInfo.getLoc(), NameInfo.getName(), T, TInfo, 1525 StartLoc), 1526 DeclContext(DK), 1527 ParamInfo(0), Body(), 1528 SClass(S), 1529 IsInline(isInlineSpecified), IsInlineSpecified(isInlineSpecified), 1530 IsVirtualAsWritten(false), IsPure(false), HasInheritedPrototype(false), 1531 HasWrittenPrototype(true), IsDeleted(false), IsTrivial(false), 1532 IsDefaulted(false), IsExplicitlyDefaulted(false), 1533 HasImplicitReturnZero(false), IsLateTemplateParsed(false), 1534 IsConstexpr(isConstexprSpecified), HasSkippedBody(false), 1535 EndRangeLoc(NameInfo.getEndLoc()), 1536 TemplateOrSpecialization(), 1537 DNLoc(NameInfo.getInfo()) {} 1538 1539 typedef Redeclarable<FunctionDecl> redeclarable_base; 1540 virtual FunctionDecl *getNextRedeclaration() { return RedeclLink.getNext(); } 1541 virtual FunctionDecl *getPreviousDeclImpl() { 1542 return getPreviousDecl(); 1543 } 1544 virtual FunctionDecl *getMostRecentDeclImpl() { 1545 return getMostRecentDecl(); 1546 } 1547 1548public: 1549 typedef redeclarable_base::redecl_iterator redecl_iterator; 1550 using redeclarable_base::redecls_begin; 1551 using redeclarable_base::redecls_end; 1552 using redeclarable_base::getPreviousDecl; 1553 using redeclarable_base::getMostRecentDecl; 1554 1555 static FunctionDecl *Create(ASTContext &C, DeclContext *DC, 1556 SourceLocation StartLoc, SourceLocation NLoc, 1557 DeclarationName N, QualType T, 1558 TypeSourceInfo *TInfo, 1559 StorageClass SC, 1560 bool isInlineSpecified = false, 1561 bool hasWrittenPrototype = true, 1562 bool isConstexprSpecified = false) { 1563 DeclarationNameInfo NameInfo(N, NLoc); 1564 return FunctionDecl::Create(C, DC, StartLoc, NameInfo, T, TInfo, 1565 SC, 1566 isInlineSpecified, hasWrittenPrototype, 1567 isConstexprSpecified); 1568 } 1569 1570 static FunctionDecl *Create(ASTContext &C, DeclContext *DC, 1571 SourceLocation StartLoc, 1572 const DeclarationNameInfo &NameInfo, 1573 QualType T, TypeSourceInfo *TInfo, 1574 StorageClass SC, 1575 bool isInlineSpecified, 1576 bool hasWrittenPrototype, 1577 bool isConstexprSpecified = false); 1578 1579 static FunctionDecl *CreateDeserialized(ASTContext &C, unsigned ID); 1580 1581 DeclarationNameInfo getNameInfo() const { 1582 return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc); 1583 } 1584 1585 virtual void getNameForDiagnostic(raw_ostream &OS, 1586 const PrintingPolicy &Policy, 1587 bool Qualified) const; 1588 1589 void setRangeEnd(SourceLocation E) { EndRangeLoc = E; } 1590 1591 virtual SourceRange getSourceRange() const LLVM_READONLY; 1592 1593 /// \brief Returns true if the function has a body (definition). The 1594 /// function body might be in any of the (re-)declarations of this 1595 /// function. The variant that accepts a FunctionDecl pointer will 1596 /// set that function declaration to the actual declaration 1597 /// containing the body (if there is one). 1598 bool hasBody(const FunctionDecl *&Definition) const; 1599 1600 virtual bool hasBody() const { 1601 const FunctionDecl* Definition; 1602 return hasBody(Definition); 1603 } 1604 1605 /// hasTrivialBody - Returns whether the function has a trivial body that does 1606 /// not require any specific codegen. 1607 bool hasTrivialBody() const; 1608 1609 /// isDefined - Returns true if the function is defined at all, including 1610 /// a deleted definition. Except for the behavior when the function is 1611 /// deleted, behaves like hasBody. 1612 bool isDefined(const FunctionDecl *&Definition) const; 1613 1614 virtual bool isDefined() const { 1615 const FunctionDecl* Definition; 1616 return isDefined(Definition); 1617 } 1618 1619 /// getBody - Retrieve the body (definition) of the function. The 1620 /// function body might be in any of the (re-)declarations of this 1621 /// function. The variant that accepts a FunctionDecl pointer will 1622 /// set that function declaration to the actual declaration 1623 /// containing the body (if there is one). 1624 /// NOTE: For checking if there is a body, use hasBody() instead, to avoid 1625 /// unnecessary AST de-serialization of the body. 1626 Stmt *getBody(const FunctionDecl *&Definition) const; 1627 1628 virtual Stmt *getBody() const { 1629 const FunctionDecl* Definition; 1630 return getBody(Definition); 1631 } 1632 1633 /// isThisDeclarationADefinition - Returns whether this specific 1634 /// declaration of the function is also a definition. This does not 1635 /// determine whether the function has been defined (e.g., in a 1636 /// previous definition); for that information, use isDefined. Note 1637 /// that this returns false for a defaulted function unless that function 1638 /// has been implicitly defined (possibly as deleted). 1639 bool isThisDeclarationADefinition() const { 1640 return IsDeleted || Body || IsLateTemplateParsed; 1641 } 1642 1643 /// doesThisDeclarationHaveABody - Returns whether this specific 1644 /// declaration of the function has a body - that is, if it is a non- 1645 /// deleted definition. 1646 bool doesThisDeclarationHaveABody() const { 1647 return Body || IsLateTemplateParsed; 1648 } 1649 1650 void setBody(Stmt *B); 1651 void setLazyBody(uint64_t Offset) { Body = Offset; } 1652 1653 /// Whether this function is variadic. 1654 bool isVariadic() const; 1655 1656 /// Whether this function is marked as virtual explicitly. 1657 bool isVirtualAsWritten() const { return IsVirtualAsWritten; } 1658 void setVirtualAsWritten(bool V) { IsVirtualAsWritten = V; } 1659 1660 /// Whether this virtual function is pure, i.e. makes the containing class 1661 /// abstract. 1662 bool isPure() const { return IsPure; } 1663 void setPure(bool P = true); 1664 1665 /// Whether this templated function will be late parsed. 1666 bool isLateTemplateParsed() const { return IsLateTemplateParsed; } 1667 void setLateTemplateParsed(bool ILT = true) { IsLateTemplateParsed = ILT; } 1668 1669 /// Whether this function is "trivial" in some specialized C++ senses. 1670 /// Can only be true for default constructors, copy constructors, 1671 /// copy assignment operators, and destructors. Not meaningful until 1672 /// the class has been fully built by Sema. 1673 bool isTrivial() const { return IsTrivial; } 1674 void setTrivial(bool IT) { IsTrivial = IT; } 1675 1676 /// Whether this function is defaulted per C++0x. Only valid for 1677 /// special member functions. 1678 bool isDefaulted() const { return IsDefaulted; } 1679 void setDefaulted(bool D = true) { IsDefaulted = D; } 1680 1681 /// Whether this function is explicitly defaulted per C++0x. Only valid 1682 /// for special member functions. 1683 bool isExplicitlyDefaulted() const { return IsExplicitlyDefaulted; } 1684 void setExplicitlyDefaulted(bool ED = true) { IsExplicitlyDefaulted = ED; } 1685 1686 /// Whether falling off this function implicitly returns null/zero. 1687 /// If a more specific implicit return value is required, front-ends 1688 /// should synthesize the appropriate return statements. 1689 bool hasImplicitReturnZero() const { return HasImplicitReturnZero; } 1690 void setHasImplicitReturnZero(bool IRZ) { HasImplicitReturnZero = IRZ; } 1691 1692 /// \brief Whether this function has a prototype, either because one 1693 /// was explicitly written or because it was "inherited" by merging 1694 /// a declaration without a prototype with a declaration that has a 1695 /// prototype. 1696 bool hasPrototype() const { 1697 return HasWrittenPrototype || HasInheritedPrototype; 1698 } 1699 1700 bool hasWrittenPrototype() const { return HasWrittenPrototype; } 1701 1702 /// \brief Whether this function inherited its prototype from a 1703 /// previous declaration. 1704 bool hasInheritedPrototype() const { return HasInheritedPrototype; } 1705 void setHasInheritedPrototype(bool P = true) { HasInheritedPrototype = P; } 1706 1707 /// Whether this is a (C++11) constexpr function or constexpr constructor. 1708 bool isConstexpr() const { return IsConstexpr; } 1709 void setConstexpr(bool IC) { IsConstexpr = IC; } 1710 1711 /// \brief Whether this function has been deleted. 1712 /// 1713 /// A function that is "deleted" (via the C++0x "= delete" syntax) 1714 /// acts like a normal function, except that it cannot actually be 1715 /// called or have its address taken. Deleted functions are 1716 /// typically used in C++ overload resolution to attract arguments 1717 /// whose type or lvalue/rvalue-ness would permit the use of a 1718 /// different overload that would behave incorrectly. For example, 1719 /// one might use deleted functions to ban implicit conversion from 1720 /// a floating-point number to an Integer type: 1721 /// 1722 /// @code 1723 /// struct Integer { 1724 /// Integer(long); // construct from a long 1725 /// Integer(double) = delete; // no construction from float or double 1726 /// Integer(long double) = delete; // no construction from long double 1727 /// }; 1728 /// @endcode 1729 // If a function is deleted, its first declaration must be. 1730 bool isDeleted() const { return getCanonicalDecl()->IsDeleted; } 1731 bool isDeletedAsWritten() const { return IsDeleted && !IsDefaulted; } 1732 void setDeletedAsWritten(bool D = true) { IsDeleted = D; } 1733 1734 /// \brief Determines whether this function is "main", which is the 1735 /// entry point into an executable program. 1736 bool isMain() const; 1737 1738 /// \brief Determines whether this function is a MSVCRT user defined entry 1739 /// point. 1740 bool isMSVCRTEntryPoint() const; 1741 1742 /// \brief Determines whether this operator new or delete is one 1743 /// of the reserved global placement operators: 1744 /// void *operator new(size_t, void *); 1745 /// void *operator new[](size_t, void *); 1746 /// void operator delete(void *, void *); 1747 /// void operator delete[](void *, void *); 1748 /// These functions have special behavior under [new.delete.placement]: 1749 /// These functions are reserved, a C++ program may not define 1750 /// functions that displace the versions in the Standard C++ library. 1751 /// The provisions of [basic.stc.dynamic] do not apply to these 1752 /// reserved placement forms of operator new and operator delete. 1753 /// 1754 /// This function must be an allocation or deallocation function. 1755 bool isReservedGlobalPlacementOperator() const; 1756 1757 /// \brief Determines whether this function is one of the replaceable 1758 /// global allocation functions: 1759 /// void *operator new(size_t); 1760 /// void *operator new(size_t, const std::nothrow_t &) noexcept; 1761 /// void *operator new[](size_t); 1762 /// void *operator new[](size_t, const std::nothrow_t &) noexcept; 1763 /// void operator delete(void *) noexcept; 1764 /// void operator delete(void *, const std::nothrow_t &) noexcept; 1765 /// void operator delete[](void *) noexcept; 1766 /// void operator delete[](void *, const std::nothrow_t &) noexcept; 1767 /// These functions have special behavior under C++1y [expr.new]: 1768 /// An implementation is allowed to omit a call to a replaceable global 1769 /// allocation function. [...] 1770 bool isReplaceableGlobalAllocationFunction() const; 1771 1772 /// Compute the language linkage. 1773 LanguageLinkage getLanguageLinkage() const; 1774 1775 /// \brief Determines whether this function is a function with 1776 /// external, C linkage. 1777 bool isExternC() const; 1778 1779 /// \brief Determines whether this function's context is, or is nested within, 1780 /// a C++ extern "C" linkage spec. 1781 bool isInExternCContext() const; 1782 1783 /// \brief Determines whether this function's context is, or is nested within, 1784 /// a C++ extern "C++" linkage spec. 1785 bool isInExternCXXContext() const; 1786 1787 /// \brief Determines whether this is a global function. 1788 bool isGlobal() const; 1789 1790 /// \brief Determines whether this function is known to be 'noreturn', through 1791 /// an attribute on its declaration or its type. 1792 bool isNoReturn() const; 1793 1794 /// \brief True if the function was a definition but its body was skipped. 1795 bool hasSkippedBody() const { return HasSkippedBody; } 1796 void setHasSkippedBody(bool Skipped = true) { HasSkippedBody = Skipped; } 1797 1798 void setPreviousDeclaration(FunctionDecl * PrevDecl); 1799 1800 virtual const FunctionDecl *getCanonicalDecl() const; 1801 virtual FunctionDecl *getCanonicalDecl(); 1802 1803 unsigned getBuiltinID() const; 1804 1805 // Iterator access to formal parameters. 1806 unsigned param_size() const { return getNumParams(); } 1807 typedef ParmVarDecl **param_iterator; 1808 typedef ParmVarDecl * const *param_const_iterator; 1809 1810 param_iterator param_begin() { return ParamInfo; } 1811 param_iterator param_end() { return ParamInfo+param_size(); } 1812 1813 param_const_iterator param_begin() const { return ParamInfo; } 1814 param_const_iterator param_end() const { return ParamInfo+param_size(); } 1815 1816 /// getNumParams - Return the number of parameters this function must have 1817 /// based on its FunctionType. This is the length of the ParamInfo array 1818 /// after it has been created. 1819 unsigned getNumParams() const; 1820 1821 const ParmVarDecl *getParamDecl(unsigned i) const { 1822 assert(i < getNumParams() && "Illegal param #"); 1823 return ParamInfo[i]; 1824 } 1825 ParmVarDecl *getParamDecl(unsigned i) { 1826 assert(i < getNumParams() && "Illegal param #"); 1827 return ParamInfo[i]; 1828 } 1829 void setParams(ArrayRef<ParmVarDecl *> NewParamInfo) { 1830 setParams(getASTContext(), NewParamInfo); 1831 } 1832 1833 const ArrayRef<NamedDecl *> &getDeclsInPrototypeScope() const { 1834 return DeclsInPrototypeScope; 1835 } 1836 void setDeclsInPrototypeScope(ArrayRef<NamedDecl *> NewDecls); 1837 1838 /// getMinRequiredArguments - Returns the minimum number of arguments 1839 /// needed to call this function. This may be fewer than the number of 1840 /// function parameters, if some of the parameters have default 1841 /// arguments (in C++). 1842 unsigned getMinRequiredArguments() const; 1843 1844 QualType getResultType() const { 1845 return getType()->getAs<FunctionType>()->getResultType(); 1846 } 1847 1848 /// \brief Determine the type of an expression that calls this function. 1849 QualType getCallResultType() const { 1850 return getType()->getAs<FunctionType>()->getCallResultType(getASTContext()); 1851 } 1852 1853 /// \brief Returns the storage class as written in the source. For the 1854 /// computed linkage of symbol, see getLinkage. 1855 StorageClass getStorageClass() const { return StorageClass(SClass); } 1856 1857 /// \brief Determine whether the "inline" keyword was specified for this 1858 /// function. 1859 bool isInlineSpecified() const { return IsInlineSpecified; } 1860 1861 /// Set whether the "inline" keyword was specified for this function. 1862 void setInlineSpecified(bool I) { 1863 IsInlineSpecified = I; 1864 IsInline = I; 1865 } 1866 1867 /// Flag that this function is implicitly inline. 1868 void setImplicitlyInline() { 1869 IsInline = true; 1870 } 1871 1872 /// \brief Determine whether this function should be inlined, because it is 1873 /// either marked "inline" or "constexpr" or is a member function of a class 1874 /// that was defined in the class body. 1875 bool isInlined() const { return IsInline; } 1876 1877 bool isInlineDefinitionExternallyVisible() const; 1878 1879 bool doesDeclarationForceExternallyVisibleDefinition() const; 1880 1881 /// isOverloadedOperator - Whether this function declaration 1882 /// represents an C++ overloaded operator, e.g., "operator+". 1883 bool isOverloadedOperator() const { 1884 return getOverloadedOperator() != OO_None; 1885 } 1886 1887 OverloadedOperatorKind getOverloadedOperator() const; 1888 1889 const IdentifierInfo *getLiteralIdentifier() const; 1890 1891 /// \brief If this function is an instantiation of a member function 1892 /// of a class template specialization, retrieves the function from 1893 /// which it was instantiated. 1894 /// 1895 /// This routine will return non-NULL for (non-templated) member 1896 /// functions of class templates and for instantiations of function 1897 /// templates. For example, given: 1898 /// 1899 /// \code 1900 /// template<typename T> 1901 /// struct X { 1902 /// void f(T); 1903 /// }; 1904 /// \endcode 1905 /// 1906 /// The declaration for X<int>::f is a (non-templated) FunctionDecl 1907 /// whose parent is the class template specialization X<int>. For 1908 /// this declaration, getInstantiatedFromFunction() will return 1909 /// the FunctionDecl X<T>::A. When a complete definition of 1910 /// X<int>::A is required, it will be instantiated from the 1911 /// declaration returned by getInstantiatedFromMemberFunction(). 1912 FunctionDecl *getInstantiatedFromMemberFunction() const; 1913 1914 /// \brief What kind of templated function this is. 1915 TemplatedKind getTemplatedKind() const; 1916 1917 /// \brief If this function is an instantiation of a member function of a 1918 /// class template specialization, retrieves the member specialization 1919 /// information. 1920 MemberSpecializationInfo *getMemberSpecializationInfo() const { 1921 return TemplateOrSpecialization.dyn_cast<MemberSpecializationInfo*>(); 1922 } 1923 1924 /// \brief Specify that this record is an instantiation of the 1925 /// member function FD. 1926 void setInstantiationOfMemberFunction(FunctionDecl *FD, 1927 TemplateSpecializationKind TSK) { 1928 setInstantiationOfMemberFunction(getASTContext(), FD, TSK); 1929 } 1930 1931 /// \brief Retrieves the function template that is described by this 1932 /// function declaration. 1933 /// 1934 /// Every function template is represented as a FunctionTemplateDecl 1935 /// and a FunctionDecl (or something derived from FunctionDecl). The 1936 /// former contains template properties (such as the template 1937 /// parameter lists) while the latter contains the actual 1938 /// description of the template's 1939 /// contents. FunctionTemplateDecl::getTemplatedDecl() retrieves the 1940 /// FunctionDecl that describes the function template, 1941 /// getDescribedFunctionTemplate() retrieves the 1942 /// FunctionTemplateDecl from a FunctionDecl. 1943 FunctionTemplateDecl *getDescribedFunctionTemplate() const { 1944 return TemplateOrSpecialization.dyn_cast<FunctionTemplateDecl*>(); 1945 } 1946 1947 void setDescribedFunctionTemplate(FunctionTemplateDecl *Template) { 1948 TemplateOrSpecialization = Template; 1949 } 1950 1951 /// \brief Determine whether this function is a function template 1952 /// specialization. 1953 bool isFunctionTemplateSpecialization() const { 1954 return getPrimaryTemplate() != 0; 1955 } 1956 1957 /// \brief Retrieve the class scope template pattern that this function 1958 /// template specialization is instantiated from. 1959 FunctionDecl *getClassScopeSpecializationPattern() const; 1960 1961 /// \brief If this function is actually a function template specialization, 1962 /// retrieve information about this function template specialization. 1963 /// Otherwise, returns NULL. 1964 FunctionTemplateSpecializationInfo *getTemplateSpecializationInfo() const { 1965 return TemplateOrSpecialization. 1966 dyn_cast<FunctionTemplateSpecializationInfo*>(); 1967 } 1968 1969 /// \brief Determines whether this function is a function template 1970 /// specialization or a member of a class template specialization that can 1971 /// be implicitly instantiated. 1972 bool isImplicitlyInstantiable() const; 1973 1974 /// \brief Determines if the given function was instantiated from a 1975 /// function template. 1976 bool isTemplateInstantiation() const; 1977 1978 /// \brief Retrieve the function declaration from which this function could 1979 /// be instantiated, if it is an instantiation (rather than a non-template 1980 /// or a specialization, for example). 1981 FunctionDecl *getTemplateInstantiationPattern() const; 1982 1983 /// \brief Retrieve the primary template that this function template 1984 /// specialization either specializes or was instantiated from. 1985 /// 1986 /// If this function declaration is not a function template specialization, 1987 /// returns NULL. 1988 FunctionTemplateDecl *getPrimaryTemplate() const; 1989 1990 /// \brief Retrieve the template arguments used to produce this function 1991 /// template specialization from the primary template. 1992 /// 1993 /// If this function declaration is not a function template specialization, 1994 /// returns NULL. 1995 const TemplateArgumentList *getTemplateSpecializationArgs() const; 1996 1997 /// \brief Retrieve the template argument list as written in the sources, 1998 /// if any. 1999 /// 2000 /// If this function declaration is not a function template specialization 2001 /// or if it had no explicit template argument list, returns NULL. 2002 /// Note that it an explicit template argument list may be written empty, 2003 /// e.g., template<> void foo<>(char* s); 2004 const ASTTemplateArgumentListInfo* 2005 getTemplateSpecializationArgsAsWritten() const; 2006 2007 /// \brief Specify that this function declaration is actually a function 2008 /// template specialization. 2009 /// 2010 /// \param Template the function template that this function template 2011 /// specialization specializes. 2012 /// 2013 /// \param TemplateArgs the template arguments that produced this 2014 /// function template specialization from the template. 2015 /// 2016 /// \param InsertPos If non-NULL, the position in the function template 2017 /// specialization set where the function template specialization data will 2018 /// be inserted. 2019 /// 2020 /// \param TSK the kind of template specialization this is. 2021 /// 2022 /// \param TemplateArgsAsWritten location info of template arguments. 2023 /// 2024 /// \param PointOfInstantiation point at which the function template 2025 /// specialization was first instantiated. 2026 void setFunctionTemplateSpecialization(FunctionTemplateDecl *Template, 2027 const TemplateArgumentList *TemplateArgs, 2028 void *InsertPos, 2029 TemplateSpecializationKind TSK = TSK_ImplicitInstantiation, 2030 const TemplateArgumentListInfo *TemplateArgsAsWritten = 0, 2031 SourceLocation PointOfInstantiation = SourceLocation()) { 2032 setFunctionTemplateSpecialization(getASTContext(), Template, TemplateArgs, 2033 InsertPos, TSK, TemplateArgsAsWritten, 2034 PointOfInstantiation); 2035 } 2036 2037 /// \brief Specifies that this function declaration is actually a 2038 /// dependent function template specialization. 2039 void setDependentTemplateSpecialization(ASTContext &Context, 2040 const UnresolvedSetImpl &Templates, 2041 const TemplateArgumentListInfo &TemplateArgs); 2042 2043 DependentFunctionTemplateSpecializationInfo * 2044 getDependentSpecializationInfo() const { 2045 return TemplateOrSpecialization. 2046 dyn_cast<DependentFunctionTemplateSpecializationInfo*>(); 2047 } 2048 2049 /// \brief Determine what kind of template instantiation this function 2050 /// represents. 2051 TemplateSpecializationKind getTemplateSpecializationKind() const; 2052 2053 /// \brief Determine what kind of template instantiation this function 2054 /// represents. 2055 void setTemplateSpecializationKind(TemplateSpecializationKind TSK, 2056 SourceLocation PointOfInstantiation = SourceLocation()); 2057 2058 /// \brief Retrieve the (first) point of instantiation of a function template 2059 /// specialization or a member of a class template specialization. 2060 /// 2061 /// \returns the first point of instantiation, if this function was 2062 /// instantiated from a template; otherwise, returns an invalid source 2063 /// location. 2064 SourceLocation getPointOfInstantiation() const; 2065 2066 /// \brief Determine whether this is or was instantiated from an out-of-line 2067 /// definition of a member function. 2068 virtual bool isOutOfLine() const; 2069 2070 /// \brief Identify a memory copying or setting function. 2071 /// If the given function is a memory copy or setting function, returns 2072 /// the corresponding Builtin ID. If the function is not a memory function, 2073 /// returns 0. 2074 unsigned getMemoryFunctionKind() const; 2075 2076 // Implement isa/cast/dyncast/etc. 2077 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2078 static bool classofKind(Kind K) { 2079 return K >= firstFunction && K <= lastFunction; 2080 } 2081 static DeclContext *castToDeclContext(const FunctionDecl *D) { 2082 return static_cast<DeclContext *>(const_cast<FunctionDecl*>(D)); 2083 } 2084 static FunctionDecl *castFromDeclContext(const DeclContext *DC) { 2085 return static_cast<FunctionDecl *>(const_cast<DeclContext*>(DC)); 2086 } 2087 2088 friend class ASTDeclReader; 2089 friend class ASTDeclWriter; 2090}; 2091 2092 2093/// FieldDecl - An instance of this class is created by Sema::ActOnField to 2094/// represent a member of a struct/union/class. 2095class FieldDecl : public DeclaratorDecl { 2096 // FIXME: This can be packed into the bitfields in Decl. 2097 bool Mutable : 1; 2098 mutable unsigned CachedFieldIndex : 31; 2099 2100 /// \brief An InClassInitStyle value, and either a bit width expression (if 2101 /// the InClassInitStyle value is ICIS_NoInit), or a pointer to the in-class 2102 /// initializer for this field (otherwise). 2103 /// 2104 /// We can safely combine these two because in-class initializers are not 2105 /// permitted for bit-fields. 2106 /// 2107 /// If the InClassInitStyle is not ICIS_NoInit and the initializer is null, 2108 /// then this field has an in-class initializer which has not yet been parsed 2109 /// and attached. 2110 llvm::PointerIntPair<Expr *, 2, unsigned> InitializerOrBitWidth; 2111protected: 2112 FieldDecl(Kind DK, DeclContext *DC, SourceLocation StartLoc, 2113 SourceLocation IdLoc, IdentifierInfo *Id, 2114 QualType T, TypeSourceInfo *TInfo, Expr *BW, bool Mutable, 2115 InClassInitStyle InitStyle) 2116 : DeclaratorDecl(DK, DC, IdLoc, Id, T, TInfo, StartLoc), 2117 Mutable(Mutable), CachedFieldIndex(0), 2118 InitializerOrBitWidth(BW, InitStyle) { 2119 assert((!BW || InitStyle == ICIS_NoInit) && "got initializer for bitfield"); 2120 } 2121 2122public: 2123 static FieldDecl *Create(const ASTContext &C, DeclContext *DC, 2124 SourceLocation StartLoc, SourceLocation IdLoc, 2125 IdentifierInfo *Id, QualType T, 2126 TypeSourceInfo *TInfo, Expr *BW, bool Mutable, 2127 InClassInitStyle InitStyle); 2128 2129 static FieldDecl *CreateDeserialized(ASTContext &C, unsigned ID); 2130 2131 /// getFieldIndex - Returns the index of this field within its record, 2132 /// as appropriate for passing to ASTRecordLayout::getFieldOffset. 2133 unsigned getFieldIndex() const; 2134 2135 /// isMutable - Determines whether this field is mutable (C++ only). 2136 bool isMutable() const { return Mutable; } 2137 2138 /// isBitfield - Determines whether this field is a bitfield. 2139 bool isBitField() const { 2140 return getInClassInitStyle() == ICIS_NoInit && 2141 InitializerOrBitWidth.getPointer(); 2142 } 2143 2144 /// @brief Determines whether this is an unnamed bitfield. 2145 bool isUnnamedBitfield() const { return isBitField() && !getDeclName(); } 2146 2147 /// isAnonymousStructOrUnion - Determines whether this field is a 2148 /// representative for an anonymous struct or union. Such fields are 2149 /// unnamed and are implicitly generated by the implementation to 2150 /// store the data for the anonymous union or struct. 2151 bool isAnonymousStructOrUnion() const; 2152 2153 Expr *getBitWidth() const { 2154 return isBitField() ? InitializerOrBitWidth.getPointer() : 0; 2155 } 2156 unsigned getBitWidthValue(const ASTContext &Ctx) const; 2157 2158 /// setBitWidth - Set the bit-field width for this member. 2159 // Note: used by some clients (i.e., do not remove it). 2160 void setBitWidth(Expr *Width); 2161 /// removeBitWidth - Remove the bit-field width from this member. 2162 // Note: used by some clients (i.e., do not remove it). 2163 void removeBitWidth() { 2164 assert(isBitField() && "no bitfield width to remove"); 2165 InitializerOrBitWidth.setPointer(0); 2166 } 2167 2168 /// getInClassInitStyle - Get the kind of (C++11) in-class initializer which 2169 /// this field has. 2170 InClassInitStyle getInClassInitStyle() const { 2171 return static_cast<InClassInitStyle>(InitializerOrBitWidth.getInt()); 2172 } 2173 2174 /// hasInClassInitializer - Determine whether this member has a C++11 in-class 2175 /// initializer. 2176 bool hasInClassInitializer() const { 2177 return getInClassInitStyle() != ICIS_NoInit; 2178 } 2179 /// getInClassInitializer - Get the C++11 in-class initializer for this 2180 /// member, or null if one has not been set. If a valid declaration has an 2181 /// in-class initializer, but this returns null, then we have not parsed and 2182 /// attached it yet. 2183 Expr *getInClassInitializer() const { 2184 return hasInClassInitializer() ? InitializerOrBitWidth.getPointer() : 0; 2185 } 2186 /// setInClassInitializer - Set the C++11 in-class initializer for this 2187 /// member. 2188 void setInClassInitializer(Expr *Init); 2189 /// removeInClassInitializer - Remove the C++11 in-class initializer from this 2190 /// member. 2191 void removeInClassInitializer() { 2192 assert(hasInClassInitializer() && "no initializer to remove"); 2193 InitializerOrBitWidth.setPointer(0); 2194 InitializerOrBitWidth.setInt(ICIS_NoInit); 2195 } 2196 2197 /// getParent - Returns the parent of this field declaration, which 2198 /// is the struct in which this method is defined. 2199 const RecordDecl *getParent() const { 2200 return cast<RecordDecl>(getDeclContext()); 2201 } 2202 2203 RecordDecl *getParent() { 2204 return cast<RecordDecl>(getDeclContext()); 2205 } 2206 2207 SourceRange getSourceRange() const LLVM_READONLY; 2208 2209 // Implement isa/cast/dyncast/etc. 2210 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2211 static bool classofKind(Kind K) { return K >= firstField && K <= lastField; } 2212 2213 friend class ASTDeclReader; 2214 friend class ASTDeclWriter; 2215}; 2216 2217/// EnumConstantDecl - An instance of this object exists for each enum constant 2218/// that is defined. For example, in "enum X {a,b}", each of a/b are 2219/// EnumConstantDecl's, X is an instance of EnumDecl, and the type of a/b is a 2220/// TagType for the X EnumDecl. 2221class EnumConstantDecl : public ValueDecl { 2222 Stmt *Init; // an integer constant expression 2223 llvm::APSInt Val; // The value. 2224protected: 2225 EnumConstantDecl(DeclContext *DC, SourceLocation L, 2226 IdentifierInfo *Id, QualType T, Expr *E, 2227 const llvm::APSInt &V) 2228 : ValueDecl(EnumConstant, DC, L, Id, T), Init((Stmt*)E), Val(V) {} 2229 2230public: 2231 2232 static EnumConstantDecl *Create(ASTContext &C, EnumDecl *DC, 2233 SourceLocation L, IdentifierInfo *Id, 2234 QualType T, Expr *E, 2235 const llvm::APSInt &V); 2236 static EnumConstantDecl *CreateDeserialized(ASTContext &C, unsigned ID); 2237 2238 const Expr *getInitExpr() const { return (const Expr*) Init; } 2239 Expr *getInitExpr() { return (Expr*) Init; } 2240 const llvm::APSInt &getInitVal() const { return Val; } 2241 2242 void setInitExpr(Expr *E) { Init = (Stmt*) E; } 2243 void setInitVal(const llvm::APSInt &V) { Val = V; } 2244 2245 SourceRange getSourceRange() const LLVM_READONLY; 2246 2247 // Implement isa/cast/dyncast/etc. 2248 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2249 static bool classofKind(Kind K) { return K == EnumConstant; } 2250 2251 friend class StmtIteratorBase; 2252}; 2253 2254/// IndirectFieldDecl - An instance of this class is created to represent a 2255/// field injected from an anonymous union/struct into the parent scope. 2256/// IndirectFieldDecl are always implicit. 2257class IndirectFieldDecl : public ValueDecl { 2258 virtual void anchor(); 2259 NamedDecl **Chaining; 2260 unsigned ChainingSize; 2261 2262 IndirectFieldDecl(DeclContext *DC, SourceLocation L, 2263 DeclarationName N, QualType T, 2264 NamedDecl **CH, unsigned CHS) 2265 : ValueDecl(IndirectField, DC, L, N, T), Chaining(CH), ChainingSize(CHS) {} 2266 2267public: 2268 static IndirectFieldDecl *Create(ASTContext &C, DeclContext *DC, 2269 SourceLocation L, IdentifierInfo *Id, 2270 QualType T, NamedDecl **CH, unsigned CHS); 2271 2272 static IndirectFieldDecl *CreateDeserialized(ASTContext &C, unsigned ID); 2273 2274 typedef NamedDecl * const *chain_iterator; 2275 chain_iterator chain_begin() const { return Chaining; } 2276 chain_iterator chain_end() const { return Chaining+ChainingSize; } 2277 2278 unsigned getChainingSize() const { return ChainingSize; } 2279 2280 FieldDecl *getAnonField() const { 2281 assert(ChainingSize >= 2); 2282 return cast<FieldDecl>(Chaining[ChainingSize - 1]); 2283 } 2284 2285 VarDecl *getVarDecl() const { 2286 assert(ChainingSize >= 2); 2287 return dyn_cast<VarDecl>(*chain_begin()); 2288 } 2289 2290 // Implement isa/cast/dyncast/etc. 2291 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2292 static bool classofKind(Kind K) { return K == IndirectField; } 2293 friend class ASTDeclReader; 2294}; 2295 2296/// TypeDecl - Represents a declaration of a type. 2297/// 2298class TypeDecl : public NamedDecl { 2299 virtual void anchor(); 2300 /// TypeForDecl - This indicates the Type object that represents 2301 /// this TypeDecl. It is a cache maintained by 2302 /// ASTContext::getTypedefType, ASTContext::getTagDeclType, and 2303 /// ASTContext::getTemplateTypeParmType, and TemplateTypeParmDecl. 2304 mutable const Type *TypeForDecl; 2305 /// LocStart - The start of the source range for this declaration. 2306 SourceLocation LocStart; 2307 friend class ASTContext; 2308 friend class DeclContext; 2309 friend class TagDecl; 2310 friend class TemplateTypeParmDecl; 2311 friend class TagType; 2312 friend class ASTReader; 2313 2314protected: 2315 TypeDecl(Kind DK, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, 2316 SourceLocation StartL = SourceLocation()) 2317 : NamedDecl(DK, DC, L, Id), TypeForDecl(0), LocStart(StartL) {} 2318 2319public: 2320 // Low-level accessor. If you just want the type defined by this node, 2321 // check out ASTContext::getTypeDeclType or one of 2322 // ASTContext::getTypedefType, ASTContext::getRecordType, etc. if you 2323 // already know the specific kind of node this is. 2324 const Type *getTypeForDecl() const { return TypeForDecl; } 2325 void setTypeForDecl(const Type *TD) { TypeForDecl = TD; } 2326 2327 SourceLocation getLocStart() const LLVM_READONLY { return LocStart; } 2328 void setLocStart(SourceLocation L) { LocStart = L; } 2329 virtual SourceRange getSourceRange() const LLVM_READONLY { 2330 if (LocStart.isValid()) 2331 return SourceRange(LocStart, getLocation()); 2332 else 2333 return SourceRange(getLocation()); 2334 } 2335 2336 // Implement isa/cast/dyncast/etc. 2337 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2338 static bool classofKind(Kind K) { return K >= firstType && K <= lastType; } 2339}; 2340 2341 2342/// Base class for declarations which introduce a typedef-name. 2343class TypedefNameDecl : public TypeDecl, public Redeclarable<TypedefNameDecl> { 2344 virtual void anchor(); 2345 typedef std::pair<TypeSourceInfo*, QualType> ModedTInfo; 2346 llvm::PointerUnion<TypeSourceInfo*, ModedTInfo*> MaybeModedTInfo; 2347 2348protected: 2349 TypedefNameDecl(Kind DK, DeclContext *DC, SourceLocation StartLoc, 2350 SourceLocation IdLoc, IdentifierInfo *Id, 2351 TypeSourceInfo *TInfo) 2352 : TypeDecl(DK, DC, IdLoc, Id, StartLoc), MaybeModedTInfo(TInfo) {} 2353 2354 typedef Redeclarable<TypedefNameDecl> redeclarable_base; 2355 virtual TypedefNameDecl *getNextRedeclaration() { 2356 return RedeclLink.getNext(); 2357 } 2358 virtual TypedefNameDecl *getPreviousDeclImpl() { 2359 return getPreviousDecl(); 2360 } 2361 virtual TypedefNameDecl *getMostRecentDeclImpl() { 2362 return getMostRecentDecl(); 2363 } 2364 2365public: 2366 typedef redeclarable_base::redecl_iterator redecl_iterator; 2367 using redeclarable_base::redecls_begin; 2368 using redeclarable_base::redecls_end; 2369 using redeclarable_base::getPreviousDecl; 2370 using redeclarable_base::getMostRecentDecl; 2371 2372 bool isModed() const { return MaybeModedTInfo.is<ModedTInfo*>(); } 2373 2374 TypeSourceInfo *getTypeSourceInfo() const { 2375 return isModed() 2376 ? MaybeModedTInfo.get<ModedTInfo*>()->first 2377 : MaybeModedTInfo.get<TypeSourceInfo*>(); 2378 } 2379 QualType getUnderlyingType() const { 2380 return isModed() 2381 ? MaybeModedTInfo.get<ModedTInfo*>()->second 2382 : MaybeModedTInfo.get<TypeSourceInfo*>()->getType(); 2383 } 2384 void setTypeSourceInfo(TypeSourceInfo *newType) { 2385 MaybeModedTInfo = newType; 2386 } 2387 void setModedTypeSourceInfo(TypeSourceInfo *unmodedTSI, QualType modedTy) { 2388 MaybeModedTInfo = new (getASTContext()) ModedTInfo(unmodedTSI, modedTy); 2389 } 2390 2391 /// Retrieves the canonical declaration of this typedef-name. 2392 TypedefNameDecl *getCanonicalDecl() { 2393 return getFirstDeclaration(); 2394 } 2395 const TypedefNameDecl *getCanonicalDecl() const { 2396 return getFirstDeclaration(); 2397 } 2398 2399 // Implement isa/cast/dyncast/etc. 2400 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2401 static bool classofKind(Kind K) { 2402 return K >= firstTypedefName && K <= lastTypedefName; 2403 } 2404}; 2405 2406/// TypedefDecl - Represents the declaration of a typedef-name via the 'typedef' 2407/// type specifier. 2408class TypedefDecl : public TypedefNameDecl { 2409 TypedefDecl(DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, 2410 IdentifierInfo *Id, TypeSourceInfo *TInfo) 2411 : TypedefNameDecl(Typedef, DC, StartLoc, IdLoc, Id, TInfo) {} 2412 2413public: 2414 static TypedefDecl *Create(ASTContext &C, DeclContext *DC, 2415 SourceLocation StartLoc, SourceLocation IdLoc, 2416 IdentifierInfo *Id, TypeSourceInfo *TInfo); 2417 static TypedefDecl *CreateDeserialized(ASTContext &C, unsigned ID); 2418 2419 SourceRange getSourceRange() const LLVM_READONLY; 2420 2421 // Implement isa/cast/dyncast/etc. 2422 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2423 static bool classofKind(Kind K) { return K == Typedef; } 2424}; 2425 2426/// TypeAliasDecl - Represents the declaration of a typedef-name via a C++0x 2427/// alias-declaration. 2428class TypeAliasDecl : public TypedefNameDecl { 2429 TypeAliasDecl(DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, 2430 IdentifierInfo *Id, TypeSourceInfo *TInfo) 2431 : TypedefNameDecl(TypeAlias, DC, StartLoc, IdLoc, Id, TInfo) {} 2432 2433public: 2434 static TypeAliasDecl *Create(ASTContext &C, DeclContext *DC, 2435 SourceLocation StartLoc, SourceLocation IdLoc, 2436 IdentifierInfo *Id, TypeSourceInfo *TInfo); 2437 static TypeAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID); 2438 2439 SourceRange getSourceRange() const LLVM_READONLY; 2440 2441 // Implement isa/cast/dyncast/etc. 2442 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2443 static bool classofKind(Kind K) { return K == TypeAlias; } 2444}; 2445 2446/// TagDecl - Represents the declaration of a struct/union/class/enum. 2447class TagDecl 2448 : public TypeDecl, public DeclContext, public Redeclarable<TagDecl> { 2449public: 2450 // This is really ugly. 2451 typedef TagTypeKind TagKind; 2452 2453private: 2454 // FIXME: This can be packed into the bitfields in Decl. 2455 /// TagDeclKind - The TagKind enum. 2456 unsigned TagDeclKind : 3; 2457 2458 /// IsCompleteDefinition - True if this is a definition ("struct foo 2459 /// {};"), false if it is a declaration ("struct foo;"). It is not 2460 /// a definition until the definition has been fully processed. 2461 bool IsCompleteDefinition : 1; 2462 2463protected: 2464 /// IsBeingDefined - True if this is currently being defined. 2465 bool IsBeingDefined : 1; 2466 2467private: 2468 /// IsEmbeddedInDeclarator - True if this tag declaration is 2469 /// "embedded" (i.e., defined or declared for the very first time) 2470 /// in the syntax of a declarator. 2471 bool IsEmbeddedInDeclarator : 1; 2472 2473 /// \brief True if this tag is free standing, e.g. "struct foo;". 2474 bool IsFreeStanding : 1; 2475 2476protected: 2477 // These are used by (and only defined for) EnumDecl. 2478 unsigned NumPositiveBits : 8; 2479 unsigned NumNegativeBits : 8; 2480 2481 /// IsScoped - True if this tag declaration is a scoped enumeration. Only 2482 /// possible in C++11 mode. 2483 bool IsScoped : 1; 2484 /// IsScopedUsingClassTag - If this tag declaration is a scoped enum, 2485 /// then this is true if the scoped enum was declared using the class 2486 /// tag, false if it was declared with the struct tag. No meaning is 2487 /// associated if this tag declaration is not a scoped enum. 2488 bool IsScopedUsingClassTag : 1; 2489 2490 /// IsFixed - True if this is an enumeration with fixed underlying type. Only 2491 /// possible in C++11, Microsoft extensions, or Objective C mode. 2492 bool IsFixed : 1; 2493 2494 /// \brief Indicates whether it is possible for declarations of this kind 2495 /// to have an out-of-date definition. 2496 /// 2497 /// This option is only enabled when modules are enabled. 2498 bool MayHaveOutOfDateDef : 1; 2499 2500 /// Has the full definition of this type been required by a use somewhere in 2501 /// the TU. 2502 bool IsCompleteDefinitionRequired : 1; 2503private: 2504 SourceLocation RBraceLoc; 2505 2506 // A struct representing syntactic qualifier info, 2507 // to be used for the (uncommon) case of out-of-line declarations. 2508 typedef QualifierInfo ExtInfo; 2509 2510 /// TypedefNameDeclOrQualifier - If the (out-of-line) tag declaration name 2511 /// is qualified, it points to the qualifier info (nns and range); 2512 /// otherwise, if the tag declaration is anonymous and it is part of 2513 /// a typedef or alias, it points to the TypedefNameDecl (used for mangling); 2514 /// otherwise, it is a null (TypedefNameDecl) pointer. 2515 llvm::PointerUnion<TypedefNameDecl*, ExtInfo*> TypedefNameDeclOrQualifier; 2516 2517 bool hasExtInfo() const { return TypedefNameDeclOrQualifier.is<ExtInfo*>(); } 2518 ExtInfo *getExtInfo() { return TypedefNameDeclOrQualifier.get<ExtInfo*>(); } 2519 const ExtInfo *getExtInfo() const { 2520 return TypedefNameDeclOrQualifier.get<ExtInfo*>(); 2521 } 2522 2523protected: 2524 TagDecl(Kind DK, TagKind TK, DeclContext *DC, SourceLocation L, 2525 IdentifierInfo *Id, TagDecl *PrevDecl, SourceLocation StartL) 2526 : TypeDecl(DK, DC, L, Id, StartL), DeclContext(DK), TagDeclKind(TK), 2527 IsCompleteDefinition(false), IsBeingDefined(false), 2528 IsEmbeddedInDeclarator(false), IsFreeStanding(false), 2529 IsCompleteDefinitionRequired(false), 2530 TypedefNameDeclOrQualifier((TypedefNameDecl *)0) { 2531 assert((DK != Enum || TK == TTK_Enum) && 2532 "EnumDecl not matched with TTK_Enum"); 2533 setPreviousDeclaration(PrevDecl); 2534 } 2535 2536 typedef Redeclarable<TagDecl> redeclarable_base; 2537 virtual TagDecl *getNextRedeclaration() { return RedeclLink.getNext(); } 2538 virtual TagDecl *getPreviousDeclImpl() { 2539 return getPreviousDecl(); 2540 } 2541 virtual TagDecl *getMostRecentDeclImpl() { 2542 return getMostRecentDecl(); 2543 } 2544 2545 /// @brief Completes the definition of this tag declaration. 2546 /// 2547 /// This is a helper function for derived classes. 2548 void completeDefinition(); 2549 2550public: 2551 typedef redeclarable_base::redecl_iterator redecl_iterator; 2552 using redeclarable_base::redecls_begin; 2553 using redeclarable_base::redecls_end; 2554 using redeclarable_base::getPreviousDecl; 2555 using redeclarable_base::getMostRecentDecl; 2556 2557 SourceLocation getRBraceLoc() const { return RBraceLoc; } 2558 void setRBraceLoc(SourceLocation L) { RBraceLoc = L; } 2559 2560 /// getInnerLocStart - Return SourceLocation representing start of source 2561 /// range ignoring outer template declarations. 2562 SourceLocation getInnerLocStart() const { return getLocStart(); } 2563 2564 /// getOuterLocStart - Return SourceLocation representing start of source 2565 /// range taking into account any outer template declarations. 2566 SourceLocation getOuterLocStart() const; 2567 virtual SourceRange getSourceRange() const LLVM_READONLY; 2568 2569 virtual TagDecl* getCanonicalDecl(); 2570 const TagDecl* getCanonicalDecl() const { 2571 return const_cast<TagDecl*>(this)->getCanonicalDecl(); 2572 } 2573 2574 /// isThisDeclarationADefinition() - Return true if this declaration 2575 /// is a completion definintion of the type. Provided for consistency. 2576 bool isThisDeclarationADefinition() const { 2577 return isCompleteDefinition(); 2578 } 2579 2580 /// isCompleteDefinition - Return true if this decl has its body 2581 /// fully specified. 2582 bool isCompleteDefinition() const { 2583 return IsCompleteDefinition; 2584 } 2585 2586 /// \brief Return true if this complete decl is 2587 /// required to be complete for some existing use. 2588 bool isCompleteDefinitionRequired() const { 2589 return IsCompleteDefinitionRequired; 2590 } 2591 2592 /// isBeingDefined - Return true if this decl is currently being defined. 2593 bool isBeingDefined() const { 2594 return IsBeingDefined; 2595 } 2596 2597 bool isEmbeddedInDeclarator() const { 2598 return IsEmbeddedInDeclarator; 2599 } 2600 void setEmbeddedInDeclarator(bool isInDeclarator) { 2601 IsEmbeddedInDeclarator = isInDeclarator; 2602 } 2603 2604 bool isFreeStanding() const { return IsFreeStanding; } 2605 void setFreeStanding(bool isFreeStanding = true) { 2606 IsFreeStanding = isFreeStanding; 2607 } 2608 2609 /// \brief Whether this declaration declares a type that is 2610 /// dependent, i.e., a type that somehow depends on template 2611 /// parameters. 2612 bool isDependentType() const { return isDependentContext(); } 2613 2614 /// @brief Starts the definition of this tag declaration. 2615 /// 2616 /// This method should be invoked at the beginning of the definition 2617 /// of this tag declaration. It will set the tag type into a state 2618 /// where it is in the process of being defined. 2619 void startDefinition(); 2620 2621 /// getDefinition - Returns the TagDecl that actually defines this 2622 /// struct/union/class/enum. When determining whether or not a 2623 /// struct/union/class/enum has a definition, one should use this 2624 /// method as opposed to 'isDefinition'. 'isDefinition' indicates 2625 /// whether or not a specific TagDecl is defining declaration, not 2626 /// whether or not the struct/union/class/enum type is defined. 2627 /// This method returns NULL if there is no TagDecl that defines 2628 /// the struct/union/class/enum. 2629 TagDecl *getDefinition() const; 2630 2631 void setCompleteDefinition(bool V) { IsCompleteDefinition = V; } 2632 2633 void setCompleteDefinitionRequired(bool V = true) { 2634 IsCompleteDefinitionRequired = V; 2635 } 2636 2637 // FIXME: Return StringRef; 2638 const char *getKindName() const { 2639 return TypeWithKeyword::getTagTypeKindName(getTagKind()); 2640 } 2641 2642 TagKind getTagKind() const { 2643 return TagKind(TagDeclKind); 2644 } 2645 2646 void setTagKind(TagKind TK) { TagDeclKind = TK; } 2647 2648 bool isStruct() const { return getTagKind() == TTK_Struct; } 2649 bool isInterface() const { return getTagKind() == TTK_Interface; } 2650 bool isClass() const { return getTagKind() == TTK_Class; } 2651 bool isUnion() const { return getTagKind() == TTK_Union; } 2652 bool isEnum() const { return getTagKind() == TTK_Enum; } 2653 2654 /// Is this tag type named, either directly or via being defined in 2655 /// a typedef of this type? 2656 /// 2657 /// C++11 [basic.link]p8: 2658 /// A type is said to have linkage if and only if: 2659 /// - it is a class or enumeration type that is named (or has a 2660 /// name for linkage purposes) and the name has linkage; ... 2661 /// C++11 [dcl.typedef]p9: 2662 /// If the typedef declaration defines an unnamed class (or enum), 2663 /// the first typedef-name declared by the declaration to be that 2664 /// class type (or enum type) is used to denote the class type (or 2665 /// enum type) for linkage purposes only. 2666 /// 2667 /// C does not have an analogous rule, but the same concept is 2668 /// nonetheless useful in some places. 2669 bool hasNameForLinkage() const { 2670 return (getDeclName() || getTypedefNameForAnonDecl()); 2671 } 2672 2673 TypedefNameDecl *getTypedefNameForAnonDecl() const { 2674 return hasExtInfo() ? 0 : 2675 TypedefNameDeclOrQualifier.get<TypedefNameDecl*>(); 2676 } 2677 2678 void setTypedefNameForAnonDecl(TypedefNameDecl *TDD); 2679 2680 /// \brief Retrieve the nested-name-specifier that qualifies the name of this 2681 /// declaration, if it was present in the source. 2682 NestedNameSpecifier *getQualifier() const { 2683 return hasExtInfo() ? getExtInfo()->QualifierLoc.getNestedNameSpecifier() 2684 : 0; 2685 } 2686 2687 /// \brief Retrieve the nested-name-specifier (with source-location 2688 /// information) that qualifies the name of this declaration, if it was 2689 /// present in the source. 2690 NestedNameSpecifierLoc getQualifierLoc() const { 2691 return hasExtInfo() ? getExtInfo()->QualifierLoc 2692 : NestedNameSpecifierLoc(); 2693 } 2694 2695 void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc); 2696 2697 unsigned getNumTemplateParameterLists() const { 2698 return hasExtInfo() ? getExtInfo()->NumTemplParamLists : 0; 2699 } 2700 TemplateParameterList *getTemplateParameterList(unsigned i) const { 2701 assert(i < getNumTemplateParameterLists()); 2702 return getExtInfo()->TemplParamLists[i]; 2703 } 2704 void setTemplateParameterListsInfo(ASTContext &Context, unsigned NumTPLists, 2705 TemplateParameterList **TPLists); 2706 2707 // Implement isa/cast/dyncast/etc. 2708 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2709 static bool classofKind(Kind K) { return K >= firstTag && K <= lastTag; } 2710 2711 static DeclContext *castToDeclContext(const TagDecl *D) { 2712 return static_cast<DeclContext *>(const_cast<TagDecl*>(D)); 2713 } 2714 static TagDecl *castFromDeclContext(const DeclContext *DC) { 2715 return static_cast<TagDecl *>(const_cast<DeclContext*>(DC)); 2716 } 2717 2718 friend class ASTDeclReader; 2719 friend class ASTDeclWriter; 2720}; 2721 2722/// EnumDecl - Represents an enum. In C++11, enums can be forward-declared 2723/// with a fixed underlying type, and in C we allow them to be forward-declared 2724/// with no underlying type as an extension. 2725class EnumDecl : public TagDecl { 2726 virtual void anchor(); 2727 /// IntegerType - This represent the integer type that the enum corresponds 2728 /// to for code generation purposes. Note that the enumerator constants may 2729 /// have a different type than this does. 2730 /// 2731 /// If the underlying integer type was explicitly stated in the source 2732 /// code, this is a TypeSourceInfo* for that type. Otherwise this type 2733 /// was automatically deduced somehow, and this is a Type*. 2734 /// 2735 /// Normally if IsFixed(), this would contain a TypeSourceInfo*, but in 2736 /// some cases it won't. 2737 /// 2738 /// The underlying type of an enumeration never has any qualifiers, so 2739 /// we can get away with just storing a raw Type*, and thus save an 2740 /// extra pointer when TypeSourceInfo is needed. 2741 2742 llvm::PointerUnion<const Type*, TypeSourceInfo*> IntegerType; 2743 2744 /// PromotionType - The integer type that values of this type should 2745 /// promote to. In C, enumerators are generally of an integer type 2746 /// directly, but gcc-style large enumerators (and all enumerators 2747 /// in C++) are of the enum type instead. 2748 QualType PromotionType; 2749 2750 /// \brief If this enumeration is an instantiation of a member enumeration 2751 /// of a class template specialization, this is the member specialization 2752 /// information. 2753 MemberSpecializationInfo *SpecializationInfo; 2754 2755 EnumDecl(DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, 2756 IdentifierInfo *Id, EnumDecl *PrevDecl, 2757 bool Scoped, bool ScopedUsingClassTag, bool Fixed) 2758 : TagDecl(Enum, TTK_Enum, DC, IdLoc, Id, PrevDecl, StartLoc), 2759 SpecializationInfo(0) { 2760 assert(Scoped || !ScopedUsingClassTag); 2761 IntegerType = (const Type*)0; 2762 NumNegativeBits = 0; 2763 NumPositiveBits = 0; 2764 IsScoped = Scoped; 2765 IsScopedUsingClassTag = ScopedUsingClassTag; 2766 IsFixed = Fixed; 2767 } 2768 2769 void setInstantiationOfMemberEnum(ASTContext &C, EnumDecl *ED, 2770 TemplateSpecializationKind TSK); 2771public: 2772 EnumDecl *getCanonicalDecl() { 2773 return cast<EnumDecl>(TagDecl::getCanonicalDecl()); 2774 } 2775 const EnumDecl *getCanonicalDecl() const { 2776 return cast<EnumDecl>(TagDecl::getCanonicalDecl()); 2777 } 2778 2779 const EnumDecl *getPreviousDecl() const { 2780 return cast_or_null<EnumDecl>(TagDecl::getPreviousDecl()); 2781 } 2782 EnumDecl *getPreviousDecl() { 2783 return cast_or_null<EnumDecl>(TagDecl::getPreviousDecl()); 2784 } 2785 2786 const EnumDecl *getMostRecentDecl() const { 2787 return cast<EnumDecl>(TagDecl::getMostRecentDecl()); 2788 } 2789 EnumDecl *getMostRecentDecl() { 2790 return cast<EnumDecl>(TagDecl::getMostRecentDecl()); 2791 } 2792 2793 EnumDecl *getDefinition() const { 2794 return cast_or_null<EnumDecl>(TagDecl::getDefinition()); 2795 } 2796 2797 static EnumDecl *Create(ASTContext &C, DeclContext *DC, 2798 SourceLocation StartLoc, SourceLocation IdLoc, 2799 IdentifierInfo *Id, EnumDecl *PrevDecl, 2800 bool IsScoped, bool IsScopedUsingClassTag, 2801 bool IsFixed); 2802 static EnumDecl *CreateDeserialized(ASTContext &C, unsigned ID); 2803 2804 /// completeDefinition - When created, the EnumDecl corresponds to a 2805 /// forward-declared enum. This method is used to mark the 2806 /// declaration as being defined; it's enumerators have already been 2807 /// added (via DeclContext::addDecl). NewType is the new underlying 2808 /// type of the enumeration type. 2809 void completeDefinition(QualType NewType, 2810 QualType PromotionType, 2811 unsigned NumPositiveBits, 2812 unsigned NumNegativeBits); 2813 2814 // enumerator_iterator - Iterates through the enumerators of this 2815 // enumeration. 2816 typedef specific_decl_iterator<EnumConstantDecl> enumerator_iterator; 2817 2818 enumerator_iterator enumerator_begin() const { 2819 const EnumDecl *E = getDefinition(); 2820 if (!E) 2821 E = this; 2822 return enumerator_iterator(E->decls_begin()); 2823 } 2824 2825 enumerator_iterator enumerator_end() const { 2826 const EnumDecl *E = getDefinition(); 2827 if (!E) 2828 E = this; 2829 return enumerator_iterator(E->decls_end()); 2830 } 2831 2832 /// getPromotionType - Return the integer type that enumerators 2833 /// should promote to. 2834 QualType getPromotionType() const { return PromotionType; } 2835 2836 /// \brief Set the promotion type. 2837 void setPromotionType(QualType T) { PromotionType = T; } 2838 2839 /// getIntegerType - Return the integer type this enum decl corresponds to. 2840 /// This returns a null qualtype for an enum forward definition. 2841 QualType getIntegerType() const { 2842 if (!IntegerType) 2843 return QualType(); 2844 if (const Type* T = IntegerType.dyn_cast<const Type*>()) 2845 return QualType(T, 0); 2846 return IntegerType.get<TypeSourceInfo*>()->getType(); 2847 } 2848 2849 /// \brief Set the underlying integer type. 2850 void setIntegerType(QualType T) { IntegerType = T.getTypePtrOrNull(); } 2851 2852 /// \brief Set the underlying integer type source info. 2853 void setIntegerTypeSourceInfo(TypeSourceInfo* TInfo) { IntegerType = TInfo; } 2854 2855 /// \brief Return the type source info for the underlying integer type, 2856 /// if no type source info exists, return 0. 2857 TypeSourceInfo* getIntegerTypeSourceInfo() const { 2858 return IntegerType.dyn_cast<TypeSourceInfo*>(); 2859 } 2860 2861 /// \brief Returns the width in bits required to store all the 2862 /// non-negative enumerators of this enum. 2863 unsigned getNumPositiveBits() const { 2864 return NumPositiveBits; 2865 } 2866 void setNumPositiveBits(unsigned Num) { 2867 NumPositiveBits = Num; 2868 assert(NumPositiveBits == Num && "can't store this bitcount"); 2869 } 2870 2871 /// \brief Returns the width in bits required to store all the 2872 /// negative enumerators of this enum. These widths include 2873 /// the rightmost leading 1; that is: 2874 /// 2875 /// MOST NEGATIVE ENUMERATOR PATTERN NUM NEGATIVE BITS 2876 /// ------------------------ ------- ----------------- 2877 /// -1 1111111 1 2878 /// -10 1110110 5 2879 /// -101 1001011 8 2880 unsigned getNumNegativeBits() const { 2881 return NumNegativeBits; 2882 } 2883 void setNumNegativeBits(unsigned Num) { 2884 NumNegativeBits = Num; 2885 } 2886 2887 /// \brief Returns true if this is a C++11 scoped enumeration. 2888 bool isScoped() const { 2889 return IsScoped; 2890 } 2891 2892 /// \brief Returns true if this is a C++11 scoped enumeration. 2893 bool isScopedUsingClassTag() const { 2894 return IsScopedUsingClassTag; 2895 } 2896 2897 /// \brief Returns true if this is an Objective-C, C++11, or 2898 /// Microsoft-style enumeration with a fixed underlying type. 2899 bool isFixed() const { 2900 return IsFixed; 2901 } 2902 2903 /// \brief Returns true if this can be considered a complete type. 2904 bool isComplete() const { 2905 return isCompleteDefinition() || isFixed(); 2906 } 2907 2908 /// \brief Returns the enumeration (declared within the template) 2909 /// from which this enumeration type was instantiated, or NULL if 2910 /// this enumeration was not instantiated from any template. 2911 EnumDecl *getInstantiatedFromMemberEnum() const; 2912 2913 /// \brief If this enumeration is a member of a specialization of a 2914 /// templated class, determine what kind of template specialization 2915 /// or instantiation this is. 2916 TemplateSpecializationKind getTemplateSpecializationKind() const; 2917 2918 /// \brief For an enumeration member that was instantiated from a member 2919 /// enumeration of a templated class, set the template specialiation kind. 2920 void setTemplateSpecializationKind(TemplateSpecializationKind TSK, 2921 SourceLocation PointOfInstantiation = SourceLocation()); 2922 2923 /// \brief If this enumeration is an instantiation of a member enumeration of 2924 /// a class template specialization, retrieves the member specialization 2925 /// information. 2926 MemberSpecializationInfo *getMemberSpecializationInfo() const { 2927 return SpecializationInfo; 2928 } 2929 2930 /// \brief Specify that this enumeration is an instantiation of the 2931 /// member enumeration ED. 2932 void setInstantiationOfMemberEnum(EnumDecl *ED, 2933 TemplateSpecializationKind TSK) { 2934 setInstantiationOfMemberEnum(getASTContext(), ED, TSK); 2935 } 2936 2937 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 2938 static bool classofKind(Kind K) { return K == Enum; } 2939 2940 friend class ASTDeclReader; 2941}; 2942 2943 2944/// RecordDecl - Represents a struct/union/class. For example: 2945/// struct X; // Forward declaration, no "body". 2946/// union Y { int A, B; }; // Has body with members A and B (FieldDecls). 2947/// This decl will be marked invalid if *any* members are invalid. 2948/// 2949class RecordDecl : public TagDecl { 2950 // FIXME: This can be packed into the bitfields in Decl. 2951 /// HasFlexibleArrayMember - This is true if this struct ends with a flexible 2952 /// array member (e.g. int X[]) or if this union contains a struct that does. 2953 /// If so, this cannot be contained in arrays or other structs as a member. 2954 bool HasFlexibleArrayMember : 1; 2955 2956 /// AnonymousStructOrUnion - Whether this is the type of an anonymous struct 2957 /// or union. 2958 bool AnonymousStructOrUnion : 1; 2959 2960 /// HasObjectMember - This is true if this struct has at least one member 2961 /// containing an Objective-C object pointer type. 2962 bool HasObjectMember : 1; 2963 2964 /// HasVolatileMember - This is true if struct has at least one member of 2965 /// 'volatile' type. 2966 bool HasVolatileMember : 1; 2967 2968 /// \brief Whether the field declarations of this record have been loaded 2969 /// from external storage. To avoid unnecessary deserialization of 2970 /// methods/nested types we allow deserialization of just the fields 2971 /// when needed. 2972 mutable bool LoadedFieldsFromExternalStorage : 1; 2973 friend class DeclContext; 2974 2975protected: 2976 RecordDecl(Kind DK, TagKind TK, DeclContext *DC, 2977 SourceLocation StartLoc, SourceLocation IdLoc, 2978 IdentifierInfo *Id, RecordDecl *PrevDecl); 2979 2980public: 2981 static RecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC, 2982 SourceLocation StartLoc, SourceLocation IdLoc, 2983 IdentifierInfo *Id, RecordDecl* PrevDecl = 0); 2984 static RecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID); 2985 2986 const RecordDecl *getPreviousDecl() const { 2987 return cast_or_null<RecordDecl>(TagDecl::getPreviousDecl()); 2988 } 2989 RecordDecl *getPreviousDecl() { 2990 return cast_or_null<RecordDecl>(TagDecl::getPreviousDecl()); 2991 } 2992 2993 const RecordDecl *getMostRecentDecl() const { 2994 return cast<RecordDecl>(TagDecl::getMostRecentDecl()); 2995 } 2996 RecordDecl *getMostRecentDecl() { 2997 return cast<RecordDecl>(TagDecl::getMostRecentDecl()); 2998 } 2999 3000 bool hasFlexibleArrayMember() const { return HasFlexibleArrayMember; } 3001 void setHasFlexibleArrayMember(bool V) { HasFlexibleArrayMember = V; } 3002 3003 /// isAnonymousStructOrUnion - Whether this is an anonymous struct 3004 /// or union. To be an anonymous struct or union, it must have been 3005 /// declared without a name and there must be no objects of this 3006 /// type declared, e.g., 3007 /// @code 3008 /// union { int i; float f; }; 3009 /// @endcode 3010 /// is an anonymous union but neither of the following are: 3011 /// @code 3012 /// union X { int i; float f; }; 3013 /// union { int i; float f; } obj; 3014 /// @endcode 3015 bool isAnonymousStructOrUnion() const { return AnonymousStructOrUnion; } 3016 void setAnonymousStructOrUnion(bool Anon) { 3017 AnonymousStructOrUnion = Anon; 3018 } 3019 3020 bool hasObjectMember() const { return HasObjectMember; } 3021 void setHasObjectMember (bool val) { HasObjectMember = val; } 3022 3023 bool hasVolatileMember() const { return HasVolatileMember; } 3024 void setHasVolatileMember (bool val) { HasVolatileMember = val; } 3025 3026 /// \brief Determines whether this declaration represents the 3027 /// injected class name. 3028 /// 3029 /// The injected class name in C++ is the name of the class that 3030 /// appears inside the class itself. For example: 3031 /// 3032 /// \code 3033 /// struct C { 3034 /// // C is implicitly declared here as a synonym for the class name. 3035 /// }; 3036 /// 3037 /// C::C c; // same as "C c;" 3038 /// \endcode 3039 bool isInjectedClassName() const; 3040 3041 /// getDefinition - Returns the RecordDecl that actually defines 3042 /// this struct/union/class. When determining whether or not a 3043 /// struct/union/class is completely defined, one should use this 3044 /// method as opposed to 'isCompleteDefinition'. 3045 /// 'isCompleteDefinition' indicates whether or not a specific 3046 /// RecordDecl is a completed definition, not whether or not the 3047 /// record type is defined. This method returns NULL if there is 3048 /// no RecordDecl that defines the struct/union/tag. 3049 RecordDecl *getDefinition() const { 3050 return cast_or_null<RecordDecl>(TagDecl::getDefinition()); 3051 } 3052 3053 // Iterator access to field members. The field iterator only visits 3054 // the non-static data members of this class, ignoring any static 3055 // data members, functions, constructors, destructors, etc. 3056 typedef specific_decl_iterator<FieldDecl> field_iterator; 3057 3058 field_iterator field_begin() const; 3059 3060 field_iterator field_end() const { 3061 return field_iterator(decl_iterator()); 3062 } 3063 3064 // field_empty - Whether there are any fields (non-static data 3065 // members) in this record. 3066 bool field_empty() const { 3067 return field_begin() == field_end(); 3068 } 3069 3070 /// completeDefinition - Notes that the definition of this type is 3071 /// now complete. 3072 virtual void completeDefinition(); 3073 3074 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 3075 static bool classofKind(Kind K) { 3076 return K >= firstRecord && K <= lastRecord; 3077 } 3078 3079 /// isMsStrust - Get whether or not this is an ms_struct which can 3080 /// be turned on with an attribute, pragma, or -mms-bitfields 3081 /// commandline option. 3082 bool isMsStruct(const ASTContext &C) const; 3083 3084private: 3085 /// \brief Deserialize just the fields. 3086 void LoadFieldsFromExternalStorage() const; 3087}; 3088 3089class FileScopeAsmDecl : public Decl { 3090 virtual void anchor(); 3091 StringLiteral *AsmString; 3092 SourceLocation RParenLoc; 3093 FileScopeAsmDecl(DeclContext *DC, StringLiteral *asmstring, 3094 SourceLocation StartL, SourceLocation EndL) 3095 : Decl(FileScopeAsm, DC, StartL), AsmString(asmstring), RParenLoc(EndL) {} 3096public: 3097 static FileScopeAsmDecl *Create(ASTContext &C, DeclContext *DC, 3098 StringLiteral *Str, SourceLocation AsmLoc, 3099 SourceLocation RParenLoc); 3100 3101 static FileScopeAsmDecl *CreateDeserialized(ASTContext &C, unsigned ID); 3102 3103 SourceLocation getAsmLoc() const { return getLocation(); } 3104 SourceLocation getRParenLoc() const { return RParenLoc; } 3105 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 3106 SourceRange getSourceRange() const LLVM_READONLY { 3107 return SourceRange(getAsmLoc(), getRParenLoc()); 3108 } 3109 3110 const StringLiteral *getAsmString() const { return AsmString; } 3111 StringLiteral *getAsmString() { return AsmString; } 3112 void setAsmString(StringLiteral *Asm) { AsmString = Asm; } 3113 3114 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 3115 static bool classofKind(Kind K) { return K == FileScopeAsm; } 3116}; 3117 3118/// BlockDecl - This represents a block literal declaration, which is like an 3119/// unnamed FunctionDecl. For example: 3120/// ^{ statement-body } or ^(int arg1, float arg2){ statement-body } 3121/// 3122class BlockDecl : public Decl, public DeclContext { 3123public: 3124 /// A class which contains all the information about a particular 3125 /// captured value. 3126 class Capture { 3127 enum { 3128 flag_isByRef = 0x1, 3129 flag_isNested = 0x2 3130 }; 3131 3132 /// The variable being captured. 3133 llvm::PointerIntPair<VarDecl*, 2> VariableAndFlags; 3134 3135 /// The copy expression, expressed in terms of a DeclRef (or 3136 /// BlockDeclRef) to the captured variable. Only required if the 3137 /// variable has a C++ class type. 3138 Expr *CopyExpr; 3139 3140 public: 3141 Capture(VarDecl *variable, bool byRef, bool nested, Expr *copy) 3142 : VariableAndFlags(variable, 3143 (byRef ? flag_isByRef : 0) | (nested ? flag_isNested : 0)), 3144 CopyExpr(copy) {} 3145 3146 /// The variable being captured. 3147 VarDecl *getVariable() const { return VariableAndFlags.getPointer(); } 3148 3149 /// Whether this is a "by ref" capture, i.e. a capture of a __block 3150 /// variable. 3151 bool isByRef() const { return VariableAndFlags.getInt() & flag_isByRef; } 3152 3153 /// Whether this is a nested capture, i.e. the variable captured 3154 /// is not from outside the immediately enclosing function/block. 3155 bool isNested() const { return VariableAndFlags.getInt() & flag_isNested; } 3156 3157 bool hasCopyExpr() const { return CopyExpr != 0; } 3158 Expr *getCopyExpr() const { return CopyExpr; } 3159 void setCopyExpr(Expr *e) { CopyExpr = e; } 3160 }; 3161 3162private: 3163 // FIXME: This can be packed into the bitfields in Decl. 3164 bool IsVariadic : 1; 3165 bool CapturesCXXThis : 1; 3166 bool BlockMissingReturnType : 1; 3167 bool IsConversionFromLambda : 1; 3168 /// ParamInfo - new[]'d array of pointers to ParmVarDecls for the formal 3169 /// parameters of this function. This is null if a prototype or if there are 3170 /// no formals. 3171 ParmVarDecl **ParamInfo; 3172 unsigned NumParams; 3173 3174 Stmt *Body; 3175 TypeSourceInfo *SignatureAsWritten; 3176 3177 Capture *Captures; 3178 unsigned NumCaptures; 3179 3180 unsigned ManglingNumber; 3181 Decl *ManglingContextDecl; 3182 3183protected: 3184 BlockDecl(DeclContext *DC, SourceLocation CaretLoc) 3185 : Decl(Block, DC, CaretLoc), DeclContext(Block), 3186 IsVariadic(false), CapturesCXXThis(false), 3187 BlockMissingReturnType(true), IsConversionFromLambda(false), 3188 ParamInfo(0), NumParams(0), Body(0), 3189 SignatureAsWritten(0), Captures(0), NumCaptures(0), 3190 ManglingNumber(0), ManglingContextDecl(0) {} 3191 3192public: 3193 static BlockDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L); 3194 static BlockDecl *CreateDeserialized(ASTContext &C, unsigned ID); 3195 3196 SourceLocation getCaretLocation() const { return getLocation(); } 3197 3198 bool isVariadic() const { return IsVariadic; } 3199 void setIsVariadic(bool value) { IsVariadic = value; } 3200 3201 CompoundStmt *getCompoundBody() const { return (CompoundStmt*) Body; } 3202 Stmt *getBody() const { return (Stmt*) Body; } 3203 void setBody(CompoundStmt *B) { Body = (Stmt*) B; } 3204 3205 void setSignatureAsWritten(TypeSourceInfo *Sig) { SignatureAsWritten = Sig; } 3206 TypeSourceInfo *getSignatureAsWritten() const { return SignatureAsWritten; } 3207 3208 // Iterator access to formal parameters. 3209 unsigned param_size() const { return getNumParams(); } 3210 typedef ParmVarDecl **param_iterator; 3211 typedef ParmVarDecl * const *param_const_iterator; 3212 3213 bool param_empty() const { return NumParams == 0; } 3214 param_iterator param_begin() { return ParamInfo; } 3215 param_iterator param_end() { return ParamInfo+param_size(); } 3216 3217 param_const_iterator param_begin() const { return ParamInfo; } 3218 param_const_iterator param_end() const { return ParamInfo+param_size(); } 3219 3220 unsigned getNumParams() const { return NumParams; } 3221 const ParmVarDecl *getParamDecl(unsigned i) const { 3222 assert(i < getNumParams() && "Illegal param #"); 3223 return ParamInfo[i]; 3224 } 3225 ParmVarDecl *getParamDecl(unsigned i) { 3226 assert(i < getNumParams() && "Illegal param #"); 3227 return ParamInfo[i]; 3228 } 3229 void setParams(ArrayRef<ParmVarDecl *> NewParamInfo); 3230 3231 /// hasCaptures - True if this block (or its nested blocks) captures 3232 /// anything of local storage from its enclosing scopes. 3233 bool hasCaptures() const { return NumCaptures != 0 || CapturesCXXThis; } 3234 3235 /// getNumCaptures - Returns the number of captured variables. 3236 /// Does not include an entry for 'this'. 3237 unsigned getNumCaptures() const { return NumCaptures; } 3238 3239 typedef const Capture *capture_iterator; 3240 typedef const Capture *capture_const_iterator; 3241 capture_iterator capture_begin() { return Captures; } 3242 capture_iterator capture_end() { return Captures + NumCaptures; } 3243 capture_const_iterator capture_begin() const { return Captures; } 3244 capture_const_iterator capture_end() const { return Captures + NumCaptures; } 3245 3246 bool capturesCXXThis() const { return CapturesCXXThis; } 3247 bool blockMissingReturnType() const { return BlockMissingReturnType; } 3248 void setBlockMissingReturnType(bool val) { BlockMissingReturnType = val; } 3249 3250 bool isConversionFromLambda() const { return IsConversionFromLambda; } 3251 void setIsConversionFromLambda(bool val) { IsConversionFromLambda = val; } 3252 3253 bool capturesVariable(const VarDecl *var) const; 3254 3255 void setCaptures(ASTContext &Context, 3256 const Capture *begin, 3257 const Capture *end, 3258 bool capturesCXXThis); 3259 3260 unsigned getBlockManglingNumber() const { 3261 return ManglingNumber; 3262 } 3263 Decl *getBlockManglingContextDecl() const { 3264 return ManglingContextDecl; 3265 } 3266 3267 void setBlockMangling(unsigned Number, Decl *Ctx) { 3268 ManglingNumber = Number; 3269 ManglingContextDecl = Ctx; 3270 } 3271 3272 virtual SourceRange getSourceRange() const LLVM_READONLY; 3273 3274 // Implement isa/cast/dyncast/etc. 3275 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 3276 static bool classofKind(Kind K) { return K == Block; } 3277 static DeclContext *castToDeclContext(const BlockDecl *D) { 3278 return static_cast<DeclContext *>(const_cast<BlockDecl*>(D)); 3279 } 3280 static BlockDecl *castFromDeclContext(const DeclContext *DC) { 3281 return static_cast<BlockDecl *>(const_cast<DeclContext*>(DC)); 3282 } 3283}; 3284 3285/// \brief This represents the body of a CapturedStmt, and serves as its 3286/// DeclContext. 3287class CapturedDecl : public Decl, public DeclContext { 3288private: 3289 /// \brief The number of parameters to the outlined function. 3290 unsigned NumParams; 3291 /// \brief The body of the outlined function. 3292 Stmt *Body; 3293 3294 explicit CapturedDecl(DeclContext *DC, unsigned NumParams) 3295 : Decl(Captured, DC, SourceLocation()), DeclContext(Captured), 3296 NumParams(NumParams), Body(0) { } 3297 3298 ImplicitParamDecl **getParams() const { 3299 return reinterpret_cast<ImplicitParamDecl **>( 3300 const_cast<CapturedDecl *>(this) + 1); 3301 } 3302 3303public: 3304 static CapturedDecl *Create(ASTContext &C, DeclContext *DC, unsigned NumParams); 3305 static CapturedDecl *CreateDeserialized(ASTContext &C, unsigned ID, 3306 unsigned NumParams); 3307 3308 Stmt *getBody() const { return Body; } 3309 void setBody(Stmt *B) { Body = B; } 3310 3311 unsigned getNumParams() const { return NumParams; } 3312 3313 ImplicitParamDecl *getParam(unsigned i) const { 3314 assert(i < NumParams); 3315 return getParams()[i]; 3316 } 3317 void setParam(unsigned i, ImplicitParamDecl *P) { 3318 assert(i < NumParams); 3319 getParams()[i] = P; 3320 } 3321 3322 /// \brief Retrieve the parameter containing captured variables. 3323 ImplicitParamDecl *getContextParam() const { return getParam(0); } 3324 void setContextParam(ImplicitParamDecl *P) { setParam(0, P); } 3325 3326 typedef ImplicitParamDecl **param_iterator; 3327 /// \brief Retrieve an iterator pointing to the first parameter decl. 3328 param_iterator param_begin() const { return getParams(); } 3329 /// \brief Retrieve an iterator one past the last parameter decl. 3330 param_iterator param_end() const { return getParams() + NumParams; } 3331 3332 // Implement isa/cast/dyncast/etc. 3333 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 3334 static bool classofKind(Kind K) { return K == Captured; } 3335 static DeclContext *castToDeclContext(const CapturedDecl *D) { 3336 return static_cast<DeclContext *>(const_cast<CapturedDecl *>(D)); 3337 } 3338 static CapturedDecl *castFromDeclContext(const DeclContext *DC) { 3339 return static_cast<CapturedDecl *>(const_cast<DeclContext *>(DC)); 3340 } 3341 3342 friend class ASTDeclReader; 3343 friend class ASTDeclWriter; 3344}; 3345 3346/// \brief Describes a module import declaration, which makes the contents 3347/// of the named module visible in the current translation unit. 3348/// 3349/// An import declaration imports the named module (or submodule). For example: 3350/// \code 3351/// @import std.vector; 3352/// \endcode 3353/// 3354/// Import declarations can also be implicitly generated from 3355/// \#include/\#import directives. 3356class ImportDecl : public Decl { 3357 /// \brief The imported module, along with a bit that indicates whether 3358 /// we have source-location information for each identifier in the module 3359 /// name. 3360 /// 3361 /// When the bit is false, we only have a single source location for the 3362 /// end of the import declaration. 3363 llvm::PointerIntPair<Module *, 1, bool> ImportedAndComplete; 3364 3365 /// \brief The next import in the list of imports local to the translation 3366 /// unit being parsed (not loaded from an AST file). 3367 ImportDecl *NextLocalImport; 3368 3369 friend class ASTReader; 3370 friend class ASTDeclReader; 3371 friend class ASTContext; 3372 3373 ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported, 3374 ArrayRef<SourceLocation> IdentifierLocs); 3375 3376 ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported, 3377 SourceLocation EndLoc); 3378 3379 ImportDecl(EmptyShell Empty) : Decl(Import, Empty), NextLocalImport() { } 3380 3381public: 3382 /// \brief Create a new module import declaration. 3383 static ImportDecl *Create(ASTContext &C, DeclContext *DC, 3384 SourceLocation StartLoc, Module *Imported, 3385 ArrayRef<SourceLocation> IdentifierLocs); 3386 3387 /// \brief Create a new module import declaration for an implicitly-generated 3388 /// import. 3389 static ImportDecl *CreateImplicit(ASTContext &C, DeclContext *DC, 3390 SourceLocation StartLoc, Module *Imported, 3391 SourceLocation EndLoc); 3392 3393 /// \brief Create a new, deserialized module import declaration. 3394 static ImportDecl *CreateDeserialized(ASTContext &C, unsigned ID, 3395 unsigned NumLocations); 3396 3397 /// \brief Retrieve the module that was imported by the import declaration. 3398 Module *getImportedModule() const { return ImportedAndComplete.getPointer(); } 3399 3400 /// \brief Retrieves the locations of each of the identifiers that make up 3401 /// the complete module name in the import declaration. 3402 /// 3403 /// This will return an empty array if the locations of the individual 3404 /// identifiers aren't available. 3405 ArrayRef<SourceLocation> getIdentifierLocs() const; 3406 3407 virtual SourceRange getSourceRange() const LLVM_READONLY; 3408 3409 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 3410 static bool classofKind(Kind K) { return K == Import; } 3411}; 3412 3413/// \brief Represents an empty-declaration. 3414class EmptyDecl : public Decl { 3415 virtual void anchor(); 3416 EmptyDecl(DeclContext *DC, SourceLocation L) 3417 : Decl(Empty, DC, L) { } 3418 3419public: 3420 static EmptyDecl *Create(ASTContext &C, DeclContext *DC, 3421 SourceLocation L); 3422 static EmptyDecl *CreateDeserialized(ASTContext &C, unsigned ID); 3423 3424 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 3425 static bool classofKind(Kind K) { return K == Empty; } 3426}; 3427 3428/// Insertion operator for diagnostics. This allows sending NamedDecl's 3429/// into a diagnostic with <<. 3430inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 3431 const NamedDecl* ND) { 3432 DB.AddTaggedVal(reinterpret_cast<intptr_t>(ND), 3433 DiagnosticsEngine::ak_nameddecl); 3434 return DB; 3435} 3436inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD, 3437 const NamedDecl* ND) { 3438 PD.AddTaggedVal(reinterpret_cast<intptr_t>(ND), 3439 DiagnosticsEngine::ak_nameddecl); 3440 return PD; 3441} 3442 3443template<typename decl_type> 3444void Redeclarable<decl_type>::setPreviousDeclaration(decl_type *PrevDecl) { 3445 // Note: This routine is implemented here because we need both NamedDecl 3446 // and Redeclarable to be defined. 3447 3448 decl_type *First; 3449 3450 if (PrevDecl) { 3451 // Point to previous. Make sure that this is actually the most recent 3452 // redeclaration, or we can build invalid chains. If the most recent 3453 // redeclaration is invalid, it won't be PrevDecl, but we want it anyway. 3454 First = PrevDecl->getFirstDeclaration(); 3455 assert(First->RedeclLink.NextIsLatest() && "Expected first"); 3456 decl_type *MostRecent = First->RedeclLink.getNext(); 3457 RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent)); 3458 3459 // If the declaration was previously visible, a redeclaration of it remains 3460 // visible even if it wouldn't be visible by itself. 3461 // FIXME: Once we handle local extern decls properly, this should inherit 3462 // the visibility from MostRecent, not from PrevDecl. 3463 static_cast<decl_type*>(this)->IdentifierNamespace |= 3464 PrevDecl->getIdentifierNamespace() & 3465 (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type); 3466 } else { 3467 // Make this first. 3468 First = static_cast<decl_type*>(this); 3469 } 3470 3471 // First one will point to this one as latest. 3472 First->RedeclLink = LatestDeclLink(static_cast<decl_type*>(this)); 3473 assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) || 3474 cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid()); 3475} 3476 3477// Inline function definitions. 3478 3479/// \brief Check if the given decl is complete. 3480/// 3481/// We use this function to break a cycle between the inline definitions in 3482/// Type.h and Decl.h. 3483inline bool IsEnumDeclComplete(EnumDecl *ED) { 3484 return ED->isComplete(); 3485} 3486 3487/// \brief Check if the given decl is scoped. 3488/// 3489/// We use this function to break a cycle between the inline definitions in 3490/// Type.h and Decl.h. 3491inline bool IsEnumDeclScoped(EnumDecl *ED) { 3492 return ED->isScoped(); 3493} 3494 3495} // end namespace clang 3496 3497#endif 3498