DeclBase.h revision ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298
1//===-- DeclBase.h - Base 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 and DeclContext interfaces. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef LLVM_CLANG_AST_DECLBASE_H 15#define LLVM_CLANG_AST_DECLBASE_H 16 17#include "clang/AST/Attr.h" 18#include "clang/AST/Type.h" 19#include "clang/Basic/Specifiers.h" 20#include "llvm/Support/PrettyStackTrace.h" 21#include "llvm/ADT/PointerUnion.h" 22 23namespace clang { 24class DeclContext; 25class TranslationUnitDecl; 26class NamespaceDecl; 27class UsingDirectiveDecl; 28class NamedDecl; 29class FunctionDecl; 30class CXXRecordDecl; 31class EnumDecl; 32class ObjCMethodDecl; 33class ObjCContainerDecl; 34class ObjCInterfaceDecl; 35class ObjCCategoryDecl; 36class ObjCProtocolDecl; 37class ObjCImplementationDecl; 38class ObjCCategoryImplDecl; 39class ObjCImplDecl; 40class LinkageSpecDecl; 41class BlockDecl; 42class DeclarationName; 43class CompoundStmt; 44class StoredDeclsMap; 45class DependentDiagnostic; 46class ASTMutationListener; 47} 48 49namespace llvm { 50// DeclContext* is only 4-byte aligned on 32-bit systems. 51template<> 52 class PointerLikeTypeTraits<clang::DeclContext*> { 53 typedef clang::DeclContext* PT; 54public: 55 static inline void *getAsVoidPointer(PT P) { return P; } 56 static inline PT getFromVoidPointer(void *P) { 57 return static_cast<PT>(P); 58 } 59 enum { NumLowBitsAvailable = 2 }; 60}; 61} 62 63namespace clang { 64 65/// Decl - This represents one declaration (or definition), e.g. a variable, 66/// typedef, function, struct, etc. 67/// 68class Decl { 69public: 70 /// \brief Lists the kind of concrete classes of Decl. 71 enum Kind { 72#define DECL(DERIVED, BASE) DERIVED, 73#define ABSTRACT_DECL(DECL) 74#define DECL_RANGE(BASE, START, END) \ 75 first##BASE = START, last##BASE = END, 76#define LAST_DECL_RANGE(BASE, START, END) \ 77 first##BASE = START, last##BASE = END 78#include "clang/AST/DeclNodes.inc" 79 }; 80 81 /// \brief A placeholder type used to construct an empty shell of a 82 /// decl-derived type that will be filled in later (e.g., by some 83 /// deserialization method). 84 struct EmptyShell { }; 85 86 /// IdentifierNamespace - The different namespaces in which 87 /// declarations may appear. According to C99 6.2.3, there are 88 /// four namespaces, labels, tags, members and ordinary 89 /// identifiers. C++ describes lookup completely differently: 90 /// certain lookups merely "ignore" certain kinds of declarations, 91 /// usually based on whether the declaration is of a type, etc. 92 /// 93 /// These are meant as bitmasks, so that searches in 94 /// C++ can look into the "tag" namespace during ordinary lookup. 95 /// 96 /// Decl currently provides 15 bits of IDNS bits. 97 enum IdentifierNamespace { 98 /// Labels, declared with 'x:' and referenced with 'goto x'. 99 IDNS_Label = 0x0001, 100 101 /// Tags, declared with 'struct foo;' and referenced with 102 /// 'struct foo'. All tags are also types. This is what 103 /// elaborated-type-specifiers look for in C. 104 IDNS_Tag = 0x0002, 105 106 /// Types, declared with 'struct foo', typedefs, etc. 107 /// This is what elaborated-type-specifiers look for in C++, 108 /// but note that it's ill-formed to find a non-tag. 109 IDNS_Type = 0x0004, 110 111 /// Members, declared with object declarations within tag 112 /// definitions. In C, these can only be found by "qualified" 113 /// lookup in member expressions. In C++, they're found by 114 /// normal lookup. 115 IDNS_Member = 0x0008, 116 117 /// Namespaces, declared with 'namespace foo {}'. 118 /// Lookup for nested-name-specifiers find these. 119 IDNS_Namespace = 0x0010, 120 121 /// Ordinary names. In C, everything that's not a label, tag, 122 /// or member ends up here. 123 IDNS_Ordinary = 0x0020, 124 125 /// Objective C @protocol. 126 IDNS_ObjCProtocol = 0x0040, 127 128 /// This declaration is a friend function. A friend function 129 /// declaration is always in this namespace but may also be in 130 /// IDNS_Ordinary if it was previously declared. 131 IDNS_OrdinaryFriend = 0x0080, 132 133 /// This declaration is a friend class. A friend class 134 /// declaration is always in this namespace but may also be in 135 /// IDNS_Tag|IDNS_Type if it was previously declared. 136 IDNS_TagFriend = 0x0100, 137 138 /// This declaration is a using declaration. A using declaration 139 /// *introduces* a number of other declarations into the current 140 /// scope, and those declarations use the IDNS of their targets, 141 /// but the actual using declarations go in this namespace. 142 IDNS_Using = 0x0200, 143 144 /// This declaration is a C++ operator declared in a non-class 145 /// context. All such operators are also in IDNS_Ordinary. 146 /// C++ lexical operator lookup looks for these. 147 IDNS_NonMemberOperator = 0x0400 148 }; 149 150 /// ObjCDeclQualifier - Qualifier used on types in method declarations 151 /// for remote messaging. They are meant for the arguments though and 152 /// applied to the Decls (ObjCMethodDecl and ParmVarDecl). 153 enum ObjCDeclQualifier { 154 OBJC_TQ_None = 0x0, 155 OBJC_TQ_In = 0x1, 156 OBJC_TQ_Inout = 0x2, 157 OBJC_TQ_Out = 0x4, 158 OBJC_TQ_Bycopy = 0x8, 159 OBJC_TQ_Byref = 0x10, 160 OBJC_TQ_Oneway = 0x20 161 }; 162 163private: 164 /// NextDeclInContext - The next declaration within the same lexical 165 /// DeclContext. These pointers form the linked list that is 166 /// traversed via DeclContext's decls_begin()/decls_end(). 167 Decl *NextDeclInContext; 168 169 friend class DeclContext; 170 171 struct MultipleDC { 172 DeclContext *SemanticDC; 173 DeclContext *LexicalDC; 174 }; 175 176 177 /// DeclCtx - Holds either a DeclContext* or a MultipleDC*. 178 /// For declarations that don't contain C++ scope specifiers, it contains 179 /// the DeclContext where the Decl was declared. 180 /// For declarations with C++ scope specifiers, it contains a MultipleDC* 181 /// with the context where it semantically belongs (SemanticDC) and the 182 /// context where it was lexically declared (LexicalDC). 183 /// e.g.: 184 /// 185 /// namespace A { 186 /// void f(); // SemanticDC == LexicalDC == 'namespace A' 187 /// } 188 /// void A::f(); // SemanticDC == namespace 'A' 189 /// // LexicalDC == global namespace 190 llvm::PointerUnion<DeclContext*, MultipleDC*> DeclCtx; 191 192 inline bool isInSemaDC() const { return DeclCtx.is<DeclContext*>(); } 193 inline bool isOutOfSemaDC() const { return DeclCtx.is<MultipleDC*>(); } 194 inline MultipleDC *getMultipleDC() const { 195 return DeclCtx.get<MultipleDC*>(); 196 } 197 inline DeclContext *getSemanticDC() const { 198 return DeclCtx.get<DeclContext*>(); 199 } 200 201 /// Loc - The location of this decl. 202 SourceLocation Loc; 203 204 /// DeclKind - This indicates which class this is. 205 unsigned DeclKind : 8; 206 207 /// InvalidDecl - This indicates a semantic error occurred. 208 unsigned InvalidDecl : 1; 209 210 /// HasAttrs - This indicates whether the decl has attributes or not. 211 unsigned HasAttrs : 1; 212 213 /// Implicit - Whether this declaration was implicitly generated by 214 /// the implementation rather than explicitly written by the user. 215 unsigned Implicit : 1; 216 217 /// \brief Whether this declaration was "used", meaning that a definition is 218 /// required. 219 unsigned Used : 1; 220 221protected: 222 /// Access - Used by C++ decls for the access specifier. 223 // NOTE: VC++ treats enums as signed, avoid using the AccessSpecifier enum 224 unsigned Access : 2; 225 friend class CXXClassMemberWrapper; 226 227 /// PCHLevel - the "level" of AST file from which this declaration was built. 228 unsigned PCHLevel : 2; 229 230 /// ChangedAfterLoad - if this declaration has changed since being loaded 231 unsigned ChangedAfterLoad : 1; 232 233 /// IdentifierNamespace - This specifies what IDNS_* namespace this lives in. 234 unsigned IdentifierNamespace : 12; 235 236 /// \brief Whether the \c CachedLinkage field is active. 237 /// 238 /// This field is only valid for NamedDecls subclasses. 239 mutable unsigned HasCachedLinkage : 1; 240 241 /// \brief If \c HasCachedLinkage, the linkage of this declaration. 242 /// 243 /// This field is only valid for NamedDecls subclasses. 244 mutable unsigned CachedLinkage : 2; 245 246 247private: 248 void CheckAccessDeclContext() const; 249 250protected: 251 252 Decl(Kind DK, DeclContext *DC, SourceLocation L) 253 : NextDeclInContext(0), DeclCtx(DC), 254 Loc(L), DeclKind(DK), InvalidDecl(0), 255 HasAttrs(false), Implicit(false), Used(false), 256 Access(AS_none), PCHLevel(0), ChangedAfterLoad(false), 257 IdentifierNamespace(getIdentifierNamespaceForKind(DK)), 258 HasCachedLinkage(0) 259 { 260 if (Decl::CollectingStats()) add(DK); 261 } 262 263 Decl(Kind DK, EmptyShell Empty) 264 : NextDeclInContext(0), DeclKind(DK), InvalidDecl(0), 265 HasAttrs(false), Implicit(false), Used(false), 266 Access(AS_none), PCHLevel(0), ChangedAfterLoad(false), 267 IdentifierNamespace(getIdentifierNamespaceForKind(DK)), 268 HasCachedLinkage(0) 269 { 270 if (Decl::CollectingStats()) add(DK); 271 } 272 273 virtual ~Decl(); 274 275public: 276 277 /// \brief Source range that this declaration covers. 278 virtual SourceRange getSourceRange() const { 279 return SourceRange(getLocation(), getLocation()); 280 } 281 SourceLocation getLocStart() const { return getSourceRange().getBegin(); } 282 SourceLocation getLocEnd() const { return getSourceRange().getEnd(); } 283 284 SourceLocation getLocation() const { return Loc; } 285 void setLocation(SourceLocation L) { Loc = L; } 286 287 Kind getKind() const { return static_cast<Kind>(DeclKind); } 288 const char *getDeclKindName() const; 289 290 Decl *getNextDeclInContext() { return NextDeclInContext; } 291 const Decl *getNextDeclInContext() const { return NextDeclInContext; } 292 293 DeclContext *getDeclContext() { 294 if (isInSemaDC()) 295 return getSemanticDC(); 296 return getMultipleDC()->SemanticDC; 297 } 298 const DeclContext *getDeclContext() const { 299 return const_cast<Decl*>(this)->getDeclContext(); 300 } 301 302 TranslationUnitDecl *getTranslationUnitDecl(); 303 const TranslationUnitDecl *getTranslationUnitDecl() const { 304 return const_cast<Decl*>(this)->getTranslationUnitDecl(); 305 } 306 307 bool isInAnonymousNamespace() const; 308 309 ASTContext &getASTContext() const; 310 311 void setAccess(AccessSpecifier AS) { 312 Access = AS; 313#ifndef NDEBUG 314 CheckAccessDeclContext(); 315#endif 316 } 317 318 AccessSpecifier getAccess() const { 319#ifndef NDEBUG 320 CheckAccessDeclContext(); 321#endif 322 return AccessSpecifier(Access); 323 } 324 325 bool hasAttrs() const { return HasAttrs; } 326 void setAttrs(const AttrVec& Attrs); 327 AttrVec &getAttrs() { 328 return const_cast<AttrVec&>(const_cast<const Decl*>(this)->getAttrs()); 329 } 330 const AttrVec &getAttrs() const; 331 void swapAttrs(Decl *D); 332 void dropAttrs(); 333 334 void addAttr(Attr *A) { 335 if (hasAttrs()) 336 getAttrs().push_back(A); 337 else 338 setAttrs(AttrVec(1, A)); 339 } 340 341 typedef AttrVec::const_iterator attr_iterator; 342 343 // FIXME: Do not rely on iterators having comparable singular values. 344 // Note that this should error out if they do not. 345 attr_iterator attr_begin() const { 346 return hasAttrs() ? getAttrs().begin() : 0; 347 } 348 attr_iterator attr_end() const { 349 return hasAttrs() ? getAttrs().end() : 0; 350 } 351 352 template <typename T> 353 specific_attr_iterator<T> specific_attr_begin() const { 354 return specific_attr_iterator<T>(attr_begin()); 355 } 356 template <typename T> 357 specific_attr_iterator<T> specific_attr_end() const { 358 return specific_attr_iterator<T>(attr_end()); 359 } 360 361 template<typename T> T *getAttr() const { 362 return hasAttrs() ? getSpecificAttr<T>(getAttrs()) : 0; 363 } 364 template<typename T> bool hasAttr() const { 365 return hasAttrs() && hasSpecificAttr<T>(getAttrs()); 366 } 367 368 /// getMaxAlignment - return the maximum alignment specified by attributes 369 /// on this decl, 0 if there are none. 370 unsigned getMaxAlignment() const { 371 return hasAttrs() ? getMaxAttrAlignment(getAttrs(), getASTContext()) : 0; 372 } 373 374 /// setInvalidDecl - Indicates the Decl had a semantic error. This 375 /// allows for graceful error recovery. 376 void setInvalidDecl(bool Invalid = true); 377 bool isInvalidDecl() const { return (bool) InvalidDecl; } 378 379 /// isImplicit - Indicates whether the declaration was implicitly 380 /// generated by the implementation. If false, this declaration 381 /// was written explicitly in the source code. 382 bool isImplicit() const { return Implicit; } 383 void setImplicit(bool I = true) { Implicit = I; } 384 385 /// \brief Whether this declaration was used, meaning that a definition 386 /// is required. 387 /// 388 /// \param CheckUsedAttr When true, also consider the "used" attribute 389 /// (in addition to the "used" bit set by \c setUsed()) when determining 390 /// whether the function is used. 391 bool isUsed(bool CheckUsedAttr = true) const; 392 393 void setUsed(bool U = true) { Used = U; } 394 395 /// \brief Retrieve the level of precompiled header from which this 396 /// declaration was generated. 397 /// 398 /// The PCH level of a declaration describes where the declaration originated 399 /// from. A PCH level of 0 indicates that the declaration was parsed from 400 /// source. A PCH level of 1 indicates that the declaration was loaded from 401 /// a top-level AST file. A PCH level 2 indicates that the declaration was 402 /// loaded from a PCH file the AST file depends on, and so on. 403 unsigned getPCHLevel() const { return PCHLevel; } 404 405 /// \brief The maximum PCH level that any declaration may have. 406 static const unsigned MaxPCHLevel = 3; 407 408 /// \brief Set the PCH level of this declaration. 409 void setPCHLevel(unsigned Level) { 410 assert(Level <= MaxPCHLevel && "PCH level exceeds the maximum"); 411 PCHLevel = Level; 412 } 413 414 /// \brief Query whether this declaration was changed in a significant way 415 /// since being loaded from an AST file. 416 /// 417 /// In an epic violation of layering, what is "significant" is entirely 418 /// up to the serialization system, but implemented in AST and Sema. 419 bool isChangedSinceDeserialization() const { return ChangedAfterLoad; } 420 421 /// \brief Mark this declaration as having changed since deserialization, or 422 /// reset the flag. 423 void setChangedSinceDeserialization(bool Changed) { 424 ChangedAfterLoad = Changed; 425 } 426 427 unsigned getIdentifierNamespace() const { 428 return IdentifierNamespace; 429 } 430 bool isInIdentifierNamespace(unsigned NS) const { 431 return getIdentifierNamespace() & NS; 432 } 433 static unsigned getIdentifierNamespaceForKind(Kind DK); 434 435 bool hasTagIdentifierNamespace() const { 436 return isTagIdentifierNamespace(getIdentifierNamespace()); 437 } 438 static bool isTagIdentifierNamespace(unsigned NS) { 439 // TagDecls have Tag and Type set and may also have TagFriend. 440 return (NS & ~IDNS_TagFriend) == (IDNS_Tag | IDNS_Type); 441 } 442 443 /// getLexicalDeclContext - The declaration context where this Decl was 444 /// lexically declared (LexicalDC). May be different from 445 /// getDeclContext() (SemanticDC). 446 /// e.g.: 447 /// 448 /// namespace A { 449 /// void f(); // SemanticDC == LexicalDC == 'namespace A' 450 /// } 451 /// void A::f(); // SemanticDC == namespace 'A' 452 /// // LexicalDC == global namespace 453 DeclContext *getLexicalDeclContext() { 454 if (isInSemaDC()) 455 return getSemanticDC(); 456 return getMultipleDC()->LexicalDC; 457 } 458 const DeclContext *getLexicalDeclContext() const { 459 return const_cast<Decl*>(this)->getLexicalDeclContext(); 460 } 461 462 /// \brief Determine whether this declaration was written out-of-line, which 463 /// typically indicates that it was written with a qualified name in a scope 464 /// outside of its semantic scope. 465 bool isOutOfLine() const; 466 467 /// setDeclContext - Set both the semantic and lexical DeclContext 468 /// to DC. 469 void setDeclContext(DeclContext *DC); 470 471 void setLexicalDeclContext(DeclContext *DC); 472 473 /// isDefinedOutsideFunctionOrMethod - This predicate returns true if this 474 /// scoped decl is defined outside the current function or method. This is 475 /// roughly global variables and functions, but also handles enums (which 476 /// could be defined inside or outside a function etc). 477 bool isDefinedOutsideFunctionOrMethod() const; 478 479 /// \brief Retrieves the "canonical" declaration of the given declaration. 480 virtual Decl *getCanonicalDecl() { return this; } 481 const Decl *getCanonicalDecl() const { 482 return const_cast<Decl*>(this)->getCanonicalDecl(); 483 } 484 485 /// \brief Whether this particular Decl is a canonical one. 486 bool isCanonicalDecl() const { return getCanonicalDecl() == this; } 487 488protected: 489 /// \brief Returns the next redeclaration or itself if this is the only decl. 490 /// 491 /// Decl subclasses that can be redeclared should override this method so that 492 /// Decl::redecl_iterator can iterate over them. 493 virtual Decl *getNextRedeclaration() { return this; } 494 495public: 496 /// \brief Iterates through all the redeclarations of the same decl. 497 class redecl_iterator { 498 /// Current - The current declaration. 499 Decl *Current; 500 Decl *Starter; 501 502 public: 503 typedef Decl* value_type; 504 typedef Decl* reference; 505 typedef Decl* pointer; 506 typedef std::forward_iterator_tag iterator_category; 507 typedef std::ptrdiff_t difference_type; 508 509 redecl_iterator() : Current(0) { } 510 explicit redecl_iterator(Decl *C) : Current(C), Starter(C) { } 511 512 reference operator*() const { return Current; } 513 pointer operator->() const { return Current; } 514 515 redecl_iterator& operator++() { 516 assert(Current && "Advancing while iterator has reached end"); 517 // Get either previous decl or latest decl. 518 Decl *Next = Current->getNextRedeclaration(); 519 assert(Next && "Should return next redeclaration or itself, never null!"); 520 Current = (Next != Starter ? Next : 0); 521 return *this; 522 } 523 524 redecl_iterator operator++(int) { 525 redecl_iterator tmp(*this); 526 ++(*this); 527 return tmp; 528 } 529 530 friend bool operator==(redecl_iterator x, redecl_iterator y) { 531 return x.Current == y.Current; 532 } 533 friend bool operator!=(redecl_iterator x, redecl_iterator y) { 534 return x.Current != y.Current; 535 } 536 }; 537 538 /// \brief Returns iterator for all the redeclarations of the same decl. 539 /// It will iterate at least once (when this decl is the only one). 540 redecl_iterator redecls_begin() const { 541 return redecl_iterator(const_cast<Decl*>(this)); 542 } 543 redecl_iterator redecls_end() const { return redecl_iterator(); } 544 545 /// getBody - If this Decl represents a declaration for a body of code, 546 /// such as a function or method definition, this method returns the 547 /// top-level Stmt* of that body. Otherwise this method returns null. 548 Stmt* getBody() const; 549 550 /// \brief Returns true if this Decl represents a declaration for a body of 551 /// code, such as a function or method definition. 552 bool hasBody() const; 553 554 /// getBodyRBrace - Gets the right brace of the body, if a body exists. 555 /// This works whether the body is a CompoundStmt or a CXXTryStmt. 556 SourceLocation getBodyRBrace() const; 557 558 // global temp stats (until we have a per-module visitor) 559 static void add(Kind k); 560 static bool CollectingStats(bool Enable = false); 561 static void PrintStats(); 562 563 /// isTemplateParameter - Determines whether this declaration is a 564 /// template parameter. 565 bool isTemplateParameter() const; 566 567 /// isTemplateParameter - Determines whether this declaration is a 568 /// template parameter pack. 569 bool isTemplateParameterPack() const; 570 571 /// \brief Whether this declaration is a parameter pack. 572 bool isParameterPack() const; 573 574 /// \brief Whether this declaration is a function or function template. 575 bool isFunctionOrFunctionTemplate() const; 576 577 /// \brief Changes the namespace of this declaration to reflect that it's 578 /// the object of a friend declaration. 579 /// 580 /// These declarations appear in the lexical context of the friending 581 /// class, but in the semantic context of the actual entity. This property 582 /// applies only to a specific decl object; other redeclarations of the 583 /// same entity may not (and probably don't) share this property. 584 void setObjectOfFriendDecl(bool PreviouslyDeclared) { 585 unsigned OldNS = IdentifierNamespace; 586 assert((OldNS & (IDNS_Tag | IDNS_Ordinary | 587 IDNS_TagFriend | IDNS_OrdinaryFriend)) && 588 "namespace includes neither ordinary nor tag"); 589 assert(!(OldNS & ~(IDNS_Tag | IDNS_Ordinary | IDNS_Type | 590 IDNS_TagFriend | IDNS_OrdinaryFriend)) && 591 "namespace includes other than ordinary or tag"); 592 593 IdentifierNamespace = 0; 594 if (OldNS & (IDNS_Tag | IDNS_TagFriend)) { 595 IdentifierNamespace |= IDNS_TagFriend; 596 if (PreviouslyDeclared) IdentifierNamespace |= IDNS_Tag | IDNS_Type; 597 } 598 599 if (OldNS & (IDNS_Ordinary | IDNS_OrdinaryFriend)) { 600 IdentifierNamespace |= IDNS_OrdinaryFriend; 601 if (PreviouslyDeclared) IdentifierNamespace |= IDNS_Ordinary; 602 } 603 } 604 605 enum FriendObjectKind { 606 FOK_None, // not a friend object 607 FOK_Declared, // a friend of a previously-declared entity 608 FOK_Undeclared // a friend of a previously-undeclared entity 609 }; 610 611 /// \brief Determines whether this declaration is the object of a 612 /// friend declaration and, if so, what kind. 613 /// 614 /// There is currently no direct way to find the associated FriendDecl. 615 FriendObjectKind getFriendObjectKind() const { 616 unsigned mask 617 = (IdentifierNamespace & (IDNS_TagFriend | IDNS_OrdinaryFriend)); 618 if (!mask) return FOK_None; 619 return (IdentifierNamespace & (IDNS_Tag | IDNS_Ordinary) ? 620 FOK_Declared : FOK_Undeclared); 621 } 622 623 /// Specifies that this declaration is a C++ overloaded non-member. 624 void setNonMemberOperator() { 625 assert(getKind() == Function || getKind() == FunctionTemplate); 626 assert((IdentifierNamespace & IDNS_Ordinary) && 627 "visible non-member operators should be in ordinary namespace"); 628 IdentifierNamespace |= IDNS_NonMemberOperator; 629 } 630 631 // Implement isa/cast/dyncast/etc. 632 static bool classof(const Decl *) { return true; } 633 static bool classofKind(Kind K) { return true; } 634 static DeclContext *castToDeclContext(const Decl *); 635 static Decl *castFromDeclContext(const DeclContext *); 636 637 void print(llvm::raw_ostream &Out, unsigned Indentation = 0) const; 638 void print(llvm::raw_ostream &Out, const PrintingPolicy &Policy, 639 unsigned Indentation = 0) const; 640 static void printGroup(Decl** Begin, unsigned NumDecls, 641 llvm::raw_ostream &Out, const PrintingPolicy &Policy, 642 unsigned Indentation = 0); 643 void dump() const; 644 void dumpXML() const; 645 void dumpXML(llvm::raw_ostream &OS) const; 646 647private: 648 const Attr *getAttrsImpl() const; 649 650protected: 651 ASTMutationListener *getASTMutationListener() const; 652}; 653 654/// PrettyStackTraceDecl - If a crash occurs, indicate that it happened when 655/// doing something to a specific decl. 656class PrettyStackTraceDecl : public llvm::PrettyStackTraceEntry { 657 const Decl *TheDecl; 658 SourceLocation Loc; 659 SourceManager &SM; 660 const char *Message; 661public: 662 PrettyStackTraceDecl(const Decl *theDecl, SourceLocation L, 663 SourceManager &sm, const char *Msg) 664 : TheDecl(theDecl), Loc(L), SM(sm), Message(Msg) {} 665 666 virtual void print(llvm::raw_ostream &OS) const; 667}; 668 669class DeclContextLookupResult 670 : public std::pair<NamedDecl**,NamedDecl**> { 671public: 672 DeclContextLookupResult(NamedDecl **I, NamedDecl **E) 673 : std::pair<NamedDecl**,NamedDecl**>(I, E) {} 674 DeclContextLookupResult() 675 : std::pair<NamedDecl**,NamedDecl**>() {} 676 677 using std::pair<NamedDecl**,NamedDecl**>::operator=; 678}; 679 680class DeclContextLookupConstResult 681 : public std::pair<NamedDecl*const*, NamedDecl*const*> { 682public: 683 DeclContextLookupConstResult(std::pair<NamedDecl**,NamedDecl**> R) 684 : std::pair<NamedDecl*const*, NamedDecl*const*>(R) {} 685 DeclContextLookupConstResult(NamedDecl * const *I, NamedDecl * const *E) 686 : std::pair<NamedDecl*const*, NamedDecl*const*>(I, E) {} 687 DeclContextLookupConstResult() 688 : std::pair<NamedDecl*const*, NamedDecl*const*>() {} 689 690 using std::pair<NamedDecl*const*,NamedDecl*const*>::operator=; 691}; 692 693/// DeclContext - This is used only as base class of specific decl types that 694/// can act as declaration contexts. These decls are (only the top classes 695/// that directly derive from DeclContext are mentioned, not their subclasses): 696/// 697/// TranslationUnitDecl 698/// NamespaceDecl 699/// FunctionDecl 700/// TagDecl 701/// ObjCMethodDecl 702/// ObjCContainerDecl 703/// LinkageSpecDecl 704/// BlockDecl 705/// 706class DeclContext { 707 /// DeclKind - This indicates which class this is. 708 unsigned DeclKind : 8; 709 710 /// \brief Whether this declaration context also has some external 711 /// storage that contains additional declarations that are lexically 712 /// part of this context. 713 mutable unsigned ExternalLexicalStorage : 1; 714 715 /// \brief Whether this declaration context also has some external 716 /// storage that contains additional declarations that are visible 717 /// in this context. 718 mutable unsigned ExternalVisibleStorage : 1; 719 720 /// \brief Pointer to the data structure used to lookup declarations 721 /// within this context (or a DependentStoredDeclsMap if this is a 722 /// dependent context). 723 mutable StoredDeclsMap *LookupPtr; 724 725protected: 726 /// FirstDecl - The first declaration stored within this declaration 727 /// context. 728 mutable Decl *FirstDecl; 729 730 /// LastDecl - The last declaration stored within this declaration 731 /// context. FIXME: We could probably cache this value somewhere 732 /// outside of the DeclContext, to reduce the size of DeclContext by 733 /// another pointer. 734 mutable Decl *LastDecl; 735 736 friend class ExternalASTSource; 737 738 /// \brief Build up a chain of declarations. 739 /// 740 /// \returns the first/last pair of declarations. 741 static std::pair<Decl *, Decl *> 742 BuildDeclChain(const llvm::SmallVectorImpl<Decl*> &Decls); 743 744 DeclContext(Decl::Kind K) 745 : DeclKind(K), ExternalLexicalStorage(false), 746 ExternalVisibleStorage(false), LookupPtr(0), FirstDecl(0), 747 LastDecl(0) { } 748 749public: 750 ~DeclContext(); 751 752 Decl::Kind getDeclKind() const { 753 return static_cast<Decl::Kind>(DeclKind); 754 } 755 const char *getDeclKindName() const; 756 757 /// getParent - Returns the containing DeclContext. 758 DeclContext *getParent() { 759 return cast<Decl>(this)->getDeclContext(); 760 } 761 const DeclContext *getParent() const { 762 return const_cast<DeclContext*>(this)->getParent(); 763 } 764 765 /// getLexicalParent - Returns the containing lexical DeclContext. May be 766 /// different from getParent, e.g.: 767 /// 768 /// namespace A { 769 /// struct S; 770 /// } 771 /// struct A::S {}; // getParent() == namespace 'A' 772 /// // getLexicalParent() == translation unit 773 /// 774 DeclContext *getLexicalParent() { 775 return cast<Decl>(this)->getLexicalDeclContext(); 776 } 777 const DeclContext *getLexicalParent() const { 778 return const_cast<DeclContext*>(this)->getLexicalParent(); 779 } 780 781 DeclContext *getLookupParent(); 782 783 const DeclContext *getLookupParent() const { 784 return const_cast<DeclContext*>(this)->getLookupParent(); 785 } 786 787 ASTContext &getParentASTContext() const { 788 return cast<Decl>(this)->getASTContext(); 789 } 790 791 bool isFunctionOrMethod() const { 792 switch (DeclKind) { 793 case Decl::Block: 794 case Decl::ObjCMethod: 795 return true; 796 default: 797 return DeclKind >= Decl::firstFunction && DeclKind <= Decl::lastFunction; 798 } 799 } 800 801 bool isFileContext() const { 802 return DeclKind == Decl::TranslationUnit || DeclKind == Decl::Namespace; 803 } 804 805 bool isTranslationUnit() const { 806 return DeclKind == Decl::TranslationUnit; 807 } 808 809 bool isRecord() const { 810 return DeclKind >= Decl::firstRecord && DeclKind <= Decl::lastRecord; 811 } 812 813 bool isNamespace() const { 814 return DeclKind == Decl::Namespace; 815 } 816 817 bool isInlineNamespace() const; 818 819 /// \brief Determines whether this context is dependent on a 820 /// template parameter. 821 bool isDependentContext() const; 822 823 /// isTransparentContext - Determines whether this context is a 824 /// "transparent" context, meaning that the members declared in this 825 /// context are semantically declared in the nearest enclosing 826 /// non-transparent (opaque) context but are lexically declared in 827 /// this context. For example, consider the enumerators of an 828 /// enumeration type: 829 /// @code 830 /// enum E { 831 /// Val1 832 /// }; 833 /// @endcode 834 /// Here, E is a transparent context, so its enumerator (Val1) will 835 /// appear (semantically) that it is in the same context of E. 836 /// Examples of transparent contexts include: enumerations (except for 837 /// C++0x scoped enums), and C++ linkage specifications. 838 bool isTransparentContext() const; 839 840 /// \brief Determines whether this context is, or is nested within, 841 /// a C++ extern "C" linkage spec. 842 bool isExternCContext() const; 843 844 /// \brief Determine whether this declaration context is equivalent 845 /// to the declaration context DC. 846 bool Equals(const DeclContext *DC) const { 847 return DC && this->getPrimaryContext() == DC->getPrimaryContext(); 848 } 849 850 /// \brief Determine whether this declaration context encloses the 851 /// declaration context DC. 852 bool Encloses(const DeclContext *DC) const; 853 854 /// getPrimaryContext - There may be many different 855 /// declarations of the same entity (including forward declarations 856 /// of classes, multiple definitions of namespaces, etc.), each with 857 /// a different set of declarations. This routine returns the 858 /// "primary" DeclContext structure, which will contain the 859 /// information needed to perform name lookup into this context. 860 DeclContext *getPrimaryContext(); 861 const DeclContext *getPrimaryContext() const { 862 return const_cast<DeclContext*>(this)->getPrimaryContext(); 863 } 864 865 /// getRedeclContext - Retrieve the context in which an entity conflicts with 866 /// other entities of the same name, or where it is a redeclaration if the 867 /// two entities are compatible. This skips through transparent contexts. 868 DeclContext *getRedeclContext(); 869 const DeclContext *getRedeclContext() const { 870 return const_cast<DeclContext *>(this)->getRedeclContext(); 871 } 872 873 /// \brief Retrieve the nearest enclosing namespace context. 874 DeclContext *getEnclosingNamespaceContext(); 875 const DeclContext *getEnclosingNamespaceContext() const { 876 return const_cast<DeclContext *>(this)->getEnclosingNamespaceContext(); 877 } 878 879 /// \brief Test if this context is part of the enclosing namespace set of 880 /// the context NS, as defined in C++0x [namespace.def]p9. If either context 881 /// isn't a namespace, this is equivalent to Equals(). 882 /// 883 /// The enclosing namespace set of a namespace is the namespace and, if it is 884 /// inline, its enclosing namespace, recursively. 885 bool InEnclosingNamespaceSetOf(const DeclContext *NS) const; 886 887 /// getNextContext - If this is a DeclContext that may have other 888 /// DeclContexts that are semantically connected but syntactically 889 /// different, such as C++ namespaces, this routine retrieves the 890 /// next DeclContext in the link. Iteration through the chain of 891 /// DeclContexts should begin at the primary DeclContext and 892 /// continue until this function returns NULL. For example, given: 893 /// @code 894 /// namespace N { 895 /// int x; 896 /// } 897 /// namespace N { 898 /// int y; 899 /// } 900 /// @endcode 901 /// The first occurrence of namespace N will be the primary 902 /// DeclContext. Its getNextContext will return the second 903 /// occurrence of namespace N. 904 DeclContext *getNextContext(); 905 906 /// decl_iterator - Iterates through the declarations stored 907 /// within this context. 908 class decl_iterator { 909 /// Current - The current declaration. 910 Decl *Current; 911 912 public: 913 typedef Decl* value_type; 914 typedef Decl* reference; 915 typedef Decl* pointer; 916 typedef std::forward_iterator_tag iterator_category; 917 typedef std::ptrdiff_t difference_type; 918 919 decl_iterator() : Current(0) { } 920 explicit decl_iterator(Decl *C) : Current(C) { } 921 922 reference operator*() const { return Current; } 923 pointer operator->() const { return Current; } 924 925 decl_iterator& operator++() { 926 Current = Current->getNextDeclInContext(); 927 return *this; 928 } 929 930 decl_iterator operator++(int) { 931 decl_iterator tmp(*this); 932 ++(*this); 933 return tmp; 934 } 935 936 friend bool operator==(decl_iterator x, decl_iterator y) { 937 return x.Current == y.Current; 938 } 939 friend bool operator!=(decl_iterator x, decl_iterator y) { 940 return x.Current != y.Current; 941 } 942 }; 943 944 /// decls_begin/decls_end - Iterate over the declarations stored in 945 /// this context. 946 decl_iterator decls_begin() const; 947 decl_iterator decls_end() const; 948 bool decls_empty() const; 949 950 /// noload_decls_begin/end - Iterate over the declarations stored in this 951 /// context that are currently loaded; don't attempt to retrieve anything 952 /// from an external source. 953 decl_iterator noload_decls_begin() const; 954 decl_iterator noload_decls_end() const; 955 956 /// specific_decl_iterator - Iterates over a subrange of 957 /// declarations stored in a DeclContext, providing only those that 958 /// are of type SpecificDecl (or a class derived from it). This 959 /// iterator is used, for example, to provide iteration over just 960 /// the fields within a RecordDecl (with SpecificDecl = FieldDecl). 961 template<typename SpecificDecl> 962 class specific_decl_iterator { 963 /// Current - The current, underlying declaration iterator, which 964 /// will either be NULL or will point to a declaration of 965 /// type SpecificDecl. 966 DeclContext::decl_iterator Current; 967 968 /// SkipToNextDecl - Advances the current position up to the next 969 /// declaration of type SpecificDecl that also meets the criteria 970 /// required by Acceptable. 971 void SkipToNextDecl() { 972 while (*Current && !isa<SpecificDecl>(*Current)) 973 ++Current; 974 } 975 976 public: 977 typedef SpecificDecl* value_type; 978 typedef SpecificDecl* reference; 979 typedef SpecificDecl* pointer; 980 typedef std::iterator_traits<DeclContext::decl_iterator>::difference_type 981 difference_type; 982 typedef std::forward_iterator_tag iterator_category; 983 984 specific_decl_iterator() : Current() { } 985 986 /// specific_decl_iterator - Construct a new iterator over a 987 /// subset of the declarations the range [C, 988 /// end-of-declarations). If A is non-NULL, it is a pointer to a 989 /// member function of SpecificDecl that should return true for 990 /// all of the SpecificDecl instances that will be in the subset 991 /// of iterators. For example, if you want Objective-C instance 992 /// methods, SpecificDecl will be ObjCMethodDecl and A will be 993 /// &ObjCMethodDecl::isInstanceMethod. 994 explicit specific_decl_iterator(DeclContext::decl_iterator C) : Current(C) { 995 SkipToNextDecl(); 996 } 997 998 reference operator*() const { return cast<SpecificDecl>(*Current); } 999 pointer operator->() const { return cast<SpecificDecl>(*Current); } 1000 1001 specific_decl_iterator& operator++() { 1002 ++Current; 1003 SkipToNextDecl(); 1004 return *this; 1005 } 1006 1007 specific_decl_iterator operator++(int) { 1008 specific_decl_iterator tmp(*this); 1009 ++(*this); 1010 return tmp; 1011 } 1012 1013 friend bool 1014 operator==(const specific_decl_iterator& x, const specific_decl_iterator& y) { 1015 return x.Current == y.Current; 1016 } 1017 1018 friend bool 1019 operator!=(const specific_decl_iterator& x, const specific_decl_iterator& y) { 1020 return x.Current != y.Current; 1021 } 1022 }; 1023 1024 /// \brief Iterates over a filtered subrange of declarations stored 1025 /// in a DeclContext. 1026 /// 1027 /// This iterator visits only those declarations that are of type 1028 /// SpecificDecl (or a class derived from it) and that meet some 1029 /// additional run-time criteria. This iterator is used, for 1030 /// example, to provide access to the instance methods within an 1031 /// Objective-C interface (with SpecificDecl = ObjCMethodDecl and 1032 /// Acceptable = ObjCMethodDecl::isInstanceMethod). 1033 template<typename SpecificDecl, bool (SpecificDecl::*Acceptable)() const> 1034 class filtered_decl_iterator { 1035 /// Current - The current, underlying declaration iterator, which 1036 /// will either be NULL or will point to a declaration of 1037 /// type SpecificDecl. 1038 DeclContext::decl_iterator Current; 1039 1040 /// SkipToNextDecl - Advances the current position up to the next 1041 /// declaration of type SpecificDecl that also meets the criteria 1042 /// required by Acceptable. 1043 void SkipToNextDecl() { 1044 while (*Current && 1045 (!isa<SpecificDecl>(*Current) || 1046 (Acceptable && !(cast<SpecificDecl>(*Current)->*Acceptable)()))) 1047 ++Current; 1048 } 1049 1050 public: 1051 typedef SpecificDecl* value_type; 1052 typedef SpecificDecl* reference; 1053 typedef SpecificDecl* pointer; 1054 typedef std::iterator_traits<DeclContext::decl_iterator>::difference_type 1055 difference_type; 1056 typedef std::forward_iterator_tag iterator_category; 1057 1058 filtered_decl_iterator() : Current() { } 1059 1060 /// specific_decl_iterator - Construct a new iterator over a 1061 /// subset of the declarations the range [C, 1062 /// end-of-declarations). If A is non-NULL, it is a pointer to a 1063 /// member function of SpecificDecl that should return true for 1064 /// all of the SpecificDecl instances that will be in the subset 1065 /// of iterators. For example, if you want Objective-C instance 1066 /// methods, SpecificDecl will be ObjCMethodDecl and A will be 1067 /// &ObjCMethodDecl::isInstanceMethod. 1068 explicit filtered_decl_iterator(DeclContext::decl_iterator C) : Current(C) { 1069 SkipToNextDecl(); 1070 } 1071 1072 reference operator*() const { return cast<SpecificDecl>(*Current); } 1073 pointer operator->() const { return cast<SpecificDecl>(*Current); } 1074 1075 filtered_decl_iterator& operator++() { 1076 ++Current; 1077 SkipToNextDecl(); 1078 return *this; 1079 } 1080 1081 filtered_decl_iterator operator++(int) { 1082 filtered_decl_iterator tmp(*this); 1083 ++(*this); 1084 return tmp; 1085 } 1086 1087 friend bool 1088 operator==(const filtered_decl_iterator& x, const filtered_decl_iterator& y) { 1089 return x.Current == y.Current; 1090 } 1091 1092 friend bool 1093 operator!=(const filtered_decl_iterator& x, const filtered_decl_iterator& y) { 1094 return x.Current != y.Current; 1095 } 1096 }; 1097 1098 /// @brief Add the declaration D into this context. 1099 /// 1100 /// This routine should be invoked when the declaration D has first 1101 /// been declared, to place D into the context where it was 1102 /// (lexically) defined. Every declaration must be added to one 1103 /// (and only one!) context, where it can be visited via 1104 /// [decls_begin(), decls_end()). Once a declaration has been added 1105 /// to its lexical context, the corresponding DeclContext owns the 1106 /// declaration. 1107 /// 1108 /// If D is also a NamedDecl, it will be made visible within its 1109 /// semantic context via makeDeclVisibleInContext. 1110 void addDecl(Decl *D); 1111 1112 /// @brief Add the declaration D to this context without modifying 1113 /// any lookup tables. 1114 /// 1115 /// This is useful for some operations in dependent contexts where 1116 /// the semantic context might not be dependent; this basically 1117 /// only happens with friends. 1118 void addHiddenDecl(Decl *D); 1119 1120 /// @brief Removes a declaration from this context. 1121 void removeDecl(Decl *D); 1122 1123 /// lookup_iterator - An iterator that provides access to the results 1124 /// of looking up a name within this context. 1125 typedef NamedDecl **lookup_iterator; 1126 1127 /// lookup_const_iterator - An iterator that provides non-mutable 1128 /// access to the results of lookup up a name within this context. 1129 typedef NamedDecl * const * lookup_const_iterator; 1130 1131 typedef DeclContextLookupResult lookup_result; 1132 typedef DeclContextLookupConstResult lookup_const_result; 1133 1134 /// lookup - Find the declarations (if any) with the given Name in 1135 /// this context. Returns a range of iterators that contains all of 1136 /// the declarations with this name, with object, function, member, 1137 /// and enumerator names preceding any tag name. Note that this 1138 /// routine will not look into parent contexts. 1139 lookup_result lookup(DeclarationName Name); 1140 lookup_const_result lookup(DeclarationName Name) const; 1141 1142 /// @brief Makes a declaration visible within this context. 1143 /// 1144 /// This routine makes the declaration D visible to name lookup 1145 /// within this context and, if this is a transparent context, 1146 /// within its parent contexts up to the first enclosing 1147 /// non-transparent context. Making a declaration visible within a 1148 /// context does not transfer ownership of a declaration, and a 1149 /// declaration can be visible in many contexts that aren't its 1150 /// lexical context. 1151 /// 1152 /// If D is a redeclaration of an existing declaration that is 1153 /// visible from this context, as determined by 1154 /// NamedDecl::declarationReplaces, the previous declaration will be 1155 /// replaced with D. 1156 /// 1157 /// @param Recoverable true if it's okay to not add this decl to 1158 /// the lookup tables because it can be easily recovered by walking 1159 /// the declaration chains. 1160 void makeDeclVisibleInContext(NamedDecl *D, bool Recoverable = true); 1161 1162 /// \brief Deserialize all the visible declarations from external storage. 1163 /// 1164 /// Name lookup deserializes visible declarations lazily, thus a DeclContext 1165 /// may not have a complete name lookup table. This function deserializes 1166 /// the rest of visible declarations from the external storage and completes 1167 /// the name lookup table. 1168 void MaterializeVisibleDeclsFromExternalStorage(); 1169 1170 /// udir_iterator - Iterates through the using-directives stored 1171 /// within this context. 1172 typedef UsingDirectiveDecl * const * udir_iterator; 1173 1174 typedef std::pair<udir_iterator, udir_iterator> udir_iterator_range; 1175 1176 udir_iterator_range getUsingDirectives() const; 1177 1178 udir_iterator using_directives_begin() const { 1179 return getUsingDirectives().first; 1180 } 1181 1182 udir_iterator using_directives_end() const { 1183 return getUsingDirectives().second; 1184 } 1185 1186 // These are all defined in DependentDiagnostic.h. 1187 class ddiag_iterator; 1188 inline ddiag_iterator ddiag_begin() const; 1189 inline ddiag_iterator ddiag_end() const; 1190 1191 // Low-level accessors 1192 1193 /// \brief Retrieve the internal representation of the lookup structure. 1194 StoredDeclsMap* getLookupPtr() const { return LookupPtr; } 1195 1196 /// \brief Whether this DeclContext has external storage containing 1197 /// additional declarations that are lexically in this context. 1198 bool hasExternalLexicalStorage() const { return ExternalLexicalStorage; } 1199 1200 /// \brief State whether this DeclContext has external storage for 1201 /// declarations lexically in this context. 1202 void setHasExternalLexicalStorage(bool ES = true) { 1203 ExternalLexicalStorage = ES; 1204 } 1205 1206 /// \brief Whether this DeclContext has external storage containing 1207 /// additional declarations that are visible in this context. 1208 bool hasExternalVisibleStorage() const { return ExternalVisibleStorage; } 1209 1210 /// \brief State whether this DeclContext has external storage for 1211 /// declarations visible in this context. 1212 void setHasExternalVisibleStorage(bool ES = true) { 1213 ExternalVisibleStorage = ES; 1214 } 1215 1216 static bool classof(const Decl *D); 1217 static bool classof(const DeclContext *D) { return true; } 1218#define DECL(NAME, BASE) 1219#define DECL_CONTEXT(NAME) \ 1220 static bool classof(const NAME##Decl *D) { return true; } 1221#include "clang/AST/DeclNodes.inc" 1222 1223 void dumpDeclContext() const; 1224 1225private: 1226 void LoadLexicalDeclsFromExternalStorage() const; 1227 1228 friend class DependentDiagnostic; 1229 StoredDeclsMap *CreateStoredDeclsMap(ASTContext &C) const; 1230 1231 void buildLookup(DeclContext *DCtx); 1232 void makeDeclVisibleInContextImpl(NamedDecl *D); 1233}; 1234 1235inline bool Decl::isTemplateParameter() const { 1236 return getKind() == TemplateTypeParm || getKind() == NonTypeTemplateParm || 1237 getKind() == TemplateTemplateParm; 1238} 1239 1240// Specialization selected when ToTy is not a known subclass of DeclContext. 1241template <class ToTy, 1242 bool IsKnownSubtype = ::llvm::is_base_of< DeclContext, ToTy>::value> 1243struct cast_convert_decl_context { 1244 static const ToTy *doit(const DeclContext *Val) { 1245 return static_cast<const ToTy*>(Decl::castFromDeclContext(Val)); 1246 } 1247 1248 static ToTy *doit(DeclContext *Val) { 1249 return static_cast<ToTy*>(Decl::castFromDeclContext(Val)); 1250 } 1251}; 1252 1253// Specialization selected when ToTy is a known subclass of DeclContext. 1254template <class ToTy> 1255struct cast_convert_decl_context<ToTy, true> { 1256 static const ToTy *doit(const DeclContext *Val) { 1257 return static_cast<const ToTy*>(Val); 1258 } 1259 1260 static ToTy *doit(DeclContext *Val) { 1261 return static_cast<ToTy*>(Val); 1262 } 1263}; 1264 1265 1266} // end clang. 1267 1268namespace llvm { 1269 1270/// isa<T>(DeclContext*) 1271template<class ToTy> 1272struct isa_impl_wrap<ToTy, 1273 const ::clang::DeclContext,const ::clang::DeclContext> { 1274 static bool doit(const ::clang::DeclContext &Val) { 1275 return ToTy::classofKind(Val.getDeclKind()); 1276 } 1277}; 1278template<class ToTy> 1279struct isa_impl_wrap<ToTy, ::clang::DeclContext, ::clang::DeclContext> 1280 : public isa_impl_wrap<ToTy, 1281 const ::clang::DeclContext,const ::clang::DeclContext> {}; 1282 1283/// cast<T>(DeclContext*) 1284template<class ToTy> 1285struct cast_convert_val<ToTy, 1286 const ::clang::DeclContext,const ::clang::DeclContext> { 1287 static const ToTy &doit(const ::clang::DeclContext &Val) { 1288 return *::clang::cast_convert_decl_context<ToTy>::doit(&Val); 1289 } 1290}; 1291template<class ToTy> 1292struct cast_convert_val<ToTy, ::clang::DeclContext, ::clang::DeclContext> { 1293 static ToTy &doit(::clang::DeclContext &Val) { 1294 return *::clang::cast_convert_decl_context<ToTy>::doit(&Val); 1295 } 1296}; 1297template<class ToTy> 1298struct cast_convert_val<ToTy, 1299 const ::clang::DeclContext*, const ::clang::DeclContext*> { 1300 static const ToTy *doit(const ::clang::DeclContext *Val) { 1301 return ::clang::cast_convert_decl_context<ToTy>::doit(Val); 1302 } 1303}; 1304template<class ToTy> 1305struct cast_convert_val<ToTy, ::clang::DeclContext*, ::clang::DeclContext*> { 1306 static ToTy *doit(::clang::DeclContext *Val) { 1307 return ::clang::cast_convert_decl_context<ToTy>::doit(Val); 1308 } 1309}; 1310 1311/// Implement cast_convert_val for Decl -> DeclContext conversions. 1312template<class FromTy> 1313struct cast_convert_val< ::clang::DeclContext, FromTy, FromTy> { 1314 static ::clang::DeclContext &doit(const FromTy &Val) { 1315 return *FromTy::castToDeclContext(&Val); 1316 } 1317}; 1318 1319template<class FromTy> 1320struct cast_convert_val< ::clang::DeclContext, FromTy*, FromTy*> { 1321 static ::clang::DeclContext *doit(const FromTy *Val) { 1322 return FromTy::castToDeclContext(Val); 1323 } 1324}; 1325 1326template<class FromTy> 1327struct cast_convert_val< const ::clang::DeclContext, FromTy, FromTy> { 1328 static const ::clang::DeclContext &doit(const FromTy &Val) { 1329 return *FromTy::castToDeclContext(&Val); 1330 } 1331}; 1332 1333template<class FromTy> 1334struct cast_convert_val< const ::clang::DeclContext, FromTy*, FromTy*> { 1335 static const ::clang::DeclContext *doit(const FromTy *Val) { 1336 return FromTy::castToDeclContext(Val); 1337 } 1338}; 1339 1340} // end namespace llvm 1341 1342#endif 1343