DeclBase.h revision eaab20669b6a9910a5deb0110fdd8f7581d86a36
10ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner//===-- 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" 220ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 230ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnernamespace clang { 2442220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisclass DeclContext; 25ef177820100ab583b08fd3056e2a5a52ee4b1629Argyrios Kyrtzidisclass TranslationUnitDecl; 262d1c5d313cd0c229cc614e74baa4c5756a4b46f4Argyrios Kyrtzidisclass NamespaceDecl; 272a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregorclass UsingDirectiveDecl; 2844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregorclass NamedDecl; 290ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnerclass FunctionDecl; 30d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidisclass CXXRecordDecl; 31b048c9835969c4f7fe06264748be18ed4b442116Chris Lattnerclass EnumDecl; 32d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidisclass ObjCMethodDecl; 3364650af7cc4352c6c67b9bd1bf8ef3ce7471b910Douglas Gregorclass ObjCContainerDecl; 340ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnerclass ObjCInterfaceDecl; 350701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroffclass ObjCCategoryDecl; 360701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroffclass ObjCProtocolDecl; 370701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroffclass ObjCImplementationDecl; 380701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroffclass ObjCCategoryImplDecl; 39074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregorclass LinkageSpecDecl; 4056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroffclass BlockDecl; 4144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregorclass DeclarationName; 42eaab20669b6a9910a5deb0110fdd8f7581d86a36Ted Kremenekclass CompoundStmt; 430ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 440ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner/// Decl - This represents one declaration (or definition), e.g. a variable, 450ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner/// typedef, function, struct, etc. 460ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner/// 470ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnerclass Decl { 480ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnerpublic: 4964650af7cc4352c6c67b9bd1bf8ef3ce7471b910Douglas Gregor /// \brief Lists the kind of concrete classes of Decl. 500ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner enum Kind { 5164650af7cc4352c6c67b9bd1bf8ef3ce7471b910Douglas Gregor#define DECL(Derived, Base) Derived, 5264650af7cc4352c6c67b9bd1bf8ef3ce7471b910Douglas Gregor#define DECL_RANGE(CommonBase, Start, End) \ 5364650af7cc4352c6c67b9bd1bf8ef3ce7471b910Douglas Gregor CommonBase##First = Start, CommonBase##Last = End, 5464650af7cc4352c6c67b9bd1bf8ef3ce7471b910Douglas Gregor#define LAST_DECL_RANGE(CommonBase, Start, End) \ 5564650af7cc4352c6c67b9bd1bf8ef3ce7471b910Douglas Gregor CommonBase##First = Start, CommonBase##Last = End 5664650af7cc4352c6c67b9bd1bf8ef3ce7471b910Douglas Gregor#include "clang/AST/DeclNodes.def" 570ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner }; 580ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 590ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// IdentifierNamespace - According to C99 6.2.3, there are four namespaces, 602ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor /// labels, tags, members and ordinary identifiers. These are meant 612ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor /// as bitmasks, so that searches in C++ can look into the "tag" namespace 622ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor /// during ordinary lookup. 630ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner enum IdentifierNamespace { 642ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor IDNS_Label = 0x1, 652ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor IDNS_Tag = 0x2, 662ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor IDNS_Member = 0x4, 677dda67d8decef1b3621a151488c4b83bd8372d6aDouglas Gregor IDNS_Ordinary = 0x8, 687dda67d8decef1b3621a151488c4b83bd8372d6aDouglas Gregor IDNS_Protocol = 0x10 690ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner }; 700ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 710ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// ObjCDeclQualifier - Qualifier used on types in method declarations 720ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// for remote messaging. They are meant for the arguments though and 730ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// applied to the Decls (ObjCMethodDecl and ParmVarDecl). 740ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner enum ObjCDeclQualifier { 750ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_None = 0x0, 760ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_In = 0x1, 770ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_Inout = 0x2, 780ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_Out = 0x4, 790ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_Bycopy = 0x8, 800ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_Byref = 0x10, 810ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_Oneway = 0x20 820ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner }; 830ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 840ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnerprivate: 854afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// NextDeclarator - If this decl was part of a multi-declarator declaration, 864afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// such as "int X, Y, *Z;" this indicates Decl for the next declarator. 874afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor Decl *NextDeclarator; 884afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 894afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// NextDeclInScope - The next declaration within the same lexical 904afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// DeclContext. These pointers form the linked list that is 914afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// traversed via DeclContext's decls_begin()/decls_end(). 924afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// FIXME: If NextDeclarator is non-NULL, will it always be the same 934afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// as NextDeclInScope? If so, we can use a 944afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// PointerIntPair<Decl*, 1> to make Decl smaller. 954afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor Decl *NextDeclInScope; 964afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 974afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor friend class DeclContext; 984afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 994afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// DeclCtx - Holds either a DeclContext* or a MultipleDC*. 1004afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// For declarations that don't contain C++ scope specifiers, it contains 1014afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// the DeclContext where the Decl was declared. 1024afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// For declarations with C++ scope specifiers, it contains a MultipleDC* 1034afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// with the context where it semantically belongs (SemanticDC) and the 1044afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// context where it was lexically declared (LexicalDC). 1054afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// e.g.: 1064afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// 1074afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// namespace A { 1084afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// void f(); // SemanticDC == LexicalDC == 'namespace A' 1094afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// } 1104afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// void A::f(); // SemanticDC == namespace 'A' 1114afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// // LexicalDC == global namespace 1124afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor uintptr_t DeclCtx; 1134afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 1144afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor struct MultipleDC { 1154afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor DeclContext *SemanticDC; 1164afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor DeclContext *LexicalDC; 1174afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor }; 1184afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 1194afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor inline bool isInSemaDC() const { return (DeclCtx & 0x1) == 0; } 1204afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor inline bool isOutOfSemaDC() const { return (DeclCtx & 0x1) != 0; } 1214afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor inline MultipleDC *getMultipleDC() const { 1224afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return reinterpret_cast<MultipleDC*>(DeclCtx & ~0x1); 1234afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 1244afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 12539d7650656fdd1be879ed7d0c722cfeae95e56d5Daniel Dunbar /// Loc - The location that this decl. 12639d7650656fdd1be879ed7d0c722cfeae95e56d5Daniel Dunbar SourceLocation Loc; 12739d7650656fdd1be879ed7d0c722cfeae95e56d5Daniel Dunbar 1280ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// DeclKind - This indicates which class this is. 1290ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner Kind DeclKind : 8; 1300ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 1310ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// InvalidDecl - This indicates a semantic error occurred. 1320ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner unsigned int InvalidDecl : 1; 1330ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 1340ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// HasAttrs - This indicates whether the decl has attributes or not. 1350ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner unsigned int HasAttrs : 1; 136d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis 1376b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor /// Implicit - Whether this declaration was implicitly generated by 1386b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor /// the implementation rather than explicitly written by the user. 1396b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor bool Implicit : 1; 1406b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor 1414afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorprotected: 142d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis /// Access - Used by C++ decls for the access specifier. 143d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis // NOTE: VC++ treats enums as signed, avoid using the AccessSpecifier enum 144d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis unsigned Access : 2; 145d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis friend class CXXClassMemberWrapper; 146d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis 1474afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor Decl(Kind DK, DeclContext *DC, SourceLocation L) 14839d7650656fdd1be879ed7d0c722cfeae95e56d5Daniel Dunbar : NextDeclarator(0), NextDeclInScope(0), 14939d7650656fdd1be879ed7d0c722cfeae95e56d5Daniel Dunbar DeclCtx(reinterpret_cast<uintptr_t>(DC)), 15039d7650656fdd1be879ed7d0c722cfeae95e56d5Daniel Dunbar Loc(L), DeclKind(DK), InvalidDecl(0), 1514afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor HasAttrs(false), Implicit(false) { 1520ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner if (Decl::CollectingStats()) addDeclKind(DK); 1530ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 1541bb19638f2ec0d63ed131b51ca8d9542d1a9afeeSam Bishop 1550ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner virtual ~Decl(); 1561bb19638f2ec0d63ed131b51ca8d9542d1a9afeeSam Bishop 1574afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// setDeclContext - Set both the semantic and lexical DeclContext 1584afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// to DC. 1594afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor void setDeclContext(DeclContext *DC); 1604afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 1611bb19638f2ec0d63ed131b51ca8d9542d1a9afeeSam Bishoppublic: 1620ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner SourceLocation getLocation() const { return Loc; } 1630ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner void setLocation(SourceLocation L) { Loc = L; } 1640ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 1650ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner Kind getKind() const { return DeclKind; } 1660ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner const char *getDeclKindName() const; 1670ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 1684afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor const DeclContext *getDeclContext() const { 1694afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor if (isInSemaDC()) 1704afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return reinterpret_cast<DeclContext*>(DeclCtx); 1714afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return getMultipleDC()->SemanticDC; 1724afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 1734afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor DeclContext *getDeclContext() { 1744afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return const_cast<DeclContext*>( 1754afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor const_cast<const Decl*>(this)->getDeclContext()); 1764afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 1774afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 1784afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor void setAccess(AccessSpecifier AS) { Access = AS; } 1794afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor AccessSpecifier getAccess() const { return AccessSpecifier(Access); } 1804afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 18176a642ff4fce7a0648c79a1f01324a8c3880e251Chris Lattner bool hasAttrs() const { return HasAttrs; } 1820ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner void addAttr(Attr *attr); 1830ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner const Attr *getAttrs() const; 184a212c56e9b7533bcc2d6be90efd52ad241bf894eChris Lattner void swapAttrs(Decl *D); 1859141bee299a05349924a34a7153d7064c9e0a107Nuno Lopes void invalidateAttrs(); 1860ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 1870ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner template<typename T> const T *getAttr() const { 1880ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner for (const Attr *attr = getAttrs(); attr; attr = attr->getNext()) 1890ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner if (const T *V = dyn_cast<T>(attr)) 1900ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner return V; 1910ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 1920ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner return 0; 1930ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 1940ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 1950ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// setInvalidDecl - Indicates the Decl had a semantic error. This 1960ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// allows for graceful error recovery. 1970ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner void setInvalidDecl() { InvalidDecl = 1; } 1980ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner bool isInvalidDecl() const { return (bool) InvalidDecl; } 1996b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor 2006b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor /// isImplicit - Indicates whether the declaration was implicitly 2016b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor /// generated by the implementation. If false, this declaration 2026b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor /// was written explicitly in the source code. 2036b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor bool isImplicit() const { return Implicit; } 2046b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor void setImplicit(bool I = true) { Implicit = I; } 2050ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 206cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor unsigned getIdentifierNamespace() const { 2070ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner switch (DeclKind) { 2089d35097bc0fefb2f77638be513cac72d1c09d840Douglas Gregor default: 2099d35097bc0fefb2f77638be513cac72d1c09d840Douglas Gregor if (DeclKind >= FunctionFirst && DeclKind <= FunctionLast) 2109d35097bc0fefb2f77638be513cac72d1c09d840Douglas Gregor return IDNS_Ordinary; 2119d35097bc0fefb2f77638be513cac72d1c09d840Douglas Gregor assert(0 && "Unknown decl kind!"); 2123fd56d755aa74f01fbe963195c95c963ea1fee91Douglas Gregor case OverloadedFunction: 2130ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner case Typedef: 2143fd56d755aa74f01fbe963195c95c963ea1fee91Douglas Gregor case EnumConstant: 215248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff case Var: 2163fd56d755aa74f01fbe963195c95c963ea1fee91Douglas Gregor case ImplicitParam: 2170ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner case ParmVar: 21873da9e462576faedc2cdf96b37a1c072b404b73dFariborz Jahanian case OriginalParmVar: 21972c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor case NonTypeTemplateParm: 2203fd56d755aa74f01fbe963195c95c963ea1fee91Douglas Gregor case ObjCMethod: 2213fd56d755aa74f01fbe963195c95c963ea1fee91Douglas Gregor case ObjCContainer: 2223fd56d755aa74f01fbe963195c95c963ea1fee91Douglas Gregor case ObjCCategory: 2230ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner case ObjCInterface: 2243fd56d755aa74f01fbe963195c95c963ea1fee91Douglas Gregor case ObjCCategoryImpl: 2253fd56d755aa74f01fbe963195c95c963ea1fee91Douglas Gregor case ObjCProperty: 2260ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner case ObjCCompatibleAlias: 2270ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner return IDNS_Ordinary; 22872de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor 2297dda67d8decef1b3621a151488c4b83bd8372d6aDouglas Gregor case ObjCProtocol: 2307dda67d8decef1b3621a151488c4b83bd8372d6aDouglas Gregor return IDNS_Protocol; 2317dda67d8decef1b3621a151488c4b83bd8372d6aDouglas Gregor 23272de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor case Field: 23372de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor case ObjCAtDefsField: 23472de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor case ObjCIvar: 23572de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor return IDNS_Member; 23672de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor 23735bc0821c4f80041724cd4c5c4889b2581546a41Argyrios Kyrtzidis case Record: 23835bc0821c4f80041724cd4c5c4889b2581546a41Argyrios Kyrtzidis case CXXRecord: 2390ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner case Enum: 240efe38bdea21953f89c1504cfd1c63bee5f15b1b6Douglas Gregor case TemplateTypeParm: 2410ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner return IDNS_Tag; 2423fd56d755aa74f01fbe963195c95c963ea1fee91Douglas Gregor 2432d1c5d313cd0c229cc614e74baa4c5756a4b46f4Argyrios Kyrtzidis case Namespace: 244aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor case Template: 245aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor case FunctionTemplate: 246aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor case ClassTemplate: 247aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor case TemplateTemplateParm: 248cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor return IDNS_Tag | IDNS_Ordinary; 249cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor 250cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor case ClassTemplateSpecialization: 251cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor return 0; 2520ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 2530ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 254792481eec23d8c1aa92173be589e2ae9d02514a5Ted Kremenek 255d62fdc448b3ace606c8c9c9f13e43218fa204dbfChris Lattner bool isInIdentifierNamespace(unsigned NS) const { 256d62fdc448b3ace606c8c9c9f13e43218fa204dbfChris Lattner return getIdentifierNamespace() & NS; 257d62fdc448b3ace606c8c9c9f13e43218fa204dbfChris Lattner } 258d62fdc448b3ace606c8c9c9f13e43218fa204dbfChris Lattner 2594afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// getLexicalDeclContext - The declaration context where this Decl was 2604afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// lexically declared (LexicalDC). May be different from 2614afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// getDeclContext() (SemanticDC). 2624afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// e.g.: 2634afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// 2644afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// namespace A { 2654afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// void f(); // SemanticDC == LexicalDC == 'namespace A' 2664afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// } 2674afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// void A::f(); // SemanticDC == namespace 'A' 2684afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// // LexicalDC == global namespace 2694afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor const DeclContext *getLexicalDeclContext() const { 2704afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor if (isInSemaDC()) 2714afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return reinterpret_cast<DeclContext*>(DeclCtx); 2724afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return getMultipleDC()->LexicalDC; 2734afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 2744afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor DeclContext *getLexicalDeclContext() { 2754afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return const_cast<DeclContext*>( 2764afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor const_cast<const Decl*>(this)->getLexicalDeclContext()); 2774afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 2784afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 2794afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor void setLexicalDeclContext(DeclContext *DC); 2804afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 2814afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// getNextDeclarator - If this decl was part of a multi-declarator 2824afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// declaration, such as "int X, Y, *Z;" this returns the decl for the next 2834afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// declarator. Otherwise it returns null. 2844afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor Decl *getNextDeclarator() { return NextDeclarator; } 2854afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor const Decl *getNextDeclarator() const { return NextDeclarator; } 2864afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor void setNextDeclarator(Decl *N) { NextDeclarator = N; } 2874afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 2884afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor // isDefinedOutsideFunctionOrMethod - This predicate returns true if this 2894afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor // scoped decl is defined outside the current function or method. This is 2904afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor // roughly global variables and functions, but also handles enums (which could 2914afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor // be defined inside or outside a function etc). 2924afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor bool isDefinedOutsideFunctionOrMethod() const; 2934afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 29469c8f0aab655257e9e532d9d53756acf4f7a2d78Ted Kremenek // getBody - If this Decl represents a declaration for a body of code, 295792481eec23d8c1aa92173be589e2ae9d02514a5Ted Kremenek // such as a function or method definition, this method returns the top-level 29669c8f0aab655257e9e532d9d53756acf4f7a2d78Ted Kremenek // Stmt* of that body. Otherwise this method returns null. 297eaab20669b6a9910a5deb0110fdd8f7581d86a36Ted Kremenek virtual CompoundStmt* getBody() const { return 0; } 298792481eec23d8c1aa92173be589e2ae9d02514a5Ted Kremenek 2990ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner // global temp stats (until we have a per-module visitor) 3000ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner static void addDeclKind(Kind k); 3010ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner static bool CollectingStats(bool Enable = false); 3020ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner static void PrintStats(); 3030ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 304f57172b24f08a68d179675989813d5479dc87829Douglas Gregor /// isTemplateParameter - Determines whether this declartion is a 305f57172b24f08a68d179675989813d5479dc87829Douglas Gregor /// template parameter. 306f57172b24f08a68d179675989813d5479dc87829Douglas Gregor bool isTemplateParameter() const; 307f57172b24f08a68d179675989813d5479dc87829Douglas Gregor 3080ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner // Implement isa/cast/dyncast/etc. 3090ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner static bool classof(const Decl *) { return true; } 31042220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis static DeclContext *castToDeclContext(const Decl *); 31142220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis static Decl *castFromDeclContext(const DeclContext *); 3120ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 3130ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// Emit - Serialize this Decl to Bitcode. 3140ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner void Emit(llvm::Serializer& S) const; 3150ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 3160ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// Create - Deserialize a Decl from Bitcode. 317e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static Decl* Create(llvm::Deserializer& D, ASTContext& C); 3180ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 319bb45c512e0dfbe96bfe377ac642e726c0ba0affaSam Bishop /// Destroy - Call destructors and release memory. 32027f8a28bee33bb0e857cfe1a61c281bbc234b338Ted Kremenek virtual void Destroy(ASTContext& C); 321bb45c512e0dfbe96bfe377ac642e726c0ba0affaSam Bishop 3220ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnerprotected: 3230ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// EmitImpl - Provides the subclass-specific serialization logic for 3240ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// serializing out a decl. 3250ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner virtual void EmitImpl(llvm::Serializer& S) const { 3260ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner // FIXME: This will eventually be a pure virtual function. 3270ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner assert (false && "Not implemented."); 3280ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 3290ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner}; 3300ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 33149f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner/// PrettyStackTraceDecl - If a crash occurs, indicate that it happened when 33249f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner/// doing something to a specific decl. 33349f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattnerclass PrettyStackTraceDecl : public llvm::PrettyStackTraceEntry { 33449f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner Decl *TheDecl; 33549f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner SourceLocation Loc; 33649f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner SourceManager &SM; 33749f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner const char *Message; 33849f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattnerpublic: 33949f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner PrettyStackTraceDecl(Decl *theDecl, SourceLocation L, 34049f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner SourceManager &sm, const char *Msg) 34149f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner : TheDecl(theDecl), Loc(L), SM(sm), Message(Msg) {} 34249f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner 34349f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner virtual void print(llvm::raw_ostream &OS) const; 34449f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner}; 34549f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner 34649f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner 347b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner/// DeclContext - This is used only as base class of specific decl types that 3481ad4dd78ec53c24ea9e752b216035d7aa666fe49Argyrios Kyrtzidis/// can act as declaration contexts. These decls are (only the top classes 3491ad4dd78ec53c24ea9e752b216035d7aa666fe49Argyrios Kyrtzidis/// that directly derive from DeclContext are mentioned, not their subclasses): 3500ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner/// 351ef177820100ab583b08fd3056e2a5a52ee4b1629Argyrios Kyrtzidis/// TranslationUnitDecl 3522d1c5d313cd0c229cc614e74baa4c5756a4b46f4Argyrios Kyrtzidis/// NamespaceDecl 3530ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner/// FunctionDecl 3541ad4dd78ec53c24ea9e752b216035d7aa666fe49Argyrios Kyrtzidis/// TagDecl 355d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis/// ObjCMethodDecl 3561ad4dd78ec53c24ea9e752b216035d7aa666fe49Argyrios Kyrtzidis/// ObjCContainerDecl 3571ad4dd78ec53c24ea9e752b216035d7aa666fe49Argyrios Kyrtzidis/// ObjCCategoryImplDecl 3581ad4dd78ec53c24ea9e752b216035d7aa666fe49Argyrios Kyrtzidis/// ObjCImplementationDecl 359074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor/// LinkageSpecDecl 36056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff/// BlockDecl 3611ad4dd78ec53c24ea9e752b216035d7aa666fe49Argyrios Kyrtzidis/// 362b048c9835969c4f7fe06264748be18ed4b442116Chris Lattnerclass DeclContext { 3630ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// DeclKind - This indicates which class this is. 3640ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner Decl::Kind DeclKind : 8; 3650ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 36644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// LookupPtrKind - Describes what kind of pointer LookupPtr 36744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// actually is. 36844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor enum LookupPtrKind { 3693fc749d899dfc194162128c1a88933148a39b68dDouglas Gregor /// LookupIsMap - Indicates that LookupPtr is actually a map. 37044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor LookupIsMap = 7 37144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor }; 37244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 37344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// LookupPtr - Pointer to a data structure used to lookup 37444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// declarations within this context. If the context contains fewer 37544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// than seven declarations, the number of declarations is provided 37644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// in the 3 lowest-order bits and the upper bits are treated as a 3774afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// pointer to an array of NamedDecl pointers. If the context 37844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// contains seven or more declarations, the upper bits are treated 3794afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// as a pointer to a DenseMap<DeclarationName, std::vector<NamedDecl*>>. 3803fc749d899dfc194162128c1a88933148a39b68dDouglas Gregor /// FIXME: We need a better data structure for this. 38144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor llvm::PointerIntPair<void*, 3> LookupPtr; 38244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 3836037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// FirstDecl - The first declaration stored within this declaration 3846037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// context. 3854afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor Decl *FirstDecl; 3866037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 3876037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// LastDecl - The last declaration stored within this declaration 3886037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// context. FIXME: We could probably cache this value somewhere 3896037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// outside of the DeclContext, to reduce the size of DeclContext by 3906037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// another pointer. 3914afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor Decl *LastDecl; 3927643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidis 39344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// isLookupMap - Determine if the lookup structure is a 39444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// DenseMap. Othewise, it is an array. 39544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor bool isLookupMap() const { return LookupPtr.getInt() == LookupIsMap; } 39644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 3970cba85577ae613bce5768f3089003629a46b0e7fDouglas Gregor static Decl *getNextDeclInScope(Decl *D) { return D->NextDeclInScope; } 3980cba85577ae613bce5768f3089003629a46b0e7fDouglas Gregor 3990ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnerprotected: 4006037fcba3431b47de1a994c9b286feac17894effDouglas Gregor DeclContext(Decl::Kind K) 4016037fcba3431b47de1a994c9b286feac17894effDouglas Gregor : DeclKind(K), LookupPtr(), FirstDecl(0), LastDecl(0) { } 40244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 40344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor void DestroyDecls(ASTContext &C); 4040ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 4050ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnerpublic: 40644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor ~DeclContext(); 40744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 4089b9ca01ff3136a7539dc08a4c4e1a3dd8c8d3a7dArgyrios Kyrtzidis Decl::Kind getDeclKind() const { 4099b9ca01ff3136a7539dc08a4c4e1a3dd8c8d3a7dArgyrios Kyrtzidis return DeclKind; 4109b9ca01ff3136a7539dc08a4c4e1a3dd8c8d3a7dArgyrios Kyrtzidis } 4110a4739305a984ef9b821cedad5f4fe235eb6ef7dSteve Naroff const char *getDeclKindName() const; 4129b9ca01ff3136a7539dc08a4c4e1a3dd8c8d3a7dArgyrios Kyrtzidis 413305ec42f971a2b3e114eb35256c23e955c497a1cArgyrios Kyrtzidis /// getParent - Returns the containing DeclContext. 414305ec42f971a2b3e114eb35256c23e955c497a1cArgyrios Kyrtzidis const DeclContext *getParent() const { 415305ec42f971a2b3e114eb35256c23e955c497a1cArgyrios Kyrtzidis return cast<Decl>(this)->getDeclContext(); 416305ec42f971a2b3e114eb35256c23e955c497a1cArgyrios Kyrtzidis } 41720bc6762282d192bd19be03094d4f311710e020cArgyrios Kyrtzidis DeclContext *getParent() { 41820bc6762282d192bd19be03094d4f311710e020cArgyrios Kyrtzidis return const_cast<DeclContext*>( 41920bc6762282d192bd19be03094d4f311710e020cArgyrios Kyrtzidis const_cast<const DeclContext*>(this)->getParent()); 420d2595ecce5f8350e485c83bfe767549a522b2802Argyrios Kyrtzidis } 4210ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 42277407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis /// getLexicalParent - Returns the containing lexical DeclContext. May be 42344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// different from getParent, e.g.: 42444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// 42544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// namespace A { 42644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// struct S; 42744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// } 42844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// struct A::S {}; // getParent() == namespace 'A' 42977407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis /// // getLexicalParent() == translation unit 43077407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis /// 431305ec42f971a2b3e114eb35256c23e955c497a1cArgyrios Kyrtzidis const DeclContext *getLexicalParent() const { 432305ec42f971a2b3e114eb35256c23e955c497a1cArgyrios Kyrtzidis return cast<Decl>(this)->getLexicalDeclContext(); 433305ec42f971a2b3e114eb35256c23e955c497a1cArgyrios Kyrtzidis } 43477407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis DeclContext *getLexicalParent() { 43577407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis return const_cast<DeclContext*>( 43677407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis const_cast<const DeclContext*>(this)->getLexicalParent()); 43777407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis } 43877407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis 4390ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner bool isFunctionOrMethod() const { 4400ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner switch (DeclKind) { 44156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff case Decl::Block: 4420ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner case Decl::ObjCMethod: 4430ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner return true; 44444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 4450ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner default: 44644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor if (DeclKind >= Decl::FunctionFirst && DeclKind <= Decl::FunctionLast) 44744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor return true; 4480ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner return false; 4490ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 4500ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 4510ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 452ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis bool isFileContext() const { 453ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis return DeclKind == Decl::TranslationUnit || DeclKind == Decl::Namespace; 454ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis } 455ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis 4565f2bfd4811996abb783aa6c7254c56baa6930e8cDouglas Gregor bool isTranslationUnit() const { 4575f2bfd4811996abb783aa6c7254c56baa6930e8cDouglas Gregor return DeclKind == Decl::TranslationUnit; 4585f2bfd4811996abb783aa6c7254c56baa6930e8cDouglas Gregor } 4595f2bfd4811996abb783aa6c7254c56baa6930e8cDouglas Gregor 460bcbffc46f1ad3796c4582fa1e3a9113b5aa26061Douglas Gregor bool isRecord() const { 46165100792a69a16895bd80f1d639b99e7ad903386Douglas Gregor return DeclKind >= Decl::RecordFirst && DeclKind <= Decl::RecordLast; 462c7ed9c60b8ee04b119e23441cae2cfec74536ba9Argyrios Kyrtzidis } 463c7ed9c60b8ee04b119e23441cae2cfec74536ba9Argyrios Kyrtzidis 46444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor bool isNamespace() const { 46544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor return DeclKind == Decl::Namespace; 46644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor } 46744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 468074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// isTransparentContext - Determines whether this context is a 469074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// "transparent" context, meaning that the members declared in this 470074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// context are semantically declared in the nearest enclosing 471074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// non-transparent (opaque) context but are lexically declared in 472074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// this context. For example, consider the enumerators of an 473074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// enumeration type: 474074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// @code 475074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// enum E { 476074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// Val1 477074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// }; 478074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// @endcode 479074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// Here, E is a transparent context, so its enumerator (Val1) will 480074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// appear (semantically) that it is in the same context of E. 481074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// Examples of transparent contexts include: enumerations (except for 482074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// C++0x scoped enums), C++ linkage specifications, and C++0x 483074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// inline namespaces. 484074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor bool isTransparentContext() const; 485074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor 486ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis bool Encloses(DeclContext *DC) const { 487ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis for (; DC; DC = DC->getParent()) 488ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis if (DC == this) 489ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis return true; 490ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis return false; 491ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis } 492ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis 49344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// getPrimaryContext - There may be many different 49444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// declarations of the same entity (including forward declarations 49544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// of classes, multiple definitions of namespaces, etc.), each with 49644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// a different set of declarations. This routine returns the 49744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// "primary" DeclContext structure, which will contain the 49844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// information needed to perform name lookup into this context. 4990701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff DeclContext *getPrimaryContext(); 50044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 501ce35607c282c845b3285d0f6e106489d8bbeba13Douglas Gregor /// getLookupContext - Retrieve the innermost non-transparent 502ce35607c282c845b3285d0f6e106489d8bbeba13Douglas Gregor /// context of this context, which corresponds to the innermost 503ce35607c282c845b3285d0f6e106489d8bbeba13Douglas Gregor /// location from which name lookup can find the entities in this 504ce35607c282c845b3285d0f6e106489d8bbeba13Douglas Gregor /// context. 50517a9b9e3ee75f5dbb4819cc8ebf40eec8015f84aDouglas Gregor DeclContext *getLookupContext() { 50617a9b9e3ee75f5dbb4819cc8ebf40eec8015f84aDouglas Gregor return const_cast<DeclContext *>( 50717a9b9e3ee75f5dbb4819cc8ebf40eec8015f84aDouglas Gregor const_cast<const DeclContext *>(this)->getLookupContext()); 50817a9b9e3ee75f5dbb4819cc8ebf40eec8015f84aDouglas Gregor } 50917a9b9e3ee75f5dbb4819cc8ebf40eec8015f84aDouglas Gregor const DeclContext *getLookupContext() const; 510ce35607c282c845b3285d0f6e106489d8bbeba13Douglas Gregor 51188b7094185b9d4fe9820c731b6936d8d37f6143eDouglas Gregor /// \brief Retrieve the nearest enclosing namespace context. 51288b7094185b9d4fe9820c731b6936d8d37f6143eDouglas Gregor DeclContext *getEnclosingNamespaceContext(); 51388b7094185b9d4fe9820c731b6936d8d37f6143eDouglas Gregor const DeclContext *getEnclosingNamespaceContext() const { 51488b7094185b9d4fe9820c731b6936d8d37f6143eDouglas Gregor return const_cast<DeclContext *>(this)->getEnclosingNamespaceContext(); 51588b7094185b9d4fe9820c731b6936d8d37f6143eDouglas Gregor } 51688b7094185b9d4fe9820c731b6936d8d37f6143eDouglas Gregor 51744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// getNextContext - If this is a DeclContext that may have other 51844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// DeclContexts that are semantically connected but syntactically 51944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// different, such as C++ namespaces, this routine retrieves the 52044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// next DeclContext in the link. Iteration through the chain of 52144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// DeclContexts should begin at the primary DeclContext and 52244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// continue until this function returns NULL. For example, given: 52344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// @code 52444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// namespace N { 52544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// int x; 52644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// } 52744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// namespace N { 52844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// int y; 52944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// } 53044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// @endcode 53144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// The first occurrence of namespace N will be the primary 53244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// DeclContext. Its getNextContext will return the second 53344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// occurrence of namespace N. 53444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor DeclContext *getNextContext(); 53544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 53644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// decl_iterator - Iterates through the declarations stored 53744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// within this context. 5386037fcba3431b47de1a994c9b286feac17894effDouglas Gregor class decl_iterator { 5396037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// Current - The current declaration. 5404afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor Decl *Current; 5416037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 5426037fcba3431b47de1a994c9b286feac17894effDouglas Gregor public: 5434afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor typedef Decl* value_type; 5444afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor typedef Decl* reference; 5454afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor typedef Decl* pointer; 5466037fcba3431b47de1a994c9b286feac17894effDouglas Gregor typedef std::forward_iterator_tag iterator_category; 5476037fcba3431b47de1a994c9b286feac17894effDouglas Gregor typedef std::ptrdiff_t difference_type; 5486037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 5496037fcba3431b47de1a994c9b286feac17894effDouglas Gregor decl_iterator() : Current(0) { } 5504afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor explicit decl_iterator(Decl *C) : Current(C) { } 5516037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 5526037fcba3431b47de1a994c9b286feac17894effDouglas Gregor reference operator*() const { return Current; } 5536037fcba3431b47de1a994c9b286feac17894effDouglas Gregor pointer operator->() const { return Current; } 5546037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 5556037fcba3431b47de1a994c9b286feac17894effDouglas Gregor decl_iterator& operator++(); 5566037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 5576037fcba3431b47de1a994c9b286feac17894effDouglas Gregor decl_iterator operator++(int) { 5586037fcba3431b47de1a994c9b286feac17894effDouglas Gregor decl_iterator tmp(*this); 5596037fcba3431b47de1a994c9b286feac17894effDouglas Gregor ++(*this); 5606037fcba3431b47de1a994c9b286feac17894effDouglas Gregor return tmp; 5616037fcba3431b47de1a994c9b286feac17894effDouglas Gregor } 5626037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 5636037fcba3431b47de1a994c9b286feac17894effDouglas Gregor friend bool operator==(decl_iterator x, decl_iterator y) { 5646037fcba3431b47de1a994c9b286feac17894effDouglas Gregor return x.Current == y.Current; 5656037fcba3431b47de1a994c9b286feac17894effDouglas Gregor } 5666037fcba3431b47de1a994c9b286feac17894effDouglas Gregor friend bool operator!=(decl_iterator x, decl_iterator y) { 5676037fcba3431b47de1a994c9b286feac17894effDouglas Gregor return x.Current != y.Current; 5686037fcba3431b47de1a994c9b286feac17894effDouglas Gregor } 5696037fcba3431b47de1a994c9b286feac17894effDouglas Gregor }; 57044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 57144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// decls_begin/decls_end - Iterate over the declarations stored in 57244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// this context. 5736037fcba3431b47de1a994c9b286feac17894effDouglas Gregor decl_iterator decls_begin() const { return decl_iterator(FirstDecl); } 5746037fcba3431b47de1a994c9b286feac17894effDouglas Gregor decl_iterator decls_end() const { return decl_iterator(); } 57544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 576f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// specific_decl_iterator - Iterates over a subrange of 577f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// declarations stored in a DeclContext, providing only those that 578669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// are of type SpecificDecl (or a class derived from it). This 579f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// iterator is used, for example, to provide iteration over just 580669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// the fields within a RecordDecl (with SpecificDecl = FieldDecl). 581f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor template<typename SpecificDecl> 582f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor class specific_decl_iterator { 583f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// Current - The current, underlying declaration iterator, which 584d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// will either be NULL or will point to a declaration of 585f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// type SpecificDecl. 586f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor DeclContext::decl_iterator Current; 587f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 588f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// SkipToNextDecl - Advances the current position up to the next 589f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// declaration of type SpecificDecl that also meets the criteria 590f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// required by Acceptable. 591f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor void SkipToNextDecl() { 592669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor while (*Current && !isa<SpecificDecl>(*Current)) 593f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor ++Current; 594f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 595f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 596f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor public: 597f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor typedef SpecificDecl* value_type; 598f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor typedef SpecificDecl* reference; 599f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor typedef SpecificDecl* pointer; 600f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor typedef std::iterator_traits<DeclContext::decl_iterator>::difference_type 601f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor difference_type; 602f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor typedef std::forward_iterator_tag iterator_category; 603f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 604669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor specific_decl_iterator() : Current() { } 605f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 606f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// specific_decl_iterator - Construct a new iterator over a 607d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// subset of the declarations the range [C, 608d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// end-of-declarations). If A is non-NULL, it is a pointer to a 609d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// member function of SpecificDecl that should return true for 610d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// all of the SpecificDecl instances that will be in the subset 611d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// of iterators. For example, if you want Objective-C instance 612d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// methods, SpecificDecl will be ObjCMethodDecl and A will be 613d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// &ObjCMethodDecl::isInstanceMethod. 614669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor explicit specific_decl_iterator(DeclContext::decl_iterator C) : Current(C) { 615f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor SkipToNextDecl(); 616f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 617f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 6186037fcba3431b47de1a994c9b286feac17894effDouglas Gregor reference operator*() const { return cast<SpecificDecl>(*Current); } 6196037fcba3431b47de1a994c9b286feac17894effDouglas Gregor pointer operator->() const { return cast<SpecificDecl>(*Current); } 620f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 621f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor specific_decl_iterator& operator++() { 622f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor ++Current; 623f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor SkipToNextDecl(); 624f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor return *this; 625f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 626f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 627f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor specific_decl_iterator operator++(int) { 628f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor specific_decl_iterator tmp(*this); 629f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor ++(*this); 630f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor return tmp; 631f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 632f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 633f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor friend bool 634f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor operator==(const specific_decl_iterator& x, const specific_decl_iterator& y) { 635f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor return x.Current == y.Current; 636f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 637f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 638f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor friend bool 639f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor operator!=(const specific_decl_iterator& x, const specific_decl_iterator& y) { 640f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor return x.Current != y.Current; 641f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 642f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor }; 643f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 644669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// \brief Iterates over a filtered subrange of declarations stored 645669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// in a DeclContext. 646669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// 647669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// This iterator visits only those declarations that are of type 648669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// SpecificDecl (or a class derived from it) and that meet some 649669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// additional run-time criteria. This iterator is used, for 650669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// example, to provide access to the instance methods within an 651669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// Objective-C interface (with SpecificDecl = ObjCMethodDecl and 652669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// Acceptable = ObjCMethodDecl::isInstanceMethod). 653669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor template<typename SpecificDecl, bool (SpecificDecl::*Acceptable)() const> 654669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor class filtered_decl_iterator { 655669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// Current - The current, underlying declaration iterator, which 656669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// will either be NULL or will point to a declaration of 657669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// type SpecificDecl. 658669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor DeclContext::decl_iterator Current; 659669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 660669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// SkipToNextDecl - Advances the current position up to the next 661669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// declaration of type SpecificDecl that also meets the criteria 662669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// required by Acceptable. 663669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor void SkipToNextDecl() { 664669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor while (*Current && 665669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor (!isa<SpecificDecl>(*Current) || 666669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor (Acceptable && !(cast<SpecificDecl>(*Current)->*Acceptable)()))) 667669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor ++Current; 668669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor } 669669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 670669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor public: 671669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor typedef SpecificDecl* value_type; 672669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor typedef SpecificDecl* reference; 673669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor typedef SpecificDecl* pointer; 674669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor typedef std::iterator_traits<DeclContext::decl_iterator>::difference_type 675669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor difference_type; 676669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor typedef std::forward_iterator_tag iterator_category; 677669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 678669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor filtered_decl_iterator() : Current() { } 679669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 680669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// specific_decl_iterator - Construct a new iterator over a 681669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// subset of the declarations the range [C, 682669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// end-of-declarations). If A is non-NULL, it is a pointer to a 683669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// member function of SpecificDecl that should return true for 684669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// all of the SpecificDecl instances that will be in the subset 685669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// of iterators. For example, if you want Objective-C instance 686669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// methods, SpecificDecl will be ObjCMethodDecl and A will be 687669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// &ObjCMethodDecl::isInstanceMethod. 688669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor explicit filtered_decl_iterator(DeclContext::decl_iterator C) : Current(C) { 689669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor SkipToNextDecl(); 690669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor } 691669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 692669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor reference operator*() const { return cast<SpecificDecl>(*Current); } 693669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor pointer operator->() const { return cast<SpecificDecl>(*Current); } 694669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 695669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor filtered_decl_iterator& operator++() { 696669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor ++Current; 697669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor SkipToNextDecl(); 698669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor return *this; 699669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor } 700669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 701669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor filtered_decl_iterator operator++(int) { 702669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor filtered_decl_iterator tmp(*this); 703669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor ++(*this); 704669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor return tmp; 705669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor } 706669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 707669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor friend bool 708669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor operator==(const filtered_decl_iterator& x, const filtered_decl_iterator& y) { 709669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor return x.Current == y.Current; 710669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor } 711669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 712669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor friend bool 713669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor operator!=(const filtered_decl_iterator& x, const filtered_decl_iterator& y) { 714669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor return x.Current != y.Current; 715669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor } 716669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor }; 717669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 71840f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// @brief Add the declaration D into this context. 71940f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// 72040f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// This routine should be invoked when the declaration D has first 72140f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// been declared, to place D into the context where it was 72240f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// (lexically) defined. Every declaration must be added to one 72340f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// (and only one!) context, where it can be visited via 72440f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// [decls_begin(), decls_end()). Once a declaration has been added 72540f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// to its lexical context, the corresponding DeclContext owns the 72640f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// declaration. 72740f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// 72840f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// If D is also a NamedDecl, it will be made visible within its 72940f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// semantic context via makeDeclVisibleInContext. 7304afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor void addDecl(Decl *D); 73144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 73244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// lookup_iterator - An iterator that provides access to the results 73344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// of looking up a name within this context. 7344afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor typedef NamedDecl **lookup_iterator; 73544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 73644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// lookup_const_iterator - An iterator that provides non-mutable 73744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// access to the results of lookup up a name within this context. 7384afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor typedef NamedDecl * const * lookup_const_iterator; 73944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 74044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor typedef std::pair<lookup_iterator, lookup_iterator> lookup_result; 74144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor typedef std::pair<lookup_const_iterator, lookup_const_iterator> 74244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor lookup_const_result; 74344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 74444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// lookup - Find the declarations (if any) with the given Name in 74544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// this context. Returns a range of iterators that contains all of 74640f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// the declarations with this name, with object, function, member, 74740f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// and enumerator names preceding any tag name. Note that this 74840f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// routine will not look into parent contexts. 7490701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff lookup_result lookup(DeclarationName Name); 7500701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff lookup_const_result lookup(DeclarationName Name) const; 75144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 75240f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// @brief Makes a declaration visible within this context. 75340f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// 75440f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// This routine makes the declaration D visible to name lookup 75540f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// within this context and, if this is a transparent context, 75640f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// within its parent contexts up to the first enclosing 75740f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// non-transparent context. Making a declaration visible within a 75840f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// context does not transfer ownership of a declaration, and a 75940f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// declaration can be visible in many contexts that aren't its 76040f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// lexical context. 76140f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// 76240f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// If D is a redeclaration of an existing declaration that is 76340f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// visible from this context, as determined by 76440f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// NamedDecl::declarationReplaces, the previous declaration will be 76540f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// replaced with D. 76640f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor void makeDeclVisibleInContext(NamedDecl *D); 7677643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidis 7682a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor /// udir_iterator - Iterates through the using-directives stored 7692a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor /// within this context. 7702a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor typedef UsingDirectiveDecl * const * udir_iterator; 7712a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor 7722a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor typedef std::pair<udir_iterator, udir_iterator> udir_iterator_range; 7732a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor 7742a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor udir_iterator_range getUsingDirectives() const; 7752a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor 7762a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor udir_iterator using_directives_begin() const { 7772a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor return getUsingDirectives().first; 7782a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor } 7792a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor 7802a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor udir_iterator using_directives_end() const { 7812a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor return getUsingDirectives().second; 7822a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor } 7832a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor 7843d7641e090cf113dec64306a1597d3e4523e2a55Argyrios Kyrtzidis static bool classof(const Decl *D); 785b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner static bool classof(const DeclContext *D) { return true; } 78664650af7cc4352c6c67b9bd1bf8ef3ce7471b910Douglas Gregor#define DECL_CONTEXT(Name) \ 78764650af7cc4352c6c67b9bd1bf8ef3ce7471b910Douglas Gregor static bool classof(const Name##Decl *D) { return true; } 78864650af7cc4352c6c67b9bd1bf8ef3ce7471b910Douglas Gregor#include "clang/AST/DeclNodes.def" 7897643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidis 7907643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidisprivate: 79140f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor void buildLookup(DeclContext *DCtx); 79240f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor void makeDeclVisibleInContextImpl(NamedDecl *D); 79344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 7947643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidis void EmitOutRec(llvm::Serializer& S) const; 7957643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidis void ReadOutRec(llvm::Deserializer& D, ASTContext& C); 7967643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidis 7977643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidis friend class Decl; 7980ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner}; 7990ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 800f57172b24f08a68d179675989813d5479dc87829Douglas Gregorinline bool Decl::isTemplateParameter() const { 801f57172b24f08a68d179675989813d5479dc87829Douglas Gregor return getKind() == TemplateTypeParm || getKind() == NonTypeTemplateParm; 802f57172b24f08a68d179675989813d5479dc87829Douglas Gregor} 803f57172b24f08a68d179675989813d5479dc87829Douglas Gregor 8044afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorinline bool Decl::isDefinedOutsideFunctionOrMethod() const { 8054afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor if (getDeclContext()) 8064afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return !getDeclContext()->getLookupContext()->isFunctionOrMethod(); 8074afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor else 8084afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return true; 8094afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor} 8104afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 8114afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorinline DeclContext::decl_iterator& DeclContext::decl_iterator::operator++() { 8120cba85577ae613bce5768f3089003629a46b0e7fDouglas Gregor Current = getNextDeclInScope(Current); 8134afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return *this; 8144afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor} 8154afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 8160ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner} // end clang. 8170ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 8180ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnernamespace llvm { 8190ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 82042220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis/// Implement a isa_impl_wrap specialization to check whether a DeclContext is 82142220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis/// a specific Decl. 82242220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidistemplate<class ToTy> 82342220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisstruct isa_impl_wrap<ToTy, 82442220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis const ::clang::DeclContext,const ::clang::DeclContext> { 82542220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis static bool doit(const ::clang::DeclContext &Val) { 82642220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis return ToTy::classof(::clang::Decl::castFromDeclContext(&Val)); 8270ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 8280ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner}; 82942220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidistemplate<class ToTy> 83042220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisstruct isa_impl_wrap<ToTy, ::clang::DeclContext, ::clang::DeclContext> 83142220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis : public isa_impl_wrap<ToTy, 83242220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis const ::clang::DeclContext,const ::clang::DeclContext> {}; 8330ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 83442220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis/// Implement cast_convert_val for Decl -> DeclContext conversions. 8350ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnertemplate<class FromTy> 83642220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisstruct cast_convert_val< ::clang::DeclContext, FromTy, FromTy> { 837b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner static ::clang::DeclContext &doit(const FromTy &Val) { 83842220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis return *FromTy::castToDeclContext(&Val); 8390ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 8400ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner}; 8410ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 8420ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnertemplate<class FromTy> 84342220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisstruct cast_convert_val< ::clang::DeclContext, FromTy*, FromTy*> { 844b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner static ::clang::DeclContext *doit(const FromTy *Val) { 84542220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis return FromTy::castToDeclContext(Val); 8460ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 8470ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner}; 84842220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis 84944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregortemplate<class FromTy> 85044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregorstruct cast_convert_val< const ::clang::DeclContext, FromTy, FromTy> { 85144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor static const ::clang::DeclContext &doit(const FromTy &Val) { 85244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor return *FromTy::castToDeclContext(&Val); 85344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor } 85444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor}; 85544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 85644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregortemplate<class FromTy> 85744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregorstruct cast_convert_val< const ::clang::DeclContext, FromTy*, FromTy*> { 85844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor static const ::clang::DeclContext *doit(const FromTy *Val) { 85944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor return FromTy::castToDeclContext(Val); 86044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor } 86144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor}; 86244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 86342220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis/// Implement cast_convert_val for DeclContext -> Decl conversions. 86442220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidistemplate<class ToTy> 86542220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisstruct cast_convert_val<ToTy, 86642220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis const ::clang::DeclContext,const ::clang::DeclContext> { 86742220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis static ToTy &doit(const ::clang::DeclContext &Val) { 86842220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis return *reinterpret_cast<ToTy*>(ToTy::castFromDeclContext(&Val)); 86942220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis } 87042220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis}; 87142220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidistemplate<class ToTy> 87242220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisstruct cast_convert_val<ToTy, ::clang::DeclContext, ::clang::DeclContext> 87342220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis : public cast_convert_val<ToTy, 87442220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis const ::clang::DeclContext,const ::clang::DeclContext> {}; 87542220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis 87642220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidistemplate<class ToTy> 87742220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisstruct cast_convert_val<ToTy, 87842220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis const ::clang::DeclContext*, const ::clang::DeclContext*> { 87942220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis static ToTy *doit(const ::clang::DeclContext *Val) { 88042220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis return reinterpret_cast<ToTy*>(ToTy::castFromDeclContext(Val)); 88142220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis } 88242220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis}; 88342220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidistemplate<class ToTy> 88442220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisstruct cast_convert_val<ToTy, ::clang::DeclContext*, ::clang::DeclContext*> 88542220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis : public cast_convert_val<ToTy, 88642220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis const ::clang::DeclContext*,const ::clang::DeclContext*> {}; 8870ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 8880ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner} // end namespace llvm 8890ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 8900ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner#endif 891