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