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