DeclBase.h revision aaba5e346dffdbad5d1c42765a89e4a7afb0da67
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" 210ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner#include "clang/Basic/SourceLocation.h" 2244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor#include "llvm/ADT/PointerIntPair.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; 40074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregorclass LinkageSpecDecl; 4156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroffclass BlockDecl; 4244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregorclass DeclarationName; 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, 672ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor IDNS_Ordinary = 0x8 680ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner }; 690ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 700ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// ObjCDeclQualifier - Qualifier used on types in method declarations 710ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// for remote messaging. They are meant for the arguments though and 720ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// applied to the Decls (ObjCMethodDecl and ParmVarDecl). 730ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner enum ObjCDeclQualifier { 740ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_None = 0x0, 750ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_In = 0x1, 760ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_Inout = 0x2, 770ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_Out = 0x4, 780ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_Bycopy = 0x8, 790ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_Byref = 0x10, 800ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_Oneway = 0x20 810ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner }; 820ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 830ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnerprivate: 840ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// Loc - The location that this decl. 850ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner SourceLocation Loc; 860ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 874afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// NextDeclarator - If this decl was part of a multi-declarator declaration, 884afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// such as "int X, Y, *Z;" this indicates Decl for the next declarator. 894afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor Decl *NextDeclarator; 904afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 914afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// NextDeclInScope - The next declaration within the same lexical 924afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// DeclContext. These pointers form the linked list that is 934afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// traversed via DeclContext's decls_begin()/decls_end(). 944afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// FIXME: If NextDeclarator is non-NULL, will it always be the same 954afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// as NextDeclInScope? If so, we can use a 964afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// PointerIntPair<Decl*, 1> to make Decl smaller. 974afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor Decl *NextDeclInScope; 984afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 994afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor friend class DeclContext; 1004afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 1014afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// DeclCtx - Holds either a DeclContext* or a MultipleDC*. 1024afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// For declarations that don't contain C++ scope specifiers, it contains 1034afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// the DeclContext where the Decl was declared. 1044afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// For declarations with C++ scope specifiers, it contains a MultipleDC* 1054afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// with the context where it semantically belongs (SemanticDC) and the 1064afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// context where it was lexically declared (LexicalDC). 1074afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// e.g.: 1084afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// 1094afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// namespace A { 1104afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// void f(); // SemanticDC == LexicalDC == 'namespace A' 1114afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// } 1124afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// void A::f(); // SemanticDC == namespace 'A' 1134afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// // LexicalDC == global namespace 1144afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor uintptr_t DeclCtx; 1154afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 1164afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor struct MultipleDC { 1174afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor DeclContext *SemanticDC; 1184afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor DeclContext *LexicalDC; 1194afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor }; 1204afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 1214afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor inline bool isInSemaDC() const { return (DeclCtx & 0x1) == 0; } 1224afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor inline bool isOutOfSemaDC() const { return (DeclCtx & 0x1) != 0; } 1234afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor inline MultipleDC *getMultipleDC() const { 1244afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return reinterpret_cast<MultipleDC*>(DeclCtx & ~0x1); 1254afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 1264afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 1270ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// DeclKind - This indicates which class this is. 1280ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner Kind DeclKind : 8; 1290ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 1300ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// InvalidDecl - This indicates a semantic error occurred. 1310ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner unsigned int InvalidDecl : 1; 1320ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 1330ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// HasAttrs - This indicates whether the decl has attributes or not. 1340ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner unsigned int HasAttrs : 1; 135d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis 1366b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor /// Implicit - Whether this declaration was implicitly generated by 1376b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor /// the implementation rather than explicitly written by the user. 1386b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor bool Implicit : 1; 1396b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor 1404afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorprotected: 141d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis /// Access - Used by C++ decls for the access specifier. 142d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis // NOTE: VC++ treats enums as signed, avoid using the AccessSpecifier enum 143d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis unsigned Access : 2; 144d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis friend class CXXClassMemberWrapper; 145d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis 1464afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor Decl(Kind DK, DeclContext *DC, SourceLocation L) 1474afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor : Loc(L), NextDeclarator(0), NextDeclInScope(0), 1484afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor DeclCtx(reinterpret_cast<uintptr_t>(DC)), DeclKind(DK), InvalidDecl(0), 1494afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor HasAttrs(false), Implicit(false) { 1500ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner if (Decl::CollectingStats()) addDeclKind(DK); 1510ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 1521bb19638f2ec0d63ed131b51ca8d9542d1a9afeeSam Bishop 1530ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner virtual ~Decl(); 1541bb19638f2ec0d63ed131b51ca8d9542d1a9afeeSam Bishop 1554afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// setDeclContext - Set both the semantic and lexical DeclContext 1564afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// to DC. 1574afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor void setDeclContext(DeclContext *DC); 1584afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 1591bb19638f2ec0d63ed131b51ca8d9542d1a9afeeSam Bishoppublic: 1600ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner SourceLocation getLocation() const { return Loc; } 1610ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner void setLocation(SourceLocation L) { Loc = L; } 1620ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 1630ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner Kind getKind() const { return DeclKind; } 1640ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner const char *getDeclKindName() const; 1650ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 1664afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor const DeclContext *getDeclContext() const { 1674afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor if (isInSemaDC()) 1684afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return reinterpret_cast<DeclContext*>(DeclCtx); 1694afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return getMultipleDC()->SemanticDC; 1704afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 1714afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor DeclContext *getDeclContext() { 1724afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return const_cast<DeclContext*>( 1734afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor const_cast<const Decl*>(this)->getDeclContext()); 1744afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 1754afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 1764afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor void setAccess(AccessSpecifier AS) { Access = AS; } 1774afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor AccessSpecifier getAccess() const { return AccessSpecifier(Access); } 1784afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 1790ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner void addAttr(Attr *attr); 1800ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner const Attr *getAttrs() const; 181a212c56e9b7533bcc2d6be90efd52ad241bf894eChris Lattner void swapAttrs(Decl *D); 1829141bee299a05349924a34a7153d7064c9e0a107Nuno Lopes void invalidateAttrs(); 1830ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 1840ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner template<typename T> const T *getAttr() const { 1850ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner for (const Attr *attr = getAttrs(); attr; attr = attr->getNext()) 1860ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner if (const T *V = dyn_cast<T>(attr)) 1870ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner return V; 1880ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 1890ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner return 0; 1900ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 1910ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 1920ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// setInvalidDecl - Indicates the Decl had a semantic error. This 1930ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// allows for graceful error recovery. 1940ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner void setInvalidDecl() { InvalidDecl = 1; } 1950ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner bool isInvalidDecl() const { return (bool) InvalidDecl; } 1966b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor 1976b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor /// isImplicit - Indicates whether the declaration was implicitly 1986b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor /// generated by the implementation. If false, this declaration 1996b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor /// was written explicitly in the source code. 2006b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor bool isImplicit() const { return Implicit; } 2016b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor void setImplicit(bool I = true) { Implicit = I; } 2020ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 2030ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner IdentifierNamespace getIdentifierNamespace() const { 2040ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner switch (DeclKind) { 2059d35097bc0fefb2f77638be513cac72d1c09d840Douglas Gregor default: 2069d35097bc0fefb2f77638be513cac72d1c09d840Douglas Gregor if (DeclKind >= FunctionFirst && DeclKind <= FunctionLast) 2079d35097bc0fefb2f77638be513cac72d1c09d840Douglas Gregor return IDNS_Ordinary; 2089d35097bc0fefb2f77638be513cac72d1c09d840Douglas Gregor assert(0 && "Unknown decl kind!"); 2093fd56d755aa74f01fbe963195c95c963ea1fee91Douglas Gregor case OverloadedFunction: 2100ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner case Typedef: 2113fd56d755aa74f01fbe963195c95c963ea1fee91Douglas Gregor case EnumConstant: 212248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff case Var: 2133fd56d755aa74f01fbe963195c95c963ea1fee91Douglas Gregor case CXXClassVar: 2143fd56d755aa74f01fbe963195c95c963ea1fee91Douglas Gregor case ImplicitParam: 2150ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner case ParmVar: 21673da9e462576faedc2cdf96b37a1c072b404b73dFariborz Jahanian case OriginalParmVar: 21772c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor case NonTypeTemplateParm: 2183fd56d755aa74f01fbe963195c95c963ea1fee91Douglas Gregor case ObjCMethod: 2193fd56d755aa74f01fbe963195c95c963ea1fee91Douglas Gregor case ObjCContainer: 2203fd56d755aa74f01fbe963195c95c963ea1fee91Douglas Gregor case ObjCCategory: 2213fd56d755aa74f01fbe963195c95c963ea1fee91Douglas Gregor case ObjCProtocol: 2220ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner case ObjCInterface: 2233fd56d755aa74f01fbe963195c95c963ea1fee91Douglas Gregor case ObjCCategoryImpl: 2243fd56d755aa74f01fbe963195c95c963ea1fee91Douglas Gregor case ObjCProperty: 2250ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner case ObjCCompatibleAlias: 2260ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner return IDNS_Ordinary; 22772de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor 22872de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor case Field: 22972de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor case ObjCAtDefsField: 23072de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor case ObjCIvar: 23172de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor return IDNS_Member; 23272de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor 23335bc0821c4f80041724cd4c5c4889b2581546a41Argyrios Kyrtzidis case Record: 23435bc0821c4f80041724cd4c5c4889b2581546a41Argyrios Kyrtzidis case CXXRecord: 2350ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner case Enum: 236efe38bdea21953f89c1504cfd1c63bee5f15b1b6Douglas Gregor case TemplateTypeParm: 2370ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner return IDNS_Tag; 2383fd56d755aa74f01fbe963195c95c963ea1fee91Douglas Gregor 2392d1c5d313cd0c229cc614e74baa4c5756a4b46f4Argyrios Kyrtzidis case Namespace: 240aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor case Template: 241aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor case FunctionTemplate: 242aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor case ClassTemplate: 243aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor case TemplateTemplateParm: 2442d1c5d313cd0c229cc614e74baa4c5756a4b46f4Argyrios Kyrtzidis return IdentifierNamespace(IDNS_Tag | IDNS_Ordinary); 2450ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 2460ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 247792481eec23d8c1aa92173be589e2ae9d02514a5Ted Kremenek 248d62fdc448b3ace606c8c9c9f13e43218fa204dbfChris Lattner bool isInIdentifierNamespace(unsigned NS) const { 249d62fdc448b3ace606c8c9c9f13e43218fa204dbfChris Lattner return getIdentifierNamespace() & NS; 250d62fdc448b3ace606c8c9c9f13e43218fa204dbfChris Lattner } 251d62fdc448b3ace606c8c9c9f13e43218fa204dbfChris Lattner 2524afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// getLexicalDeclContext - The declaration context where this Decl was 2534afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// lexically declared (LexicalDC). May be different from 2544afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// getDeclContext() (SemanticDC). 2554afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// e.g.: 2564afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// 2574afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// namespace A { 2584afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// void f(); // SemanticDC == LexicalDC == 'namespace A' 2594afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// } 2604afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// void A::f(); // SemanticDC == namespace 'A' 2614afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// // LexicalDC == global namespace 2624afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor const DeclContext *getLexicalDeclContext() const { 2634afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor if (isInSemaDC()) 2644afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return reinterpret_cast<DeclContext*>(DeclCtx); 2654afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return getMultipleDC()->LexicalDC; 2664afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 2674afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor DeclContext *getLexicalDeclContext() { 2684afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return const_cast<DeclContext*>( 2694afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor const_cast<const Decl*>(this)->getLexicalDeclContext()); 2704afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 2714afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 2724afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor void setLexicalDeclContext(DeclContext *DC); 2734afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 2744afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// getNextDeclarator - If this decl was part of a multi-declarator 2754afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// declaration, such as "int X, Y, *Z;" this returns the decl for the next 2764afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// declarator. Otherwise it returns null. 2774afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor Decl *getNextDeclarator() { return NextDeclarator; } 2784afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor const Decl *getNextDeclarator() const { return NextDeclarator; } 2794afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor void setNextDeclarator(Decl *N) { NextDeclarator = N; } 2804afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 2814afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor // isDefinedOutsideFunctionOrMethod - This predicate returns true if this 2824afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor // scoped decl is defined outside the current function or method. This is 2834afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor // roughly global variables and functions, but also handles enums (which could 2844afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor // be defined inside or outside a function etc). 2854afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor bool isDefinedOutsideFunctionOrMethod() const; 2864afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 28769c8f0aab655257e9e532d9d53756acf4f7a2d78Ted Kremenek // getBody - If this Decl represents a declaration for a body of code, 288792481eec23d8c1aa92173be589e2ae9d02514a5Ted Kremenek // such as a function or method definition, this method returns the top-level 28969c8f0aab655257e9e532d9d53756acf4f7a2d78Ted Kremenek // Stmt* of that body. Otherwise this method returns null. 29069c8f0aab655257e9e532d9d53756acf4f7a2d78Ted Kremenek virtual Stmt* getBody() const { return 0; } 291792481eec23d8c1aa92173be589e2ae9d02514a5Ted Kremenek 2920ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner // global temp stats (until we have a per-module visitor) 2930ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner static void addDeclKind(Kind k); 2940ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner static bool CollectingStats(bool Enable = false); 2950ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner static void PrintStats(); 2960ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 297f57172b24f08a68d179675989813d5479dc87829Douglas Gregor /// isTemplateParameter - Determines whether this declartion is a 298f57172b24f08a68d179675989813d5479dc87829Douglas Gregor /// template parameter. 299f57172b24f08a68d179675989813d5479dc87829Douglas Gregor bool isTemplateParameter() const; 300f57172b24f08a68d179675989813d5479dc87829Douglas Gregor 3010ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner // Implement isa/cast/dyncast/etc. 3020ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner static bool classof(const Decl *) { return true; } 30342220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis static DeclContext *castToDeclContext(const Decl *); 30442220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis static Decl *castFromDeclContext(const DeclContext *); 3050ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 3060ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// Emit - Serialize this Decl to Bitcode. 3070ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner void Emit(llvm::Serializer& S) const; 3080ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 3090ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// Create - Deserialize a Decl from Bitcode. 310e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static Decl* Create(llvm::Deserializer& D, ASTContext& C); 3110ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 312bb45c512e0dfbe96bfe377ac642e726c0ba0affaSam Bishop /// Destroy - Call destructors and release memory. 31327f8a28bee33bb0e857cfe1a61c281bbc234b338Ted Kremenek virtual void Destroy(ASTContext& C); 314bb45c512e0dfbe96bfe377ac642e726c0ba0affaSam Bishop 3150ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnerprotected: 3160ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// EmitImpl - Provides the subclass-specific serialization logic for 3170ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// serializing out a decl. 3180ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner virtual void EmitImpl(llvm::Serializer& S) const { 3190ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner // FIXME: This will eventually be a pure virtual function. 3200ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner assert (false && "Not implemented."); 3210ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 3220ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner}; 3230ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 324b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner/// DeclContext - This is used only as base class of specific decl types that 3250ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner/// can act as declaration contexts. These decls are: 3260ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner/// 327ef177820100ab583b08fd3056e2a5a52ee4b1629Argyrios Kyrtzidis/// TranslationUnitDecl 3282d1c5d313cd0c229cc614e74baa4c5756a4b46f4Argyrios Kyrtzidis/// NamespaceDecl 3290ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner/// FunctionDecl 33044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor/// RecordDecl/CXXRecordDecl 331b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner/// EnumDecl 332d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis/// ObjCMethodDecl 3330ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner/// ObjCInterfaceDecl 334074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor/// LinkageSpecDecl 33556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff/// BlockDecl 336b048c9835969c4f7fe06264748be18ed4b442116Chris Lattnerclass DeclContext { 3370ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// DeclKind - This indicates which class this is. 3380ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner Decl::Kind DeclKind : 8; 3390ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 34044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// LookupPtrKind - Describes what kind of pointer LookupPtr 34144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// actually is. 34244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor enum LookupPtrKind { 3433fc749d899dfc194162128c1a88933148a39b68dDouglas Gregor /// LookupIsMap - Indicates that LookupPtr is actually a map. 34444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor LookupIsMap = 7 34544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor }; 34644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 34744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// LookupPtr - Pointer to a data structure used to lookup 34844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// declarations within this context. If the context contains fewer 34944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// than seven declarations, the number of declarations is provided 35044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// in the 3 lowest-order bits and the upper bits are treated as a 3514afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// pointer to an array of NamedDecl pointers. If the context 35244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// contains seven or more declarations, the upper bits are treated 3534afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// as a pointer to a DenseMap<DeclarationName, std::vector<NamedDecl*>>. 3543fc749d899dfc194162128c1a88933148a39b68dDouglas Gregor /// FIXME: We need a better data structure for this. 35544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor llvm::PointerIntPair<void*, 3> LookupPtr; 35644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 3576037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// FirstDecl - The first declaration stored within this declaration 3586037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// context. 3594afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor Decl *FirstDecl; 3606037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 3616037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// LastDecl - The last declaration stored within this declaration 3626037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// context. FIXME: We could probably cache this value somewhere 3636037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// outside of the DeclContext, to reduce the size of DeclContext by 3646037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// another pointer. 3654afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor Decl *LastDecl; 3667643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidis 3670ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner // Used in the CastTo template to get the DeclKind 368b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner // from a Decl or a DeclContext. DeclContext doesn't have a getKind() method 3690ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner // to avoid 'ambiguous access' compiler errors. 3700ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner template<typename T> struct KindTrait { 3710ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner static Decl::Kind getKind(const T *D) { return D->getKind(); } 3720ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner }; 3730ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 3740ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner // Used only by the ToDecl and FromDecl methods 3750ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner template<typename To, typename From> 3760ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner static To *CastTo(const From *D) { 3770ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner Decl::Kind DK = KindTrait<From>::getKind(D); 3780ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner switch(DK) { 379ef177820100ab583b08fd3056e2a5a52ee4b1629Argyrios Kyrtzidis case Decl::TranslationUnit: 380ef177820100ab583b08fd3056e2a5a52ee4b1629Argyrios Kyrtzidis return static_cast<TranslationUnitDecl*>(const_cast<From*>(D)); 3812d1c5d313cd0c229cc614e74baa4c5756a4b46f4Argyrios Kyrtzidis case Decl::Namespace: 3822d1c5d313cd0c229cc614e74baa4c5756a4b46f4Argyrios Kyrtzidis return static_cast<NamespaceDecl*>(const_cast<From*>(D)); 383d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis case Decl::Enum: 384d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis return static_cast<EnumDecl*>(const_cast<From*>(D)); 38544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor case Decl::Record: 38644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor return static_cast<RecordDecl*>(const_cast<From*>(D)); 38735bc0821c4f80041724cd4c5c4889b2581546a41Argyrios Kyrtzidis case Decl::CXXRecord: 38835bc0821c4f80041724cd4c5c4889b2581546a41Argyrios Kyrtzidis return static_cast<CXXRecordDecl*>(const_cast<From*>(D)); 3890ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner case Decl::ObjCMethod: 3900ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner return static_cast<ObjCMethodDecl*>(const_cast<From*>(D)); 3910ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner case Decl::ObjCInterface: 3920ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner return static_cast<ObjCInterfaceDecl*>(const_cast<From*>(D)); 3930701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff case Decl::ObjCCategory: 3940701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff return static_cast<ObjCCategoryDecl*>(const_cast<From*>(D)); 3950701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff case Decl::ObjCProtocol: 3960701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff return static_cast<ObjCProtocolDecl*>(const_cast<From*>(D)); 3970701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff case Decl::ObjCImplementation: 3980701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff return static_cast<ObjCImplementationDecl*>(const_cast<From*>(D)); 3990701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff case Decl::ObjCCategoryImpl: 4000701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff return static_cast<ObjCCategoryImplDecl*>(const_cast<From*>(D)); 401074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor case Decl::LinkageSpec: 402074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor return static_cast<LinkageSpecDecl*>(const_cast<From*>(D)); 403074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor case Decl::Block: 404074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor return static_cast<BlockDecl*>(const_cast<From*>(D)); 4050ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner default: 406d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis if (DK >= Decl::FunctionFirst && DK <= Decl::FunctionLast) 407d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis return static_cast<FunctionDecl*>(const_cast<From*>(D)); 408d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis 409b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner assert(false && "a decl that inherits DeclContext isn't handled"); 4100ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner return 0; 4110ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 4120ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 4130ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 41444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// isLookupMap - Determine if the lookup structure is a 41544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// DenseMap. Othewise, it is an array. 41644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor bool isLookupMap() const { return LookupPtr.getInt() == LookupIsMap; } 41744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 4180cba85577ae613bce5768f3089003629a46b0e7fDouglas Gregor static Decl *getNextDeclInScope(Decl *D) { return D->NextDeclInScope; } 4190cba85577ae613bce5768f3089003629a46b0e7fDouglas Gregor 4200ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnerprotected: 4216037fcba3431b47de1a994c9b286feac17894effDouglas Gregor DeclContext(Decl::Kind K) 4226037fcba3431b47de1a994c9b286feac17894effDouglas Gregor : DeclKind(K), LookupPtr(), FirstDecl(0), LastDecl(0) { } 42344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 42444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor void DestroyDecls(ASTContext &C); 4250ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 4260ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnerpublic: 42744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor ~DeclContext(); 42844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 4299b9ca01ff3136a7539dc08a4c4e1a3dd8c8d3a7dArgyrios Kyrtzidis Decl::Kind getDeclKind() const { 4309b9ca01ff3136a7539dc08a4c4e1a3dd8c8d3a7dArgyrios Kyrtzidis return DeclKind; 4319b9ca01ff3136a7539dc08a4c4e1a3dd8c8d3a7dArgyrios Kyrtzidis } 4320a4739305a984ef9b821cedad5f4fe235eb6ef7dSteve Naroff const char *getDeclKindName() const; 4339b9ca01ff3136a7539dc08a4c4e1a3dd8c8d3a7dArgyrios Kyrtzidis 4344afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// getParent - Returns the containing DeclContext if this is a Decl, 4350ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// else returns NULL. 43620bc6762282d192bd19be03094d4f311710e020cArgyrios Kyrtzidis const DeclContext *getParent() const; 43720bc6762282d192bd19be03094d4f311710e020cArgyrios Kyrtzidis DeclContext *getParent() { 43820bc6762282d192bd19be03094d4f311710e020cArgyrios Kyrtzidis return const_cast<DeclContext*>( 43920bc6762282d192bd19be03094d4f311710e020cArgyrios Kyrtzidis const_cast<const DeclContext*>(this)->getParent()); 440d2595ecce5f8350e485c83bfe767549a522b2802Argyrios Kyrtzidis } 4410ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 44277407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis /// getLexicalParent - Returns the containing lexical DeclContext. May be 44344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// different from getParent, e.g.: 44444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// 44544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// namespace A { 44644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// struct S; 44744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// } 44844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// struct A::S {}; // getParent() == namespace 'A' 44977407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis /// // getLexicalParent() == translation unit 45077407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis /// 45177407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis const DeclContext *getLexicalParent() const; 45277407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis DeclContext *getLexicalParent() { 45377407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis return const_cast<DeclContext*>( 45477407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis const_cast<const DeclContext*>(this)->getLexicalParent()); 45577407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis } 45677407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis 4570ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner bool isFunctionOrMethod() const { 4580ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner switch (DeclKind) { 45956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff case Decl::Block: 4600ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner case Decl::ObjCMethod: 4610ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner return true; 46244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 4630ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner default: 46444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor if (DeclKind >= Decl::FunctionFirst && DeclKind <= Decl::FunctionLast) 46544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor return true; 4660ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner return false; 4670ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 4680ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 4690ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 470ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis bool isFileContext() const { 471ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis return DeclKind == Decl::TranslationUnit || DeclKind == Decl::Namespace; 472ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis } 473ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis 474bcbffc46f1ad3796c4582fa1e3a9113b5aa26061Douglas Gregor bool isRecord() const { 475bcbffc46f1ad3796c4582fa1e3a9113b5aa26061Douglas Gregor return DeclKind == Decl::Record || DeclKind == Decl::CXXRecord; 476c7ed9c60b8ee04b119e23441cae2cfec74536ba9Argyrios Kyrtzidis } 477c7ed9c60b8ee04b119e23441cae2cfec74536ba9Argyrios Kyrtzidis 47844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor bool isNamespace() const { 47944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor return DeclKind == Decl::Namespace; 48044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor } 48144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 482074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// isTransparentContext - Determines whether this context is a 483074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// "transparent" context, meaning that the members declared in this 484074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// context are semantically declared in the nearest enclosing 485074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// non-transparent (opaque) context but are lexically declared in 486074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// this context. For example, consider the enumerators of an 487074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// enumeration type: 488074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// @code 489074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// enum E { 490074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// Val1 491074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// }; 492074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// @endcode 493074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// Here, E is a transparent context, so its enumerator (Val1) will 494074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// appear (semantically) that it is in the same context of E. 495074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// Examples of transparent contexts include: enumerations (except for 496074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// C++0x scoped enums), C++ linkage specifications, and C++0x 497074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// inline namespaces. 498074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor bool isTransparentContext() const; 499074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor 500ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis bool Encloses(DeclContext *DC) const { 501ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis for (; DC; DC = DC->getParent()) 502ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis if (DC == this) 503ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis return true; 504ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis return false; 505ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis } 506ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis 50744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// getPrimaryContext - There may be many different 50844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// declarations of the same entity (including forward declarations 50944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// of classes, multiple definitions of namespaces, etc.), each with 51044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// a different set of declarations. This routine returns the 51144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// "primary" DeclContext structure, which will contain the 51244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// information needed to perform name lookup into this context. 5130701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff DeclContext *getPrimaryContext(); 51444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 515ce35607c282c845b3285d0f6e106489d8bbeba13Douglas Gregor /// getLookupContext - Retrieve the innermost non-transparent 516ce35607c282c845b3285d0f6e106489d8bbeba13Douglas Gregor /// context of this context, which corresponds to the innermost 517ce35607c282c845b3285d0f6e106489d8bbeba13Douglas Gregor /// location from which name lookup can find the entities in this 518ce35607c282c845b3285d0f6e106489d8bbeba13Douglas Gregor /// context. 51917a9b9e3ee75f5dbb4819cc8ebf40eec8015f84aDouglas Gregor DeclContext *getLookupContext() { 52017a9b9e3ee75f5dbb4819cc8ebf40eec8015f84aDouglas Gregor return const_cast<DeclContext *>( 52117a9b9e3ee75f5dbb4819cc8ebf40eec8015f84aDouglas Gregor const_cast<const DeclContext *>(this)->getLookupContext()); 52217a9b9e3ee75f5dbb4819cc8ebf40eec8015f84aDouglas Gregor } 52317a9b9e3ee75f5dbb4819cc8ebf40eec8015f84aDouglas Gregor const DeclContext *getLookupContext() const; 524ce35607c282c845b3285d0f6e106489d8bbeba13Douglas Gregor 52544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// getNextContext - If this is a DeclContext that may have other 52644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// DeclContexts that are semantically connected but syntactically 52744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// different, such as C++ namespaces, this routine retrieves the 52844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// next DeclContext in the link. Iteration through the chain of 52944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// DeclContexts should begin at the primary DeclContext and 53044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// continue until this function returns NULL. For example, given: 53144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// @code 53244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// namespace N { 53344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// int x; 53444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// } 53544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// namespace N { 53644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// int y; 53744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// } 53844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// @endcode 53944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// The first occurrence of namespace N will be the primary 54044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// DeclContext. Its getNextContext will return the second 54144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// occurrence of namespace N. 54244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor DeclContext *getNextContext(); 54344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 54444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// decl_iterator - Iterates through the declarations stored 54544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// within this context. 5466037fcba3431b47de1a994c9b286feac17894effDouglas Gregor class decl_iterator { 5476037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// Current - The current declaration. 5484afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor Decl *Current; 5496037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 5506037fcba3431b47de1a994c9b286feac17894effDouglas Gregor public: 5514afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor typedef Decl* value_type; 5524afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor typedef Decl* reference; 5534afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor typedef Decl* pointer; 5546037fcba3431b47de1a994c9b286feac17894effDouglas Gregor typedef std::forward_iterator_tag iterator_category; 5556037fcba3431b47de1a994c9b286feac17894effDouglas Gregor typedef std::ptrdiff_t difference_type; 5566037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 5576037fcba3431b47de1a994c9b286feac17894effDouglas Gregor decl_iterator() : Current(0) { } 5584afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor explicit decl_iterator(Decl *C) : Current(C) { } 5596037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 5606037fcba3431b47de1a994c9b286feac17894effDouglas Gregor reference operator*() const { return Current; } 5616037fcba3431b47de1a994c9b286feac17894effDouglas Gregor pointer operator->() const { return Current; } 5626037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 5636037fcba3431b47de1a994c9b286feac17894effDouglas Gregor decl_iterator& operator++(); 5646037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 5656037fcba3431b47de1a994c9b286feac17894effDouglas Gregor decl_iterator operator++(int) { 5666037fcba3431b47de1a994c9b286feac17894effDouglas Gregor decl_iterator tmp(*this); 5676037fcba3431b47de1a994c9b286feac17894effDouglas Gregor ++(*this); 5686037fcba3431b47de1a994c9b286feac17894effDouglas Gregor return tmp; 5696037fcba3431b47de1a994c9b286feac17894effDouglas Gregor } 5706037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 5716037fcba3431b47de1a994c9b286feac17894effDouglas Gregor friend bool operator==(decl_iterator x, decl_iterator y) { 5726037fcba3431b47de1a994c9b286feac17894effDouglas Gregor return x.Current == y.Current; 5736037fcba3431b47de1a994c9b286feac17894effDouglas Gregor } 5746037fcba3431b47de1a994c9b286feac17894effDouglas Gregor friend bool operator!=(decl_iterator x, decl_iterator y) { 5756037fcba3431b47de1a994c9b286feac17894effDouglas Gregor return x.Current != y.Current; 5766037fcba3431b47de1a994c9b286feac17894effDouglas Gregor } 5776037fcba3431b47de1a994c9b286feac17894effDouglas Gregor }; 57844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 57944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// decls_begin/decls_end - Iterate over the declarations stored in 58044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// this context. 5816037fcba3431b47de1a994c9b286feac17894effDouglas Gregor decl_iterator decls_begin() const { return decl_iterator(FirstDecl); } 5826037fcba3431b47de1a994c9b286feac17894effDouglas Gregor decl_iterator decls_end() const { return decl_iterator(); } 58344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 584f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// specific_decl_iterator - Iterates over a subrange of 585f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// declarations stored in a DeclContext, providing only those that 586669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// are of type SpecificDecl (or a class derived from it). This 587f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// iterator is used, for example, to provide iteration over just 588669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// the fields within a RecordDecl (with SpecificDecl = FieldDecl). 589f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor template<typename SpecificDecl> 590f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor class specific_decl_iterator { 591f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// Current - The current, underlying declaration iterator, which 592d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// will either be NULL or will point to a declaration of 593f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// type SpecificDecl. 594f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor DeclContext::decl_iterator Current; 595f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 596f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// SkipToNextDecl - Advances the current position up to the next 597f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// declaration of type SpecificDecl that also meets the criteria 598f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// required by Acceptable. 599f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor void SkipToNextDecl() { 600669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor while (*Current && !isa<SpecificDecl>(*Current)) 601f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor ++Current; 602f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 603f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 604f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor public: 605f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor typedef SpecificDecl* value_type; 606f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor typedef SpecificDecl* reference; 607f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor typedef SpecificDecl* pointer; 608f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor typedef std::iterator_traits<DeclContext::decl_iterator>::difference_type 609f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor difference_type; 610f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor typedef std::forward_iterator_tag iterator_category; 611f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 612669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor specific_decl_iterator() : Current() { } 613f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 614f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// specific_decl_iterator - Construct a new iterator over a 615d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// subset of the declarations the range [C, 616d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// end-of-declarations). If A is non-NULL, it is a pointer to a 617d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// member function of SpecificDecl that should return true for 618d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// all of the SpecificDecl instances that will be in the subset 619d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// of iterators. For example, if you want Objective-C instance 620d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// methods, SpecificDecl will be ObjCMethodDecl and A will be 621d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// &ObjCMethodDecl::isInstanceMethod. 622669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor explicit specific_decl_iterator(DeclContext::decl_iterator C) : Current(C) { 623f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor SkipToNextDecl(); 624f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 625f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 6266037fcba3431b47de1a994c9b286feac17894effDouglas Gregor reference operator*() const { return cast<SpecificDecl>(*Current); } 6276037fcba3431b47de1a994c9b286feac17894effDouglas Gregor pointer operator->() const { return cast<SpecificDecl>(*Current); } 628f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 629f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor specific_decl_iterator& operator++() { 630f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor ++Current; 631f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor SkipToNextDecl(); 632f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor return *this; 633f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 634f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 635f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor specific_decl_iterator operator++(int) { 636f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor specific_decl_iterator tmp(*this); 637f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor ++(*this); 638f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor return tmp; 639f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 640f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 641f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor friend bool 642f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor operator==(const specific_decl_iterator& x, const specific_decl_iterator& y) { 643f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor return x.Current == y.Current; 644f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 645f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 646f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor friend bool 647f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor operator!=(const specific_decl_iterator& x, const specific_decl_iterator& y) { 648f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor return x.Current != y.Current; 649f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 650f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor }; 651f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 652669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// \brief Iterates over a filtered subrange of declarations stored 653669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// in a DeclContext. 654669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// 655669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// This iterator visits only those declarations that are of type 656669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// SpecificDecl (or a class derived from it) and that meet some 657669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// additional run-time criteria. This iterator is used, for 658669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// example, to provide access to the instance methods within an 659669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// Objective-C interface (with SpecificDecl = ObjCMethodDecl and 660669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// Acceptable = ObjCMethodDecl::isInstanceMethod). 661669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor template<typename SpecificDecl, bool (SpecificDecl::*Acceptable)() const> 662669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor class filtered_decl_iterator { 663669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// Current - The current, underlying declaration iterator, which 664669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// will either be NULL or will point to a declaration of 665669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// type SpecificDecl. 666669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor DeclContext::decl_iterator Current; 667669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 668669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// SkipToNextDecl - Advances the current position up to the next 669669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// declaration of type SpecificDecl that also meets the criteria 670669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// required by Acceptable. 671669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor void SkipToNextDecl() { 672669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor while (*Current && 673669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor (!isa<SpecificDecl>(*Current) || 674669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor (Acceptable && !(cast<SpecificDecl>(*Current)->*Acceptable)()))) 675669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor ++Current; 676669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor } 677669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 678669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor public: 679669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor typedef SpecificDecl* value_type; 680669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor typedef SpecificDecl* reference; 681669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor typedef SpecificDecl* pointer; 682669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor typedef std::iterator_traits<DeclContext::decl_iterator>::difference_type 683669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor difference_type; 684669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor typedef std::forward_iterator_tag iterator_category; 685669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 686669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor filtered_decl_iterator() : Current() { } 687669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 688669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// specific_decl_iterator - Construct a new iterator over a 689669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// subset of the declarations the range [C, 690669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// end-of-declarations). If A is non-NULL, it is a pointer to a 691669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// member function of SpecificDecl that should return true for 692669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// all of the SpecificDecl instances that will be in the subset 693669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// of iterators. For example, if you want Objective-C instance 694669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// methods, SpecificDecl will be ObjCMethodDecl and A will be 695669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// &ObjCMethodDecl::isInstanceMethod. 696669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor explicit filtered_decl_iterator(DeclContext::decl_iterator C) : Current(C) { 697669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor SkipToNextDecl(); 698669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor } 699669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 700669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor reference operator*() const { return cast<SpecificDecl>(*Current); } 701669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor pointer operator->() const { return cast<SpecificDecl>(*Current); } 702669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 703669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor filtered_decl_iterator& operator++() { 704669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor ++Current; 705669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor SkipToNextDecl(); 706669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor return *this; 707669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor } 708669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 709669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor filtered_decl_iterator operator++(int) { 710669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor filtered_decl_iterator tmp(*this); 711669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor ++(*this); 712669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor return tmp; 713669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor } 714669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 715669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor friend bool 716669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor operator==(const filtered_decl_iterator& x, const filtered_decl_iterator& y) { 717669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor return x.Current == y.Current; 718669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor } 719669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 720669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor friend bool 721669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor operator!=(const filtered_decl_iterator& x, const filtered_decl_iterator& y) { 722669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor return x.Current != y.Current; 723669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor } 724669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor }; 725669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 72640f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// @brief Add the declaration D into this context. 72740f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// 72840f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// This routine should be invoked when the declaration D has first 72940f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// been declared, to place D into the context where it was 73040f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// (lexically) defined. Every declaration must be added to one 73140f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// (and only one!) context, where it can be visited via 73240f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// [decls_begin(), decls_end()). Once a declaration has been added 73340f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// to its lexical context, the corresponding DeclContext owns the 73440f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// declaration. 73540f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// 73640f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// If D is also a NamedDecl, it will be made visible within its 73740f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// semantic context via makeDeclVisibleInContext. 7384afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor void addDecl(Decl *D); 73944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 74044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// lookup_iterator - An iterator that provides access to the results 74144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// of looking up a name within this context. 7424afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor typedef NamedDecl **lookup_iterator; 74344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 74444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// lookup_const_iterator - An iterator that provides non-mutable 74544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// access to the results of lookup up a name within this context. 7464afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor typedef NamedDecl * const * lookup_const_iterator; 74744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 74844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor typedef std::pair<lookup_iterator, lookup_iterator> lookup_result; 74944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor typedef std::pair<lookup_const_iterator, lookup_const_iterator> 75044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor lookup_const_result; 75144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 75244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// lookup - Find the declarations (if any) with the given Name in 75344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// this context. Returns a range of iterators that contains all of 75440f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// the declarations with this name, with object, function, member, 75540f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// and enumerator names preceding any tag name. Note that this 75640f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// routine will not look into parent contexts. 7570701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff lookup_result lookup(DeclarationName Name); 7580701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff lookup_const_result lookup(DeclarationName Name) const; 75944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 76040f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// @brief Makes a declaration visible within this context. 76140f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// 76240f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// This routine makes the declaration D visible to name lookup 76340f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// within this context and, if this is a transparent context, 76440f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// within its parent contexts up to the first enclosing 76540f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// non-transparent context. Making a declaration visible within a 76640f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// context does not transfer ownership of a declaration, and a 76740f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// declaration can be visible in many contexts that aren't its 76840f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// lexical context. 76940f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// 77040f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// If D is a redeclaration of an existing declaration that is 77140f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// visible from this context, as determined by 77240f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// NamedDecl::declarationReplaces, the previous declaration will be 77340f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// replaced with D. 77440f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor void makeDeclVisibleInContext(NamedDecl *D); 7757643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidis 7762a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor /// udir_iterator - Iterates through the using-directives stored 7772a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor /// within this context. 7782a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor typedef UsingDirectiveDecl * const * udir_iterator; 7792a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor 7802a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor typedef std::pair<udir_iterator, udir_iterator> udir_iterator_range; 7812a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor 7822a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor udir_iterator_range getUsingDirectives() const; 7832a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor 7842a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor udir_iterator using_directives_begin() const { 7852a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor return getUsingDirectives().first; 7862a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor } 7872a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor 7882a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor udir_iterator using_directives_end() const { 7892a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor return getUsingDirectives().second; 7902a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor } 7912a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor 7920ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner static bool classof(const Decl *D) { 7930ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner switch (D->getKind()) { 79464650af7cc4352c6c67b9bd1bf8ef3ce7471b910Douglas Gregor#define DECL_CONTEXT(Name) case Decl::Name: 79564650af7cc4352c6c67b9bd1bf8ef3ce7471b910Douglas Gregor#include "clang/AST/DeclNodes.def" 7960ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner return true; 7970ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner default: 798d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis if (D->getKind() >= Decl::FunctionFirst && 799d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis D->getKind() <= Decl::FunctionLast) 800d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis return true; 801b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner return false; 8020ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 8030ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 804b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner static bool classof(const DeclContext *D) { return true; } 80564650af7cc4352c6c67b9bd1bf8ef3ce7471b910Douglas Gregor#define DECL_CONTEXT(Name) \ 80664650af7cc4352c6c67b9bd1bf8ef3ce7471b910Douglas Gregor static bool classof(const Name##Decl *D) { return true; } 80764650af7cc4352c6c67b9bd1bf8ef3ce7471b910Douglas Gregor#include "clang/AST/DeclNodes.def" 8087643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidis 8097643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidisprivate: 81040f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor void buildLookup(DeclContext *DCtx); 81140f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor void makeDeclVisibleInContextImpl(NamedDecl *D); 81244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 8137643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidis void EmitOutRec(llvm::Serializer& S) const; 8147643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidis void ReadOutRec(llvm::Deserializer& D, ASTContext& C); 8157643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidis 8167643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidis friend class Decl; 8170ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner}; 8180ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 819b048c9835969c4f7fe06264748be18ed4b442116Chris Lattnertemplate<> struct DeclContext::KindTrait<DeclContext> { 820b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner static Decl::Kind getKind(const DeclContext *D) { return D->DeclKind; } 8210ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner}; 8220ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 823f57172b24f08a68d179675989813d5479dc87829Douglas Gregorinline bool Decl::isTemplateParameter() const { 824f57172b24f08a68d179675989813d5479dc87829Douglas Gregor return getKind() == TemplateTypeParm || getKind() == NonTypeTemplateParm; 825f57172b24f08a68d179675989813d5479dc87829Douglas Gregor} 826f57172b24f08a68d179675989813d5479dc87829Douglas Gregor 8274afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorinline bool Decl::isDefinedOutsideFunctionOrMethod() const { 8284afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor if (getDeclContext()) 8294afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return !getDeclContext()->getLookupContext()->isFunctionOrMethod(); 8304afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor else 8314afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return true; 8324afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor} 8334afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 8344afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorinline DeclContext::decl_iterator& DeclContext::decl_iterator::operator++() { 8350cba85577ae613bce5768f3089003629a46b0e7fDouglas Gregor Current = getNextDeclInScope(Current); 8364afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return *this; 8374afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor} 8384afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 8390ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner} // end clang. 8400ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 8410ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnernamespace llvm { 8420ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 84342220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis/// Implement a isa_impl_wrap specialization to check whether a DeclContext is 84442220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis/// a specific Decl. 84542220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidistemplate<class ToTy> 84642220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisstruct isa_impl_wrap<ToTy, 84742220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis const ::clang::DeclContext,const ::clang::DeclContext> { 84842220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis static bool doit(const ::clang::DeclContext &Val) { 84942220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis return ToTy::classof(::clang::Decl::castFromDeclContext(&Val)); 8500ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 8510ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner}; 85242220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidistemplate<class ToTy> 85342220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisstruct isa_impl_wrap<ToTy, ::clang::DeclContext, ::clang::DeclContext> 85442220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis : public isa_impl_wrap<ToTy, 85542220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis const ::clang::DeclContext,const ::clang::DeclContext> {}; 8560ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 85742220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis/// Implement cast_convert_val for Decl -> DeclContext conversions. 8580ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnertemplate<class FromTy> 85942220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisstruct cast_convert_val< ::clang::DeclContext, FromTy, FromTy> { 860b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner static ::clang::DeclContext &doit(const FromTy &Val) { 86142220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis return *FromTy::castToDeclContext(&Val); 8620ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 8630ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner}; 8640ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 8650ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnertemplate<class FromTy> 86642220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisstruct cast_convert_val< ::clang::DeclContext, FromTy*, FromTy*> { 867b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner static ::clang::DeclContext *doit(const FromTy *Val) { 86842220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis return FromTy::castToDeclContext(Val); 8690ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 8700ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner}; 87142220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis 87244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregortemplate<class FromTy> 87344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregorstruct cast_convert_val< const ::clang::DeclContext, FromTy, FromTy> { 87444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor static const ::clang::DeclContext &doit(const FromTy &Val) { 87544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor return *FromTy::castToDeclContext(&Val); 87644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor } 87744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor}; 87844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 87944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregortemplate<class FromTy> 88044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregorstruct cast_convert_val< const ::clang::DeclContext, FromTy*, FromTy*> { 88144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor static const ::clang::DeclContext *doit(const FromTy *Val) { 88244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor return FromTy::castToDeclContext(Val); 88344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor } 88444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor}; 88544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 88642220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis/// Implement cast_convert_val for DeclContext -> Decl conversions. 88742220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidistemplate<class ToTy> 88842220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisstruct cast_convert_val<ToTy, 88942220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis const ::clang::DeclContext,const ::clang::DeclContext> { 89042220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis static ToTy &doit(const ::clang::DeclContext &Val) { 89142220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis return *reinterpret_cast<ToTy*>(ToTy::castFromDeclContext(&Val)); 89242220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis } 89342220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis}; 89442220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidistemplate<class ToTy> 89542220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisstruct cast_convert_val<ToTy, ::clang::DeclContext, ::clang::DeclContext> 89642220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis : public cast_convert_val<ToTy, 89742220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis const ::clang::DeclContext,const ::clang::DeclContext> {}; 89842220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis 89942220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidistemplate<class ToTy> 90042220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisstruct cast_convert_val<ToTy, 90142220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis const ::clang::DeclContext*, const ::clang::DeclContext*> { 90242220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis static ToTy *doit(const ::clang::DeclContext *Val) { 90342220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis return reinterpret_cast<ToTy*>(ToTy::castFromDeclContext(Val)); 90442220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis } 90542220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis}; 90642220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidistemplate<class ToTy> 90742220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisstruct cast_convert_val<ToTy, ::clang::DeclContext*, ::clang::DeclContext*> 90842220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis : public cast_convert_val<ToTy, 90942220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis const ::clang::DeclContext*,const ::clang::DeclContext*> {}; 9100ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 9110ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner} // end namespace llvm 9120ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 9130ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner#endif 914