DeclBase.h revision 0cba85577ae613bce5768f3089003629a46b0e7f
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; 2844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregorclass NamedDecl; 290ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnerclass FunctionDecl; 30d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidisclass CXXRecordDecl; 31b048c9835969c4f7fe06264748be18ed4b442116Chris Lattnerclass EnumDecl; 32d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidisclass ObjCMethodDecl; 330ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnerclass ObjCInterfaceDecl; 340701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroffclass ObjCCategoryDecl; 350701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroffclass ObjCProtocolDecl; 360701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroffclass ObjCImplementationDecl; 370701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroffclass ObjCCategoryImplDecl; 38074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregorclass LinkageSpecDecl; 3956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroffclass BlockDecl; 4044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregorclass DeclarationName; 410ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 420ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner/// Decl - This represents one declaration (or definition), e.g. a variable, 430ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner/// typedef, function, struct, etc. 440ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner/// 450ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnerclass Decl { 460ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnerpublic: 470ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner enum Kind { 480ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner // This lists the concrete classes of Decl in order of the inheritance 490ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner // hierarchy. This allows us to do efficient classof tests based on the 500ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner // enums below. The commented out names are abstract class names. 51a34ea072371154c9042ce86321d17fbb4df1f84dTed Kremenek // [DeclContext] indicates that the class also inherits from DeclContext. 520ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 530ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner // Decl 54d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis TranslationUnit, // [DeclContext] 550ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner // NamedDecl 568e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor OverloadedFunction, 574afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor Field, 584afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor ObjCIvar, 594afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor ObjCAtDefsField, 604afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor Namespace, // [DeclContext] 614afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor // TypeDecl 624afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor Typedef, 634afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor // TagDecl // [DeclContext] 644afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor Enum, 654afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor Record, 664afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor CXXRecord, 674afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor TemplateTypeParm, 684afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor // ValueDecl 694afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor EnumConstant, 704afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor Function, // [DeclContext] 714afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor CXXMethod, 724afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor CXXConstructor, 734afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor CXXDestructor, 744afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor CXXConversion, 754afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor Var, 764afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor ImplicitParam, 774afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor CXXClassVar, 784afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor ParmVar, 794afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor OriginalParmVar, 804afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor NonTypeTemplateParm, 814afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor ObjCMethod, // [DeclContext] 8209c4719788a5cea09897525e528fa00420f1677bSteve Naroff ObjCContainer, // [DeclContext] 8309c4719788a5cea09897525e528fa00420f1677bSteve Naroff ObjCCategory, 8409c4719788a5cea09897525e528fa00420f1677bSteve Naroff ObjCProtocol, 8509c4719788a5cea09897525e528fa00420f1677bSteve Naroff ObjCInterface, 86d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor ObjCCategoryImpl, // [DeclContext] 87d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor ObjCProperty, 88d04341000d35c8808a72838b057eed7bf13b7661Douglas Gregor ObjCCompatibleAlias, 894afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor LinkageSpec, // [DeclContext] 904afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor ObjCPropertyImpl, 914afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor ObjCImplementation, // [DeclContext] 924afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor ObjCForwardProtocol, 934afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor ObjCClass, 94226e04a9b7790a7311aff2aa9df340c1841e20e3Daniel Dunbar FileScopeAsm, 954afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor Block, // [DeclContext] 960ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 970ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner // For each non-leaf class, we now define a mapping to the first/last member 980ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner // of the class, to allow efficient classof. 994afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor NamedFirst = OverloadedFunction, NamedLast = ObjCCompatibleAlias, 10009c4719788a5cea09897525e528fa00420f1677bSteve Naroff ObjCContainerFirst = ObjCContainer, ObjCContainerLast = ObjCInterface, 10109c4719788a5cea09897525e528fa00420f1677bSteve Naroff FieldFirst = Field , FieldLast = ObjCAtDefsField, 10209c4719788a5cea09897525e528fa00420f1677bSteve Naroff TypeFirst = Typedef , TypeLast = TemplateTypeParm, 10309c4719788a5cea09897525e528fa00420f1677bSteve Naroff TagFirst = Enum , TagLast = CXXRecord, 10409c4719788a5cea09897525e528fa00420f1677bSteve Naroff RecordFirst = Record , RecordLast = CXXRecord, 10509c4719788a5cea09897525e528fa00420f1677bSteve Naroff ValueFirst = EnumConstant , ValueLast = NonTypeTemplateParm, 10609c4719788a5cea09897525e528fa00420f1677bSteve Naroff FunctionFirst = Function , FunctionLast = CXXConversion, 10709c4719788a5cea09897525e528fa00420f1677bSteve Naroff VarFirst = Var , VarLast = NonTypeTemplateParm 1080ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner }; 1090ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 1100ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// IdentifierNamespace - According to C99 6.2.3, there are four namespaces, 1112ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor /// labels, tags, members and ordinary identifiers. These are meant 1122ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor /// as bitmasks, so that searches in C++ can look into the "tag" namespace 1132ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor /// during ordinary lookup. 1140ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner enum IdentifierNamespace { 1152ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor IDNS_Label = 0x1, 1162ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor IDNS_Tag = 0x2, 1172ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor IDNS_Member = 0x4, 1182ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor IDNS_Ordinary = 0x8 1190ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner }; 1200ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 1210ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// ObjCDeclQualifier - Qualifier used on types in method declarations 1220ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// for remote messaging. They are meant for the arguments though and 1230ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// applied to the Decls (ObjCMethodDecl and ParmVarDecl). 1240ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner enum ObjCDeclQualifier { 1250ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_None = 0x0, 1260ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_In = 0x1, 1270ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_Inout = 0x2, 1280ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_Out = 0x4, 1290ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_Bycopy = 0x8, 1300ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_Byref = 0x10, 1310ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_Oneway = 0x20 1320ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner }; 1330ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 1340ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnerprivate: 1350ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// Loc - The location that this decl. 1360ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner SourceLocation Loc; 1370ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 1384afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// NextDeclarator - If this decl was part of a multi-declarator declaration, 1394afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// such as "int X, Y, *Z;" this indicates Decl for the next declarator. 1404afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor Decl *NextDeclarator; 1414afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 1424afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// NextDeclInScope - The next declaration within the same lexical 1434afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// DeclContext. These pointers form the linked list that is 1444afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// traversed via DeclContext's decls_begin()/decls_end(). 1454afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// FIXME: If NextDeclarator is non-NULL, will it always be the same 1464afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// as NextDeclInScope? If so, we can use a 1474afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// PointerIntPair<Decl*, 1> to make Decl smaller. 1484afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor Decl *NextDeclInScope; 1494afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 1504afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor friend class DeclContext; 1514afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 1524afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// DeclCtx - Holds either a DeclContext* or a MultipleDC*. 1534afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// For declarations that don't contain C++ scope specifiers, it contains 1544afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// the DeclContext where the Decl was declared. 1554afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// For declarations with C++ scope specifiers, it contains a MultipleDC* 1564afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// with the context where it semantically belongs (SemanticDC) and the 1574afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// context where it was lexically declared (LexicalDC). 1584afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// e.g.: 1594afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// 1604afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// namespace A { 1614afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// void f(); // SemanticDC == LexicalDC == 'namespace A' 1624afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// } 1634afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// void A::f(); // SemanticDC == namespace 'A' 1644afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// // LexicalDC == global namespace 1654afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor uintptr_t DeclCtx; 1664afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 1674afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor struct MultipleDC { 1684afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor DeclContext *SemanticDC; 1694afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor DeclContext *LexicalDC; 1704afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor }; 1714afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 1724afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor inline bool isInSemaDC() const { return (DeclCtx & 0x1) == 0; } 1734afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor inline bool isOutOfSemaDC() const { return (DeclCtx & 0x1) != 0; } 1744afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor inline MultipleDC *getMultipleDC() const { 1754afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return reinterpret_cast<MultipleDC*>(DeclCtx & ~0x1); 1764afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 1774afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 1780ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// DeclKind - This indicates which class this is. 1790ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner Kind DeclKind : 8; 1800ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 1810ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// InvalidDecl - This indicates a semantic error occurred. 1820ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner unsigned int InvalidDecl : 1; 1830ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 1840ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// HasAttrs - This indicates whether the decl has attributes or not. 1850ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner unsigned int HasAttrs : 1; 186d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis 1876b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor /// Implicit - Whether this declaration was implicitly generated by 1886b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor /// the implementation rather than explicitly written by the user. 1896b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor bool Implicit : 1; 1906b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor 1914afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorprotected: 192d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis /// Access - Used by C++ decls for the access specifier. 193d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis // NOTE: VC++ treats enums as signed, avoid using the AccessSpecifier enum 194d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis unsigned Access : 2; 195d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis friend class CXXClassMemberWrapper; 196d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis 1974afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor Decl(Kind DK, DeclContext *DC, SourceLocation L) 1984afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor : Loc(L), NextDeclarator(0), NextDeclInScope(0), 1994afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor DeclCtx(reinterpret_cast<uintptr_t>(DC)), DeclKind(DK), InvalidDecl(0), 2004afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor HasAttrs(false), Implicit(false) { 2010ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner if (Decl::CollectingStats()) addDeclKind(DK); 2020ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 2031bb19638f2ec0d63ed131b51ca8d9542d1a9afeeSam Bishop 2040ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner virtual ~Decl(); 2051bb19638f2ec0d63ed131b51ca8d9542d1a9afeeSam Bishop 2064afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// setDeclContext - Set both the semantic and lexical DeclContext 2074afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// to DC. 2084afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor void setDeclContext(DeclContext *DC); 2094afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 2101bb19638f2ec0d63ed131b51ca8d9542d1a9afeeSam Bishoppublic: 2110ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner SourceLocation getLocation() const { return Loc; } 2120ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner void setLocation(SourceLocation L) { Loc = L; } 2130ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 2140ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner Kind getKind() const { return DeclKind; } 2150ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner const char *getDeclKindName() const; 2160ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 2174afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor const DeclContext *getDeclContext() const { 2184afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor if (isInSemaDC()) 2194afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return reinterpret_cast<DeclContext*>(DeclCtx); 2204afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return getMultipleDC()->SemanticDC; 2214afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 2224afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor DeclContext *getDeclContext() { 2234afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return const_cast<DeclContext*>( 2244afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor const_cast<const Decl*>(this)->getDeclContext()); 2254afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 2264afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 2274afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor void setAccess(AccessSpecifier AS) { Access = AS; } 2284afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor AccessSpecifier getAccess() const { return AccessSpecifier(Access); } 2294afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 2300ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner void addAttr(Attr *attr); 2310ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner const Attr *getAttrs() const; 232a212c56e9b7533bcc2d6be90efd52ad241bf894eChris Lattner void swapAttrs(Decl *D); 2339141bee299a05349924a34a7153d7064c9e0a107Nuno Lopes void invalidateAttrs(); 2340ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 2350ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner template<typename T> const T *getAttr() const { 2360ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner for (const Attr *attr = getAttrs(); attr; attr = attr->getNext()) 2370ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner if (const T *V = dyn_cast<T>(attr)) 2380ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner return V; 2390ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 2400ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner return 0; 2410ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 2420ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 2430ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// setInvalidDecl - Indicates the Decl had a semantic error. This 2440ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// allows for graceful error recovery. 2450ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner void setInvalidDecl() { InvalidDecl = 1; } 2460ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner bool isInvalidDecl() const { return (bool) InvalidDecl; } 2476b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor 2486b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor /// isImplicit - Indicates whether the declaration was implicitly 2496b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor /// generated by the implementation. If false, this declaration 2506b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor /// was written explicitly in the source code. 2516b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor bool isImplicit() const { return Implicit; } 2526b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor void setImplicit(bool I = true) { Implicit = I; } 2530ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 2540ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner IdentifierNamespace getIdentifierNamespace() const { 2550ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner switch (DeclKind) { 2569d35097bc0fefb2f77638be513cac72d1c09d840Douglas Gregor default: 2579d35097bc0fefb2f77638be513cac72d1c09d840Douglas Gregor if (DeclKind >= FunctionFirst && DeclKind <= FunctionLast) 2589d35097bc0fefb2f77638be513cac72d1c09d840Douglas Gregor return IDNS_Ordinary; 2599d35097bc0fefb2f77638be513cac72d1c09d840Douglas Gregor assert(0 && "Unknown decl kind!"); 2604111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner case ImplicitParam: 2610ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner case Typedef: 262248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff case Var: 2630ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner case ParmVar: 26473da9e462576faedc2cdf96b37a1c072b404b73dFariborz Jahanian case OriginalParmVar: 2650ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner case EnumConstant: 26672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor case NonTypeTemplateParm: 2670ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner case ObjCInterface: 2680ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner case ObjCCompatibleAlias: 2698e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor case OverloadedFunction: 2701ce6eadf80453d132d378ee031f3fbf5259a7d2aArgyrios Kyrtzidis case CXXMethod: 2712def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor case CXXConversion: 27209c31b0d78fc4e7f1d1828d01d9977cc3e242ea3Argyrios Kyrtzidis case CXXClassVar: 2730ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner return IDNS_Ordinary; 27472de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor 27572de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor case Field: 27672de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor case ObjCAtDefsField: 27772de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor case ObjCIvar: 27872de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor return IDNS_Member; 27972de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor 28035bc0821c4f80041724cd4c5c4889b2581546a41Argyrios Kyrtzidis case Record: 28135bc0821c4f80041724cd4c5c4889b2581546a41Argyrios Kyrtzidis case CXXRecord: 28272c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor case TemplateTypeParm: 2830ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner case Enum: 2840ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner return IDNS_Tag; 2852d1c5d313cd0c229cc614e74baa4c5756a4b46f4Argyrios Kyrtzidis case Namespace: 2862d1c5d313cd0c229cc614e74baa4c5756a4b46f4Argyrios Kyrtzidis return IdentifierNamespace(IDNS_Tag | IDNS_Ordinary); 2870ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 2880ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 289792481eec23d8c1aa92173be589e2ae9d02514a5Ted Kremenek 290d62fdc448b3ace606c8c9c9f13e43218fa204dbfChris Lattner bool isInIdentifierNamespace(unsigned NS) const { 291d62fdc448b3ace606c8c9c9f13e43218fa204dbfChris Lattner return getIdentifierNamespace() & NS; 292d62fdc448b3ace606c8c9c9f13e43218fa204dbfChris Lattner } 293d62fdc448b3ace606c8c9c9f13e43218fa204dbfChris Lattner 2944afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// getLexicalDeclContext - The declaration context where this Decl was 2954afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// lexically declared (LexicalDC). May be different from 2964afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// getDeclContext() (SemanticDC). 2974afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// e.g.: 2984afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// 2994afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// namespace A { 3004afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// void f(); // SemanticDC == LexicalDC == 'namespace A' 3014afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// } 3024afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// void A::f(); // SemanticDC == namespace 'A' 3034afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// // LexicalDC == global namespace 3044afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor const DeclContext *getLexicalDeclContext() const { 3054afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor if (isInSemaDC()) 3064afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return reinterpret_cast<DeclContext*>(DeclCtx); 3074afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return getMultipleDC()->LexicalDC; 3084afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 3094afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor DeclContext *getLexicalDeclContext() { 3104afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return const_cast<DeclContext*>( 3114afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor const_cast<const Decl*>(this)->getLexicalDeclContext()); 3124afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 3134afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 3144afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor void setLexicalDeclContext(DeclContext *DC); 3154afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 3164afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// getNextDeclarator - If this decl was part of a multi-declarator 3174afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// declaration, such as "int X, Y, *Z;" this returns the decl for the next 3184afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// declarator. Otherwise it returns null. 3194afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor Decl *getNextDeclarator() { return NextDeclarator; } 3204afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor const Decl *getNextDeclarator() const { return NextDeclarator; } 3214afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor void setNextDeclarator(Decl *N) { NextDeclarator = N; } 3224afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 3234afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor // isDefinedOutsideFunctionOrMethod - This predicate returns true if this 3244afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor // scoped decl is defined outside the current function or method. This is 3254afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor // roughly global variables and functions, but also handles enums (which could 3264afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor // be defined inside or outside a function etc). 3274afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor bool isDefinedOutsideFunctionOrMethod() const; 3284afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 32969c8f0aab655257e9e532d9d53756acf4f7a2d78Ted Kremenek // getBody - If this Decl represents a declaration for a body of code, 330792481eec23d8c1aa92173be589e2ae9d02514a5Ted Kremenek // such as a function or method definition, this method returns the top-level 33169c8f0aab655257e9e532d9d53756acf4f7a2d78Ted Kremenek // Stmt* of that body. Otherwise this method returns null. 33269c8f0aab655257e9e532d9d53756acf4f7a2d78Ted Kremenek virtual Stmt* getBody() const { return 0; } 333792481eec23d8c1aa92173be589e2ae9d02514a5Ted Kremenek 3340ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner // global temp stats (until we have a per-module visitor) 3350ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner static void addDeclKind(Kind k); 3360ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner static bool CollectingStats(bool Enable = false); 3370ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner static void PrintStats(); 3380ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 339f57172b24f08a68d179675989813d5479dc87829Douglas Gregor /// isTemplateParameter - Determines whether this declartion is a 340f57172b24f08a68d179675989813d5479dc87829Douglas Gregor /// template parameter. 341f57172b24f08a68d179675989813d5479dc87829Douglas Gregor bool isTemplateParameter() const; 342f57172b24f08a68d179675989813d5479dc87829Douglas Gregor 3430ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner // Implement isa/cast/dyncast/etc. 3440ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner static bool classof(const Decl *) { return true; } 34542220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis static DeclContext *castToDeclContext(const Decl *); 34642220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis static Decl *castFromDeclContext(const DeclContext *); 3470ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 3480ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// Emit - Serialize this Decl to Bitcode. 3490ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner void Emit(llvm::Serializer& S) const; 3500ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 3510ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// Create - Deserialize a Decl from Bitcode. 352e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static Decl* Create(llvm::Deserializer& D, ASTContext& C); 3530ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 354bb45c512e0dfbe96bfe377ac642e726c0ba0affaSam Bishop /// Destroy - Call destructors and release memory. 35527f8a28bee33bb0e857cfe1a61c281bbc234b338Ted Kremenek virtual void Destroy(ASTContext& C); 356bb45c512e0dfbe96bfe377ac642e726c0ba0affaSam Bishop 3570ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnerprotected: 3580ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// EmitImpl - Provides the subclass-specific serialization logic for 3590ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// serializing out a decl. 3600ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner virtual void EmitImpl(llvm::Serializer& S) const { 3610ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner // FIXME: This will eventually be a pure virtual function. 3620ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner assert (false && "Not implemented."); 3630ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 3640ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner}; 3650ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 366b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner/// DeclContext - This is used only as base class of specific decl types that 3670ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner/// can act as declaration contexts. These decls are: 3680ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner/// 369ef177820100ab583b08fd3056e2a5a52ee4b1629Argyrios Kyrtzidis/// TranslationUnitDecl 3702d1c5d313cd0c229cc614e74baa4c5756a4b46f4Argyrios Kyrtzidis/// NamespaceDecl 3710ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner/// FunctionDecl 37244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor/// RecordDecl/CXXRecordDecl 373b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner/// EnumDecl 374d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis/// ObjCMethodDecl 3750ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner/// ObjCInterfaceDecl 376074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor/// LinkageSpecDecl 37756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff/// BlockDecl 378b048c9835969c4f7fe06264748be18ed4b442116Chris Lattnerclass DeclContext { 3790ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// DeclKind - This indicates which class this is. 3800ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner Decl::Kind DeclKind : 8; 3810ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 38244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// LookupPtrKind - Describes what kind of pointer LookupPtr 38344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// actually is. 38444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor enum LookupPtrKind { 3853fc749d899dfc194162128c1a88933148a39b68dDouglas Gregor /// LookupIsMap - Indicates that LookupPtr is actually a map. 38644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor LookupIsMap = 7 38744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor }; 38844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 38944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// LookupPtr - Pointer to a data structure used to lookup 39044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// declarations within this context. If the context contains fewer 39144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// than seven declarations, the number of declarations is provided 39244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// in the 3 lowest-order bits and the upper bits are treated as a 3934afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// pointer to an array of NamedDecl pointers. If the context 39444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// contains seven or more declarations, the upper bits are treated 3954afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// as a pointer to a DenseMap<DeclarationName, std::vector<NamedDecl*>>. 3963fc749d899dfc194162128c1a88933148a39b68dDouglas Gregor /// FIXME: We need a better data structure for this. 39744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor llvm::PointerIntPair<void*, 3> LookupPtr; 39844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 3996037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// FirstDecl - The first declaration stored within this declaration 4006037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// context. 4014afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor Decl *FirstDecl; 4026037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 4036037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// LastDecl - The last declaration stored within this declaration 4046037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// context. FIXME: We could probably cache this value somewhere 4056037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// outside of the DeclContext, to reduce the size of DeclContext by 4066037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// another pointer. 4074afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor Decl *LastDecl; 4087643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidis 4090ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner // Used in the CastTo template to get the DeclKind 410b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner // from a Decl or a DeclContext. DeclContext doesn't have a getKind() method 4110ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner // to avoid 'ambiguous access' compiler errors. 4120ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner template<typename T> struct KindTrait { 4130ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner static Decl::Kind getKind(const T *D) { return D->getKind(); } 4140ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner }; 4150ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 4160ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner // Used only by the ToDecl and FromDecl methods 4170ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner template<typename To, typename From> 4180ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner static To *CastTo(const From *D) { 4190ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner Decl::Kind DK = KindTrait<From>::getKind(D); 4200ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner switch(DK) { 421ef177820100ab583b08fd3056e2a5a52ee4b1629Argyrios Kyrtzidis case Decl::TranslationUnit: 422ef177820100ab583b08fd3056e2a5a52ee4b1629Argyrios Kyrtzidis return static_cast<TranslationUnitDecl*>(const_cast<From*>(D)); 4232d1c5d313cd0c229cc614e74baa4c5756a4b46f4Argyrios Kyrtzidis case Decl::Namespace: 4242d1c5d313cd0c229cc614e74baa4c5756a4b46f4Argyrios Kyrtzidis return static_cast<NamespaceDecl*>(const_cast<From*>(D)); 425d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis case Decl::Enum: 426d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis return static_cast<EnumDecl*>(const_cast<From*>(D)); 42744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor case Decl::Record: 42844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor return static_cast<RecordDecl*>(const_cast<From*>(D)); 42935bc0821c4f80041724cd4c5c4889b2581546a41Argyrios Kyrtzidis case Decl::CXXRecord: 43035bc0821c4f80041724cd4c5c4889b2581546a41Argyrios Kyrtzidis return static_cast<CXXRecordDecl*>(const_cast<From*>(D)); 4310ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner case Decl::ObjCMethod: 4320ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner return static_cast<ObjCMethodDecl*>(const_cast<From*>(D)); 4330ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner case Decl::ObjCInterface: 4340ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner return static_cast<ObjCInterfaceDecl*>(const_cast<From*>(D)); 4350701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff case Decl::ObjCCategory: 4360701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff return static_cast<ObjCCategoryDecl*>(const_cast<From*>(D)); 4370701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff case Decl::ObjCProtocol: 4380701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff return static_cast<ObjCProtocolDecl*>(const_cast<From*>(D)); 4390701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff case Decl::ObjCImplementation: 4400701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff return static_cast<ObjCImplementationDecl*>(const_cast<From*>(D)); 4410701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff case Decl::ObjCCategoryImpl: 4420701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff return static_cast<ObjCCategoryImplDecl*>(const_cast<From*>(D)); 443074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor case Decl::LinkageSpec: 444074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor return static_cast<LinkageSpecDecl*>(const_cast<From*>(D)); 445074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor case Decl::Block: 446074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor return static_cast<BlockDecl*>(const_cast<From*>(D)); 4470ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner default: 448d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis if (DK >= Decl::FunctionFirst && DK <= Decl::FunctionLast) 449d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis return static_cast<FunctionDecl*>(const_cast<From*>(D)); 450d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis 451b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner assert(false && "a decl that inherits DeclContext isn't handled"); 4520ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner return 0; 4530ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 4540ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 4550ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 45644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// isLookupMap - Determine if the lookup structure is a 45744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// DenseMap. Othewise, it is an array. 45844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor bool isLookupMap() const { return LookupPtr.getInt() == LookupIsMap; } 45944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 4600cba85577ae613bce5768f3089003629a46b0e7fDouglas Gregor static Decl *getNextDeclInScope(Decl *D) { return D->NextDeclInScope; } 4610cba85577ae613bce5768f3089003629a46b0e7fDouglas Gregor 4620ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnerprotected: 4636037fcba3431b47de1a994c9b286feac17894effDouglas Gregor DeclContext(Decl::Kind K) 4646037fcba3431b47de1a994c9b286feac17894effDouglas Gregor : DeclKind(K), LookupPtr(), FirstDecl(0), LastDecl(0) { } 46544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 46644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor void DestroyDecls(ASTContext &C); 4670ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 4680ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnerpublic: 46944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor ~DeclContext(); 47044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 4719b9ca01ff3136a7539dc08a4c4e1a3dd8c8d3a7dArgyrios Kyrtzidis Decl::Kind getDeclKind() const { 4729b9ca01ff3136a7539dc08a4c4e1a3dd8c8d3a7dArgyrios Kyrtzidis return DeclKind; 4739b9ca01ff3136a7539dc08a4c4e1a3dd8c8d3a7dArgyrios Kyrtzidis } 4749b9ca01ff3136a7539dc08a4c4e1a3dd8c8d3a7dArgyrios Kyrtzidis 4754afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// getParent - Returns the containing DeclContext if this is a Decl, 4760ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// else returns NULL. 47720bc6762282d192bd19be03094d4f311710e020cArgyrios Kyrtzidis const DeclContext *getParent() const; 47820bc6762282d192bd19be03094d4f311710e020cArgyrios Kyrtzidis DeclContext *getParent() { 47920bc6762282d192bd19be03094d4f311710e020cArgyrios Kyrtzidis return const_cast<DeclContext*>( 48020bc6762282d192bd19be03094d4f311710e020cArgyrios Kyrtzidis const_cast<const DeclContext*>(this)->getParent()); 481d2595ecce5f8350e485c83bfe767549a522b2802Argyrios Kyrtzidis } 4820ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 48377407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis /// getLexicalParent - Returns the containing lexical DeclContext. May be 48444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// different from getParent, e.g.: 48544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// 48644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// namespace A { 48744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// struct S; 48844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// } 48944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// struct A::S {}; // getParent() == namespace 'A' 49077407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis /// // getLexicalParent() == translation unit 49177407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis /// 49277407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis const DeclContext *getLexicalParent() const; 49377407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis DeclContext *getLexicalParent() { 49477407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis return const_cast<DeclContext*>( 49577407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis const_cast<const DeclContext*>(this)->getLexicalParent()); 49677407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis } 49777407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis 4980ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner bool isFunctionOrMethod() const { 4990ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner switch (DeclKind) { 50056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff case Decl::Block: 5010ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner case Decl::ObjCMethod: 5020ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner return true; 50344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 5040ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner default: 50544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor if (DeclKind >= Decl::FunctionFirst && DeclKind <= Decl::FunctionLast) 50644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor return true; 5070ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner return false; 5080ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 5090ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 5100ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 511ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis bool isFileContext() const { 512ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis return DeclKind == Decl::TranslationUnit || DeclKind == Decl::Namespace; 513ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis } 514ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis 515bcbffc46f1ad3796c4582fa1e3a9113b5aa26061Douglas Gregor bool isRecord() const { 516bcbffc46f1ad3796c4582fa1e3a9113b5aa26061Douglas Gregor return DeclKind == Decl::Record || DeclKind == Decl::CXXRecord; 517c7ed9c60b8ee04b119e23441cae2cfec74536ba9Argyrios Kyrtzidis } 518c7ed9c60b8ee04b119e23441cae2cfec74536ba9Argyrios Kyrtzidis 51944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor bool isNamespace() const { 52044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor return DeclKind == Decl::Namespace; 52144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor } 52244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 523074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// isTransparentContext - Determines whether this context is a 524074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// "transparent" context, meaning that the members declared in this 525074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// context are semantically declared in the nearest enclosing 526074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// non-transparent (opaque) context but are lexically declared in 527074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// this context. For example, consider the enumerators of an 528074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// enumeration type: 529074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// @code 530074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// enum E { 531074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// Val1 532074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// }; 533074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// @endcode 534074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// Here, E is a transparent context, so its enumerator (Val1) will 535074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// appear (semantically) that it is in the same context of E. 536074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// Examples of transparent contexts include: enumerations (except for 537074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// C++0x scoped enums), C++ linkage specifications, and C++0x 538074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// inline namespaces. 539074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor bool isTransparentContext() const; 540074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor 541ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis bool Encloses(DeclContext *DC) const { 542ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis for (; DC; DC = DC->getParent()) 543ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis if (DC == this) 544ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis return true; 545ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis return false; 546ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis } 547ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis 54844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// getPrimaryContext - There may be many different 54944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// declarations of the same entity (including forward declarations 55044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// of classes, multiple definitions of namespaces, etc.), each with 55144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// a different set of declarations. This routine returns the 55244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// "primary" DeclContext structure, which will contain the 55344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// information needed to perform name lookup into this context. 5540701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff DeclContext *getPrimaryContext(); 55544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 556ce35607c282c845b3285d0f6e106489d8bbeba13Douglas Gregor /// getLookupContext - Retrieve the innermost non-transparent 557ce35607c282c845b3285d0f6e106489d8bbeba13Douglas Gregor /// context of this context, which corresponds to the innermost 558ce35607c282c845b3285d0f6e106489d8bbeba13Douglas Gregor /// location from which name lookup can find the entities in this 559ce35607c282c845b3285d0f6e106489d8bbeba13Douglas Gregor /// context. 56017a9b9e3ee75f5dbb4819cc8ebf40eec8015f84aDouglas Gregor DeclContext *getLookupContext() { 56117a9b9e3ee75f5dbb4819cc8ebf40eec8015f84aDouglas Gregor return const_cast<DeclContext *>( 56217a9b9e3ee75f5dbb4819cc8ebf40eec8015f84aDouglas Gregor const_cast<const DeclContext *>(this)->getLookupContext()); 56317a9b9e3ee75f5dbb4819cc8ebf40eec8015f84aDouglas Gregor } 56417a9b9e3ee75f5dbb4819cc8ebf40eec8015f84aDouglas Gregor const DeclContext *getLookupContext() const; 565ce35607c282c845b3285d0f6e106489d8bbeba13Douglas Gregor 56644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// getNextContext - If this is a DeclContext that may have other 56744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// DeclContexts that are semantically connected but syntactically 56844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// different, such as C++ namespaces, this routine retrieves the 56944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// next DeclContext in the link. Iteration through the chain of 57044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// DeclContexts should begin at the primary DeclContext and 57144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// continue until this function returns NULL. For example, given: 57244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// @code 57344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// namespace N { 57444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// int x; 57544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// } 57644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// namespace N { 57744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// int y; 57844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// } 57944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// @endcode 58044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// The first occurrence of namespace N will be the primary 58144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// DeclContext. Its getNextContext will return the second 58244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// occurrence of namespace N. 58344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor DeclContext *getNextContext(); 58444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 58544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// decl_iterator - Iterates through the declarations stored 58644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// within this context. 5876037fcba3431b47de1a994c9b286feac17894effDouglas Gregor class decl_iterator { 5886037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// Current - The current declaration. 5894afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor Decl *Current; 5906037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 5916037fcba3431b47de1a994c9b286feac17894effDouglas Gregor public: 5924afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor typedef Decl* value_type; 5934afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor typedef Decl* reference; 5944afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor typedef Decl* pointer; 5956037fcba3431b47de1a994c9b286feac17894effDouglas Gregor typedef std::forward_iterator_tag iterator_category; 5966037fcba3431b47de1a994c9b286feac17894effDouglas Gregor typedef std::ptrdiff_t difference_type; 5976037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 5986037fcba3431b47de1a994c9b286feac17894effDouglas Gregor decl_iterator() : Current(0) { } 5994afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor explicit decl_iterator(Decl *C) : Current(C) { } 6006037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 6016037fcba3431b47de1a994c9b286feac17894effDouglas Gregor reference operator*() const { return Current; } 6026037fcba3431b47de1a994c9b286feac17894effDouglas Gregor pointer operator->() const { return Current; } 6036037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 6046037fcba3431b47de1a994c9b286feac17894effDouglas Gregor decl_iterator& operator++(); 6056037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 6066037fcba3431b47de1a994c9b286feac17894effDouglas Gregor decl_iterator operator++(int) { 6076037fcba3431b47de1a994c9b286feac17894effDouglas Gregor decl_iterator tmp(*this); 6086037fcba3431b47de1a994c9b286feac17894effDouglas Gregor ++(*this); 6096037fcba3431b47de1a994c9b286feac17894effDouglas Gregor return tmp; 6106037fcba3431b47de1a994c9b286feac17894effDouglas Gregor } 6116037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 6126037fcba3431b47de1a994c9b286feac17894effDouglas Gregor friend bool operator==(decl_iterator x, decl_iterator y) { 6136037fcba3431b47de1a994c9b286feac17894effDouglas Gregor return x.Current == y.Current; 6146037fcba3431b47de1a994c9b286feac17894effDouglas Gregor } 6156037fcba3431b47de1a994c9b286feac17894effDouglas Gregor friend bool operator!=(decl_iterator x, decl_iterator y) { 6166037fcba3431b47de1a994c9b286feac17894effDouglas Gregor return x.Current != y.Current; 6176037fcba3431b47de1a994c9b286feac17894effDouglas Gregor } 6186037fcba3431b47de1a994c9b286feac17894effDouglas Gregor }; 61944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 62044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// decls_begin/decls_end - Iterate over the declarations stored in 62144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// this context. 6226037fcba3431b47de1a994c9b286feac17894effDouglas Gregor decl_iterator decls_begin() const { return decl_iterator(FirstDecl); } 6236037fcba3431b47de1a994c9b286feac17894effDouglas Gregor decl_iterator decls_end() const { return decl_iterator(); } 62444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 625f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// specific_decl_iterator - Iterates over a subrange of 626f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// declarations stored in a DeclContext, providing only those that 627f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// are of type SpecificDecl (or a class derived from it) and, 628f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// optionally, that meet some additional run-time criteria. This 629f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// iterator is used, for example, to provide iteration over just 630f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// the fields within a RecordDecl (with SpecificDecl = FieldDecl) 631f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// or the instance methods within an Objective-C interface (with 632f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// SpecificDecl = ObjCMethodDecl and using 633f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// ObjCMethodDecl::isInstanceMethod as the run-time criteria). 634f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor template<typename SpecificDecl> 635f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor class specific_decl_iterator { 636f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// Current - The current, underlying declaration iterator, which 637f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// will either be the same as End or will point to a declaration of 638f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// type SpecificDecl. 639f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor DeclContext::decl_iterator Current; 640f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 641f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// End - One past the last declaration within the DeclContext. 642f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor DeclContext::decl_iterator End; 643f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 644f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// Acceptable - If non-NULL, points to a member function that 645f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// will determine if a particular declaration of type 646f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// SpecificDecl should be visited by the iteration. 647f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor bool (SpecificDecl::*Acceptable)() const; 648f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 649f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// SkipToNextDecl - Advances the current position up to the next 650f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// declaration of type SpecificDecl that also meets the criteria 651f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// required by Acceptable. 652f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor void SkipToNextDecl() { 653f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor while (Current != End && 654f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor (!isa<SpecificDecl>(*Current) || 655f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor (Acceptable && !(cast<SpecificDecl>(*Current)->*Acceptable)()))) 656f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor ++Current; 657f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 658f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 659f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor public: 660f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor typedef SpecificDecl* value_type; 661f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor typedef SpecificDecl* reference; 662f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor typedef SpecificDecl* pointer; 663f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor typedef std::iterator_traits<DeclContext::decl_iterator>::difference_type 664f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor difference_type; 665f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor typedef std::forward_iterator_tag iterator_category; 666f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 667f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor specific_decl_iterator() : Current(), End(), Acceptable(0) { } 668f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 669f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// specific_decl_iterator - Construct a new iterator over a 670f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// subset of the declarations in [C, E). If A is non-NULL, it is 671f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// a pointer to a member function of SpecificDecl that should 672f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// return true for all of the SpecificDecl instances that will be 673f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// in the subset of iterators. For example, if you want 674f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// Objective-C instance methods, SpecificDecl will be 675f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// ObjCMethodDecl and A will be &ObjCMethodDecl::isInstanceMethod. 676f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor specific_decl_iterator(DeclContext::decl_iterator C, 677f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor DeclContext::decl_iterator E, 678f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor bool (SpecificDecl::*A)() const = 0) 679f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor : Current(C), End(E), Acceptable(A) { 680f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor SkipToNextDecl(); 681f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 682f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 6836037fcba3431b47de1a994c9b286feac17894effDouglas Gregor reference operator*() const { return cast<SpecificDecl>(*Current); } 6846037fcba3431b47de1a994c9b286feac17894effDouglas Gregor pointer operator->() const { return cast<SpecificDecl>(*Current); } 685f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 686f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor specific_decl_iterator& operator++() { 687f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor ++Current; 688f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor SkipToNextDecl(); 689f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor return *this; 690f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 691f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 692f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor specific_decl_iterator operator++(int) { 693f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor specific_decl_iterator tmp(*this); 694f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor ++(*this); 695f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor return tmp; 696f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 697f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 698f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor friend bool 699f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor operator==(const specific_decl_iterator& x, const specific_decl_iterator& y) { 700f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor return x.Current == y.Current; 701f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 702f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 703f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor friend bool 704f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor operator!=(const specific_decl_iterator& x, const specific_decl_iterator& y) { 705f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor return x.Current != y.Current; 706f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 707f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor }; 708f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 709482b77d1cb4ca08391d1f749436f092a4cc24427Douglas Gregor /// addDecl - Add the declaration D to this scope, and into data structure 710482b77d1cb4ca08391d1f749436f092a4cc24427Douglas Gregor /// for name lookup. 7114afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor void addDecl(Decl *D); 71244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 7130701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff void buildLookup(DeclContext *DCtx); 71444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 71544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// lookup_iterator - An iterator that provides access to the results 71644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// of looking up a name within this context. 7174afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor typedef NamedDecl **lookup_iterator; 71844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 71944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// lookup_const_iterator - An iterator that provides non-mutable 72044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// access to the results of lookup up a name within this context. 7214afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor typedef NamedDecl * const * lookup_const_iterator; 72244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 72344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor typedef std::pair<lookup_iterator, lookup_iterator> lookup_result; 72444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor typedef std::pair<lookup_const_iterator, lookup_const_iterator> 72544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor lookup_const_result; 72644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 72744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// lookup - Find the declarations (if any) with the given Name in 72844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// this context. Returns a range of iterators that contains all of 72941761d67291ae9ac74843f31737a96157d982c0bZhongxing Xu /// the declarations with this name (which may be 0, 1, or more 73044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// declarations). If two declarations are returned, the declaration 73144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// in the "ordinary" identifier namespace will precede the 73244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// declaration in the "tag" identifier namespace (e.g., values 73344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// before types). Note that this routine will not look into parent 73444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// contexts. 7350701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff lookup_result lookup(DeclarationName Name); 7360701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff lookup_const_result lookup(DeclarationName Name) const; 73744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 73844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// insert - Insert the declaration D into this context. Up to two 73944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// declarations with the same name can be inserted into a single 74044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// declaration context, one in the "tag" namespace (e.g., for 74144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// classes and enums) and one in the "ordinary" namespaces (e.g., 74244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// for variables, functions, and other values). Note that, if there 74344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// is already a declaration with the same name and identifier 74444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// namespace, D will replace it. It is up to the caller to ensure 74544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// that this replacement is semantically correct, e.g., that 74644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// declarations are only replaced by later declarations of the same 74744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// entity and not a declaration of some other kind of entity. 7484afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor void insert(NamedDecl *D); 7497643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidis 7500ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner static bool classof(const Decl *D) { 7510ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner switch (D->getKind()) { 752ef177820100ab583b08fd3056e2a5a52ee4b1629Argyrios Kyrtzidis case Decl::TranslationUnit: 7532d1c5d313cd0c229cc614e74baa4c5756a4b46f4Argyrios Kyrtzidis case Decl::Namespace: 754d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis case Decl::Enum: 75544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor case Decl::Record: 75635bc0821c4f80041724cd4c5c4889b2581546a41Argyrios Kyrtzidis case Decl::CXXRecord: 7570ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner case Decl::ObjCMethod: 7580ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner case Decl::ObjCInterface: 7590701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff case Decl::ObjCCategory: 7600701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff case Decl::ObjCProtocol: 7610701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff case Decl::ObjCImplementation: 7620701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff case Decl::ObjCCategoryImpl: 763074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor case Decl::LinkageSpec: 76456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff case Decl::Block: 7650ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner return true; 7660ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner default: 767d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis if (D->getKind() >= Decl::FunctionFirst && 768d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis D->getKind() <= Decl::FunctionLast) 769d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis return true; 770b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner return false; 7710ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 7720ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 773b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner static bool classof(const DeclContext *D) { return true; } 774ef177820100ab583b08fd3056e2a5a52ee4b1629Argyrios Kyrtzidis static bool classof(const TranslationUnitDecl *D) { return true; } 7752d1c5d313cd0c229cc614e74baa4c5756a4b46f4Argyrios Kyrtzidis static bool classof(const NamespaceDecl *D) { return true; } 7760ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner static bool classof(const FunctionDecl *D) { return true; } 77744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor static bool classof(const RecordDecl *D) { return true; } 778d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis static bool classof(const CXXRecordDecl *D) { return true; } 779b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner static bool classof(const EnumDecl *D) { return true; } 780d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis static bool classof(const ObjCMethodDecl *D) { return true; } 7810ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner static bool classof(const ObjCInterfaceDecl *D) { return true; } 7820701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff static bool classof(const ObjCCategoryDecl *D) { return true; } 7830701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff static bool classof(const ObjCProtocolDecl *D) { return true; } 7840701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff static bool classof(const ObjCImplementationDecl *D) { return true; } 7850701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff static bool classof(const ObjCCategoryImplDecl *D) { return true; } 786074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor static bool classof(const LinkageSpecDecl *D) { return true; } 78756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff static bool classof(const BlockDecl *D) { return true; } 7887643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidis 7897643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidisprivate: 7904afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor void insertImpl(NamedDecl *D); 79144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 7927643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidis void EmitOutRec(llvm::Serializer& S) const; 7937643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidis void ReadOutRec(llvm::Deserializer& D, ASTContext& C); 7947643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidis 7957643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidis friend class Decl; 7960ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner}; 7970ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 798b048c9835969c4f7fe06264748be18ed4b442116Chris Lattnertemplate<> struct DeclContext::KindTrait<DeclContext> { 799b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner static Decl::Kind getKind(const DeclContext *D) { return D->DeclKind; } 8000ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner}; 8010ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 802f57172b24f08a68d179675989813d5479dc87829Douglas Gregorinline bool Decl::isTemplateParameter() const { 803f57172b24f08a68d179675989813d5479dc87829Douglas Gregor return getKind() == TemplateTypeParm || getKind() == NonTypeTemplateParm; 804f57172b24f08a68d179675989813d5479dc87829Douglas Gregor} 805f57172b24f08a68d179675989813d5479dc87829Douglas Gregor 8064afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorinline bool Decl::isDefinedOutsideFunctionOrMethod() const { 8074afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor if (getDeclContext()) 8084afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return !getDeclContext()->getLookupContext()->isFunctionOrMethod(); 8094afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor else 8104afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return true; 8114afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor} 8124afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 8134afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorinline DeclContext::decl_iterator& DeclContext::decl_iterator::operator++() { 8140cba85577ae613bce5768f3089003629a46b0e7fDouglas Gregor Current = getNextDeclInScope(Current); 8154afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return *this; 8164afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor} 8174afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 8180ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner} // end clang. 8190ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 8200ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnernamespace llvm { 8210ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 82242220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis/// Implement a isa_impl_wrap specialization to check whether a DeclContext is 82342220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis/// a specific Decl. 82442220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidistemplate<class ToTy> 82542220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisstruct isa_impl_wrap<ToTy, 82642220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis const ::clang::DeclContext,const ::clang::DeclContext> { 82742220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis static bool doit(const ::clang::DeclContext &Val) { 82842220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis return ToTy::classof(::clang::Decl::castFromDeclContext(&Val)); 8290ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 8300ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner}; 83142220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidistemplate<class ToTy> 83242220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisstruct isa_impl_wrap<ToTy, ::clang::DeclContext, ::clang::DeclContext> 83342220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis : public isa_impl_wrap<ToTy, 83442220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis const ::clang::DeclContext,const ::clang::DeclContext> {}; 8350ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 83642220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis/// Implement cast_convert_val for Decl -> DeclContext conversions. 8370ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnertemplate<class FromTy> 83842220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisstruct cast_convert_val< ::clang::DeclContext, FromTy, FromTy> { 839b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner static ::clang::DeclContext &doit(const FromTy &Val) { 84042220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis return *FromTy::castToDeclContext(&Val); 8410ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 8420ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner}; 8430ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 8440ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnertemplate<class FromTy> 84542220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisstruct cast_convert_val< ::clang::DeclContext, FromTy*, FromTy*> { 846b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner static ::clang::DeclContext *doit(const FromTy *Val) { 84742220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis return FromTy::castToDeclContext(Val); 8480ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 8490ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner}; 85042220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis 85144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregortemplate<class FromTy> 85244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregorstruct cast_convert_val< const ::clang::DeclContext, FromTy, FromTy> { 85344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor static const ::clang::DeclContext &doit(const FromTy &Val) { 85444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor return *FromTy::castToDeclContext(&Val); 85544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor } 85644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor}; 85744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 85844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregortemplate<class FromTy> 85944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregorstruct cast_convert_val< const ::clang::DeclContext, FromTy*, FromTy*> { 86044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor static const ::clang::DeclContext *doit(const FromTy *Val) { 86144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor return FromTy::castToDeclContext(Val); 86244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor } 86344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor}; 86444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 86542220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis/// Implement cast_convert_val for DeclContext -> Decl conversions. 86642220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidistemplate<class ToTy> 86742220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisstruct cast_convert_val<ToTy, 86842220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis const ::clang::DeclContext,const ::clang::DeclContext> { 86942220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis static ToTy &doit(const ::clang::DeclContext &Val) { 87042220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis return *reinterpret_cast<ToTy*>(ToTy::castFromDeclContext(&Val)); 87142220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis } 87242220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis}; 87342220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidistemplate<class ToTy> 87442220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisstruct cast_convert_val<ToTy, ::clang::DeclContext, ::clang::DeclContext> 87542220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis : public cast_convert_val<ToTy, 87642220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis const ::clang::DeclContext,const ::clang::DeclContext> {}; 87742220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis 87842220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidistemplate<class ToTy> 87942220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisstruct cast_convert_val<ToTy, 88042220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis const ::clang::DeclContext*, const ::clang::DeclContext*> { 88142220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis static ToTy *doit(const ::clang::DeclContext *Val) { 88242220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis return reinterpret_cast<ToTy*>(ToTy::castFromDeclContext(Val)); 88342220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis } 88442220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis}; 88542220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidistemplate<class ToTy> 88642220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisstruct cast_convert_val<ToTy, ::clang::DeclContext*, ::clang::DeclContext*> 88742220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis : public cast_convert_val<ToTy, 88842220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis const ::clang::DeclContext*,const ::clang::DeclContext*> {}; 8890ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 8900ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner} // end namespace llvm 8910ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 8920ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner#endif 893