DeclBase.h revision 7d1d49d2971b20a97b3c2a301470b9eaaa130137
16ab3524f72a6e64aa04973fa9433b5559abb3525Douglas Gregor//===-- DeclBase.h - Base Classes for representing declarations -*- C++ -*-===// 20ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner// 30ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner// The LLVM Compiler Infrastructure 40ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner// 50ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner// This file is distributed under the University of Illinois Open Source 60ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner// License. See LICENSE.TXT for details. 70ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner// 80ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner//===----------------------------------------------------------------------===// 90ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner// 10b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner// This file defines the Decl and DeclContext interfaces. 110ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner// 120ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner//===----------------------------------------------------------------------===// 130ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 140ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner#ifndef LLVM_CLANG_AST_DECLBASE_H 150ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner#define LLVM_CLANG_AST_DECLBASE_H 160ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 170ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner#include "clang/AST/Attr.h" 180ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner#include "clang/AST/Type.h" 194afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor// FIXME: Layering violation 204afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor#include "clang/Parse/AccessSpecifier.h" 2149f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner#include "llvm/Support/PrettyStackTrace.h" 22ee219fd5f2776d8dd39d857f87304297b5ed743aChris Lattner#include "llvm/ADT/PointerUnion.h" 230ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 240ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnernamespace clang { 2542220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisclass DeclContext; 26ef177820100ab583b08fd3056e2a5a52ee4b1629Argyrios Kyrtzidisclass TranslationUnitDecl; 272d1c5d313cd0c229cc614e74baa4c5756a4b46f4Argyrios Kyrtzidisclass NamespaceDecl; 282a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregorclass UsingDirectiveDecl; 2944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregorclass NamedDecl; 300ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnerclass FunctionDecl; 31d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidisclass CXXRecordDecl; 32b048c9835969c4f7fe06264748be18ed4b442116Chris Lattnerclass EnumDecl; 33d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidisclass ObjCMethodDecl; 3464650af7cc4352c6c67b9bd1bf8ef3ce7471b910Douglas Gregorclass ObjCContainerDecl; 350ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnerclass ObjCInterfaceDecl; 360701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroffclass ObjCCategoryDecl; 370701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroffclass ObjCProtocolDecl; 380701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroffclass ObjCImplementationDecl; 390701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroffclass ObjCCategoryImplDecl; 40bfb498d0996ef049efe9476f2802976fd145cd60Argyrios Kyrtzidisclass ObjCImplDecl; 41074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregorclass LinkageSpecDecl; 4256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroffclass BlockDecl; 4344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregorclass DeclarationName; 44eaab20669b6a9910a5deb0110fdd8f7581d86a36Ted Kremenekclass CompoundStmt; 450eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner} 460eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner 470eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattnernamespace llvm { 480eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner// DeclContext* is only 4-byte aligned on 32-bit systems. 490eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattnertemplate<> 500eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner class PointerLikeTypeTraits<clang::DeclContext*> { 510eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner typedef clang::DeclContext* PT; 520eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattnerpublic: 530eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner static inline void *getAsVoidPointer(PT P) { return P; } 540eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner static inline PT getFromVoidPointer(void *P) { 550eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner return static_cast<PT>(P); 560eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner } 570eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner enum { NumLowBitsAvailable = 2 }; 580eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner}; 590eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner} 600eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner 610eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattnernamespace clang { 620ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Decl - This represents one declaration (or definition), e.g. a variable, 641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// typedef, function, struct, etc. 650ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner/// 660ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnerclass Decl { 670ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnerpublic: 6864650af7cc4352c6c67b9bd1bf8ef3ce7471b910Douglas Gregor /// \brief Lists the kind of concrete classes of Decl. 690ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner enum Kind { 7064650af7cc4352c6c67b9bd1bf8ef3ce7471b910Douglas Gregor#define DECL(Derived, Base) Derived, 7164650af7cc4352c6c67b9bd1bf8ef3ce7471b910Douglas Gregor#define DECL_RANGE(CommonBase, Start, End) \ 721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CommonBase##First = Start, CommonBase##Last = End, 7364650af7cc4352c6c67b9bd1bf8ef3ce7471b910Douglas Gregor#define LAST_DECL_RANGE(CommonBase, Start, End) \ 7464650af7cc4352c6c67b9bd1bf8ef3ce7471b910Douglas Gregor CommonBase##First = Start, CommonBase##Last = End 7564650af7cc4352c6c67b9bd1bf8ef3ce7471b910Douglas Gregor#include "clang/AST/DeclNodes.def" 760ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner }; 770ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 788fc463adf0116fdcbff86e9cca11955aad1649feDouglas Gregor /// IdentifierNamespace - According to C99 6.2.3, there are four 798fc463adf0116fdcbff86e9cca11955aad1649feDouglas Gregor /// namespaces, labels, tags, members and ordinary 808fc463adf0116fdcbff86e9cca11955aad1649feDouglas Gregor /// identifiers. These are meant as bitmasks, so that searches in 818fc463adf0116fdcbff86e9cca11955aad1649feDouglas Gregor /// C++ can look into the "tag" namespace during ordinary lookup. We 8202cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// use additional namespaces for Objective-C entities. We also 8302cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// put C++ friend declarations (of previously-undeclared entities) in 8402cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// shadow namespaces. 850ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner enum IdentifierNamespace { 862ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor IDNS_Label = 0x1, 872ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor IDNS_Tag = 0x2, 882ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor IDNS_Member = 0x4, 897dda67d8decef1b3621a151488c4b83bd8372d6aDouglas Gregor IDNS_Ordinary = 0x8, 908fc463adf0116fdcbff86e9cca11955aad1649feDouglas Gregor IDNS_ObjCProtocol = 0x10, 918fc463adf0116fdcbff86e9cca11955aad1649feDouglas Gregor IDNS_ObjCImplementation = 0x20, 926ff0785f1e58fb2cfb702d2995d076c6648a9a13John McCall IDNS_ObjCCategoryImpl = 0x40, 9302cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall IDNS_OrdinaryFriend = 0x80, 9402cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall IDNS_TagFriend = 0x100 950ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner }; 961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 970ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// ObjCDeclQualifier - Qualifier used on types in method declarations 980ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// for remote messaging. They are meant for the arguments though and 990ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// applied to the Decls (ObjCMethodDecl and ParmVarDecl). 1000ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner enum ObjCDeclQualifier { 1010ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_None = 0x0, 1020ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_In = 0x1, 1030ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_Inout = 0x2, 1040ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_Out = 0x4, 1050ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_Bycopy = 0x8, 1060ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_Byref = 0x10, 1070ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_Oneway = 0x20 1080ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner }; 1091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1100ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnerprivate: 111244a67d911d08c3757a18ad666e4a268cf3ee285Chris Lattner /// NextDeclInContext - The next declaration within the same lexical 1124afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// DeclContext. These pointers form the linked list that is 1134afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// traversed via DeclContext's decls_begin()/decls_end(). 114244a67d911d08c3757a18ad666e4a268cf3ee285Chris Lattner Decl *NextDeclInContext; 1154afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 1164afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor friend class DeclContext; 1174afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 118ee219fd5f2776d8dd39d857f87304297b5ed743aChris Lattner struct MultipleDC { 119ee219fd5f2776d8dd39d857f87304297b5ed743aChris Lattner DeclContext *SemanticDC; 120ee219fd5f2776d8dd39d857f87304297b5ed743aChris Lattner DeclContext *LexicalDC; 121ee219fd5f2776d8dd39d857f87304297b5ed743aChris Lattner }; 1221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1244afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// DeclCtx - Holds either a DeclContext* or a MultipleDC*. 1254afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// For declarations that don't contain C++ scope specifiers, it contains 1264afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// the DeclContext where the Decl was declared. 1274afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// For declarations with C++ scope specifiers, it contains a MultipleDC* 1284afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// with the context where it semantically belongs (SemanticDC) and the 1294afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// context where it was lexically declared (LexicalDC). 1304afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// e.g.: 1314afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// 1324afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// namespace A { 1334afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// void f(); // SemanticDC == LexicalDC == 'namespace A' 1344afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// } 1354afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// void A::f(); // SemanticDC == namespace 'A' 1364afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// // LexicalDC == global namespace 137ee219fd5f2776d8dd39d857f87304297b5ed743aChris Lattner llvm::PointerUnion<DeclContext*, MultipleDC*> DeclCtx; 1384afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 139ee219fd5f2776d8dd39d857f87304297b5ed743aChris Lattner inline bool isInSemaDC() const { return DeclCtx.is<DeclContext*>(); } 140ee219fd5f2776d8dd39d857f87304297b5ed743aChris Lattner inline bool isOutOfSemaDC() const { return DeclCtx.is<MultipleDC*>(); } 1414afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor inline MultipleDC *getMultipleDC() const { 142ee219fd5f2776d8dd39d857f87304297b5ed743aChris Lattner return DeclCtx.get<MultipleDC*>(); 1434afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 14410d8379676f32b493740a5509e2cd7f0d6433139Chris Lattner inline DeclContext *getSemanticDC() const { 145ee219fd5f2776d8dd39d857f87304297b5ed743aChris Lattner return DeclCtx.get<DeclContext*>(); 14610d8379676f32b493740a5509e2cd7f0d6433139Chris Lattner } 1471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14839d7650656fdd1be879ed7d0c722cfeae95e56d5Daniel Dunbar /// Loc - The location that this decl. 14939d7650656fdd1be879ed7d0c722cfeae95e56d5Daniel Dunbar SourceLocation Loc; 1501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1510ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// DeclKind - This indicates which class this is. 1520ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner Kind DeclKind : 8; 1531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1540ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// InvalidDecl - This indicates a semantic error occurred. 1550ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner unsigned int InvalidDecl : 1; 1561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1570ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// HasAttrs - This indicates whether the decl has attributes or not. 1580ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner unsigned int HasAttrs : 1; 159d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis 1606b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor /// Implicit - Whether this declaration was implicitly generated by 1616b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor /// the implementation rather than explicitly written by the user. 1626b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor bool Implicit : 1; 1636b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor 164e0762c92110dfdcdd207db461a4ea17afd168f1eDouglas Gregor /// \brief Whether this declaration was "used", meaning that a definition is 165e0762c92110dfdcdd207db461a4ea17afd168f1eDouglas Gregor /// required. 166e0762c92110dfdcdd207db461a4ea17afd168f1eDouglas Gregor bool Used : 1; 1679cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor 1689cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregorprotected: 1697d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor /// Access - Used by C++ decls for the access specifier. 1707d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor // NOTE: VC++ treats enums as signed, avoid using the AccessSpecifier enum 1717d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor unsigned Access : 2; 1727d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor friend class CXXClassMemberWrapper; 1737d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor 1747d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor // PCHLevel - the "level" of precompiled header/AST file from which this 1757d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor // declaration was built. 1767d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor unsigned PCHLevel : 2; 1777d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor 178769dbdf467681f6020ff248b969c2d41a4fdccd3Chris Lattner /// IdentifierNamespace - This specifies what IDNS_* namespace this lives in. 17902cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall unsigned IdentifierNamespace : 16; 1801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1819cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregorprivate: 1821329c274628cc8c4e8ad472b41d1a78c8123f611Anders Carlsson#ifndef NDEBUG 1831329c274628cc8c4e8ad472b41d1a78c8123f611Anders Carlsson void CheckAccessDeclContext() const; 1841329c274628cc8c4e8ad472b41d1a78c8123f611Anders Carlsson#else 1851329c274628cc8c4e8ad472b41d1a78c8123f611Anders Carlsson void CheckAccessDeclContext() const { } 1861329c274628cc8c4e8ad472b41d1a78c8123f611Anders Carlsson#endif 1871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1884afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorprotected: 189d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis 1901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Decl(Kind DK, DeclContext *DC, SourceLocation L) 1911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : NextDeclInContext(0), DeclCtx(DC), 19239d7650656fdd1be879ed7d0c722cfeae95e56d5Daniel Dunbar Loc(L), DeclKind(DK), InvalidDecl(0), 193e0762c92110dfdcdd207db461a4ea17afd168f1eDouglas Gregor HasAttrs(false), Implicit(false), Used(false), 1947d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor Access(AS_none), PCHLevel(0), 1957d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor IdentifierNamespace(getIdentifierNamespaceForKind(DK)) { 1960ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner if (Decl::CollectingStats()) addDeclKind(DK); 1970ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 1981bb19638f2ec0d63ed131b51ca8d9542d1a9afeeSam Bishop 1990ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner virtual ~Decl(); 2001bb19638f2ec0d63ed131b51ca8d9542d1a9afeeSam Bishop 2011bb19638f2ec0d63ed131b51ca8d9542d1a9afeeSam Bishoppublic: 20255d608cbadf1e9c05064f9287c057d50b7df65b4Argyrios Kyrtzidis 20355d608cbadf1e9c05064f9287c057d50b7df65b4Argyrios Kyrtzidis /// \brief Source range that this declaration covers. 20455d608cbadf1e9c05064f9287c057d50b7df65b4Argyrios Kyrtzidis virtual SourceRange getSourceRange() const { 20555d608cbadf1e9c05064f9287c057d50b7df65b4Argyrios Kyrtzidis return SourceRange(getLocation(), getLocation()); 20655d608cbadf1e9c05064f9287c057d50b7df65b4Argyrios Kyrtzidis } 20755d608cbadf1e9c05064f9287c057d50b7df65b4Argyrios Kyrtzidis SourceLocation getLocStart() const { return getSourceRange().getBegin(); } 20855d608cbadf1e9c05064f9287c057d50b7df65b4Argyrios Kyrtzidis SourceLocation getLocEnd() const { return getSourceRange().getEnd(); } 20955d608cbadf1e9c05064f9287c057d50b7df65b4Argyrios Kyrtzidis 2100ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner SourceLocation getLocation() const { return Loc; } 2110ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner void setLocation(SourceLocation L) { Loc = L; } 2120ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 2130ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner Kind getKind() const { return DeclKind; } 2140ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner const char *getDeclKindName() const; 2151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 216244a67d911d08c3757a18ad666e4a268cf3ee285Chris Lattner Decl *getNextDeclInContext() { return NextDeclInContext; } 217244a67d911d08c3757a18ad666e4a268cf3ee285Chris Lattner const Decl *getNextDeclInContext() const { return NextDeclInContext; } 21896f4468b6b1bf69bb01c1207f716a3ffaeb4a8d3Chris Lattner 2194afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor DeclContext *getDeclContext() { 22010d8379676f32b493740a5509e2cd7f0d6433139Chris Lattner if (isInSemaDC()) 22110d8379676f32b493740a5509e2cd7f0d6433139Chris Lattner return getSemanticDC(); 22210d8379676f32b493740a5509e2cd7f0d6433139Chris Lattner return getMultipleDC()->SemanticDC; 2234afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 2240cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner const DeclContext *getDeclContext() const { 2250cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner return const_cast<Decl*>(this)->getDeclContext(); 2260cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner } 2273708b3df2e86998dca4c006939014ea1174da834Argyrios Kyrtzidis 2283708b3df2e86998dca4c006939014ea1174da834Argyrios Kyrtzidis TranslationUnitDecl *getTranslationUnitDecl(); 2293708b3df2e86998dca4c006939014ea1174da834Argyrios Kyrtzidis const TranslationUnitDecl *getTranslationUnitDecl() const { 2303708b3df2e86998dca4c006939014ea1174da834Argyrios Kyrtzidis return const_cast<Decl*>(this)->getTranslationUnitDecl(); 2313708b3df2e86998dca4c006939014ea1174da834Argyrios Kyrtzidis } 2323708b3df2e86998dca4c006939014ea1174da834Argyrios Kyrtzidis 2339aeed32282fe8a775c24c01c923717ca86695685John McCall bool isInAnonymousNamespace() const; 2349aeed32282fe8a775c24c01c923717ca86695685John McCall 2353708b3df2e86998dca4c006939014ea1174da834Argyrios Kyrtzidis ASTContext &getASTContext() const; 2361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2371329c274628cc8c4e8ad472b41d1a78c8123f611Anders Carlsson void setAccess(AccessSpecifier AS) { 2381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Access = AS; 2391329c274628cc8c4e8ad472b41d1a78c8123f611Anders Carlsson CheckAccessDeclContext(); 2401329c274628cc8c4e8ad472b41d1a78c8123f611Anders Carlsson } 2411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump AccessSpecifier getAccess() const { 2431329c274628cc8c4e8ad472b41d1a78c8123f611Anders Carlsson CheckAccessDeclContext(); 2441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return AccessSpecifier(Access); 245b8547e800f9553a72c2f3635ae2371692bd4411aAnders Carlsson } 2464afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 24776a642ff4fce7a0648c79a1f01324a8c3880e251Chris Lattner bool hasAttrs() const { return HasAttrs; } 24840b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis void addAttr(Attr *attr); 24940b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis const Attr *getAttrs() const { 25081abbdd848aa02c30242bd22dcc6ffe024ae2957Chris Lattner if (!HasAttrs) return 0; // common case, no attributes. 25140b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis return getAttrsImpl(); // Uncommon case, out of line hash lookup. 25281abbdd848aa02c30242bd22dcc6ffe024ae2957Chris Lattner } 25340b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis void swapAttrs(Decl *D); 25440b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis void invalidateAttrs(); 2550ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 25640b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis template<typename T> const T *getAttr() const { 25740b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis for (const Attr *attr = getAttrs(); attr; attr = attr->getNext()) 2580ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner if (const T *V = dyn_cast<T>(attr)) 2590ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner return V; 2600ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner return 0; 2610ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 2621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 26340b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis template<typename T> bool hasAttr() const { 26440b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis return getAttr<T>() != 0; 265115cafcafec3572756635ca81ef83999ae0c8af7Chris Lattner } 2661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2670ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// setInvalidDecl - Indicates the Decl had a semantic error. This 2680ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// allows for graceful error recovery. 2696ab3524f72a6e64aa04973fa9433b5559abb3525Douglas Gregor void setInvalidDecl(bool Invalid = true) { InvalidDecl = Invalid; } 2700ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner bool isInvalidDecl() const { return (bool) InvalidDecl; } 2716b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor 2726b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor /// isImplicit - Indicates whether the declaration was implicitly 2736b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor /// generated by the implementation. If false, this declaration 2746b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor /// was written explicitly in the source code. 2756b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor bool isImplicit() const { return Implicit; } 2766b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor void setImplicit(bool I = true) { Implicit = I; } 2771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 278e0762c92110dfdcdd207db461a4ea17afd168f1eDouglas Gregor /// \brief Whether this declaration was used, meaning that a definition 279e0762c92110dfdcdd207db461a4ea17afd168f1eDouglas Gregor /// is required. 280e0762c92110dfdcdd207db461a4ea17afd168f1eDouglas Gregor bool isUsed() const { return Used; } 281e0762c92110dfdcdd207db461a4ea17afd168f1eDouglas Gregor void setUsed(bool U = true) { Used = U; } 2821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2837d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor /// \brief Retrieve the level of precompiled header from which this 2847d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor /// declaration was generated. 2857d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor /// 2867d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor /// The PCH level of a declaration describes where the declaration originated 2877d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor /// from. A PCH level of 0 indicates that the declaration was not from a 2887d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor /// precompiled header. A PCH level of 1 indicates that the declaration was 2897d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor /// from a top-level precompiled header; 2 indicates that the declaration 2907d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor /// comes from a precompiled header on which the top-level precompiled header 2917d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor /// depends, and so on. 2927d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor unsigned getPCHLevel() const { return PCHLevel; } 2937d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor 2947d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor /// \brief The maximum PCH level that any declaration may have. 2957d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor static const unsigned MaxPCHLevel = 3; 2967d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor 2977d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor /// \brief Set the PCH level of this declaration. 2987d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor void setPCHLevel(unsigned Level) { 2997d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor assert(Level < MaxPCHLevel && "PCH level exceeds the maximum"); 3007d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor PCHLevel = Level; 3017d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor } 3027d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor 303cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor unsigned getIdentifierNamespace() const { 304769dbdf467681f6020ff248b969c2d41a4fdccd3Chris Lattner return IdentifierNamespace; 3050ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 306d62fdc448b3ace606c8c9c9f13e43218fa204dbfChris Lattner bool isInIdentifierNamespace(unsigned NS) const { 307d62fdc448b3ace606c8c9c9f13e43218fa204dbfChris Lattner return getIdentifierNamespace() & NS; 308d62fdc448b3ace606c8c9c9f13e43218fa204dbfChris Lattner } 309769dbdf467681f6020ff248b969c2d41a4fdccd3Chris Lattner static unsigned getIdentifierNamespaceForKind(Kind DK); 310769dbdf467681f6020ff248b969c2d41a4fdccd3Chris Lattner 3111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3124afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// getLexicalDeclContext - The declaration context where this Decl was 3134afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// lexically declared (LexicalDC). May be different from 3144afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// getDeclContext() (SemanticDC). 3154afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// e.g.: 3164afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// 3174afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// namespace A { 3184afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// void f(); // SemanticDC == LexicalDC == 'namespace A' 3194afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// } 3204afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// void A::f(); // SemanticDC == namespace 'A' 3214afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// // LexicalDC == global namespace 32210d8379676f32b493740a5509e2cd7f0d6433139Chris Lattner DeclContext *getLexicalDeclContext() { 3234afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor if (isInSemaDC()) 32410d8379676f32b493740a5509e2cd7f0d6433139Chris Lattner return getSemanticDC(); 3254afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return getMultipleDC()->LexicalDC; 3264afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 32710d8379676f32b493740a5509e2cd7f0d6433139Chris Lattner const DeclContext *getLexicalDeclContext() const { 32810d8379676f32b493740a5509e2cd7f0d6433139Chris Lattner return const_cast<Decl*>(this)->getLexicalDeclContext(); 3294afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 330f5cecfbdcd20be224861f9e67c5973a9a2b61512Argyrios Kyrtzidis 331f5cecfbdcd20be224861f9e67c5973a9a2b61512Argyrios Kyrtzidis bool isOutOfLine() const { 332f5cecfbdcd20be224861f9e67c5973a9a2b61512Argyrios Kyrtzidis return getLexicalDeclContext() != getDeclContext(); 333f5cecfbdcd20be224861f9e67c5973a9a2b61512Argyrios Kyrtzidis } 3341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3356ab3524f72a6e64aa04973fa9433b5559abb3525Douglas Gregor /// setDeclContext - Set both the semantic and lexical DeclContext 3366ab3524f72a6e64aa04973fa9433b5559abb3525Douglas Gregor /// to DC. 3376ab3524f72a6e64aa04973fa9433b5559abb3525Douglas Gregor void setDeclContext(DeclContext *DC); 3386ab3524f72a6e64aa04973fa9433b5559abb3525Douglas Gregor 3394afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor void setLexicalDeclContext(DeclContext *DC); 3404afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 3414afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor // isDefinedOutsideFunctionOrMethod - This predicate returns true if this 3424afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor // scoped decl is defined outside the current function or method. This is 3434afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor // roughly global variables and functions, but also handles enums (which could 3444afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor // be defined inside or outside a function etc). 3454afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor bool isDefinedOutsideFunctionOrMethod() const; 3464afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 347b57a4fe73b8227c0dba651818b8495dfca61e530Argyrios Kyrtzidis /// \brief Retrieves the "canonical" declaration of the given declaration. 348b57a4fe73b8227c0dba651818b8495dfca61e530Argyrios Kyrtzidis virtual Decl *getCanonicalDecl() { return this; } 349b57a4fe73b8227c0dba651818b8495dfca61e530Argyrios Kyrtzidis const Decl *getCanonicalDecl() const { 350b57a4fe73b8227c0dba651818b8495dfca61e530Argyrios Kyrtzidis return const_cast<Decl*>(this)->getCanonicalDecl(); 351b57a4fe73b8227c0dba651818b8495dfca61e530Argyrios Kyrtzidis } 352fc7e2a8fbb08f0f496ac6cea0721fe72db8ce240Argyrios Kyrtzidis 353ac4e3794c60fc194fb2bd9764aa81d4cae530eccArgyrios Kyrtzidis /// \brief Whether this particular Decl is a canonical one. 354b57a4fe73b8227c0dba651818b8495dfca61e530Argyrios Kyrtzidis bool isCanonicalDecl() const { return getCanonicalDecl() == this; } 3551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3561e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidisprotected: 3571e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis /// \brief Returns the next redeclaration or itself if this is the only decl. 3581e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis /// 3591e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis /// Decl subclasses that can be redeclared should override this method so that 3601e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis /// Decl::redecl_iterator can iterate over them. 3611e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis virtual Decl *getNextRedeclaration() { return this; } 3621e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis 3631e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidispublic: 3641e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis /// \brief Iterates through all the redeclarations of the same decl. 3651e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis class redecl_iterator { 3661e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis /// Current - The current declaration. 3671e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis Decl *Current; 3681e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis Decl *Starter; 3691e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis 3701e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis public: 3711e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis typedef Decl* value_type; 3721e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis typedef Decl* reference; 3731e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis typedef Decl* pointer; 3741e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis typedef std::forward_iterator_tag iterator_category; 3751e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis typedef std::ptrdiff_t difference_type; 3761e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis 3771e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis redecl_iterator() : Current(0) { } 3781e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis explicit redecl_iterator(Decl *C) : Current(C), Starter(C) { } 3791e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis 3801e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis reference operator*() const { return Current; } 3811e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis pointer operator->() const { return Current; } 3821e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis 3831e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis redecl_iterator& operator++() { 3841e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis assert(Current && "Advancing while iterator has reached end"); 3851e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis // Get either previous decl or latest decl. 3861e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis Decl *Next = Current->getNextRedeclaration(); 38722cbd2b794676c3b29c2b401c26730ed7047809eArgyrios Kyrtzidis assert(Next && "Should return next redeclaration or itself, never null!"); 3881e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis Current = (Next != Starter ? Next : 0); 3891e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis return *this; 3901e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis } 3911e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis 3921e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis redecl_iterator operator++(int) { 3931e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis redecl_iterator tmp(*this); 3941e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis ++(*this); 3951e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis return tmp; 3961e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis } 3971e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis 3981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump friend bool operator==(redecl_iterator x, redecl_iterator y) { 3991e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis return x.Current == y.Current; 4001e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis } 4011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump friend bool operator!=(redecl_iterator x, redecl_iterator y) { 4021e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis return x.Current != y.Current; 4031e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis } 4041e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis }; 4051e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis 4061e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis /// \brief Returns iterator for all the redeclarations of the same decl. 4071e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis /// It will iterate at least once (when this decl is the only one). 4081e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis redecl_iterator redecls_begin() const { 4091e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis return redecl_iterator(const_cast<Decl*>(this)); 4101e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis } 4111e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis redecl_iterator redecls_end() const { return redecl_iterator(); } 412fc7e2a8fbb08f0f496ac6cea0721fe72db8ce240Argyrios Kyrtzidis 413d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl /// getBody - If this Decl represents a declaration for a body of code, 414d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl /// such as a function or method definition, this method returns the 415d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl /// top-level Stmt* of that body. Otherwise this method returns null. 4166fb0aee4f9dc261bbec72e1283ad8dc0557a6d96Argyrios Kyrtzidis virtual Stmt* getBody() const { return 0; } 417d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl 418d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl /// getCompoundBody - Returns getBody(), dyn_casted to a CompoundStmt. 4196fb0aee4f9dc261bbec72e1283ad8dc0557a6d96Argyrios Kyrtzidis CompoundStmt* getCompoundBody() const; 420d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl 421d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl /// getBodyRBrace - Gets the right brace of the body, if a body exists. 422d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl /// This works whether the body is a CompoundStmt or a CXXTryStmt. 4236fb0aee4f9dc261bbec72e1283ad8dc0557a6d96Argyrios Kyrtzidis SourceLocation getBodyRBrace() const; 424d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl 4250ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner // global temp stats (until we have a per-module visitor) 4260ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner static void addDeclKind(Kind k); 4270ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner static bool CollectingStats(bool Enable = false); 4280ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner static void PrintStats(); 4291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 43067e332009c6e349dc34700f539747afcff990336Anders Carlsson /// isTemplateParameter - Determines whether this declaration is a 431f57172b24f08a68d179675989813d5479dc87829Douglas Gregor /// template parameter. 432f57172b24f08a68d179675989813d5479dc87829Douglas Gregor bool isTemplateParameter() const; 4331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 43467e332009c6e349dc34700f539747afcff990336Anders Carlsson /// isTemplateParameter - Determines whether this declaration is a 43567e332009c6e349dc34700f539747afcff990336Anders Carlsson /// template parameter pack. 43667e332009c6e349dc34700f539747afcff990336Anders Carlsson bool isTemplateParameterPack() const; 437f57172b24f08a68d179675989813d5479dc87829Douglas Gregor 438e53060fa78ad7e98352049f72787bdb7543e2a48Douglas Gregor /// \brief Whether this declaration is a function or function template. 439e53060fa78ad7e98352049f72787bdb7543e2a48Douglas Gregor bool isFunctionOrFunctionTemplate() const; 44002cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall 44102cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// \brief Changes the namespace of this declaration to reflect that it's 44202cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// the object of a friend declaration. 44302cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// 44402cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// These declarations appear in the lexical context of the friending 44502cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// class, but in the semantic context of the actual entity. This property 44602cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// applies only to a specific decl object; other redeclarations of the 44702cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// same entity may not (and probably don't) share this property. 44802cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall void setObjectOfFriendDecl(bool PreviouslyDeclared) { 44902cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall unsigned OldNS = IdentifierNamespace; 45005b23ea2119b4c411719bd6631e5d679ba5e7ef1John McCall assert((OldNS == IDNS_Tag || OldNS == IDNS_Ordinary || 45105b23ea2119b4c411719bd6631e5d679ba5e7ef1John McCall OldNS == (IDNS_Tag | IDNS_Ordinary)) 45202cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall && "unsupported namespace for undeclared friend"); 45302cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall if (!PreviouslyDeclared) IdentifierNamespace = 0; 45402cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall 45502cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall if (OldNS == IDNS_Tag) 45602cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall IdentifierNamespace |= IDNS_TagFriend; 45702cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall else 45802cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall IdentifierNamespace |= IDNS_OrdinaryFriend; 45902cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall } 46002cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall 46102cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall enum FriendObjectKind { 46202cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall FOK_None, // not a friend object 46302cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall FOK_Declared, // a friend of a previously-declared entity 46402cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall FOK_Undeclared // a friend of a previously-undeclared entity 46502cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall }; 46602cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall 46702cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// \brief Determines whether this declaration is the object of a 46802cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// friend declaration and, if so, what kind. 46902cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// 47002cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// There is currently no direct way to find the associated FriendDecl. 47102cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall FriendObjectKind getFriendObjectKind() const { 47202cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall unsigned mask 47302cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall = (IdentifierNamespace & (IDNS_TagFriend | IDNS_OrdinaryFriend)); 47402cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall if (!mask) return FOK_None; 475255d6415a692e8384971755f91541497d54b3193Anders Carlsson return (IdentifierNamespace & (IDNS_Tag | IDNS_Ordinary) ? 476255d6415a692e8384971755f91541497d54b3193Anders Carlsson FOK_Declared : FOK_Undeclared); 47702cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall } 4781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4790ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner // Implement isa/cast/dyncast/etc. 4800ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner static bool classof(const Decl *) { return true; } 48142220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis static DeclContext *castToDeclContext(const Decl *); 48242220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis static Decl *castFromDeclContext(const DeclContext *); 4831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 484bb45c512e0dfbe96bfe377ac642e726c0ba0affaSam Bishop /// Destroy - Call destructors and release memory. 48527f8a28bee33bb0e857cfe1a61c281bbc234b338Ted Kremenek virtual void Destroy(ASTContext& C); 486bb45c512e0dfbe96bfe377ac642e726c0ba0affaSam Bishop 487f88df8652e0726fe9eee5d78f92e3c5b34d0a537Anders Carlsson void print(llvm::raw_ostream &Out, unsigned Indentation = 0) const; 488f1d60eaf3f70975ee262852af2d6aeabd140ed58Argyrios Kyrtzidis void print(llvm::raw_ostream &Out, const PrintingPolicy &Policy, 489f88df8652e0726fe9eee5d78f92e3c5b34d0a537Anders Carlsson unsigned Indentation = 0) const; 49042f42c0dd5cf71fbfc6fa282d03079a902f6e342Eli Friedman static void printGroup(Decl** Begin, unsigned NumDecls, 491f1d60eaf3f70975ee262852af2d6aeabd140ed58Argyrios Kyrtzidis llvm::raw_ostream &Out, const PrintingPolicy &Policy, 49242f42c0dd5cf71fbfc6fa282d03079a902f6e342Eli Friedman unsigned Indentation = 0); 493f88df8652e0726fe9eee5d78f92e3c5b34d0a537Anders Carlsson void dump() const; 4944fe0c8e9c76b96e7aff21696a40dacc09d0237bcDouglas Gregor 49581abbdd848aa02c30242bd22dcc6ffe024ae2957Chris Lattnerprivate: 49640b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis const Attr *getAttrsImpl() const; 49781abbdd848aa02c30242bd22dcc6ffe024ae2957Chris Lattner 4980ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner}; 4990ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 50049f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner/// PrettyStackTraceDecl - If a crash occurs, indicate that it happened when 50149f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner/// doing something to a specific decl. 50249f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattnerclass PrettyStackTraceDecl : public llvm::PrettyStackTraceEntry { 50349f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner Decl *TheDecl; 50449f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner SourceLocation Loc; 50549f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner SourceManager &SM; 50649f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner const char *Message; 50749f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattnerpublic: 50849f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner PrettyStackTraceDecl(Decl *theDecl, SourceLocation L, 50949f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner SourceManager &sm, const char *Msg) 51049f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner : TheDecl(theDecl), Loc(L), SM(sm), Message(Msg) {} 5111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 51249f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner virtual void print(llvm::raw_ostream &OS) const; 5131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump}; 5141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 51549f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner 516b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner/// DeclContext - This is used only as base class of specific decl types that 5171ad4dd78ec53c24ea9e752b216035d7aa666fe49Argyrios Kyrtzidis/// can act as declaration contexts. These decls are (only the top classes 5181ad4dd78ec53c24ea9e752b216035d7aa666fe49Argyrios Kyrtzidis/// that directly derive from DeclContext are mentioned, not their subclasses): 5190ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner/// 520ef177820100ab583b08fd3056e2a5a52ee4b1629Argyrios Kyrtzidis/// TranslationUnitDecl 5212d1c5d313cd0c229cc614e74baa4c5756a4b46f4Argyrios Kyrtzidis/// NamespaceDecl 5220ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner/// FunctionDecl 5231ad4dd78ec53c24ea9e752b216035d7aa666fe49Argyrios Kyrtzidis/// TagDecl 524d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis/// ObjCMethodDecl 5251ad4dd78ec53c24ea9e752b216035d7aa666fe49Argyrios Kyrtzidis/// ObjCContainerDecl 526074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor/// LinkageSpecDecl 52756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff/// BlockDecl 5281ad4dd78ec53c24ea9e752b216035d7aa666fe49Argyrios Kyrtzidis/// 529b048c9835969c4f7fe06264748be18ed4b442116Chris Lattnerclass DeclContext { 5300ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// DeclKind - This indicates which class this is. 5310ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner Decl::Kind DeclKind : 8; 5320ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 5332cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// \brief Whether this declaration context also has some external 5342cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// storage that contains additional declarations that are lexically 5352cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// part of this context. 5362cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor mutable bool ExternalLexicalStorage : 1; 5372cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 5382cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// \brief Whether this declaration context also has some external 5392cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// storage that contains additional declarations that are visible 5402cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// in this context. 5412cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor mutable bool ExternalVisibleStorage : 1; 5422cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 543c36c540c5bfce941f3d892919394d092491211f2Douglas Gregor /// \brief Pointer to the data structure used to lookup declarations 544c36c540c5bfce941f3d892919394d092491211f2Douglas Gregor /// within this context, which is a DenseMap<DeclarationName, 545c36c540c5bfce941f3d892919394d092491211f2Douglas Gregor /// StoredDeclsList>. 5462cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor mutable void* LookupPtr; 54744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 5486037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// FirstDecl - The first declaration stored within this declaration 5496037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// context. 5502cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor mutable Decl *FirstDecl; 5516037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 5526037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// LastDecl - The last declaration stored within this declaration 5536037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// context. FIXME: We could probably cache this value somewhere 5546037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// outside of the DeclContext, to reduce the size of DeclContext by 5556037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// another pointer. 5562cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor mutable Decl *LastDecl; 5577643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidis 5580ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnerprotected: 5591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclContext(Decl::Kind K) 5602cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor : DeclKind(K), ExternalLexicalStorage(false), 5611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ExternalVisibleStorage(false), LookupPtr(0), FirstDecl(0), 5622cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor LastDecl(0) { } 56344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 56444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor void DestroyDecls(ASTContext &C); 5650ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 5660ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnerpublic: 56744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor ~DeclContext(); 56844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 5699b9ca01ff3136a7539dc08a4c4e1a3dd8c8d3a7dArgyrios Kyrtzidis Decl::Kind getDeclKind() const { 5709b9ca01ff3136a7539dc08a4c4e1a3dd8c8d3a7dArgyrios Kyrtzidis return DeclKind; 5719b9ca01ff3136a7539dc08a4c4e1a3dd8c8d3a7dArgyrios Kyrtzidis } 5720a4739305a984ef9b821cedad5f4fe235eb6ef7dSteve Naroff const char *getDeclKindName() const; 5739b9ca01ff3136a7539dc08a4c4e1a3dd8c8d3a7dArgyrios Kyrtzidis 574305ec42f971a2b3e114eb35256c23e955c497a1cArgyrios Kyrtzidis /// getParent - Returns the containing DeclContext. 5750cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner DeclContext *getParent() { 576305ec42f971a2b3e114eb35256c23e955c497a1cArgyrios Kyrtzidis return cast<Decl>(this)->getDeclContext(); 577305ec42f971a2b3e114eb35256c23e955c497a1cArgyrios Kyrtzidis } 5780cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner const DeclContext *getParent() const { 5790cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner return const_cast<DeclContext*>(this)->getParent(); 580d2595ecce5f8350e485c83bfe767549a522b2802Argyrios Kyrtzidis } 5811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 58277407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis /// getLexicalParent - Returns the containing lexical DeclContext. May be 58344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// different from getParent, e.g.: 58444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// 58544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// namespace A { 58644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// struct S; 58744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// } 58844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// struct A::S {}; // getParent() == namespace 'A' 58977407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis /// // getLexicalParent() == translation unit 59077407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis /// 59177407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis DeclContext *getLexicalParent() { 5920cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner return cast<Decl>(this)->getLexicalDeclContext(); 59377407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis } 5940cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner const DeclContext *getLexicalParent() const { 5950cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner return const_cast<DeclContext*>(this)->getLexicalParent(); 5961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 597048f30a483ca352ee7f235a5be181b9dcc5f9d9cArgyrios Kyrtzidis 598e942bbe02b6fb332d1f13d38c6e1980b416cf89aDouglas Gregor DeclContext *getLookupParent(); 599e942bbe02b6fb332d1f13d38c6e1980b416cf89aDouglas Gregor 600e942bbe02b6fb332d1f13d38c6e1980b416cf89aDouglas Gregor const DeclContext *getLookupParent() const { 601e942bbe02b6fb332d1f13d38c6e1980b416cf89aDouglas Gregor return const_cast<DeclContext*>(this)->getLookupParent(); 602e942bbe02b6fb332d1f13d38c6e1980b416cf89aDouglas Gregor } 603e942bbe02b6fb332d1f13d38c6e1980b416cf89aDouglas Gregor 604048f30a483ca352ee7f235a5be181b9dcc5f9d9cArgyrios Kyrtzidis ASTContext &getParentASTContext() const { 605048f30a483ca352ee7f235a5be181b9dcc5f9d9cArgyrios Kyrtzidis return cast<Decl>(this)->getASTContext(); 606048f30a483ca352ee7f235a5be181b9dcc5f9d9cArgyrios Kyrtzidis } 607048f30a483ca352ee7f235a5be181b9dcc5f9d9cArgyrios Kyrtzidis 6080ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner bool isFunctionOrMethod() const { 6090ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner switch (DeclKind) { 6100cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner case Decl::Block: 6110cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner case Decl::ObjCMethod: 6120cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner return true; 6130cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner default: 6140cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner return DeclKind >= Decl::FunctionFirst && DeclKind <= Decl::FunctionLast; 6150ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 6160ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 6170ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 618ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis bool isFileContext() const { 619ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis return DeclKind == Decl::TranslationUnit || DeclKind == Decl::Namespace; 620ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis } 621ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis 6225f2bfd4811996abb783aa6c7254c56baa6930e8cDouglas Gregor bool isTranslationUnit() const { 6235f2bfd4811996abb783aa6c7254c56baa6930e8cDouglas Gregor return DeclKind == Decl::TranslationUnit; 6245f2bfd4811996abb783aa6c7254c56baa6930e8cDouglas Gregor } 6255f2bfd4811996abb783aa6c7254c56baa6930e8cDouglas Gregor 626bcbffc46f1ad3796c4582fa1e3a9113b5aa26061Douglas Gregor bool isRecord() const { 62765100792a69a16895bd80f1d639b99e7ad903386Douglas Gregor return DeclKind >= Decl::RecordFirst && DeclKind <= Decl::RecordLast; 628c7ed9c60b8ee04b119e23441cae2cfec74536ba9Argyrios Kyrtzidis } 629c7ed9c60b8ee04b119e23441cae2cfec74536ba9Argyrios Kyrtzidis 63044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor bool isNamespace() const { 63144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor return DeclKind == Decl::Namespace; 63244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor } 63344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 634bc221637f5ed3538b8495dd13b831c11e821c712Douglas Gregor /// \brief Determines whether this context is dependent on a 635bc221637f5ed3538b8495dd13b831c11e821c712Douglas Gregor /// template parameter. 636bc221637f5ed3538b8495dd13b831c11e821c712Douglas Gregor bool isDependentContext() const; 637bc221637f5ed3538b8495dd13b831c11e821c712Douglas Gregor 638074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// isTransparentContext - Determines whether this context is a 639074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// "transparent" context, meaning that the members declared in this 640074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// context are semantically declared in the nearest enclosing 641074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// non-transparent (opaque) context but are lexically declared in 642074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// this context. For example, consider the enumerators of an 6431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// enumeration type: 644074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// @code 645074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// enum E { 6461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// Val1 647074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// }; 648074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// @endcode 649074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// Here, E is a transparent context, so its enumerator (Val1) will 650074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// appear (semantically) that it is in the same context of E. 651074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// Examples of transparent contexts include: enumerations (except for 652074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// C++0x scoped enums), C++ linkage specifications, and C++0x 653074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// inline namespaces. 654074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor bool isTransparentContext() const; 655074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor 65661481dad22ebca3fba3fe4fb67a3b926d0895e9cDouglas Gregor /// \brief Determine whether this declaration context is equivalent 65761481dad22ebca3fba3fe4fb67a3b926d0895e9cDouglas Gregor /// to the declaration context DC. 65861481dad22ebca3fba3fe4fb67a3b926d0895e9cDouglas Gregor bool Equals(DeclContext *DC) { 65961481dad22ebca3fba3fe4fb67a3b926d0895e9cDouglas Gregor return this->getPrimaryContext() == DC->getPrimaryContext(); 66061481dad22ebca3fba3fe4fb67a3b926d0895e9cDouglas Gregor } 6611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6626dd38daf1495367db8fe9e9a5cacb7420cf08e27Douglas Gregor /// \brief Determine whether this declaration context encloses the 6636dd38daf1495367db8fe9e9a5cacb7420cf08e27Douglas Gregor /// declaration context DC. 6646dd38daf1495367db8fe9e9a5cacb7420cf08e27Douglas Gregor bool Encloses(DeclContext *DC); 665ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis 66644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// getPrimaryContext - There may be many different 66744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// declarations of the same entity (including forward declarations 66844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// of classes, multiple definitions of namespaces, etc.), each with 66944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// a different set of declarations. This routine returns the 67044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// "primary" DeclContext structure, which will contain the 67144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// information needed to perform name lookup into this context. 6720701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff DeclContext *getPrimaryContext(); 67344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 674ce35607c282c845b3285d0f6e106489d8bbeba13Douglas Gregor /// getLookupContext - Retrieve the innermost non-transparent 675ce35607c282c845b3285d0f6e106489d8bbeba13Douglas Gregor /// context of this context, which corresponds to the innermost 676ce35607c282c845b3285d0f6e106489d8bbeba13Douglas Gregor /// location from which name lookup can find the entities in this 677ce35607c282c845b3285d0f6e106489d8bbeba13Douglas Gregor /// context. 6780cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner DeclContext *getLookupContext(); 6790cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner const DeclContext *getLookupContext() const { 6800cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner return const_cast<DeclContext *>(this)->getLookupContext(); 68117a9b9e3ee75f5dbb4819cc8ebf40eec8015f84aDouglas Gregor } 6821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 68388b7094185b9d4fe9820c731b6936d8d37f6143eDouglas Gregor /// \brief Retrieve the nearest enclosing namespace context. 68488b7094185b9d4fe9820c731b6936d8d37f6143eDouglas Gregor DeclContext *getEnclosingNamespaceContext(); 68588b7094185b9d4fe9820c731b6936d8d37f6143eDouglas Gregor const DeclContext *getEnclosingNamespaceContext() const { 68688b7094185b9d4fe9820c731b6936d8d37f6143eDouglas Gregor return const_cast<DeclContext *>(this)->getEnclosingNamespaceContext(); 68788b7094185b9d4fe9820c731b6936d8d37f6143eDouglas Gregor } 68888b7094185b9d4fe9820c731b6936d8d37f6143eDouglas Gregor 68944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// getNextContext - If this is a DeclContext that may have other 69044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// DeclContexts that are semantically connected but syntactically 69144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// different, such as C++ namespaces, this routine retrieves the 69244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// next DeclContext in the link. Iteration through the chain of 69344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// DeclContexts should begin at the primary DeclContext and 69444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// continue until this function returns NULL. For example, given: 69544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// @code 69644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// namespace N { 69744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// int x; 69844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// } 69944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// namespace N { 70044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// int y; 70144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// } 70244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// @endcode 70344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// The first occurrence of namespace N will be the primary 70444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// DeclContext. Its getNextContext will return the second 70544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// occurrence of namespace N. 70644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor DeclContext *getNextContext(); 70744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 70844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// decl_iterator - Iterates through the declarations stored 70944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// within this context. 7106037fcba3431b47de1a994c9b286feac17894effDouglas Gregor class decl_iterator { 7116037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// Current - The current declaration. 7124afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor Decl *Current; 7136037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 7146037fcba3431b47de1a994c9b286feac17894effDouglas Gregor public: 7154afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor typedef Decl* value_type; 7164afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor typedef Decl* reference; 7174afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor typedef Decl* pointer; 7186037fcba3431b47de1a994c9b286feac17894effDouglas Gregor typedef std::forward_iterator_tag iterator_category; 7196037fcba3431b47de1a994c9b286feac17894effDouglas Gregor typedef std::ptrdiff_t difference_type; 7206037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 7216037fcba3431b47de1a994c9b286feac17894effDouglas Gregor decl_iterator() : Current(0) { } 7224afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor explicit decl_iterator(Decl *C) : Current(C) { } 7236037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 7246037fcba3431b47de1a994c9b286feac17894effDouglas Gregor reference operator*() const { return Current; } 7256037fcba3431b47de1a994c9b286feac17894effDouglas Gregor pointer operator->() const { return Current; } 7266037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 72796f4468b6b1bf69bb01c1207f716a3ffaeb4a8d3Chris Lattner decl_iterator& operator++() { 728244a67d911d08c3757a18ad666e4a268cf3ee285Chris Lattner Current = Current->getNextDeclInContext(); 72996f4468b6b1bf69bb01c1207f716a3ffaeb4a8d3Chris Lattner return *this; 73096f4468b6b1bf69bb01c1207f716a3ffaeb4a8d3Chris Lattner } 7316037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 7326037fcba3431b47de1a994c9b286feac17894effDouglas Gregor decl_iterator operator++(int) { 7336037fcba3431b47de1a994c9b286feac17894effDouglas Gregor decl_iterator tmp(*this); 7346037fcba3431b47de1a994c9b286feac17894effDouglas Gregor ++(*this); 7356037fcba3431b47de1a994c9b286feac17894effDouglas Gregor return tmp; 7366037fcba3431b47de1a994c9b286feac17894effDouglas Gregor } 7376037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 7381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump friend bool operator==(decl_iterator x, decl_iterator y) { 7396037fcba3431b47de1a994c9b286feac17894effDouglas Gregor return x.Current == y.Current; 7406037fcba3431b47de1a994c9b286feac17894effDouglas Gregor } 7411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump friend bool operator!=(decl_iterator x, decl_iterator y) { 7426037fcba3431b47de1a994c9b286feac17894effDouglas Gregor return x.Current != y.Current; 7436037fcba3431b47de1a994c9b286feac17894effDouglas Gregor } 7446037fcba3431b47de1a994c9b286feac17894effDouglas Gregor }; 74544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 74644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// decls_begin/decls_end - Iterate over the declarations stored in 7471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// this context. 74817945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis decl_iterator decls_begin() const; 74917945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis decl_iterator decls_end() const; 75017945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis bool decls_empty() const; 75144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 752f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// specific_decl_iterator - Iterates over a subrange of 753f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// declarations stored in a DeclContext, providing only those that 754669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// are of type SpecificDecl (or a class derived from it). This 755f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// iterator is used, for example, to provide iteration over just 756669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// the fields within a RecordDecl (with SpecificDecl = FieldDecl). 757f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor template<typename SpecificDecl> 758f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor class specific_decl_iterator { 759f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// Current - The current, underlying declaration iterator, which 760d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// will either be NULL or will point to a declaration of 761f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// type SpecificDecl. 762f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor DeclContext::decl_iterator Current; 7631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 764f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// SkipToNextDecl - Advances the current position up to the next 765f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// declaration of type SpecificDecl that also meets the criteria 766f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// required by Acceptable. 767f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor void SkipToNextDecl() { 768669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor while (*Current && !isa<SpecificDecl>(*Current)) 769f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor ++Current; 770f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 771f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 772f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor public: 773f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor typedef SpecificDecl* value_type; 774f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor typedef SpecificDecl* reference; 775f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor typedef SpecificDecl* pointer; 776f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor typedef std::iterator_traits<DeclContext::decl_iterator>::difference_type 777f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor difference_type; 778f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor typedef std::forward_iterator_tag iterator_category; 779f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 780669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor specific_decl_iterator() : Current() { } 781f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 782f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// specific_decl_iterator - Construct a new iterator over a 783d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// subset of the declarations the range [C, 784d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// end-of-declarations). If A is non-NULL, it is a pointer to a 785d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// member function of SpecificDecl that should return true for 786d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// all of the SpecificDecl instances that will be in the subset 787d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// of iterators. For example, if you want Objective-C instance 788d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// methods, SpecificDecl will be ObjCMethodDecl and A will be 789d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// &ObjCMethodDecl::isInstanceMethod. 790669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor explicit specific_decl_iterator(DeclContext::decl_iterator C) : Current(C) { 791f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor SkipToNextDecl(); 792f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 793f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 7946037fcba3431b47de1a994c9b286feac17894effDouglas Gregor reference operator*() const { return cast<SpecificDecl>(*Current); } 7956037fcba3431b47de1a994c9b286feac17894effDouglas Gregor pointer operator->() const { return cast<SpecificDecl>(*Current); } 796f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 797f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor specific_decl_iterator& operator++() { 798f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor ++Current; 799f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor SkipToNextDecl(); 800f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor return *this; 801f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 802f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 803f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor specific_decl_iterator operator++(int) { 804f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor specific_decl_iterator tmp(*this); 805f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor ++(*this); 806f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor return tmp; 807f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 8081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 809f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor friend bool 810f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor operator==(const specific_decl_iterator& x, const specific_decl_iterator& y) { 811f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor return x.Current == y.Current; 812f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 8131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump friend bool 815f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor operator!=(const specific_decl_iterator& x, const specific_decl_iterator& y) { 816f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor return x.Current != y.Current; 817f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 818f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor }; 819f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 820669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// \brief Iterates over a filtered subrange of declarations stored 821669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// in a DeclContext. 822669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// 823669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// This iterator visits only those declarations that are of type 824669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// SpecificDecl (or a class derived from it) and that meet some 825669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// additional run-time criteria. This iterator is used, for 826669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// example, to provide access to the instance methods within an 827669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// Objective-C interface (with SpecificDecl = ObjCMethodDecl and 828669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// Acceptable = ObjCMethodDecl::isInstanceMethod). 829669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor template<typename SpecificDecl, bool (SpecificDecl::*Acceptable)() const> 830669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor class filtered_decl_iterator { 831669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// Current - The current, underlying declaration iterator, which 832669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// will either be NULL or will point to a declaration of 833669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// type SpecificDecl. 834669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor DeclContext::decl_iterator Current; 8351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 836669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// SkipToNextDecl - Advances the current position up to the next 837669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// declaration of type SpecificDecl that also meets the criteria 838669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// required by Acceptable. 839669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor void SkipToNextDecl() { 840669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor while (*Current && 841669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor (!isa<SpecificDecl>(*Current) || 842669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor (Acceptable && !(cast<SpecificDecl>(*Current)->*Acceptable)()))) 843669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor ++Current; 844669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor } 845669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 846669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor public: 847669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor typedef SpecificDecl* value_type; 848669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor typedef SpecificDecl* reference; 849669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor typedef SpecificDecl* pointer; 850669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor typedef std::iterator_traits<DeclContext::decl_iterator>::difference_type 851669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor difference_type; 852669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor typedef std::forward_iterator_tag iterator_category; 853669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 854669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor filtered_decl_iterator() : Current() { } 855669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 856669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// specific_decl_iterator - Construct a new iterator over a 857669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// subset of the declarations the range [C, 858669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// end-of-declarations). If A is non-NULL, it is a pointer to a 859669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// member function of SpecificDecl that should return true for 860669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// all of the SpecificDecl instances that will be in the subset 861669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// of iterators. For example, if you want Objective-C instance 862669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// methods, SpecificDecl will be ObjCMethodDecl and A will be 863669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// &ObjCMethodDecl::isInstanceMethod. 864669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor explicit filtered_decl_iterator(DeclContext::decl_iterator C) : Current(C) { 865669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor SkipToNextDecl(); 866669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor } 867669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 868669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor reference operator*() const { return cast<SpecificDecl>(*Current); } 869669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor pointer operator->() const { return cast<SpecificDecl>(*Current); } 870669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 871669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor filtered_decl_iterator& operator++() { 872669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor ++Current; 873669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor SkipToNextDecl(); 874669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor return *this; 875669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor } 876669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 877669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor filtered_decl_iterator operator++(int) { 878669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor filtered_decl_iterator tmp(*this); 879669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor ++(*this); 880669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor return tmp; 881669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor } 8821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 883669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor friend bool 884669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor operator==(const filtered_decl_iterator& x, const filtered_decl_iterator& y) { 885669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor return x.Current == y.Current; 886669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor } 8871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump friend bool 889669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor operator!=(const filtered_decl_iterator& x, const filtered_decl_iterator& y) { 890669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor return x.Current != y.Current; 891669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor } 892669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor }; 893669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 89440f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// @brief Add the declaration D into this context. 89540f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// 89640f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// This routine should be invoked when the declaration D has first 89740f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// been declared, to place D into the context where it was 89840f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// (lexically) defined. Every declaration must be added to one 89940f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// (and only one!) context, where it can be visited via 90040f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// [decls_begin(), decls_end()). Once a declaration has been added 90140f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// to its lexical context, the corresponding DeclContext owns the 90240f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// declaration. 90340f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// 90440f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// If D is also a NamedDecl, it will be made visible within its 90540f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// semantic context via makeDeclVisibleInContext. 90617945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis void addDecl(Decl *D); 90744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 9083f9a8a60614b763785d54ad08821745d03a4af70John McCall /// @brief Add the declaration D to this context without modifying 9093f9a8a60614b763785d54ad08821745d03a4af70John McCall /// any lookup tables. 9103f9a8a60614b763785d54ad08821745d03a4af70John McCall /// 9113f9a8a60614b763785d54ad08821745d03a4af70John McCall /// This is useful for some operations in dependent contexts where 9123f9a8a60614b763785d54ad08821745d03a4af70John McCall /// the semantic context might not be dependent; this basically 9133f9a8a60614b763785d54ad08821745d03a4af70John McCall /// only happens with friends. 9143f9a8a60614b763785d54ad08821745d03a4af70John McCall void addHiddenDecl(Decl *D); 9153f9a8a60614b763785d54ad08821745d03a4af70John McCall 91644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// lookup_iterator - An iterator that provides access to the results 91744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// of looking up a name within this context. 9184afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor typedef NamedDecl **lookup_iterator; 91944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 92044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// lookup_const_iterator - An iterator that provides non-mutable 92144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// access to the results of lookup up a name within this context. 9224afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor typedef NamedDecl * const * lookup_const_iterator; 92344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 92444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor typedef std::pair<lookup_iterator, lookup_iterator> lookup_result; 92544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor typedef std::pair<lookup_const_iterator, lookup_const_iterator> 92644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor lookup_const_result; 92744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 92844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// lookup - Find the declarations (if any) with the given Name in 92944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// this context. Returns a range of iterators that contains all of 93040f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// the declarations with this name, with object, function, member, 93140f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// and enumerator names preceding any tag name. Note that this 93240f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// routine will not look into parent contexts. 93317945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis lookup_result lookup(DeclarationName Name); 93417945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis lookup_const_result lookup(DeclarationName Name) const; 93544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 93640f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// @brief Makes a declaration visible within this context. 93740f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// 93840f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// This routine makes the declaration D visible to name lookup 93940f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// within this context and, if this is a transparent context, 94040f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// within its parent contexts up to the first enclosing 94140f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// non-transparent context. Making a declaration visible within a 94240f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// context does not transfer ownership of a declaration, and a 94340f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// declaration can be visible in many contexts that aren't its 94440f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// lexical context. 94540f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// 94640f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// If D is a redeclaration of an existing declaration that is 94740f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// visible from this context, as determined by 94840f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// NamedDecl::declarationReplaces, the previous declaration will be 94940f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// replaced with D. 950ab88d97734f1260402a0c6a8f6b77bed7ed4e295John McCall /// 951ab88d97734f1260402a0c6a8f6b77bed7ed4e295John McCall /// @param Recoverable true if it's okay to not add this decl to 952ab88d97734f1260402a0c6a8f6b77bed7ed4e295John McCall /// the lookup tables because it can be easily recovered by walking 953ab88d97734f1260402a0c6a8f6b77bed7ed4e295John McCall /// the declaration chains. 954ab88d97734f1260402a0c6a8f6b77bed7ed4e295John McCall void makeDeclVisibleInContext(NamedDecl *D, bool Recoverable = true); 9557643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidis 9562a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor /// udir_iterator - Iterates through the using-directives stored 9572a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor /// within this context. 9582a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor typedef UsingDirectiveDecl * const * udir_iterator; 9591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9602a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor typedef std::pair<udir_iterator, udir_iterator> udir_iterator_range; 9612a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor 96217945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis udir_iterator_range getUsingDirectives() const; 9632a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor 96417945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis udir_iterator using_directives_begin() const { 96517945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis return getUsingDirectives().first; 9662a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor } 9672a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor 96817945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis udir_iterator using_directives_end() const { 96917945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis return getUsingDirectives().second; 9702a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor } 9712a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor 972c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor // Low-level accessors 973c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor 974c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor /// \brief Retrieve the internal representation of the lookup structure. 975c36c540c5bfce941f3d892919394d092491211f2Douglas Gregor void* getLookupPtr() const { return LookupPtr; } 976c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor 9772cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// \brief Whether this DeclContext has external storage containing 9782cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// additional declarations that are lexically in this context. 9792cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor bool hasExternalLexicalStorage() const { return ExternalLexicalStorage; } 9802cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 9812cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// \brief State whether this DeclContext has external storage for 9822cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// declarations lexically in this context. 9831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setHasExternalLexicalStorage(bool ES = true) { 9841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ExternalLexicalStorage = ES; 9852cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor } 9862cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 9872cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// \brief Whether this DeclContext has external storage containing 9882cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// additional declarations that are visible in this context. 9892cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor bool hasExternalVisibleStorage() const { return ExternalVisibleStorage; } 9902cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 9912cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// \brief State whether this DeclContext has external storage for 9922cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// declarations visible in this context. 9931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setHasExternalVisibleStorage(bool ES = true) { 9941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ExternalVisibleStorage = ES; 9952cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor } 9962cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 9973d7641e090cf113dec64306a1597d3e4523e2a55Argyrios Kyrtzidis static bool classof(const Decl *D); 998b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner static bool classof(const DeclContext *D) { return true; } 99964650af7cc4352c6c67b9bd1bf8ef3ce7471b910Douglas Gregor#define DECL_CONTEXT(Name) \ 100064650af7cc4352c6c67b9bd1bf8ef3ce7471b910Douglas Gregor static bool classof(const Name##Decl *D) { return true; } 100164650af7cc4352c6c67b9bd1bf8ef3ce7471b910Douglas Gregor#include "clang/AST/DeclNodes.def" 10027643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidis 10037643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidisprivate: 100417945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis void LoadLexicalDeclsFromExternalStorage() const; 100517945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis void LoadVisibleDeclsFromExternalStorage() const; 10062cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 100717945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis void buildLookup(DeclContext *DCtx); 100817945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis void makeDeclVisibleInContextImpl(NamedDecl *D); 10090ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner}; 10100ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 1011f57172b24f08a68d179675989813d5479dc87829Douglas Gregorinline bool Decl::isTemplateParameter() const { 1012f57172b24f08a68d179675989813d5479dc87829Douglas Gregor return getKind() == TemplateTypeParm || getKind() == NonTypeTemplateParm; 1013f57172b24f08a68d179675989813d5479dc87829Douglas Gregor} 1014f57172b24f08a68d179675989813d5479dc87829Douglas Gregor 10154afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorinline bool Decl::isDefinedOutsideFunctionOrMethod() const { 10164afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor if (getDeclContext()) 10174afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return !getDeclContext()->getLookupContext()->isFunctionOrMethod(); 101896f4468b6b1bf69bb01c1207f716a3ffaeb4a8d3Chris Lattner return true; 10194afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor} 10204afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 10210ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner} // end clang. 10220ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 10230ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnernamespace llvm { 10240ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 102542220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis/// Implement a isa_impl_wrap specialization to check whether a DeclContext is 102642220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis/// a specific Decl. 102742220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidistemplate<class ToTy> 102842220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisstruct isa_impl_wrap<ToTy, 102942220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis const ::clang::DeclContext,const ::clang::DeclContext> { 103042220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis static bool doit(const ::clang::DeclContext &Val) { 103142220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis return ToTy::classof(::clang::Decl::castFromDeclContext(&Val)); 10320ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 10330ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner}; 103442220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidistemplate<class ToTy> 103542220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisstruct isa_impl_wrap<ToTy, ::clang::DeclContext, ::clang::DeclContext> 103642220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis : public isa_impl_wrap<ToTy, 103742220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis const ::clang::DeclContext,const ::clang::DeclContext> {}; 10380ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 103942220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis/// Implement cast_convert_val for Decl -> DeclContext conversions. 10400ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnertemplate<class FromTy> 104142220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisstruct cast_convert_val< ::clang::DeclContext, FromTy, FromTy> { 1042b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner static ::clang::DeclContext &doit(const FromTy &Val) { 104342220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis return *FromTy::castToDeclContext(&Val); 10440ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 10450ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner}; 10460ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 10470ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnertemplate<class FromTy> 104842220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisstruct cast_convert_val< ::clang::DeclContext, FromTy*, FromTy*> { 1049b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner static ::clang::DeclContext *doit(const FromTy *Val) { 105042220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis return FromTy::castToDeclContext(Val); 10510ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 10520ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner}; 105342220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis 105444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregortemplate<class FromTy> 105544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregorstruct cast_convert_val< const ::clang::DeclContext, FromTy, FromTy> { 105644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor static const ::clang::DeclContext &doit(const FromTy &Val) { 105744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor return *FromTy::castToDeclContext(&Val); 105844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor } 105944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor}; 106044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 106144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregortemplate<class FromTy> 106244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregorstruct cast_convert_val< const ::clang::DeclContext, FromTy*, FromTy*> { 106344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor static const ::clang::DeclContext *doit(const FromTy *Val) { 106444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor return FromTy::castToDeclContext(Val); 106544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor } 106644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor}; 106744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 106842220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis/// Implement cast_convert_val for DeclContext -> Decl conversions. 106942220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidistemplate<class ToTy> 107042220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisstruct cast_convert_val<ToTy, 107142220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis const ::clang::DeclContext,const ::clang::DeclContext> { 107242220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis static ToTy &doit(const ::clang::DeclContext &Val) { 107342220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis return *reinterpret_cast<ToTy*>(ToTy::castFromDeclContext(&Val)); 107442220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis } 107542220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis}; 107642220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidistemplate<class ToTy> 107742220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisstruct cast_convert_val<ToTy, ::clang::DeclContext, ::clang::DeclContext> 107842220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis : public cast_convert_val<ToTy, 107942220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis const ::clang::DeclContext,const ::clang::DeclContext> {}; 108042220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis 108142220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidistemplate<class ToTy> 108242220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisstruct cast_convert_val<ToTy, 108342220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis const ::clang::DeclContext*, const ::clang::DeclContext*> { 108442220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis static ToTy *doit(const ::clang::DeclContext *Val) { 108542220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis return reinterpret_cast<ToTy*>(ToTy::castFromDeclContext(Val)); 108642220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis } 108742220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis}; 108842220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidistemplate<class ToTy> 108942220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisstruct cast_convert_val<ToTy, ::clang::DeclContext*, ::clang::DeclContext*> 109042220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis : public cast_convert_val<ToTy, 109142220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis const ::clang::DeclContext*,const ::clang::DeclContext*> {}; 10920ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 10930ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner} // end namespace llvm 10940ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 10950ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner#endif 1096