DeclBase.h revision 206084
118334Speter//===-- DeclBase.h - Base Classes for representing declarations -*- C++ -*-===// 290075Sobrien// 3169689Skan// The LLVM Compiler Infrastructure 4169689Skan// 518334Speter// This file is distributed under the University of Illinois Open Source 690075Sobrien// License. See LICENSE.TXT for details. 718334Speter// 890075Sobrien//===----------------------------------------------------------------------===// 990075Sobrien// 1090075Sobrien// This file defines the Decl and DeclContext interfaces. 1190075Sobrien// 1218334Speter//===----------------------------------------------------------------------===// 1390075Sobrien 1490075Sobrien#ifndef LLVM_CLANG_AST_DECLBASE_H 1590075Sobrien#define LLVM_CLANG_AST_DECLBASE_H 1690075Sobrien 1718334Speter#include "clang/AST/Attr.h" 1818334Speter#include "clang/AST/Type.h" 1990075Sobrien#include "clang/Basic/Specifiers.h" 20169689Skan#include "llvm/Support/PrettyStackTrace.h" 21169689Skan#include "llvm/ADT/PointerUnion.h" 2218334Speter 2318334Speternamespace clang { 2418334Speterclass DeclContext; 2550397Sobrienclass TranslationUnitDecl; 26132718Skanclass NamespaceDecl; 27132718Skanclass UsingDirectiveDecl; 2852284Sobrienclass NamedDecl; 2952284Sobrienclass FunctionDecl; 3052284Sobrienclass CXXRecordDecl; 3190075Sobrienclass EnumDecl; 3252284Sobrienclass ObjCMethodDecl; 3318334Speterclass ObjCContainerDecl; 3418334Speterclass ObjCInterfaceDecl; 3590075Sobrienclass ObjCCategoryDecl; 3618334Speterclass ObjCProtocolDecl; 3790075Sobrienclass ObjCImplementationDecl; 3890075Sobrienclass ObjCCategoryImplDecl; 3918334Speterclass ObjCImplDecl; 4090075Sobrienclass LinkageSpecDecl; 4190075Sobrienclass BlockDecl; 4218334Speterclass DeclarationName; 4318334Speterclass CompoundStmt; 4490075Sobrienclass StoredDeclsMap; 4590075Sobrienclass DependentDiagnostic; 46110611Skan} 47132718Skan 4818334Speternamespace llvm { 4918334Speter// DeclContext* is only 4-byte aligned on 32-bit systems. 5018334Spetertemplate<> 5118334Speter class PointerLikeTypeTraits<clang::DeclContext*> { 5218334Speter typedef clang::DeclContext* PT; 5318334Speterpublic: 5418334Speter static inline void *getAsVoidPointer(PT P) { return P; } 5518334Speter static inline PT getFromVoidPointer(void *P) { 5618334Speter return static_cast<PT>(P); 5718334Speter } 5890075Sobrien enum { NumLowBitsAvailable = 2 }; 5918334Speter}; 6090075Sobrien} 6118334Speter 62132718Skannamespace clang { 63169689Skan 6418334Speter/// Decl - This represents one declaration (or definition), e.g. a variable, 6518334Speter/// typedef, function, struct, etc. 6618334Speter/// 6718334Speterclass Decl { 6818334Speterpublic: 6918334Speter /// \brief Lists the kind of concrete classes of Decl. 7018334Speter enum Kind { 7118334Speter#define DECL(Derived, Base) Derived, 7218334Speter#define DECL_RANGE(CommonBase, Start, End) \ 7318334Speter CommonBase##First = Start, CommonBase##Last = End, 7418334Speter#define LAST_DECL_RANGE(CommonBase, Start, End) \ 7518334Speter CommonBase##First = Start, CommonBase##Last = End 7618334Speter#include "clang/AST/DeclNodes.def" 7718334Speter }; 7818334Speter 7918334Speter /// IdentifierNamespace - According to C99 6.2.3, there are four 8018334Speter /// namespaces, labels, tags, members and ordinary 8118334Speter /// identifiers. These are meant as bitmasks, so that searches in 8218334Speter /// C++ can look into the "tag" namespace during ordinary lookup. We 8318334Speter /// use additional namespaces for Objective-C entities. We also put 8418334Speter /// C++ friend declarations (of previously-undeclared entities) in 8518334Speter /// shadow namespaces, and 'using' declarations (as opposed to their 8618334Speter /// implicit shadow declarations) can be found in their own 8718334Speter /// namespace. 88169689Skan enum IdentifierNamespace { 89169689Skan IDNS_Label = 0x1, 90169689Skan IDNS_Tag = 0x2, 91169689Skan IDNS_Member = 0x4, 92169689Skan IDNS_Ordinary = 0x8, 93169689Skan IDNS_ObjCProtocol = 0x10, 94117395Skan IDNS_ObjCImplementation = 0x20, 95117395Skan IDNS_ObjCCategoryName = 0x40, 96117395Skan IDNS_OrdinaryFriend = 0x80, 97117395Skan IDNS_TagFriend = 0x100, 98117395Skan IDNS_Using = 0x200 99132718Skan }; 100132718Skan 101132718Skan /// ObjCDeclQualifier - Qualifier used on types in method declarations 102132718Skan /// for remote messaging. They are meant for the arguments though and 103132718Skan /// applied to the Decls (ObjCMethodDecl and ParmVarDecl). 104132718Skan enum ObjCDeclQualifier { 105132718Skan OBJC_TQ_None = 0x0, 106132718Skan OBJC_TQ_In = 0x1, 107132718Skan OBJC_TQ_Inout = 0x2, 108132718Skan OBJC_TQ_Out = 0x4, 109132718Skan OBJC_TQ_Bycopy = 0x8, 110132718Skan OBJC_TQ_Byref = 0x10, 111132718Skan OBJC_TQ_Oneway = 0x20 112132718Skan }; 113132718Skan 114132718Skanprivate: 115132718Skan /// NextDeclInContext - The next declaration within the same lexical 116132718Skan /// DeclContext. These pointers form the linked list that is 117132718Skan /// traversed via DeclContext's decls_begin()/decls_end(). 118132718Skan Decl *NextDeclInContext; 119132718Skan 120132718Skan friend class DeclContext; 121132718Skan 122132718Skan struct MultipleDC { 123132718Skan DeclContext *SemanticDC; 124132718Skan DeclContext *LexicalDC; 125132718Skan }; 126169689Skan 127169689Skan 128117395Skan /// DeclCtx - Holds either a DeclContext* or a MultipleDC*. 129117395Skan /// For declarations that don't contain C++ scope specifiers, it contains 130117395Skan /// the DeclContext where the Decl was declared. 131169689Skan /// For declarations with C++ scope specifiers, it contains a MultipleDC* 132117395Skan /// with the context where it semantically belongs (SemanticDC) and the 13318334Speter /// context where it was lexically declared (LexicalDC). 134117395Skan /// e.g.: 13518334Speter /// 13618334Speter /// namespace A { 13718334Speter /// void f(); // SemanticDC == LexicalDC == 'namespace A' 13818334Speter /// } 13918334Speter /// void A::f(); // SemanticDC == namespace 'A' 14018334Speter /// // LexicalDC == global namespace 14118334Speter llvm::PointerUnion<DeclContext*, MultipleDC*> DeclCtx; 14218334Speter 14318334Speter inline bool isInSemaDC() const { return DeclCtx.is<DeclContext*>(); } 14418334Speter inline bool isOutOfSemaDC() const { return DeclCtx.is<MultipleDC*>(); } 145132718Skan inline MultipleDC *getMultipleDC() const { 14618334Speter return DeclCtx.get<MultipleDC*>(); 147117395Skan } 14818334Speter inline DeclContext *getSemanticDC() const { 14918334Speter return DeclCtx.get<DeclContext*>(); 150169689Skan } 151117395Skan 152169689Skan /// Loc - The location that this decl. 153169689Skan SourceLocation Loc; 154169689Skan 155169689Skan /// DeclKind - This indicates which class this is. 156169689Skan Kind DeclKind : 8; 15718334Speter 15818334Speter /// InvalidDecl - This indicates a semantic error occurred. 159117395Skan unsigned int InvalidDecl : 1; 160117395Skan 161117395Skan /// HasAttrs - This indicates whether the decl has attributes or not. 162117395Skan unsigned int HasAttrs : 1; 163117395Skan 164117395Skan /// Implicit - Whether this declaration was implicitly generated by 165117395Skan /// the implementation rather than explicitly written by the user. 166117395Skan bool Implicit : 1; 167117395Skan 168117395Skan /// \brief Whether this declaration was "used", meaning that a definition is 169117395Skan /// required. 170117395Skan bool Used : 1; 171117395Skan 172132718Skanprotected: 173117395Skan /// Access - Used by C++ decls for the access specifier. 174132718Skan // NOTE: VC++ treats enums as signed, avoid using the AccessSpecifier enum 175117395Skan unsigned Access : 2; 176117395Skan friend class CXXClassMemberWrapper; 17718334Speter 17818334Speter // PCHLevel - the "level" of precompiled header/AST file from which this 17918334Speter // declaration was built. 18018334Speter unsigned PCHLevel : 2; 181117395Skan 182117395Skan /// IdentifierNamespace - This specifies what IDNS_* namespace this lives in. 183117395Skan unsigned IdentifierNamespace : 16; 184117395Skan 185117395Skanprivate: 186117395Skan#ifndef NDEBUG 18718334Speter void CheckAccessDeclContext() const; 188117395Skan#else 189117395Skan void CheckAccessDeclContext() const { } 190117395Skan#endif 191117395Skan 192169689Skanprotected: 19350397Sobrien 19418334Speter Decl(Kind DK, DeclContext *DC, SourceLocation L) 19550397Sobrien : NextDeclInContext(0), DeclCtx(DC), 19618334Speter Loc(L), DeclKind(DK), InvalidDecl(0), 197117395Skan HasAttrs(false), Implicit(false), Used(false), 19818334Speter Access(AS_none), PCHLevel(0), 19918334Speter IdentifierNamespace(getIdentifierNamespaceForKind(DK)) { 20018334Speter if (Decl::CollectingStats()) addDeclKind(DK); 20118334Speter } 20218334Speter 20318334Speter virtual ~Decl(); 204132718Skan 20518334Speterpublic: 20618334Speter 20718334Speter /// \brief Source range that this declaration covers. 20818334Speter virtual SourceRange getSourceRange() const { 209132718Skan return SourceRange(getLocation(), getLocation()); 210132718Skan } 21118334Speter SourceLocation getLocStart() const { return getSourceRange().getBegin(); } 21218334Speter SourceLocation getLocEnd() const { return getSourceRange().getEnd(); } 21318334Speter 21496263Sobrien SourceLocation getLocation() const { return Loc; } 21596263Sobrien void setLocation(SourceLocation L) { Loc = L; } 21696263Sobrien 21796263Sobrien Kind getKind() const { return DeclKind; } 21896263Sobrien const char *getDeclKindName() const; 21996263Sobrien 22096263Sobrien Decl *getNextDeclInContext() { return NextDeclInContext; } 22118334Speter const Decl *getNextDeclInContext() const { return NextDeclInContext; } 22296263Sobrien 22396263Sobrien DeclContext *getDeclContext() { 22418334Speter if (isInSemaDC()) 22518334Speter return getSemanticDC(); 22618334Speter return getMultipleDC()->SemanticDC; 22718334Speter } 22818334Speter const DeclContext *getDeclContext() const { 22950397Sobrien return const_cast<Decl*>(this)->getDeclContext(); 23018334Speter } 23118334Speter 23218334Speter TranslationUnitDecl *getTranslationUnitDecl(); 23318334Speter const TranslationUnitDecl *getTranslationUnitDecl() const { 23418334Speter return const_cast<Decl*>(this)->getTranslationUnitDecl(); 23550397Sobrien } 23618334Speter 23718334Speter bool isInAnonymousNamespace() const; 23818334Speter 23918334Speter ASTContext &getASTContext() const; 240169689Skan 241169689Skan void setAccess(AccessSpecifier AS) { 242169689Skan Access = AS; 243169689Skan CheckAccessDeclContext(); 244169689Skan } 245169689Skan 246169689Skan AccessSpecifier getAccess() const { 24752284Sobrien CheckAccessDeclContext(); 248169689Skan return AccessSpecifier(Access); 249169689Skan } 25090075Sobrien 251169689Skan bool hasAttrs() const { return HasAttrs; } 252169689Skan void addAttr(Attr *attr); 25390075Sobrien const Attr *getAttrs() const { 254169689Skan if (!HasAttrs) return 0; // common case, no attributes. 255169689Skan return getAttrsImpl(); // Uncommon case, out of line hash lookup. 25652284Sobrien } 257169689Skan void swapAttrs(Decl *D); 258169689Skan void invalidateAttrs(); 25952284Sobrien 260169689Skan template<typename T> const T *getAttr() const { 261169689Skan for (const Attr *attr = getAttrs(); attr; attr = attr->getNext()) 26252284Sobrien if (const T *V = dyn_cast<T>(attr)) 263169689Skan return V; 264169689Skan return 0; 265169689Skan } 266169689Skan 267169689Skan template<typename T> bool hasAttr() const { 26852284Sobrien return getAttr<T>() != 0; 269169689Skan } 270169689Skan 271169689Skan /// setInvalidDecl - Indicates the Decl had a semantic error. This 272169689Skan /// allows for graceful error recovery. 273169689Skan void setInvalidDecl(bool Invalid = true); 274169689Skan bool isInvalidDecl() const { return (bool) InvalidDecl; } 275169689Skan 27652284Sobrien /// isImplicit - Indicates whether the declaration was implicitly 277169689Skan /// generated by the implementation. If false, this declaration 278169689Skan /// was written explicitly in the source code. 27952284Sobrien bool isImplicit() const { return Implicit; } 280169689Skan void setImplicit(bool I = true) { Implicit = I; } 281169689Skan 28252284Sobrien /// \brief Whether this declaration was used, meaning that a definition 283169689Skan /// is required. 284169689Skan bool isUsed() const; 28552284Sobrien 286169689Skan void setUsed(bool U = true) { Used = U; } 287169689Skan 288132718Skan /// \brief Retrieve the level of precompiled header from which this 289169689Skan /// declaration was generated. 290169689Skan /// 29152284Sobrien /// The PCH level of a declaration describes where the declaration originated 292169689Skan /// from. A PCH level of 0 indicates that the declaration was not from a 293169689Skan /// precompiled header. A PCH level of 1 indicates that the declaration was 29452284Sobrien /// from a top-level precompiled header; 2 indicates that the declaration 295169689Skan /// comes from a precompiled header on which the top-level precompiled header 296169689Skan /// depends, and so on. 29752284Sobrien unsigned getPCHLevel() const { return PCHLevel; } 298169689Skan 299169689Skan /// \brief The maximum PCH level that any declaration may have. 30052284Sobrien static const unsigned MaxPCHLevel = 3; 301169689Skan 302169689Skan /// \brief Set the PCH level of this declaration. 30352284Sobrien void setPCHLevel(unsigned Level) { 304169689Skan assert(Level < MaxPCHLevel && "PCH level exceeds the maximum"); 305169689Skan PCHLevel = Level; 306132718Skan } 307169689Skan 308169689Skan unsigned getIdentifierNamespace() const { 30952284Sobrien return IdentifierNamespace; 310169689Skan } 311169689Skan bool isInIdentifierNamespace(unsigned NS) const { 31252284Sobrien return getIdentifierNamespace() & NS; 313169689Skan } 314169689Skan static unsigned getIdentifierNamespaceForKind(Kind DK); 31552284Sobrien 316169689Skan 317169689Skan /// getLexicalDeclContext - The declaration context where this Decl was 31852284Sobrien /// lexically declared (LexicalDC). May be different from 319169689Skan /// getDeclContext() (SemanticDC). 320169689Skan /// e.g.: 32152284Sobrien /// 32252284Sobrien /// namespace A { 323169689Skan /// void f(); // SemanticDC == LexicalDC == 'namespace A' 324169689Skan /// } 325169689Skan /// void A::f(); // SemanticDC == namespace 'A' 326169689Skan /// // LexicalDC == global namespace 327169689Skan DeclContext *getLexicalDeclContext() { 32852284Sobrien if (isInSemaDC()) 329169689Skan return getSemanticDC(); 330169689Skan return getMultipleDC()->LexicalDC; 33152284Sobrien } 332169689Skan const DeclContext *getLexicalDeclContext() const { 333169689Skan return const_cast<Decl*>(this)->getLexicalDeclContext(); 33452284Sobrien } 335169689Skan 336169689Skan virtual bool isOutOfLine() const { 33752284Sobrien return getLexicalDeclContext() != getDeclContext(); 338169689Skan } 339169689Skan 34052284Sobrien /// setDeclContext - Set both the semantic and lexical DeclContext 341169689Skan /// to DC. 342169689Skan void setDeclContext(DeclContext *DC); 343169689Skan 34452284Sobrien void setLexicalDeclContext(DeclContext *DC); 34552284Sobrien 34652284Sobrien // isDefinedOutsideFunctionOrMethod - This predicate returns true if this 347169689Skan // scoped decl is defined outside the current function or method. This is 34890075Sobrien // roughly global variables and functions, but also handles enums (which could 349169689Skan // be defined inside or outside a function etc). 350169689Skan bool isDefinedOutsideFunctionOrMethod() const; 351169689Skan 352169689Skan /// \brief Retrieves the "canonical" declaration of the given declaration. 353169689Skan virtual Decl *getCanonicalDecl() { return this; } 354169689Skan const Decl *getCanonicalDecl() const { 355169689Skan return const_cast<Decl*>(this)->getCanonicalDecl(); 356169689Skan } 357169689Skan 358169689Skan /// \brief Whether this particular Decl is a canonical one. 359169689Skan bool isCanonicalDecl() const { return getCanonicalDecl() == this; } 360169689Skan 361169689Skanprotected: 362169689Skan /// \brief Returns the next redeclaration or itself if this is the only decl. 363169689Skan /// 364169689Skan /// Decl subclasses that can be redeclared should override this method so that 365169689Skan /// Decl::redecl_iterator can iterate over them. 366169689Skan virtual Decl *getNextRedeclaration() { return this; } 367169689Skan 368169689Skanpublic: 369169689Skan /// \brief Iterates through all the redeclarations of the same decl. 370169689Skan class redecl_iterator { 371169689Skan /// Current - The current declaration. 372169689Skan Decl *Current; 373169689Skan Decl *Starter; 374169689Skan 375169689Skan public: 376169689Skan typedef Decl* value_type; 377169689Skan typedef Decl* reference; 378169689Skan typedef Decl* pointer; 379169689Skan typedef std::forward_iterator_tag iterator_category; 380169689Skan typedef std::ptrdiff_t difference_type; 381169689Skan 382169689Skan redecl_iterator() : Current(0) { } 383169689Skan explicit redecl_iterator(Decl *C) : Current(C), Starter(C) { } 384169689Skan 385169689Skan reference operator*() const { return Current; } 386169689Skan pointer operator->() const { return Current; } 387169689Skan 388169689Skan redecl_iterator& operator++() { 389169689Skan assert(Current && "Advancing while iterator has reached end"); 39090075Sobrien // Get either previous decl or latest decl. 391169689Skan Decl *Next = Current->getNextRedeclaration(); 392169689Skan assert(Next && "Should return next redeclaration or itself, never null!"); 393169689Skan Current = (Next != Starter ? Next : 0); 39490075Sobrien return *this; 395132718Skan } 396169689Skan 397169689Skan redecl_iterator operator++(int) { 398169689Skan redecl_iterator tmp(*this); 399169689Skan ++(*this); 400169689Skan return tmp; 401169689Skan } 402169689Skan 403169689Skan friend bool operator==(redecl_iterator x, redecl_iterator y) { 404169689Skan return x.Current == y.Current; 405169689Skan } 406169689Skan friend bool operator!=(redecl_iterator x, redecl_iterator y) { 407169689Skan return x.Current != y.Current; 408169689Skan } 409169689Skan }; 41052284Sobrien 411169689Skan /// \brief Returns iterator for all the redeclarations of the same decl. 412169689Skan /// It will iterate at least once (when this decl is the only one). 41352284Sobrien redecl_iterator redecls_begin() const { 414169689Skan return redecl_iterator(const_cast<Decl*>(this)); 415169689Skan } 416169689Skan redecl_iterator redecls_end() const { return redecl_iterator(); } 417169689Skan 418169689Skan /// getBody - If this Decl represents a declaration for a body of code, 41952284Sobrien /// such as a function or method definition, this method returns the 420169689Skan /// top-level Stmt* of that body. Otherwise this method returns null. 421169689Skan virtual Stmt* getBody() const { return 0; } 422169689Skan 423169689Skan /// getCompoundBody - Returns getBody(), dyn_casted to a CompoundStmt. 424169689Skan CompoundStmt* getCompoundBody() const; 425169689Skan 426169689Skan /// getBodyRBrace - Gets the right brace of the body, if a body exists. 427169689Skan /// This works whether the body is a CompoundStmt or a CXXTryStmt. 428169689Skan SourceLocation getBodyRBrace() const; 429169689Skan 430169689Skan // global temp stats (until we have a per-module visitor) 431169689Skan static void addDeclKind(Kind k); 432169689Skan static bool CollectingStats(bool Enable = false); 433169689Skan static void PrintStats(); 434169689Skan 435169689Skan /// isTemplateParameter - Determines whether this declaration is a 436169689Skan /// template parameter. 437169689Skan bool isTemplateParameter() const; 438169689Skan 439169689Skan /// isTemplateParameter - Determines whether this declaration is a 440169689Skan /// template parameter pack. 441169689Skan bool isTemplateParameterPack() const; 442169689Skan 443169689Skan /// \brief Whether this declaration is a function or function template. 444169689Skan bool isFunctionOrFunctionTemplate() const; 445169689Skan 446169689Skan /// \brief Changes the namespace of this declaration to reflect that it's 447169689Skan /// the object of a friend declaration. 448169689Skan /// 449169689Skan /// These declarations appear in the lexical context of the friending 450169689Skan /// class, but in the semantic context of the actual entity. This property 451169689Skan /// applies only to a specific decl object; other redeclarations of the 452169689Skan /// same entity may not (and probably don't) share this property. 453169689Skan void setObjectOfFriendDecl(bool PreviouslyDeclared) { 454169689Skan unsigned OldNS = IdentifierNamespace; 455169689Skan assert((OldNS & (IDNS_Tag | IDNS_Ordinary | 456169689Skan IDNS_TagFriend | IDNS_OrdinaryFriend)) && 457169689Skan "namespace includes neither ordinary nor tag"); 458169689Skan assert(!(OldNS & ~(IDNS_Tag | IDNS_Ordinary | 459169689Skan IDNS_TagFriend | IDNS_OrdinaryFriend)) && 460169689Skan "namespace includes other than ordinary or tag"); 46152284Sobrien 462169689Skan IdentifierNamespace = 0; 463169689Skan if (OldNS & (IDNS_Tag | IDNS_TagFriend)) { 464169689Skan IdentifierNamespace |= IDNS_TagFriend; 465169689Skan if (PreviouslyDeclared) IdentifierNamespace |= IDNS_Tag; 466169689Skan } 467169689Skan 468169689Skan if (OldNS & (IDNS_Ordinary | IDNS_OrdinaryFriend)) { 469169689Skan IdentifierNamespace |= IDNS_OrdinaryFriend; 470169689Skan if (PreviouslyDeclared) IdentifierNamespace |= IDNS_Ordinary; 471169689Skan } 472169689Skan } 473169689Skan 474169689Skan enum FriendObjectKind { 475169689Skan FOK_None, // not a friend object 47652284Sobrien FOK_Declared, // a friend of a previously-declared entity 47752284Sobrien FOK_Undeclared // a friend of a previously-undeclared entity 47852284Sobrien }; 479169689Skan 480169689Skan /// \brief Determines whether this declaration is the object of a 481169689Skan /// friend declaration and, if so, what kind. 482169689Skan /// 483169689Skan /// There is currently no direct way to find the associated FriendDecl. 484169689Skan FriendObjectKind getFriendObjectKind() const { 485169689Skan unsigned mask 486169689Skan = (IdentifierNamespace & (IDNS_TagFriend | IDNS_OrdinaryFriend)); 487169689Skan if (!mask) return FOK_None; 488169689Skan return (IdentifierNamespace & (IDNS_Tag | IDNS_Ordinary) ? 48952284Sobrien FOK_Declared : FOK_Undeclared); 49052284Sobrien } 491169689Skan 492169689Skan // Implement isa/cast/dyncast/etc. 493169689Skan static bool classof(const Decl *) { return true; } 49452284Sobrien static bool classofKind(Kind K) { return true; } 495169689Skan static DeclContext *castToDeclContext(const Decl *); 496169689Skan static Decl *castFromDeclContext(const DeclContext *); 49752284Sobrien 498169689Skan /// Destroy - Call destructors and release memory. 499169689Skan virtual void Destroy(ASTContext& C); 50052284Sobrien 501169689Skan void print(llvm::raw_ostream &Out, unsigned Indentation = 0) const; 502169689Skan void print(llvm::raw_ostream &Out, const PrintingPolicy &Policy, 503169689Skan unsigned Indentation = 0) const; 504169689Skan static void printGroup(Decl** Begin, unsigned NumDecls, 505169689Skan llvm::raw_ostream &Out, const PrintingPolicy &Policy, 506169689Skan unsigned Indentation = 0); 507169689Skan void dump() const; 508169689Skan 509169689Skanprivate: 510169689Skan const Attr *getAttrsImpl() const; 511169689Skan 512169689Skan}; 513169689Skan 514169689Skan/// PrettyStackTraceDecl - If a crash occurs, indicate that it happened when 515169689Skan/// doing something to a specific decl. 516169689Skanclass PrettyStackTraceDecl : public llvm::PrettyStackTraceEntry { 517169689Skan const Decl *TheDecl; 518169689Skan SourceLocation Loc; 519169689Skan SourceManager &SM; 520169689Skan const char *Message; 521169689Skanpublic: 522169689Skan PrettyStackTraceDecl(const Decl *theDecl, SourceLocation L, 52352284Sobrien SourceManager &sm, const char *Msg) 524169689Skan : TheDecl(theDecl), Loc(L), SM(sm), Message(Msg) {} 52552284Sobrien 526169689Skan virtual void print(llvm::raw_ostream &OS) const; 527169689Skan}; 528169689Skan 529169689Skan 530169689Skan/// DeclContext - This is used only as base class of specific decl types that 53152284Sobrien/// can act as declaration contexts. These decls are (only the top classes 532169689Skan/// that directly derive from DeclContext are mentioned, not their subclasses): 533169689Skan/// 534169689Skan/// TranslationUnitDecl 535169689Skan/// NamespaceDecl 536169689Skan/// FunctionDecl 537169689Skan/// TagDecl 53852284Sobrien/// ObjCMethodDecl 539169689Skan/// ObjCContainerDecl 540169689Skan/// LinkageSpecDecl 541169689Skan/// BlockDecl 542169689Skan/// 543169689Skanclass DeclContext { 544169689Skan /// DeclKind - This indicates which class this is. 54552284Sobrien Decl::Kind DeclKind : 8; 546169689Skan 547169689Skan /// \brief Whether this declaration context also has some external 548169689Skan /// storage that contains additional declarations that are lexically 549169689Skan /// part of this context. 550169689Skan mutable bool ExternalLexicalStorage : 1; 551169689Skan 55252284Sobrien /// \brief Whether this declaration context also has some external 553169689Skan /// storage that contains additional declarations that are visible 554169689Skan /// in this context. 55552284Sobrien mutable bool ExternalVisibleStorage : 1; 556169689Skan 557169689Skan /// \brief Pointer to the data structure used to lookup declarations 558169689Skan /// within this context (or a DependentStoredDeclsMap if this is a 55952284Sobrien /// dependent context). 560169689Skan mutable StoredDeclsMap *LookupPtr; 561169689Skan 562169689Skan /// FirstDecl - The first declaration stored within this declaration 56352284Sobrien /// context. 564169689Skan mutable Decl *FirstDecl; 565169689Skan 566169689Skan /// LastDecl - The last declaration stored within this declaration 567169689Skan /// context. FIXME: We could probably cache this value somewhere 568169689Skan /// outside of the DeclContext, to reduce the size of DeclContext by 569169689Skan /// another pointer. 570169689Skan mutable Decl *LastDecl; 571169689Skan 572169689Skanprotected: 573169689Skan DeclContext(Decl::Kind K) 574169689Skan : DeclKind(K), ExternalLexicalStorage(false), 575169689Skan ExternalVisibleStorage(false), LookupPtr(0), FirstDecl(0), 576169689Skan LastDecl(0) { } 577169689Skan 578169689Skan void DestroyDecls(ASTContext &C); 579169689Skan 580169689Skanpublic: 581169689Skan ~DeclContext(); 582169689Skan 583169689Skan Decl::Kind getDeclKind() const { 584169689Skan return DeclKind; 58552284Sobrien } 586169689Skan const char *getDeclKindName() const; 58752284Sobrien 588169689Skan /// getParent - Returns the containing DeclContext. 589169689Skan DeclContext *getParent() { 590169689Skan return cast<Decl>(this)->getDeclContext(); 59152284Sobrien } 592169689Skan const DeclContext *getParent() const { 593169689Skan return const_cast<DeclContext*>(this)->getParent(); 59452284Sobrien } 595169689Skan 596169689Skan /// getLexicalParent - Returns the containing lexical DeclContext. May be 59752284Sobrien /// different from getParent, e.g.: 598169689Skan /// 599169689Skan /// namespace A { 600169689Skan /// struct S; 601169689Skan /// } 602169689Skan /// struct A::S {}; // getParent() == namespace 'A' 603169689Skan /// // getLexicalParent() == translation unit 604169689Skan /// 605169689Skan DeclContext *getLexicalParent() { 606169689Skan return cast<Decl>(this)->getLexicalDeclContext(); 607169689Skan } 608169689Skan const DeclContext *getLexicalParent() const { 609169689Skan return const_cast<DeclContext*>(this)->getLexicalParent(); 610169689Skan } 61152284Sobrien 612169689Skan DeclContext *getLookupParent(); 613169689Skan 614169689Skan const DeclContext *getLookupParent() const { 615169689Skan return const_cast<DeclContext*>(this)->getLookupParent(); 616169689Skan } 617169689Skan 618169689Skan ASTContext &getParentASTContext() const { 619169689Skan return cast<Decl>(this)->getASTContext(); 620169689Skan } 621169689Skan 622169689Skan bool isFunctionOrMethod() const { 623169689Skan switch (DeclKind) { 624169689Skan case Decl::Block: 625169689Skan case Decl::ObjCMethod: 626169689Skan return true; 627169689Skan default: 628169689Skan return DeclKind >= Decl::FunctionFirst && DeclKind <= Decl::FunctionLast; 629169689Skan } 630169689Skan } 631169689Skan 632169689Skan bool isFileContext() const { 633169689Skan return DeclKind == Decl::TranslationUnit || DeclKind == Decl::Namespace; 634169689Skan } 635169689Skan 636169689Skan bool isTranslationUnit() const { 63752284Sobrien return DeclKind == Decl::TranslationUnit; 63852284Sobrien } 639169689Skan 640169689Skan bool isRecord() const { 64152284Sobrien return DeclKind >= Decl::RecordFirst && DeclKind <= Decl::RecordLast; 642169689Skan } 643169689Skan 64452284Sobrien bool isNamespace() const { 645169689Skan return DeclKind == Decl::Namespace; 646169689Skan } 647169689Skan 648169689Skan /// \brief Determines whether this context is dependent on a 64952284Sobrien /// template parameter. 650169689Skan bool isDependentContext() const; 651169689Skan 652169689Skan /// isTransparentContext - Determines whether this context is a 653169689Skan /// "transparent" context, meaning that the members declared in this 65452284Sobrien /// context are semantically declared in the nearest enclosing 655169689Skan /// non-transparent (opaque) context but are lexically declared in 656169689Skan /// this context. For example, consider the enumerators of an 657169689Skan /// enumeration type: 65852284Sobrien /// @code 659169689Skan /// enum E { 660169689Skan /// Val1 661169689Skan /// }; 662169689Skan /// @endcode 66352284Sobrien /// Here, E is a transparent context, so its enumerator (Val1) will 664169689Skan /// appear (semantically) that it is in the same context of E. 665169689Skan /// Examples of transparent contexts include: enumerations (except for 666169689Skan /// C++0x scoped enums), C++ linkage specifications, and C++0x 667169689Skan /// inline namespaces. 668169689Skan bool isTransparentContext() const; 669169689Skan 670169689Skan /// \brief Determine whether this declaration context is equivalent 671169689Skan /// to the declaration context DC. 672169689Skan bool Equals(DeclContext *DC) { 673169689Skan return DC && this->getPrimaryContext() == DC->getPrimaryContext(); 674169689Skan } 675169689Skan 676169689Skan /// \brief Determine whether this declaration context encloses the 677169689Skan /// declaration context DC. 678169689Skan bool Encloses(DeclContext *DC); 679169689Skan 680169689Skan /// getPrimaryContext - There may be many different 681169689Skan /// declarations of the same entity (including forward declarations 682169689Skan /// of classes, multiple definitions of namespaces, etc.), each with 683169689Skan /// a different set of declarations. This routine returns the 684169689Skan /// "primary" DeclContext structure, which will contain the 685169689Skan /// information needed to perform name lookup into this context. 686169689Skan DeclContext *getPrimaryContext(); 687169689Skan const DeclContext *getPrimaryContext() const { 688169689Skan return const_cast<DeclContext*>(this)->getPrimaryContext(); 689169689Skan } 690169689Skan 691169689Skan /// getLookupContext - Retrieve the innermost non-transparent 692169689Skan /// context of this context, which corresponds to the innermost 693169689Skan /// location from which name lookup can find the entities in this 69452284Sobrien /// context. 695169689Skan DeclContext *getLookupContext(); 696169689Skan const DeclContext *getLookupContext() const { 69752284Sobrien return const_cast<DeclContext *>(this)->getLookupContext(); 698169689Skan } 699169689Skan 700169689Skan /// \brief Retrieve the nearest enclosing namespace context. 70152284Sobrien DeclContext *getEnclosingNamespaceContext(); 702169689Skan const DeclContext *getEnclosingNamespaceContext() const { 703169689Skan return const_cast<DeclContext *>(this)->getEnclosingNamespaceContext(); 704169689Skan } 705169689Skan 706169689Skan /// getNextContext - If this is a DeclContext that may have other 707169689Skan /// DeclContexts that are semantically connected but syntactically 708169689Skan /// different, such as C++ namespaces, this routine retrieves the 709169689Skan /// next DeclContext in the link. Iteration through the chain of 710169689Skan /// DeclContexts should begin at the primary DeclContext and 71152284Sobrien /// continue until this function returns NULL. For example, given: 712169689Skan /// @code 713169689Skan /// namespace N { 71452284Sobrien /// int x; 715169689Skan /// } 716169689Skan /// namespace N { 717169689Skan /// int y; 718169689Skan /// } 719169689Skan /// @endcode 720169689Skan /// The first occurrence of namespace N will be the primary 721169689Skan /// DeclContext. Its getNextContext will return the second 722169689Skan /// occurrence of namespace N. 723169689Skan DeclContext *getNextContext(); 724169689Skan 72552284Sobrien /// decl_iterator - Iterates through the declarations stored 726169689Skan /// within this context. 727169689Skan class decl_iterator { 728169689Skan /// Current - The current declaration. 729169689Skan Decl *Current; 730169689Skan 731169689Skan public: 732169689Skan typedef Decl* value_type; 733169689Skan typedef Decl* reference; 734169689Skan typedef Decl* pointer; 735169689Skan typedef std::forward_iterator_tag iterator_category; 736169689Skan typedef std::ptrdiff_t difference_type; 737169689Skan 738169689Skan decl_iterator() : Current(0) { } 739169689Skan explicit decl_iterator(Decl *C) : Current(C) { } 740169689Skan 741169689Skan reference operator*() const { return Current; } 742169689Skan pointer operator->() const { return Current; } 743169689Skan 744169689Skan decl_iterator& operator++() { 745169689Skan Current = Current->getNextDeclInContext(); 746169689Skan return *this; 747169689Skan } 748169689Skan 749169689Skan decl_iterator operator++(int) { 750169689Skan decl_iterator tmp(*this); 751169689Skan ++(*this); 752169689Skan return tmp; 75352284Sobrien } 754169689Skan 755169689Skan friend bool operator==(decl_iterator x, decl_iterator y) { 756169689Skan return x.Current == y.Current; 757169689Skan } 758169689Skan friend bool operator!=(decl_iterator x, decl_iterator y) { 759169689Skan return x.Current != y.Current; 76052284Sobrien } 761169689Skan }; 762169689Skan 763169689Skan /// decls_begin/decls_end - Iterate over the declarations stored in 764169689Skan /// this context. 76552284Sobrien decl_iterator decls_begin() const; 766169689Skan decl_iterator decls_end() const; 767169689Skan bool decls_empty() const; 768169689Skan 769169689Skan /// specific_decl_iterator - Iterates over a subrange of 770169689Skan /// declarations stored in a DeclContext, providing only those that 77152284Sobrien /// are of type SpecificDecl (or a class derived from it). This 772169689Skan /// iterator is used, for example, to provide iteration over just 773169689Skan /// the fields within a RecordDecl (with SpecificDecl = FieldDecl). 77452284Sobrien template<typename SpecificDecl> 77552284Sobrien class specific_decl_iterator { 776169689Skan /// Current - The current, underlying declaration iterator, which 777169689Skan /// will either be NULL or will point to a declaration of 778169689Skan /// type SpecificDecl. 779169689Skan DeclContext::decl_iterator Current; 780169689Skan 781169689Skan /// SkipToNextDecl - Advances the current position up to the next 782169689Skan /// declaration of type SpecificDecl that also meets the criteria 783169689Skan /// required by Acceptable. 784169689Skan void SkipToNextDecl() { 785169689Skan while (*Current && !isa<SpecificDecl>(*Current)) 786169689Skan ++Current; 787169689Skan } 788169689Skan 789169689Skan public: 790169689Skan typedef SpecificDecl* value_type; 791169689Skan typedef SpecificDecl* reference; 792169689Skan typedef SpecificDecl* pointer; 793169689Skan typedef std::iterator_traits<DeclContext::decl_iterator>::difference_type 794169689Skan difference_type; 795169689Skan typedef std::forward_iterator_tag iterator_category; 796169689Skan 797169689Skan specific_decl_iterator() : Current() { } 798169689Skan 799169689Skan /// specific_decl_iterator - Construct a new iterator over a 800169689Skan /// subset of the declarations the range [C, 801169689Skan /// end-of-declarations). If A is non-NULL, it is a pointer to a 802169689Skan /// member function of SpecificDecl that should return true for 803169689Skan /// all of the SpecificDecl instances that will be in the subset 804169689Skan /// of iterators. For example, if you want Objective-C instance 805169689Skan /// methods, SpecificDecl will be ObjCMethodDecl and A will be 80652284Sobrien /// &ObjCMethodDecl::isInstanceMethod. 807169689Skan explicit specific_decl_iterator(DeclContext::decl_iterator C) : Current(C) { 808169689Skan SkipToNextDecl(); 809169689Skan } 810169689Skan 811169689Skan reference operator*() const { return cast<SpecificDecl>(*Current); } 812169689Skan pointer operator->() const { return cast<SpecificDecl>(*Current); } 813169689Skan 81452284Sobrien specific_decl_iterator& operator++() { 815169689Skan ++Current; 816169689Skan SkipToNextDecl(); 817169689Skan return *this; 818169689Skan } 819169689Skan 820169689Skan specific_decl_iterator operator++(int) { 82152284Sobrien specific_decl_iterator tmp(*this); 822169689Skan ++(*this); 823169689Skan return tmp; 824169689Skan } 825169689Skan 826169689Skan friend bool 82752284Sobrien operator==(const specific_decl_iterator& x, const specific_decl_iterator& y) { 828169689Skan return x.Current == y.Current; 829169689Skan } 830169689Skan 831169689Skan friend bool 832169689Skan operator!=(const specific_decl_iterator& x, const specific_decl_iterator& y) { 83352284Sobrien return x.Current != y.Current; 834169689Skan } 835169689Skan }; 836169689Skan 83752284Sobrien /// \brief Iterates over a filtered subrange of declarations stored 838169689Skan /// in a DeclContext. 839169689Skan /// 840169689Skan /// This iterator visits only those declarations that are of type 841169689Skan /// SpecificDecl (or a class derived from it) and that meet some 842169689Skan /// additional run-time criteria. This iterator is used, for 843169689Skan /// example, to provide access to the instance methods within an 844169689Skan /// Objective-C interface (with SpecificDecl = ObjCMethodDecl and 84552284Sobrien /// Acceptable = ObjCMethodDecl::isInstanceMethod). 846169689Skan template<typename SpecificDecl, bool (SpecificDecl::*Acceptable)() const> 847169689Skan class filtered_decl_iterator { 848169689Skan /// Current - The current, underlying declaration iterator, which 84952284Sobrien /// will either be NULL or will point to a declaration of 850169689Skan /// type SpecificDecl. 851169689Skan DeclContext::decl_iterator Current; 852169689Skan 85352284Sobrien /// SkipToNextDecl - Advances the current position up to the next 854169689Skan /// declaration of type SpecificDecl that also meets the criteria 855169689Skan /// required by Acceptable. 856169689Skan void SkipToNextDecl() { 857169689Skan while (*Current && 858169689Skan (!isa<SpecificDecl>(*Current) || 85952284Sobrien (Acceptable && !(cast<SpecificDecl>(*Current)->*Acceptable)()))) 860169689Skan ++Current; 861169689Skan } 862169689Skan 863169689Skan public: 86452284Sobrien typedef SpecificDecl* value_type; 865169689Skan typedef SpecificDecl* reference; 86652284Sobrien typedef SpecificDecl* pointer; 867169689Skan typedef std::iterator_traits<DeclContext::decl_iterator>::difference_type 868169689Skan difference_type; 869169689Skan typedef std::forward_iterator_tag iterator_category; 870169689Skan 871169689Skan filtered_decl_iterator() : Current() { } 872169689Skan 873169689Skan /// specific_decl_iterator - Construct a new iterator over a 874169689Skan /// subset of the declarations the range [C, 875169689Skan /// end-of-declarations). If A is non-NULL, it is a pointer to a 876169689Skan /// member function of SpecificDecl that should return true for 877169689Skan /// all of the SpecificDecl instances that will be in the subset 878169689Skan /// of iterators. For example, if you want Objective-C instance 879169689Skan /// methods, SpecificDecl will be ObjCMethodDecl and A will be 880169689Skan /// &ObjCMethodDecl::isInstanceMethod. 881169689Skan explicit filtered_decl_iterator(DeclContext::decl_iterator C) : Current(C) { 882169689Skan SkipToNextDecl(); 883169689Skan } 884169689Skan 885169689Skan reference operator*() const { return cast<SpecificDecl>(*Current); } 886169689Skan pointer operator->() const { return cast<SpecificDecl>(*Current); } 887169689Skan 888169689Skan filtered_decl_iterator& operator++() { 889169689Skan ++Current; 890169689Skan SkipToNextDecl(); 891169689Skan return *this; 892169689Skan } 893169689Skan 894169689Skan filtered_decl_iterator operator++(int) { 895169689Skan filtered_decl_iterator tmp(*this); 896169689Skan ++(*this); 897169689Skan return tmp; 898169689Skan } 89952284Sobrien 900169689Skan friend bool 901169689Skan operator==(const filtered_decl_iterator& x, const filtered_decl_iterator& y) { 902169689Skan return x.Current == y.Current; 903169689Skan } 904169689Skan 905169689Skan friend bool 906169689Skan operator!=(const filtered_decl_iterator& x, const filtered_decl_iterator& y) { 907169689Skan return x.Current != y.Current; 908169689Skan } 909169689Skan }; 910169689Skan 911169689Skan /// @brief Add the declaration D into this context. 912169689Skan /// 913169689Skan /// This routine should be invoked when the declaration D has first 914169689Skan /// been declared, to place D into the context where it was 915169689Skan /// (lexically) defined. Every declaration must be added to one 91652284Sobrien /// (and only one!) context, where it can be visited via 91752284Sobrien /// [decls_begin(), decls_end()). Once a declaration has been added 918169689Skan /// to its lexical context, the corresponding DeclContext owns the 919169689Skan /// declaration. 920169689Skan /// 921169689Skan /// If D is also a NamedDecl, it will be made visible within its 922169689Skan /// semantic context via makeDeclVisibleInContext. 923169689Skan void addDecl(Decl *D); 924169689Skan 925169689Skan /// @brief Add the declaration D to this context without modifying 926169689Skan /// any lookup tables. 92752284Sobrien /// 928169689Skan /// This is useful for some operations in dependent contexts where 929169689Skan /// the semantic context might not be dependent; this basically 930169689Skan /// only happens with friends. 931169689Skan void addHiddenDecl(Decl *D); 932169689Skan 933169689Skan /// @brief Removes a declaration from this context. 934169689Skan void removeDecl(Decl *D); 935169689Skan 936169689Skan /// lookup_iterator - An iterator that provides access to the results 937169689Skan /// of looking up a name within this context. 938169689Skan typedef NamedDecl **lookup_iterator; 939169689Skan 940169689Skan /// lookup_const_iterator - An iterator that provides non-mutable 941169689Skan /// access to the results of lookup up a name within this context. 942169689Skan typedef NamedDecl * const * lookup_const_iterator; 94352284Sobrien 944169689Skan typedef std::pair<lookup_iterator, lookup_iterator> lookup_result; 945169689Skan typedef std::pair<lookup_const_iterator, lookup_const_iterator> 946169689Skan lookup_const_result; 947169689Skan 948169689Skan /// lookup - Find the declarations (if any) with the given Name in 949169689Skan /// this context. Returns a range of iterators that contains all of 950169689Skan /// the declarations with this name, with object, function, member, 951169689Skan /// and enumerator names preceding any tag name. Note that this 952169689Skan /// routine will not look into parent contexts. 953169689Skan lookup_result lookup(DeclarationName Name); 954169689Skan lookup_const_result lookup(DeclarationName Name) const; 955169689Skan 956169689Skan /// @brief Makes a declaration visible within this context. 957169689Skan /// 95852284Sobrien /// This routine makes the declaration D visible to name lookup 959169689Skan /// within this context and, if this is a transparent context, 960169689Skan /// within its parent contexts up to the first enclosing 961169689Skan /// non-transparent context. Making a declaration visible within a 96252284Sobrien /// context does not transfer ownership of a declaration, and a 963169689Skan /// declaration can be visible in many contexts that aren't its 964169689Skan /// lexical context. 965169689Skan /// 966169689Skan /// If D is a redeclaration of an existing declaration that is 96752284Sobrien /// visible from this context, as determined by 968169689Skan /// NamedDecl::declarationReplaces, the previous declaration will be 969169689Skan /// replaced with D. 970169689Skan /// 971169689Skan /// @param Recoverable true if it's okay to not add this decl to 97252284Sobrien /// the lookup tables because it can be easily recovered by walking 973169689Skan /// the declaration chains. 974169689Skan void makeDeclVisibleInContext(NamedDecl *D, bool Recoverable = true); 975169689Skan 97652284Sobrien /// udir_iterator - Iterates through the using-directives stored 977169689Skan /// within this context. 978169689Skan typedef UsingDirectiveDecl * const * udir_iterator; 979169689Skan 980169689Skan typedef std::pair<udir_iterator, udir_iterator> udir_iterator_range; 981169689Skan 982169689Skan udir_iterator_range getUsingDirectives() const; 983169689Skan 984169689Skan udir_iterator using_directives_begin() const { 985169689Skan return getUsingDirectives().first; 986169689Skan } 987169689Skan 988169689Skan udir_iterator using_directives_end() const { 989169689Skan return getUsingDirectives().second; 990169689Skan } 991169689Skan 992169689Skan // These are all defined in DependentDiagnostic.h. 993169689Skan class ddiag_iterator; 994169689Skan inline ddiag_iterator ddiag_begin() const; 995169689Skan inline ddiag_iterator ddiag_end() const; 996169689Skan 997169689Skan // Low-level accessors 998169689Skan 999169689Skan /// \brief Retrieve the internal representation of the lookup structure. 1000169689Skan StoredDeclsMap* getLookupPtr() const { return LookupPtr; } 1001169689Skan 1002169689Skan /// \brief Whether this DeclContext has external storage containing 1003169689Skan /// additional declarations that are lexically in this context. 1004169689Skan bool hasExternalLexicalStorage() const { return ExternalLexicalStorage; } 1005169689Skan 1006169689Skan /// \brief State whether this DeclContext has external storage for 1007169689Skan /// declarations lexically in this context. 1008169689Skan void setHasExternalLexicalStorage(bool ES = true) { 1009169689Skan ExternalLexicalStorage = ES; 1010169689Skan } 1011169689Skan 1012169689Skan /// \brief Whether this DeclContext has external storage containing 1013169689Skan /// additional declarations that are visible in this context. 1014169689Skan bool hasExternalVisibleStorage() const { return ExternalVisibleStorage; } 1015169689Skan 1016169689Skan /// \brief State whether this DeclContext has external storage for 1017169689Skan /// declarations visible in this context. 1018169689Skan void setHasExternalVisibleStorage(bool ES = true) { 1019169689Skan ExternalVisibleStorage = ES; 1020169689Skan } 1021169689Skan 1022169689Skan static bool classof(const Decl *D); 1023169689Skan static bool classof(const DeclContext *D) { return true; } 1024169689Skan#define DECL_CONTEXT(Name) \ 1025169689Skan static bool classof(const Name##Decl *D) { return true; } 1026169689Skan#include "clang/AST/DeclNodes.def" 1027169689Skan 1028169689Skan void dumpDeclContext() const; 1029169689Skan 1030169689Skanprivate: 1031169689Skan void LoadLexicalDeclsFromExternalStorage() const; 1032169689Skan void LoadVisibleDeclsFromExternalStorage() const; 1033169689Skan 1034169689Skan friend class DependentDiagnostic; 1035169689Skan StoredDeclsMap *CreateStoredDeclsMap(ASTContext &C) const; 1036169689Skan 1037169689Skan void buildLookup(DeclContext *DCtx); 1038169689Skan void makeDeclVisibleInContextImpl(NamedDecl *D); 1039169689Skan}; 1040169689Skan 1041169689Skaninline bool Decl::isTemplateParameter() const { 1042169689Skan return getKind() == TemplateTypeParm || getKind() == NonTypeTemplateParm || 1043169689Skan getKind() == TemplateTemplateParm; 1044169689Skan} 1045169689Skan 1046169689Skan 1047169689Skan// Specialization selected when ToTy is not a known subclass of DeclContext. 1048169689Skantemplate <class ToTy, 1049169689Skan bool IsKnownSubtype = ::llvm::is_base_of< DeclContext, ToTy>::value> 1050169689Skanstruct cast_convert_decl_context { 1051169689Skan static const ToTy *doit(const DeclContext *Val) { 1052169689Skan return static_cast<const ToTy*>(Decl::castFromDeclContext(Val)); 1053169689Skan } 1054169689Skan 1055169689Skan static ToTy *doit(DeclContext *Val) { 1056169689Skan return static_cast<ToTy*>(Decl::castFromDeclContext(Val)); 1057169689Skan } 1058169689Skan}; 1059169689Skan 1060169689Skan// Specialization selected when ToTy is a known subclass of DeclContext. 1061169689Skantemplate <class ToTy> 1062169689Skanstruct cast_convert_decl_context<ToTy, true> { 1063169689Skan static const ToTy *doit(const DeclContext *Val) { 1064169689Skan return static_cast<const ToTy*>(Val); 1065169689Skan } 1066169689Skan 1067169689Skan static ToTy *doit(DeclContext *Val) { 1068169689Skan return static_cast<ToTy*>(Val); 1069169689Skan } 1070169689Skan}; 1071169689Skan 1072169689Skan 1073169689Skan} // end clang. 1074169689Skan 1075169689Skannamespace llvm { 1076169689Skan 1077169689Skan/// isa<T>(DeclContext*) 1078169689Skantemplate<class ToTy> 1079169689Skanstruct isa_impl_wrap<ToTy, 1080169689Skan const ::clang::DeclContext,const ::clang::DeclContext> { 1081169689Skan static bool doit(const ::clang::DeclContext &Val) { 1082169689Skan return ToTy::classofKind(Val.getDeclKind()); 1083169689Skan } 1084169689Skan}; 1085169689Skantemplate<class ToTy> 1086169689Skanstruct isa_impl_wrap<ToTy, ::clang::DeclContext, ::clang::DeclContext> 108752284Sobrien : public isa_impl_wrap<ToTy, 108852284Sobrien const ::clang::DeclContext,const ::clang::DeclContext> {}; 1089169689Skan 1090169689Skan/// cast<T>(DeclContext*) 1091169689Skantemplate<class ToTy> 1092169689Skanstruct cast_convert_val<ToTy, 109352284Sobrien const ::clang::DeclContext,const ::clang::DeclContext> { 1094169689Skan static const ToTy &doit(const ::clang::DeclContext &Val) { 109552284Sobrien return *::clang::cast_convert_decl_context<ToTy>::doit(&Val); 1096169689Skan } 1097169689Skan}; 1098169689Skantemplate<class ToTy> 1099169689Skanstruct cast_convert_val<ToTy, ::clang::DeclContext, ::clang::DeclContext> { 1100169689Skan static ToTy &doit(::clang::DeclContext &Val) { 1101169689Skan return *::clang::cast_convert_decl_context<ToTy>::doit(&Val); 1102169689Skan } 1103169689Skan}; 1104169689Skantemplate<class ToTy> 1105169689Skanstruct cast_convert_val<ToTy, 1106169689Skan const ::clang::DeclContext*, const ::clang::DeclContext*> { 1107169689Skan static const ToTy *doit(const ::clang::DeclContext *Val) { 1108169689Skan return ::clang::cast_convert_decl_context<ToTy>::doit(Val); 1109169689Skan } 1110169689Skan}; 1111169689Skantemplate<class ToTy> 1112169689Skanstruct cast_convert_val<ToTy, ::clang::DeclContext*, ::clang::DeclContext*> { 111352284Sobrien static ToTy *doit(::clang::DeclContext *Val) { 1114169689Skan return ::clang::cast_convert_decl_context<ToTy>::doit(Val); 1115169689Skan } 1116169689Skan}; 111752284Sobrien 1118169689Skan/// Implement cast_convert_val for Decl -> DeclContext conversions. 1119169689Skantemplate<class FromTy> 1120169689Skanstruct cast_convert_val< ::clang::DeclContext, FromTy, FromTy> { 1121169689Skan static ::clang::DeclContext &doit(const FromTy &Val) { 112252284Sobrien return *FromTy::castToDeclContext(&Val); 1123169689Skan } 112452284Sobrien}; 1125169689Skan 1126169689Skantemplate<class FromTy> 112752284Sobrienstruct cast_convert_val< ::clang::DeclContext, FromTy*, FromTy*> { 1128169689Skan static ::clang::DeclContext *doit(const FromTy *Val) { 1129169689Skan return FromTy::castToDeclContext(Val); 1130169689Skan } 1131169689Skan}; 1132169689Skan 1133169689Skantemplate<class FromTy> 1134169689Skanstruct cast_convert_val< const ::clang::DeclContext, FromTy, FromTy> { 1135169689Skan static const ::clang::DeclContext &doit(const FromTy &Val) { 1136169689Skan return *FromTy::castToDeclContext(&Val); 1137169689Skan } 1138169689Skan}; 1139169689Skan 1140169689Skantemplate<class FromTy> 1141169689Skanstruct cast_convert_val< const ::clang::DeclContext, FromTy*, FromTy*> { 1142169689Skan static const ::clang::DeclContext *doit(const FromTy *Val) { 1143169689Skan return FromTy::castToDeclContext(Val); 1144169689Skan } 1145169689Skan}; 1146169689Skan 114752284Sobrien} // end namespace llvm 114852284Sobrien 114990075Sobrien#endif 115090075Sobrien