16ab3524f72a6e64aa04973fa9433b5559abb3525Douglas Gregor//===-- DeclBase.h - Base Classes for representing declarations -*- C++ -*-===// 20ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner// 30ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner// The LLVM Compiler Infrastructure 40ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner// 50ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner// This file is distributed under the University of Illinois Open Source 60ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner// License. See LICENSE.TXT for details. 70ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner// 80ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner//===----------------------------------------------------------------------===// 90ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner// 10b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner// This file defines the Decl and DeclContext interfaces. 110ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner// 120ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner//===----------------------------------------------------------------------===// 130ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 140ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner#ifndef LLVM_CLANG_AST_DECLBASE_H 150ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner#define LLVM_CLANG_AST_DECLBASE_H 160ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 170ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner#include "clang/AST/Attr.h" 180ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner#include "clang/AST/Type.h" 19ad2b804faf29042e6c4e331d0987f103f1e2fd31John McCall#include "clang/Basic/Specifiers.h" 2049f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner#include "llvm/Support/PrettyStackTrace.h" 21ee219fd5f2776d8dd39d857f87304297b5ed743aChris Lattner#include "llvm/ADT/PointerUnion.h" 220ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 230ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnernamespace clang { 2442220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisclass DeclContext; 25ef177820100ab583b08fd3056e2a5a52ee4b1629Argyrios Kyrtzidisclass TranslationUnitDecl; 262d1c5d313cd0c229cc614e74baa4c5756a4b46f4Argyrios Kyrtzidisclass NamespaceDecl; 272a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregorclass UsingDirectiveDecl; 2844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregorclass NamedDecl; 290ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnerclass FunctionDecl; 30d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidisclass CXXRecordDecl; 31b048c9835969c4f7fe06264748be18ed4b442116Chris Lattnerclass EnumDecl; 32d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidisclass ObjCMethodDecl; 3364650af7cc4352c6c67b9bd1bf8ef3ce7471b910Douglas Gregorclass ObjCContainerDecl; 340ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnerclass ObjCInterfaceDecl; 350701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroffclass ObjCCategoryDecl; 360701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroffclass ObjCProtocolDecl; 370701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroffclass ObjCImplementationDecl; 380701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroffclass ObjCCategoryImplDecl; 39bfb498d0996ef049efe9476f2802976fd145cd60Argyrios Kyrtzidisclass ObjCImplDecl; 40074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregorclass LinkageSpecDecl; 4156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroffclass BlockDecl; 4244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregorclass DeclarationName; 43eaab20669b6a9910a5deb0110fdd8f7581d86a36Ted Kremenekclass CompoundStmt; 440c01d18094100db92d38daa923c95661512db203John McCallclass StoredDeclsMap; 450c01d18094100db92d38daa923c95661512db203John McCallclass DependentDiagnostic; 467b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidisclass ASTMutationListener; 470eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner} 480eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner 490eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattnernamespace llvm { 500eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner// DeclContext* is only 4-byte aligned on 32-bit systems. 510eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattnertemplate<> 520eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner class PointerLikeTypeTraits<clang::DeclContext*> { 530eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner typedef clang::DeclContext* PT; 540eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattnerpublic: 550eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner static inline void *getAsVoidPointer(PT P) { return P; } 560eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner static inline PT getFromVoidPointer(void *P) { 570eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner return static_cast<PT>(P); 580eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner } 590eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner enum { NumLowBitsAvailable = 2 }; 600eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner}; 610eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner} 620eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner 630eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattnernamespace clang { 640ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 650a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \brief Captures the result of checking the availability of a 660a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// declaration. 670a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor enum AvailabilityResult { 680a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor AR_Available = 0, 690a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor AR_NotYetIntroduced, 700a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor AR_Deprecated, 710a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor AR_Unavailable 720a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor }; 730a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor 741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Decl - This represents one declaration (or definition), e.g. a variable, 751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// typedef, function, struct, etc. 760ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner/// 770ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnerclass Decl { 780ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnerpublic: 7964650af7cc4352c6c67b9bd1bf8ef3ce7471b910Douglas Gregor /// \brief Lists the kind of concrete classes of Decl. 800ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner enum Kind { 819a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt#define DECL(DERIVED, BASE) DERIVED, 829a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt#define ABSTRACT_DECL(DECL) 839a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt#define DECL_RANGE(BASE, START, END) \ 849a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt first##BASE = START, last##BASE = END, 859a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt#define LAST_DECL_RANGE(BASE, START, END) \ 869a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt first##BASE = START, last##BASE = END 879a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt#include "clang/AST/DeclNodes.inc" 880ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner }; 890ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 906ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner /// \brief A placeholder type used to construct an empty shell of a 916ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner /// decl-derived type that will be filled in later (e.g., by some 926ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner /// deserialization method). 936ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner struct EmptyShell { }; 946ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner 950d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// IdentifierNamespace - The different namespaces in which 960d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// declarations may appear. According to C99 6.2.3, there are 970d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// four namespaces, labels, tags, members and ordinary 980d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// identifiers. C++ describes lookup completely differently: 990d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// certain lookups merely "ignore" certain kinds of declarations, 1000d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// usually based on whether the declaration is of a type, etc. 1010d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// 1020d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// These are meant as bitmasks, so that searches in 1030d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// C++ can look into the "tag" namespace during ordinary lookup. 1040d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// 10507a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl /// Decl currently provides 15 bits of IDNS bits. 1060ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner enum IdentifierNamespace { 1070d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// Labels, declared with 'x:' and referenced with 'goto x'. 1080d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall IDNS_Label = 0x0001, 1090d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall 1100d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// Tags, declared with 'struct foo;' and referenced with 1110d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// 'struct foo'. All tags are also types. This is what 1120d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// elaborated-type-specifiers look for in C. 1130d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall IDNS_Tag = 0x0002, 1140d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall 1150d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// Types, declared with 'struct foo', typedefs, etc. 1160d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// This is what elaborated-type-specifiers look for in C++, 1170d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// but note that it's ill-formed to find a non-tag. 1180d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall IDNS_Type = 0x0004, 1190d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall 1200d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// Members, declared with object declarations within tag 1210d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// definitions. In C, these can only be found by "qualified" 1220d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// lookup in member expressions. In C++, they're found by 1230d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// normal lookup. 1240d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall IDNS_Member = 0x0008, 1250d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall 1260d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// Namespaces, declared with 'namespace foo {}'. 1270d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// Lookup for nested-name-specifiers find these. 1280d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall IDNS_Namespace = 0x0010, 1290d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall 1300d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// Ordinary names. In C, everything that's not a label, tag, 1310d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// or member ends up here. 1320d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall IDNS_Ordinary = 0x0020, 1330d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall 1340d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// Objective C @protocol. 1350d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall IDNS_ObjCProtocol = 0x0040, 1360d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall 1370d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// This declaration is a friend function. A friend function 1380d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// declaration is always in this namespace but may also be in 1390d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// IDNS_Ordinary if it was previously declared. 1400d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall IDNS_OrdinaryFriend = 0x0080, 1410d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall 1420d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// This declaration is a friend class. A friend class 1430d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// declaration is always in this namespace but may also be in 1440d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// IDNS_Tag|IDNS_Type if it was previously declared. 1450d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall IDNS_TagFriend = 0x0100, 1460d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall 1470d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// This declaration is a using declaration. A using declaration 1480d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// *introduces* a number of other declarations into the current 1490d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// scope, and those declarations use the IDNS of their targets, 1500d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// but the actual using declarations go in this namespace. 15176d326448d7e4c10b2896edc2ee855d1e68d1b88John McCall IDNS_Using = 0x0200, 15276d326448d7e4c10b2896edc2ee855d1e68d1b88John McCall 15376d326448d7e4c10b2896edc2ee855d1e68d1b88John McCall /// This declaration is a C++ operator declared in a non-class 15476d326448d7e4c10b2896edc2ee855d1e68d1b88John McCall /// context. All such operators are also in IDNS_Ordinary. 15576d326448d7e4c10b2896edc2ee855d1e68d1b88John McCall /// C++ lexical operator lookup looks for these. 15676d326448d7e4c10b2896edc2ee855d1e68d1b88John McCall IDNS_NonMemberOperator = 0x0400 1570ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner }; 1581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15909e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// ObjCDeclQualifier - 'Qualifiers' written next to the return and 16009e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// parameter types in method declarations. Other than remembering 16109e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// them and mangling them into the method's signature string, these 16209e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// are ignored by the compiler; they are consumed by certain 16309e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// remote-messaging frameworks. 16409e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// 16509e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// in, inout, and out are mutually exclusive and apply only to 16609e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// method parameters. bycopy and byref are mutually exclusive and 16709e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// apply only to method parameters (?). oneway applies only to 16809e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// results. All of these expect their corresponding parameter to 16909e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// have a particular type. None of this is currently enforced by 17009e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// clang. 17109e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// 17209e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// This should be kept in sync with ObjCDeclSpec::ObjCDeclQualifier. 1730ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner enum ObjCDeclQualifier { 1740ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_None = 0x0, 1750ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_In = 0x1, 1760ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_Inout = 0x2, 1770ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_Out = 0x4, 1780ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_Bycopy = 0x8, 1790ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_Byref = 0x10, 1800ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_Oneway = 0x20 1810ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner }; 1821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1830ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnerprivate: 184244a67d911d08c3757a18ad666e4a268cf3ee285Chris Lattner /// NextDeclInContext - The next declaration within the same lexical 1854afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// DeclContext. These pointers form the linked list that is 1864afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// traversed via DeclContext's decls_begin()/decls_end(). 187244a67d911d08c3757a18ad666e4a268cf3ee285Chris Lattner Decl *NextDeclInContext; 1884afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 1894afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor friend class DeclContext; 1904afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 191ee219fd5f2776d8dd39d857f87304297b5ed743aChris Lattner struct MultipleDC { 192ee219fd5f2776d8dd39d857f87304297b5ed743aChris Lattner DeclContext *SemanticDC; 193ee219fd5f2776d8dd39d857f87304297b5ed743aChris Lattner DeclContext *LexicalDC; 194ee219fd5f2776d8dd39d857f87304297b5ed743aChris Lattner }; 1951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1974afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// DeclCtx - Holds either a DeclContext* or a MultipleDC*. 1984afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// For declarations that don't contain C++ scope specifiers, it contains 1994afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// the DeclContext where the Decl was declared. 2004afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// For declarations with C++ scope specifiers, it contains a MultipleDC* 2014afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// with the context where it semantically belongs (SemanticDC) and the 2024afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// context where it was lexically declared (LexicalDC). 2034afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// e.g.: 2044afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// 2054afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// namespace A { 2064afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// void f(); // SemanticDC == LexicalDC == 'namespace A' 2074afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// } 2084afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// void A::f(); // SemanticDC == namespace 'A' 2094afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// // LexicalDC == global namespace 210ee219fd5f2776d8dd39d857f87304297b5ed743aChris Lattner llvm::PointerUnion<DeclContext*, MultipleDC*> DeclCtx; 2114afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 212ee219fd5f2776d8dd39d857f87304297b5ed743aChris Lattner inline bool isInSemaDC() const { return DeclCtx.is<DeclContext*>(); } 213ee219fd5f2776d8dd39d857f87304297b5ed743aChris Lattner inline bool isOutOfSemaDC() const { return DeclCtx.is<MultipleDC*>(); } 2144afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor inline MultipleDC *getMultipleDC() const { 215ee219fd5f2776d8dd39d857f87304297b5ed743aChris Lattner return DeclCtx.get<MultipleDC*>(); 2164afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 21710d8379676f32b493740a5509e2cd7f0d6433139Chris Lattner inline DeclContext *getSemanticDC() const { 218ee219fd5f2776d8dd39d857f87304297b5ed743aChris Lattner return DeclCtx.get<DeclContext*>(); 21910d8379676f32b493740a5509e2cd7f0d6433139Chris Lattner } 2201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 221381d34e0b205ca27bcc7e7c1652561941c437965Douglas Gregor /// Loc - The location of this decl. 22239d7650656fdd1be879ed7d0c722cfeae95e56d5Daniel Dunbar SourceLocation Loc; 2231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2240ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// DeclKind - This indicates which class this is. 22535043e56150dc4eda882acd5ddfe0f8e3c0a8cb1John McCall unsigned DeclKind : 8; 2261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2270ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// InvalidDecl - This indicates a semantic error occurred. 22835043e56150dc4eda882acd5ddfe0f8e3c0a8cb1John McCall unsigned InvalidDecl : 1; 2291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2300ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// HasAttrs - This indicates whether the decl has attributes or not. 23135043e56150dc4eda882acd5ddfe0f8e3c0a8cb1John McCall unsigned HasAttrs : 1; 232d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis 2336b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor /// Implicit - Whether this declaration was implicitly generated by 2346b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor /// the implementation rather than explicitly written by the user. 23535043e56150dc4eda882acd5ddfe0f8e3c0a8cb1John McCall unsigned Implicit : 1; 2366b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor 237e0762c92110dfdcdd207db461a4ea17afd168f1eDouglas Gregor /// \brief Whether this declaration was "used", meaning that a definition is 238e0762c92110dfdcdd207db461a4ea17afd168f1eDouglas Gregor /// required. 23935043e56150dc4eda882acd5ddfe0f8e3c0a8cb1John McCall unsigned Used : 1; 2409cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor 2416b6b42aed07726178f61954ac6e51f47da00275cArgyrios Kyrtzidis /// \brief Whether this declaration was "referenced". 2426b6b42aed07726178f61954ac6e51f47da00275cArgyrios Kyrtzidis /// The difference with 'Used' is whether the reference appears in a 2436b6b42aed07726178f61954ac6e51f47da00275cArgyrios Kyrtzidis /// evaluated context or not, e.g. functions used in uninstantiated templates 2446b6b42aed07726178f61954ac6e51f47da00275cArgyrios Kyrtzidis /// are regarded as "referenced" but not "used". 2456b6b42aed07726178f61954ac6e51f47da00275cArgyrios Kyrtzidis unsigned Referenced : 1; 2468d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor 2479cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregorprotected: 2487d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor /// Access - Used by C++ decls for the access specifier. 2497d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor // NOTE: VC++ treats enums as signed, avoid using the AccessSpecifier enum 2507d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor unsigned Access : 2; 2517d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor friend class CXXClassMemberWrapper; 2520b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl 25308e0bc16b3312c27e87d33be7dcf3d4fe5bdd2e2Douglas Gregor /// \brief Whether this declaration was loaded from an AST file. 25408e0bc16b3312c27e87d33be7dcf3d4fe5bdd2e2Douglas Gregor unsigned FromASTFile : 1; 25508e0bc16b3312c27e87d33be7dcf3d4fe5bdd2e2Douglas Gregor 2563c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl /// ChangedAfterLoad - if this declaration has changed since being loaded 25735043e56150dc4eda882acd5ddfe0f8e3c0a8cb1John McCall unsigned ChangedAfterLoad : 1; 2580b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl 2598d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor /// \brief Whether this declaration is private to the module in which it was 2608d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor /// defined. 2618d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor unsigned ModulePrivate : 1; 2628d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor 263769dbdf467681f6020ff248b969c2d41a4fdccd3Chris Lattner /// IdentifierNamespace - This specifies what IDNS_* namespace this lives in. 264381d34e0b205ca27bcc7e7c1652561941c437965Douglas Gregor unsigned IdentifierNamespace : 12; 2651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 266381d34e0b205ca27bcc7e7c1652561941c437965Douglas Gregor /// \brief Whether the \c CachedLinkage field is active. 267381d34e0b205ca27bcc7e7c1652561941c437965Douglas Gregor /// 268381d34e0b205ca27bcc7e7c1652561941c437965Douglas Gregor /// This field is only valid for NamedDecls subclasses. 269381d34e0b205ca27bcc7e7c1652561941c437965Douglas Gregor mutable unsigned HasCachedLinkage : 1; 270381d34e0b205ca27bcc7e7c1652561941c437965Douglas Gregor 271381d34e0b205ca27bcc7e7c1652561941c437965Douglas Gregor /// \brief If \c HasCachedLinkage, the linkage of this declaration. 272381d34e0b205ca27bcc7e7c1652561941c437965Douglas Gregor /// 273381d34e0b205ca27bcc7e7c1652561941c437965Douglas Gregor /// This field is only valid for NamedDecls subclasses. 274381d34e0b205ca27bcc7e7c1652561941c437965Douglas Gregor mutable unsigned CachedLinkage : 2; 275381d34e0b205ca27bcc7e7c1652561941c437965Douglas Gregor 2768d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor friend class ASTDeclWriter; 2778d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor friend class ASTDeclReader; 2788d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor 2799cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregorprivate: 2801329c274628cc8c4e8ad472b41d1a78c8123f611Anders Carlsson void CheckAccessDeclContext() const; 2811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2824afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorprotected: 283d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis 2841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Decl(Kind DK, DeclContext *DC, SourceLocation L) 2851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : NextDeclInContext(0), DeclCtx(DC), 28639d7650656fdd1be879ed7d0c722cfeae95e56d5Daniel Dunbar Loc(L), DeclKind(DK), InvalidDecl(0), 2876b6b42aed07726178f61954ac6e51f47da00275cArgyrios Kyrtzidis HasAttrs(false), Implicit(false), Used(false), Referenced(false), 28808e0bc16b3312c27e87d33be7dcf3d4fe5bdd2e2Douglas Gregor Access(AS_none), FromASTFile(0), ChangedAfterLoad(false), 2898d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor ModulePrivate(0), 290381d34e0b205ca27bcc7e7c1652561941c437965Douglas Gregor IdentifierNamespace(getIdentifierNamespaceForKind(DK)), 291381d34e0b205ca27bcc7e7c1652561941c437965Douglas Gregor HasCachedLinkage(0) 292381d34e0b205ca27bcc7e7c1652561941c437965Douglas Gregor { 2939a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt if (Decl::CollectingStats()) add(DK); 2940ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 2951bb19638f2ec0d63ed131b51ca8d9542d1a9afeeSam Bishop 2966764334dfa73d67cbbb1b1fc8fe00440aad00f2aArgyrios Kyrtzidis Decl(Kind DK, EmptyShell Empty) 2976764334dfa73d67cbbb1b1fc8fe00440aad00f2aArgyrios Kyrtzidis : NextDeclInContext(0), DeclKind(DK), InvalidDecl(0), 2986b6b42aed07726178f61954ac6e51f47da00275cArgyrios Kyrtzidis HasAttrs(false), Implicit(false), Used(false), Referenced(false), 29908e0bc16b3312c27e87d33be7dcf3d4fe5bdd2e2Douglas Gregor Access(AS_none), FromASTFile(0), ChangedAfterLoad(false), 3008d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor ModulePrivate(0), 301381d34e0b205ca27bcc7e7c1652561941c437965Douglas Gregor IdentifierNamespace(getIdentifierNamespaceForKind(DK)), 302381d34e0b205ca27bcc7e7c1652561941c437965Douglas Gregor HasCachedLinkage(0) 303381d34e0b205ca27bcc7e7c1652561941c437965Douglas Gregor { 3046764334dfa73d67cbbb1b1fc8fe00440aad00f2aArgyrios Kyrtzidis if (Decl::CollectingStats()) add(DK); 3056764334dfa73d67cbbb1b1fc8fe00440aad00f2aArgyrios Kyrtzidis } 3066764334dfa73d67cbbb1b1fc8fe00440aad00f2aArgyrios Kyrtzidis 307da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor virtual ~Decl(); 308da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor 3091bb19638f2ec0d63ed131b51ca8d9542d1a9afeeSam Bishoppublic: 31055d608cbadf1e9c05064f9287c057d50b7df65b4Argyrios Kyrtzidis 31155d608cbadf1e9c05064f9287c057d50b7df65b4Argyrios Kyrtzidis /// \brief Source range that this declaration covers. 312da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor virtual SourceRange getSourceRange() const { 313da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor return SourceRange(getLocation(), getLocation()); 314da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor } 31555d608cbadf1e9c05064f9287c057d50b7df65b4Argyrios Kyrtzidis SourceLocation getLocStart() const { return getSourceRange().getBegin(); } 31655d608cbadf1e9c05064f9287c057d50b7df65b4Argyrios Kyrtzidis SourceLocation getLocEnd() const { return getSourceRange().getEnd(); } 31755d608cbadf1e9c05064f9287c057d50b7df65b4Argyrios Kyrtzidis 3180ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner SourceLocation getLocation() const { return Loc; } 3190ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner void setLocation(SourceLocation L) { Loc = L; } 3200ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 32135043e56150dc4eda882acd5ddfe0f8e3c0a8cb1John McCall Kind getKind() const { return static_cast<Kind>(DeclKind); } 3220ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner const char *getDeclKindName() const; 3231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 324244a67d911d08c3757a18ad666e4a268cf3ee285Chris Lattner Decl *getNextDeclInContext() { return NextDeclInContext; } 325244a67d911d08c3757a18ad666e4a268cf3ee285Chris Lattner const Decl *getNextDeclInContext() const { return NextDeclInContext; } 32696f4468b6b1bf69bb01c1207f716a3ffaeb4a8d3Chris Lattner 3274afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor DeclContext *getDeclContext() { 32810d8379676f32b493740a5509e2cd7f0d6433139Chris Lattner if (isInSemaDC()) 32910d8379676f32b493740a5509e2cd7f0d6433139Chris Lattner return getSemanticDC(); 33010d8379676f32b493740a5509e2cd7f0d6433139Chris Lattner return getMultipleDC()->SemanticDC; 3314afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 3320cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner const DeclContext *getDeclContext() const { 3330cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner return const_cast<Decl*>(this)->getDeclContext(); 3340cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner } 3353708b3df2e86998dca4c006939014ea1174da834Argyrios Kyrtzidis 336aab9e315184d344bbd733f13b68915d02db7b32bJohn McCall /// Finds the innermost non-closure context of this declaration. 337aab9e315184d344bbd733f13b68915d02db7b32bJohn McCall /// That is, walk out the DeclContext chain, skipping any blocks. 338aab9e315184d344bbd733f13b68915d02db7b32bJohn McCall DeclContext *getNonClosureContext(); 339aab9e315184d344bbd733f13b68915d02db7b32bJohn McCall const DeclContext *getNonClosureContext() const { 340aab9e315184d344bbd733f13b68915d02db7b32bJohn McCall return const_cast<Decl*>(this)->getNonClosureContext(); 341aab9e315184d344bbd733f13b68915d02db7b32bJohn McCall } 342aab9e315184d344bbd733f13b68915d02db7b32bJohn McCall 3433708b3df2e86998dca4c006939014ea1174da834Argyrios Kyrtzidis TranslationUnitDecl *getTranslationUnitDecl(); 3443708b3df2e86998dca4c006939014ea1174da834Argyrios Kyrtzidis const TranslationUnitDecl *getTranslationUnitDecl() const { 3453708b3df2e86998dca4c006939014ea1174da834Argyrios Kyrtzidis return const_cast<Decl*>(this)->getTranslationUnitDecl(); 3463708b3df2e86998dca4c006939014ea1174da834Argyrios Kyrtzidis } 3473708b3df2e86998dca4c006939014ea1174da834Argyrios Kyrtzidis 3489aeed32282fe8a775c24c01c923717ca86695685John McCall bool isInAnonymousNamespace() const; 3499aeed32282fe8a775c24c01c923717ca86695685John McCall 3503708b3df2e86998dca4c006939014ea1174da834Argyrios Kyrtzidis ASTContext &getASTContext() const; 3511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3521329c274628cc8c4e8ad472b41d1a78c8123f611Anders Carlsson void setAccess(AccessSpecifier AS) { 3531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Access = AS; 3543a1c36c099df4dcc94d1d24516a8a2c809c764d4Douglas Gregor#ifndef NDEBUG 3551329c274628cc8c4e8ad472b41d1a78c8123f611Anders Carlsson CheckAccessDeclContext(); 3563a1c36c099df4dcc94d1d24516a8a2c809c764d4Douglas Gregor#endif 3571329c274628cc8c4e8ad472b41d1a78c8123f611Anders Carlsson } 3581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump AccessSpecifier getAccess() const { 3603a1c36c099df4dcc94d1d24516a8a2c809c764d4Douglas Gregor#ifndef NDEBUG 3611329c274628cc8c4e8ad472b41d1a78c8123f611Anders Carlsson CheckAccessDeclContext(); 3623a1c36c099df4dcc94d1d24516a8a2c809c764d4Douglas Gregor#endif 3631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return AccessSpecifier(Access); 364b8547e800f9553a72c2f3635ae2371692bd4411aAnders Carlsson } 3654afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 36676a642ff4fce7a0648c79a1f01324a8c3880e251Chris Lattner bool hasAttrs() const { return HasAttrs; } 367cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt void setAttrs(const AttrVec& Attrs); 368ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner AttrVec &getAttrs() { 369cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt return const_cast<AttrVec&>(const_cast<const Decl*>(this)->getAttrs()); 37081abbdd848aa02c30242bd22dcc6ffe024ae2957Chris Lattner } 371cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt const AttrVec &getAttrs() const; 37240b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis void swapAttrs(Decl *D); 373cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt void dropAttrs(); 3740ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 375b5f35bae05f1ce3ae62ca52b266a086fd019e89bDouglas Gregor void addAttr(Attr *A) { 376b5f35bae05f1ce3ae62ca52b266a086fd019e89bDouglas Gregor if (hasAttrs()) 377b5f35bae05f1ce3ae62ca52b266a086fd019e89bDouglas Gregor getAttrs().push_back(A); 378b5f35bae05f1ce3ae62ca52b266a086fd019e89bDouglas Gregor else 379b5f35bae05f1ce3ae62ca52b266a086fd019e89bDouglas Gregor setAttrs(AttrVec(1, A)); 380b5f35bae05f1ce3ae62ca52b266a086fd019e89bDouglas Gregor } 3811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 382cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt typedef AttrVec::const_iterator attr_iterator; 383cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt 384cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt // FIXME: Do not rely on iterators having comparable singular values. 385cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt // Note that this should error out if they do not. 386cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt attr_iterator attr_begin() const { 387cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt return hasAttrs() ? getAttrs().begin() : 0; 388cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt } 389cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt attr_iterator attr_end() const { 390cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt return hasAttrs() ? getAttrs().end() : 0; 391cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt } 392c3ca14d13741889a9b924d0ca32e818f07a9834aFariborz Jahanian 393c3ca14d13741889a9b924d0ca32e818f07a9834aFariborz Jahanian template <typename T> 3948cf0f52037e0c4bf656953ae63a07e8156aeb5fbFariborz Jahanian void dropAttr() { 3958cf0f52037e0c4bf656953ae63a07e8156aeb5fbFariborz Jahanian if (!HasAttrs) return; 3968cf0f52037e0c4bf656953ae63a07e8156aeb5fbFariborz Jahanian 3978cf0f52037e0c4bf656953ae63a07e8156aeb5fbFariborz Jahanian AttrVec &Attrs = getAttrs(); 3988cf0f52037e0c4bf656953ae63a07e8156aeb5fbFariborz Jahanian for (unsigned i = 0, e = Attrs.size(); i != e; /* in loop */) { 3998cf0f52037e0c4bf656953ae63a07e8156aeb5fbFariborz Jahanian if (isa<T>(Attrs[i])) { 4008cf0f52037e0c4bf656953ae63a07e8156aeb5fbFariborz Jahanian Attrs.erase(Attrs.begin() + i); 4018cf0f52037e0c4bf656953ae63a07e8156aeb5fbFariborz Jahanian --e; 4028cf0f52037e0c4bf656953ae63a07e8156aeb5fbFariborz Jahanian } 4038cf0f52037e0c4bf656953ae63a07e8156aeb5fbFariborz Jahanian else 4048cf0f52037e0c4bf656953ae63a07e8156aeb5fbFariborz Jahanian ++i; 4058cf0f52037e0c4bf656953ae63a07e8156aeb5fbFariborz Jahanian } 4068cf0f52037e0c4bf656953ae63a07e8156aeb5fbFariborz Jahanian if (Attrs.empty()) 4078cf0f52037e0c4bf656953ae63a07e8156aeb5fbFariborz Jahanian HasAttrs = false; 4088cf0f52037e0c4bf656953ae63a07e8156aeb5fbFariborz Jahanian } 4098cf0f52037e0c4bf656953ae63a07e8156aeb5fbFariborz Jahanian 410cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt template <typename T> 411cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt specific_attr_iterator<T> specific_attr_begin() const { 412cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt return specific_attr_iterator<T>(attr_begin()); 413cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt } 414cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt template <typename T> 415cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt specific_attr_iterator<T> specific_attr_end() const { 416cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt return specific_attr_iterator<T>(attr_end()); 417cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt } 418cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt 419cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt template<typename T> T *getAttr() const { 420cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt return hasAttrs() ? getSpecificAttr<T>(getAttrs()) : 0; 421cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt } 42240b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis template<typename T> bool hasAttr() const { 423cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt return hasAttrs() && hasSpecificAttr<T>(getAttrs()); 424cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt } 425cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt 426cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt /// getMaxAlignment - return the maximum alignment specified by attributes 427cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt /// on this decl, 0 if there are none. 428cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt unsigned getMaxAlignment() const { 429cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt return hasAttrs() ? getMaxAttrAlignment(getAttrs(), getASTContext()) : 0; 430115cafcafec3572756635ca81ef83999ae0c8af7Chris Lattner } 4311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4320ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// setInvalidDecl - Indicates the Decl had a semantic error. This 4330ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// allows for graceful error recovery. 43442738573253da1bd61f9c44f8d77f600d3b0cd1cDouglas Gregor void setInvalidDecl(bool Invalid = true); 4350ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner bool isInvalidDecl() const { return (bool) InvalidDecl; } 4366b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor 4376b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor /// isImplicit - Indicates whether the declaration was implicitly 4386b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor /// generated by the implementation. If false, this declaration 4396b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor /// was written explicitly in the source code. 4406b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor bool isImplicit() const { return Implicit; } 4416b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor void setImplicit(bool I = true) { Implicit = I; } 4421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 443e0762c92110dfdcdd207db461a4ea17afd168f1eDouglas Gregor /// \brief Whether this declaration was used, meaning that a definition 444e0762c92110dfdcdd207db461a4ea17afd168f1eDouglas Gregor /// is required. 445c070cc602d6eefea881f71a60de09e05b54c3fddDouglas Gregor /// 446c070cc602d6eefea881f71a60de09e05b54c3fddDouglas Gregor /// \param CheckUsedAttr When true, also consider the "used" attribute 447c070cc602d6eefea881f71a60de09e05b54c3fddDouglas Gregor /// (in addition to the "used" bit set by \c setUsed()) when determining 448c070cc602d6eefea881f71a60de09e05b54c3fddDouglas Gregor /// whether the function is used. 449c070cc602d6eefea881f71a60de09e05b54c3fddDouglas Gregor bool isUsed(bool CheckUsedAttr = true) const; 450cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt 451e0762c92110dfdcdd207db461a4ea17afd168f1eDouglas Gregor void setUsed(bool U = true) { Used = U; } 4521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4536b6b42aed07726178f61954ac6e51f47da00275cArgyrios Kyrtzidis /// \brief Whether this declaration was referenced. 4546b6b42aed07726178f61954ac6e51f47da00275cArgyrios Kyrtzidis bool isReferenced() const; 4556b6b42aed07726178f61954ac6e51f47da00275cArgyrios Kyrtzidis 4566b6b42aed07726178f61954ac6e51f47da00275cArgyrios Kyrtzidis void setReferenced(bool R = true) { Referenced = R; } 4576b6b42aed07726178f61954ac6e51f47da00275cArgyrios Kyrtzidis 4580a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \brief Determine the availability of the given declaration. 4590a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// 4600a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// This routine will determine the most restrictive availability of 4610a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// the given declaration (e.g., preferring 'unavailable' to 4620a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// 'deprecated'). 4630a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// 4640a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \param Message If non-NULL and the result is not \c 4650a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// AR_Available, will be set to a (possibly empty) message 4660a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// describing why the declaration has not been introduced, is 4670a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// deprecated, or is unavailable. 4680a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor AvailabilityResult getAvailability(std::string *Message = 0) const; 4690a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor 4700a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \brief Determine whether this declaration is marked 'deprecated'. 4710a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// 4720a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \param Message If non-NULL and the declaration is deprecated, 4730a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// this will be set to the message describing why the declaration 4740a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// was deprecated (which may be empty). 4750a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor bool isDeprecated(std::string *Message = 0) const { 4760a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor return getAvailability(Message) == AR_Deprecated; 4770a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor } 4780a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor 4790a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \brief Determine whether this declaration is marked 'unavailable'. 4800a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// 4810a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \param Message If non-NULL and the declaration is unavailable, 4820a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// this will be set to the message describing why the declaration 4830a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// was made unavailable (which may be empty). 4840a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor bool isUnavailable(std::string *Message = 0) const { 4850a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor return getAvailability(Message) == AR_Unavailable; 4860a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor } 4870a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor 4880a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \brief Determine whether this is a weak-imported symbol. 4890a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// 4900a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// Weak-imported symbols are typically marked with the 4917f3ad231bed2184694e407772689e8903068bdcaEli Friedman /// 'weak_import' attribute, but may also be marked with an 4920a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// 'availability' attribute where we're targing a platform prior to 4930a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// the introduction of this feature. 4940a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor bool isWeakImported() const; 4950a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor 4960a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \brief Determines whether this symbol can be weak-imported, 4970a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// e.g., whether it would be well-formed to add the weak_import 4980a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// attribute. 4990a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// 5000a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \param IsDefinition Set to \c true to indicate that this 5010a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// declaration cannot be weak-imported because it has a definition. 5020a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor bool canBeWeakImported(bool &IsDefinition) const; 5030a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor 504919814def90acecd25a35445862f0c0ff72a9b05Douglas Gregor /// \brief Determine whether this declaration came from an AST file (such as 505919814def90acecd25a35445862f0c0ff72a9b05Douglas Gregor /// a precompiled header or module) rather than having been parsed. 50608e0bc16b3312c27e87d33be7dcf3d4fe5bdd2e2Douglas Gregor bool isFromASTFile() const { return FromASTFile; } 507919814def90acecd25a35445862f0c0ff72a9b05Douglas Gregor 5080b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl /// \brief Query whether this declaration was changed in a significant way 5093397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl /// since being loaded from an AST file. 5100b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl /// 5110b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl /// In an epic violation of layering, what is "significant" is entirely 5123397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl /// up to the serialization system, but implemented in AST and Sema. 5133c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl bool isChangedSinceDeserialization() const { return ChangedAfterLoad; } 5140b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl 5150b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl /// \brief Mark this declaration as having changed since deserialization, or 5160b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl /// reset the flag. 5173c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl void setChangedSinceDeserialization(bool Changed) { 5183c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl ChangedAfterLoad = Changed; 5193c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl } 5200b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl 521cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor unsigned getIdentifierNamespace() const { 522769dbdf467681f6020ff248b969c2d41a4fdccd3Chris Lattner return IdentifierNamespace; 5230ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 524d62fdc448b3ace606c8c9c9f13e43218fa204dbfChris Lattner bool isInIdentifierNamespace(unsigned NS) const { 525d62fdc448b3ace606c8c9c9f13e43218fa204dbfChris Lattner return getIdentifierNamespace() & NS; 526d62fdc448b3ace606c8c9c9f13e43218fa204dbfChris Lattner } 527769dbdf467681f6020ff248b969c2d41a4fdccd3Chris Lattner static unsigned getIdentifierNamespaceForKind(Kind DK); 528769dbdf467681f6020ff248b969c2d41a4fdccd3Chris Lattner 5290d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall bool hasTagIdentifierNamespace() const { 5300d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall return isTagIdentifierNamespace(getIdentifierNamespace()); 5310d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall } 5320d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall static bool isTagIdentifierNamespace(unsigned NS) { 5330d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall // TagDecls have Tag and Type set and may also have TagFriend. 5340d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall return (NS & ~IDNS_TagFriend) == (IDNS_Tag | IDNS_Type); 5350d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall } 5361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5374afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// getLexicalDeclContext - The declaration context where this Decl was 5384afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// lexically declared (LexicalDC). May be different from 5394afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// getDeclContext() (SemanticDC). 5404afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// e.g.: 5414afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// 5424afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// namespace A { 5434afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// void f(); // SemanticDC == LexicalDC == 'namespace A' 5444afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// } 5454afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// void A::f(); // SemanticDC == namespace 'A' 5464afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// // LexicalDC == global namespace 54710d8379676f32b493740a5509e2cd7f0d6433139Chris Lattner DeclContext *getLexicalDeclContext() { 5484afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor if (isInSemaDC()) 54910d8379676f32b493740a5509e2cd7f0d6433139Chris Lattner return getSemanticDC(); 5504afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return getMultipleDC()->LexicalDC; 5514afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 55210d8379676f32b493740a5509e2cd7f0d6433139Chris Lattner const DeclContext *getLexicalDeclContext() const { 55310d8379676f32b493740a5509e2cd7f0d6433139Chris Lattner return const_cast<Decl*>(this)->getLexicalDeclContext(); 5544afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 555f5cecfbdcd20be224861f9e67c5973a9a2b61512Argyrios Kyrtzidis 556da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor virtual bool isOutOfLine() const { 557da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor return getLexicalDeclContext() != getDeclContext(); 558da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor } 5591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5606ab3524f72a6e64aa04973fa9433b5559abb3525Douglas Gregor /// setDeclContext - Set both the semantic and lexical DeclContext 5616ab3524f72a6e64aa04973fa9433b5559abb3525Douglas Gregor /// to DC. 5626ab3524f72a6e64aa04973fa9433b5559abb3525Douglas Gregor void setDeclContext(DeclContext *DC); 5636ab3524f72a6e64aa04973fa9433b5559abb3525Douglas Gregor 5644afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor void setLexicalDeclContext(DeclContext *DC); 5654afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 5667a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl /// isDefinedOutsideFunctionOrMethod - This predicate returns true if this 5677a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl /// scoped decl is defined outside the current function or method. This is 5687a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl /// roughly global variables and functions, but also handles enums (which 5697a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl /// could be defined inside or outside a function etc). 570c8680f46970a5a53d07e05edd93657e64764da3cArgyrios Kyrtzidis bool isDefinedOutsideFunctionOrMethod() const { 571c8680f46970a5a53d07e05edd93657e64764da3cArgyrios Kyrtzidis return getParentFunctionOrMethod() == 0; 572c8680f46970a5a53d07e05edd93657e64764da3cArgyrios Kyrtzidis } 573c8680f46970a5a53d07e05edd93657e64764da3cArgyrios Kyrtzidis 574c8680f46970a5a53d07e05edd93657e64764da3cArgyrios Kyrtzidis /// \brief If this decl is defined inside a function/method/block it returns 575c8680f46970a5a53d07e05edd93657e64764da3cArgyrios Kyrtzidis /// the corresponding DeclContext, otherwise it returns null. 576c8680f46970a5a53d07e05edd93657e64764da3cArgyrios Kyrtzidis const DeclContext *getParentFunctionOrMethod() const; 577fcc1e50ebcb441c6c610ccd539f57c57549bd66cArgyrios Kyrtzidis DeclContext *getParentFunctionOrMethod() { 578fcc1e50ebcb441c6c610ccd539f57c57549bd66cArgyrios Kyrtzidis return const_cast<DeclContext*>( 579fcc1e50ebcb441c6c610ccd539f57c57549bd66cArgyrios Kyrtzidis const_cast<const Decl*>(this)->getParentFunctionOrMethod()); 580fcc1e50ebcb441c6c610ccd539f57c57549bd66cArgyrios Kyrtzidis } 5814afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 582b57a4fe73b8227c0dba651818b8495dfca61e530Argyrios Kyrtzidis /// \brief Retrieves the "canonical" declaration of the given declaration. 583da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor virtual Decl *getCanonicalDecl() { return this; } 584b57a4fe73b8227c0dba651818b8495dfca61e530Argyrios Kyrtzidis const Decl *getCanonicalDecl() const { 585b57a4fe73b8227c0dba651818b8495dfca61e530Argyrios Kyrtzidis return const_cast<Decl*>(this)->getCanonicalDecl(); 586b57a4fe73b8227c0dba651818b8495dfca61e530Argyrios Kyrtzidis } 587fc7e2a8fbb08f0f496ac6cea0721fe72db8ce240Argyrios Kyrtzidis 588ac4e3794c60fc194fb2bd9764aa81d4cae530eccArgyrios Kyrtzidis /// \brief Whether this particular Decl is a canonical one. 589b57a4fe73b8227c0dba651818b8495dfca61e530Argyrios Kyrtzidis bool isCanonicalDecl() const { return getCanonicalDecl() == this; } 5901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5911e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidisprotected: 5921e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis /// \brief Returns the next redeclaration or itself if this is the only decl. 5931e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis /// 5941e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis /// Decl subclasses that can be redeclared should override this method so that 5951e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis /// Decl::redecl_iterator can iterate over them. 596da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor virtual Decl *getNextRedeclaration() { return this; } 5971e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis 5981e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidispublic: 5991e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis /// \brief Iterates through all the redeclarations of the same decl. 6001e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis class redecl_iterator { 6011e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis /// Current - The current declaration. 6021e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis Decl *Current; 6031e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis Decl *Starter; 6041e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis 6051e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis public: 6061e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis typedef Decl* value_type; 6071e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis typedef Decl* reference; 6081e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis typedef Decl* pointer; 6091e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis typedef std::forward_iterator_tag iterator_category; 6101e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis typedef std::ptrdiff_t difference_type; 6111e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis 6121e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis redecl_iterator() : Current(0) { } 6131e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis explicit redecl_iterator(Decl *C) : Current(C), Starter(C) { } 6141e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis 6151e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis reference operator*() const { return Current; } 6161e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis pointer operator->() const { return Current; } 6171e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis 6181e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis redecl_iterator& operator++() { 6191e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis assert(Current && "Advancing while iterator has reached end"); 6201e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis // Get either previous decl or latest decl. 6211e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis Decl *Next = Current->getNextRedeclaration(); 62222cbd2b794676c3b29c2b401c26730ed7047809eArgyrios Kyrtzidis assert(Next && "Should return next redeclaration or itself, never null!"); 6231e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis Current = (Next != Starter ? Next : 0); 6241e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis return *this; 6251e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis } 6261e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis 6271e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis redecl_iterator operator++(int) { 6281e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis redecl_iterator tmp(*this); 6291e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis ++(*this); 6301e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis return tmp; 6311e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis } 6321e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis 6331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump friend bool operator==(redecl_iterator x, redecl_iterator y) { 6341e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis return x.Current == y.Current; 6351e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis } 6361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump friend bool operator!=(redecl_iterator x, redecl_iterator y) { 6371e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis return x.Current != y.Current; 6381e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis } 6391e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis }; 6401e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis 6411e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis /// \brief Returns iterator for all the redeclarations of the same decl. 6421e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis /// It will iterate at least once (when this decl is the only one). 6431e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis redecl_iterator redecls_begin() const { 6441e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis return redecl_iterator(const_cast<Decl*>(this)); 6451e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis } 6461e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis redecl_iterator redecls_end() const { return redecl_iterator(); } 647fc7e2a8fbb08f0f496ac6cea0721fe72db8ce240Argyrios Kyrtzidis 648d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl /// getBody - If this Decl represents a declaration for a body of code, 649d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl /// such as a function or method definition, this method returns the 650d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl /// top-level Stmt* of that body. Otherwise this method returns null. 651da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor virtual Stmt* getBody() const { return 0; } 652d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl 65306a54a38be5054c910ffc92db60edab23f9ea105Argyrios Kyrtzidis /// \brief Returns true if this Decl represents a declaration for a body of 65406a54a38be5054c910ffc92db60edab23f9ea105Argyrios Kyrtzidis /// code, such as a function or method definition. 655da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor virtual bool hasBody() const { return getBody() != 0; } 65606a54a38be5054c910ffc92db60edab23f9ea105Argyrios Kyrtzidis 657d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl /// getBodyRBrace - Gets the right brace of the body, if a body exists. 658d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl /// This works whether the body is a CompoundStmt or a CXXTryStmt. 6596fb0aee4f9dc261bbec72e1283ad8dc0557a6d96Argyrios Kyrtzidis SourceLocation getBodyRBrace() const; 660d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl 6610ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner // global temp stats (until we have a per-module visitor) 6629a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt static void add(Kind k); 6630ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner static bool CollectingStats(bool Enable = false); 6640ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner static void PrintStats(); 6651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 66667e332009c6e349dc34700f539747afcff990336Anders Carlsson /// isTemplateParameter - Determines whether this declaration is a 667f57172b24f08a68d179675989813d5479dc87829Douglas Gregor /// template parameter. 668f57172b24f08a68d179675989813d5479dc87829Douglas Gregor bool isTemplateParameter() const; 6691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 67067e332009c6e349dc34700f539747afcff990336Anders Carlsson /// isTemplateParameter - Determines whether this declaration is a 67167e332009c6e349dc34700f539747afcff990336Anders Carlsson /// template parameter pack. 67267e332009c6e349dc34700f539747afcff990336Anders Carlsson bool isTemplateParameterPack() const; 673f57172b24f08a68d179675989813d5479dc87829Douglas Gregor 6741fe85ea697fb5c85acded3ac0ddbc19f89c2e181Douglas Gregor /// \brief Whether this declaration is a parameter pack. 6751fe85ea697fb5c85acded3ac0ddbc19f89c2e181Douglas Gregor bool isParameterPack() const; 6761fe85ea697fb5c85acded3ac0ddbc19f89c2e181Douglas Gregor 677ed9d84a2112e2bd56befb5f4fa8fc5bdf71fafa3Caitlin Sadowski /// \brief returns true if this declaration is a template 678ed9d84a2112e2bd56befb5f4fa8fc5bdf71fafa3Caitlin Sadowski bool isTemplateDecl() const; 679ed9d84a2112e2bd56befb5f4fa8fc5bdf71fafa3Caitlin Sadowski 680e53060fa78ad7e98352049f72787bdb7543e2a48Douglas Gregor /// \brief Whether this declaration is a function or function template. 681e53060fa78ad7e98352049f72787bdb7543e2a48Douglas Gregor bool isFunctionOrFunctionTemplate() const; 68202cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall 68302cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// \brief Changes the namespace of this declaration to reflect that it's 68402cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// the object of a friend declaration. 68502cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// 68602cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// These declarations appear in the lexical context of the friending 68702cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// class, but in the semantic context of the actual entity. This property 68802cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// applies only to a specific decl object; other redeclarations of the 68902cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// same entity may not (and probably don't) share this property. 69002cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall void setObjectOfFriendDecl(bool PreviouslyDeclared) { 69102cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall unsigned OldNS = IdentifierNamespace; 692b0cb022daec8671406ab25f4b5d5a6d48d823bc4John McCall assert((OldNS & (IDNS_Tag | IDNS_Ordinary | 693b0cb022daec8671406ab25f4b5d5a6d48d823bc4John McCall IDNS_TagFriend | IDNS_OrdinaryFriend)) && 694b0cb022daec8671406ab25f4b5d5a6d48d823bc4John McCall "namespace includes neither ordinary nor tag"); 6950d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall assert(!(OldNS & ~(IDNS_Tag | IDNS_Ordinary | IDNS_Type | 696b0cb022daec8671406ab25f4b5d5a6d48d823bc4John McCall IDNS_TagFriend | IDNS_OrdinaryFriend)) && 697b0cb022daec8671406ab25f4b5d5a6d48d823bc4John McCall "namespace includes other than ordinary or tag"); 698b0cb022daec8671406ab25f4b5d5a6d48d823bc4John McCall 699b0cb022daec8671406ab25f4b5d5a6d48d823bc4John McCall IdentifierNamespace = 0; 700b0cb022daec8671406ab25f4b5d5a6d48d823bc4John McCall if (OldNS & (IDNS_Tag | IDNS_TagFriend)) { 70102cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall IdentifierNamespace |= IDNS_TagFriend; 7020d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall if (PreviouslyDeclared) IdentifierNamespace |= IDNS_Tag | IDNS_Type; 703b0cb022daec8671406ab25f4b5d5a6d48d823bc4John McCall } 704b0cb022daec8671406ab25f4b5d5a6d48d823bc4John McCall 705b0cb022daec8671406ab25f4b5d5a6d48d823bc4John McCall if (OldNS & (IDNS_Ordinary | IDNS_OrdinaryFriend)) { 70602cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall IdentifierNamespace |= IDNS_OrdinaryFriend; 707b0cb022daec8671406ab25f4b5d5a6d48d823bc4John McCall if (PreviouslyDeclared) IdentifierNamespace |= IDNS_Ordinary; 708b0cb022daec8671406ab25f4b5d5a6d48d823bc4John McCall } 70902cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall } 71002cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall 71102cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall enum FriendObjectKind { 71202cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall FOK_None, // not a friend object 71302cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall FOK_Declared, // a friend of a previously-declared entity 71402cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall FOK_Undeclared // a friend of a previously-undeclared entity 71502cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall }; 71602cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall 71702cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// \brief Determines whether this declaration is the object of a 71802cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// friend declaration and, if so, what kind. 71902cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// 72002cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// There is currently no direct way to find the associated FriendDecl. 72102cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall FriendObjectKind getFriendObjectKind() const { 72202cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall unsigned mask 72302cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall = (IdentifierNamespace & (IDNS_TagFriend | IDNS_OrdinaryFriend)); 72402cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall if (!mask) return FOK_None; 725255d6415a692e8384971755f91541497d54b3193Anders Carlsson return (IdentifierNamespace & (IDNS_Tag | IDNS_Ordinary) ? 726255d6415a692e8384971755f91541497d54b3193Anders Carlsson FOK_Declared : FOK_Undeclared); 72702cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall } 7281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 72976d326448d7e4c10b2896edc2ee855d1e68d1b88John McCall /// Specifies that this declaration is a C++ overloaded non-member. 73076d326448d7e4c10b2896edc2ee855d1e68d1b88John McCall void setNonMemberOperator() { 73176d326448d7e4c10b2896edc2ee855d1e68d1b88John McCall assert(getKind() == Function || getKind() == FunctionTemplate); 73276d326448d7e4c10b2896edc2ee855d1e68d1b88John McCall assert((IdentifierNamespace & IDNS_Ordinary) && 73376d326448d7e4c10b2896edc2ee855d1e68d1b88John McCall "visible non-member operators should be in ordinary namespace"); 73476d326448d7e4c10b2896edc2ee855d1e68d1b88John McCall IdentifierNamespace |= IDNS_NonMemberOperator; 73576d326448d7e4c10b2896edc2ee855d1e68d1b88John McCall } 73676d326448d7e4c10b2896edc2ee855d1e68d1b88John McCall 7370ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner // Implement isa/cast/dyncast/etc. 7380ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner static bool classof(const Decl *) { return true; } 73980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { return true; } 74042220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis static DeclContext *castToDeclContext(const Decl *); 74142220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis static Decl *castFromDeclContext(const DeclContext *); 7421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7435cb3d699f0e37de1767eb23d26d03953a46cf1ffRichard Trieu void print(raw_ostream &Out, unsigned Indentation = 0, 7445cb3d699f0e37de1767eb23d26d03953a46cf1ffRichard Trieu bool PrintInstantiation = false) const; 7458cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner void print(raw_ostream &Out, const PrintingPolicy &Policy, 7465cb3d699f0e37de1767eb23d26d03953a46cf1ffRichard Trieu unsigned Indentation = 0, bool PrintInstantiation = false) const; 74742f42c0dd5cf71fbfc6fa282d03079a902f6e342Eli Friedman static void printGroup(Decl** Begin, unsigned NumDecls, 7488cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner raw_ostream &Out, const PrintingPolicy &Policy, 74942f42c0dd5cf71fbfc6fa282d03079a902f6e342Eli Friedman unsigned Indentation = 0); 750f88df8652e0726fe9eee5d78f92e3c5b34d0a537Anders Carlsson void dump() const; 751f35142413974e9dfe2c5f202084db4bd1c2073e9John McCall void dumpXML() const; 7528cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner void dumpXML(raw_ostream &OS) const; 7534fe0c8e9c76b96e7aff21696a40dacc09d0237bcDouglas Gregor 75481abbdd848aa02c30242bd22dcc6ffe024ae2957Chris Lattnerprivate: 75540b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis const Attr *getAttrsImpl() const; 75681abbdd848aa02c30242bd22dcc6ffe024ae2957Chris Lattner 7577b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidisprotected: 7587b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis ASTMutationListener *getASTMutationListener() const; 7590ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner}; 7600ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 76149f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner/// PrettyStackTraceDecl - If a crash occurs, indicate that it happened when 76249f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner/// doing something to a specific decl. 76349f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattnerclass PrettyStackTraceDecl : public llvm::PrettyStackTraceEntry { 764c52365674b5b157a0486f75c12dd9f4cc41d8089Daniel Dunbar const Decl *TheDecl; 76549f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner SourceLocation Loc; 76649f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner SourceManager &SM; 76749f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner const char *Message; 76849f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattnerpublic: 769c52365674b5b157a0486f75c12dd9f4cc41d8089Daniel Dunbar PrettyStackTraceDecl(const Decl *theDecl, SourceLocation L, 77049f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner SourceManager &sm, const char *Msg) 77149f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner : TheDecl(theDecl), Loc(L), SM(sm), Message(Msg) {} 7721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7738cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner virtual void print(raw_ostream &OS) const; 7741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump}; 7751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7766d9496d2d22817aeb286dd7007923e14f10fa8a6John McCallclass DeclContextLookupResult 7776d9496d2d22817aeb286dd7007923e14f10fa8a6John McCall : public std::pair<NamedDecl**,NamedDecl**> { 778ea318642072d3d94b5c3cff0fa6f4b33d2db0768John McCallpublic: 7796d9496d2d22817aeb286dd7007923e14f10fa8a6John McCall DeclContextLookupResult(NamedDecl **I, NamedDecl **E) 7806d9496d2d22817aeb286dd7007923e14f10fa8a6John McCall : std::pair<NamedDecl**,NamedDecl**>(I, E) {} 7816d9496d2d22817aeb286dd7007923e14f10fa8a6John McCall DeclContextLookupResult() 7826d9496d2d22817aeb286dd7007923e14f10fa8a6John McCall : std::pair<NamedDecl**,NamedDecl**>() {} 783ea318642072d3d94b5c3cff0fa6f4b33d2db0768John McCall 784f29815affe5d28c499d21c0be9bb078c52025ae6John McCall using std::pair<NamedDecl**,NamedDecl**>::operator=; 785ea318642072d3d94b5c3cff0fa6f4b33d2db0768John McCall}; 786ea318642072d3d94b5c3cff0fa6f4b33d2db0768John McCall 787ea318642072d3d94b5c3cff0fa6f4b33d2db0768John McCallclass DeclContextLookupConstResult 788ea318642072d3d94b5c3cff0fa6f4b33d2db0768John McCall : public std::pair<NamedDecl*const*, NamedDecl*const*> { 789ea318642072d3d94b5c3cff0fa6f4b33d2db0768John McCallpublic: 790ea318642072d3d94b5c3cff0fa6f4b33d2db0768John McCall DeclContextLookupConstResult(std::pair<NamedDecl**,NamedDecl**> R) 7916d9496d2d22817aeb286dd7007923e14f10fa8a6John McCall : std::pair<NamedDecl*const*, NamedDecl*const*>(R) {} 792ea318642072d3d94b5c3cff0fa6f4b33d2db0768John McCall DeclContextLookupConstResult(NamedDecl * const *I, NamedDecl * const *E) 7936d9496d2d22817aeb286dd7007923e14f10fa8a6John McCall : std::pair<NamedDecl*const*, NamedDecl*const*>(I, E) {} 7946d9496d2d22817aeb286dd7007923e14f10fa8a6John McCall DeclContextLookupConstResult() 7956d9496d2d22817aeb286dd7007923e14f10fa8a6John McCall : std::pair<NamedDecl*const*, NamedDecl*const*>() {} 796ea318642072d3d94b5c3cff0fa6f4b33d2db0768John McCall 797f29815affe5d28c499d21c0be9bb078c52025ae6John McCall using std::pair<NamedDecl*const*,NamedDecl*const*>::operator=; 798ea318642072d3d94b5c3cff0fa6f4b33d2db0768John McCall}; 79949f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner 800b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner/// DeclContext - This is used only as base class of specific decl types that 8011ad4dd78ec53c24ea9e752b216035d7aa666fe49Argyrios Kyrtzidis/// can act as declaration contexts. These decls are (only the top classes 8021ad4dd78ec53c24ea9e752b216035d7aa666fe49Argyrios Kyrtzidis/// that directly derive from DeclContext are mentioned, not their subclasses): 8030ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner/// 804ef177820100ab583b08fd3056e2a5a52ee4b1629Argyrios Kyrtzidis/// TranslationUnitDecl 8052d1c5d313cd0c229cc614e74baa4c5756a4b46f4Argyrios Kyrtzidis/// NamespaceDecl 8060ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner/// FunctionDecl 8071ad4dd78ec53c24ea9e752b216035d7aa666fe49Argyrios Kyrtzidis/// TagDecl 808d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis/// ObjCMethodDecl 8091ad4dd78ec53c24ea9e752b216035d7aa666fe49Argyrios Kyrtzidis/// ObjCContainerDecl 810074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor/// LinkageSpecDecl 81156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff/// BlockDecl 8121ad4dd78ec53c24ea9e752b216035d7aa666fe49Argyrios Kyrtzidis/// 813b048c9835969c4f7fe06264748be18ed4b442116Chris Lattnerclass DeclContext { 8140ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// DeclKind - This indicates which class this is. 81535043e56150dc4eda882acd5ddfe0f8e3c0a8cb1John McCall unsigned DeclKind : 8; 8160ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 8172cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// \brief Whether this declaration context also has some external 8182cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// storage that contains additional declarations that are lexically 8192cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// part of this context. 82035043e56150dc4eda882acd5ddfe0f8e3c0a8cb1John McCall mutable unsigned ExternalLexicalStorage : 1; 8212cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 8222cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// \brief Whether this declaration context also has some external 8232cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// storage that contains additional declarations that are visible 8242cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// in this context. 82535043e56150dc4eda882acd5ddfe0f8e3c0a8cb1John McCall mutable unsigned ExternalVisibleStorage : 1; 8262cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 827c36c540c5bfce941f3d892919394d092491211f2Douglas Gregor /// \brief Pointer to the data structure used to lookup declarations 8280c01d18094100db92d38daa923c95661512db203John McCall /// within this context (or a DependentStoredDeclsMap if this is a 8290c01d18094100db92d38daa923c95661512db203John McCall /// dependent context). 8300c01d18094100db92d38daa923c95661512db203John McCall mutable StoredDeclsMap *LookupPtr; 83144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 832eb5e9986e577b1e2bff3cca5973a2494fb593fbbArgyrios Kyrtzidisprotected: 8336037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// FirstDecl - The first declaration stored within this declaration 8346037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// context. 8352cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor mutable Decl *FirstDecl; 8366037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 8376037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// LastDecl - The last declaration stored within this declaration 8386037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// context. FIXME: We could probably cache this value somewhere 8396037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// outside of the DeclContext, to reduce the size of DeclContext by 8406037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// another pointer. 8412cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor mutable Decl *LastDecl; 8427643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidis 84376bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall friend class ExternalASTSource; 84476bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall 845eb5e9986e577b1e2bff3cca5973a2494fb593fbbArgyrios Kyrtzidis /// \brief Build up a chain of declarations. 846eb5e9986e577b1e2bff3cca5973a2494fb593fbbArgyrios Kyrtzidis /// 847eb5e9986e577b1e2bff3cca5973a2494fb593fbbArgyrios Kyrtzidis /// \returns the first/last pair of declarations. 848eb5e9986e577b1e2bff3cca5973a2494fb593fbbArgyrios Kyrtzidis static std::pair<Decl *, Decl *> 849ec2ec1f20322076717c3865b196f7a1c95d883a4Argyrios Kyrtzidis BuildDeclChain(const SmallVectorImpl<Decl*> &Decls, bool FieldsAlreadyLoaded); 850eb5e9986e577b1e2bff3cca5973a2494fb593fbbArgyrios Kyrtzidis 8511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclContext(Decl::Kind K) 8522cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor : DeclKind(K), ExternalLexicalStorage(false), 8531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ExternalVisibleStorage(false), LookupPtr(0), FirstDecl(0), 8542cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor LastDecl(0) { } 85544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 8560ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnerpublic: 85744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor ~DeclContext(); 85844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 8599b9ca01ff3136a7539dc08a4c4e1a3dd8c8d3a7dArgyrios Kyrtzidis Decl::Kind getDeclKind() const { 86035043e56150dc4eda882acd5ddfe0f8e3c0a8cb1John McCall return static_cast<Decl::Kind>(DeclKind); 8619b9ca01ff3136a7539dc08a4c4e1a3dd8c8d3a7dArgyrios Kyrtzidis } 8620a4739305a984ef9b821cedad5f4fe235eb6ef7dSteve Naroff const char *getDeclKindName() const; 8639b9ca01ff3136a7539dc08a4c4e1a3dd8c8d3a7dArgyrios Kyrtzidis 864305ec42f971a2b3e114eb35256c23e955c497a1cArgyrios Kyrtzidis /// getParent - Returns the containing DeclContext. 8650cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner DeclContext *getParent() { 866305ec42f971a2b3e114eb35256c23e955c497a1cArgyrios Kyrtzidis return cast<Decl>(this)->getDeclContext(); 867305ec42f971a2b3e114eb35256c23e955c497a1cArgyrios Kyrtzidis } 8680cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner const DeclContext *getParent() const { 8690cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner return const_cast<DeclContext*>(this)->getParent(); 870d2595ecce5f8350e485c83bfe767549a522b2802Argyrios Kyrtzidis } 8711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 87277407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis /// getLexicalParent - Returns the containing lexical DeclContext. May be 87344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// different from getParent, e.g.: 87444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// 87544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// namespace A { 87644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// struct S; 87744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// } 87844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// struct A::S {}; // getParent() == namespace 'A' 87977407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis /// // getLexicalParent() == translation unit 88077407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis /// 88177407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis DeclContext *getLexicalParent() { 8820cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner return cast<Decl>(this)->getLexicalDeclContext(); 88377407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis } 8840cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner const DeclContext *getLexicalParent() const { 8850cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner return const_cast<DeclContext*>(this)->getLexicalParent(); 8861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 887048f30a483ca352ee7f235a5be181b9dcc5f9d9cArgyrios Kyrtzidis 888e942bbe02b6fb332d1f13d38c6e1980b416cf89aDouglas Gregor DeclContext *getLookupParent(); 889e942bbe02b6fb332d1f13d38c6e1980b416cf89aDouglas Gregor 890e942bbe02b6fb332d1f13d38c6e1980b416cf89aDouglas Gregor const DeclContext *getLookupParent() const { 891e942bbe02b6fb332d1f13d38c6e1980b416cf89aDouglas Gregor return const_cast<DeclContext*>(this)->getLookupParent(); 892e942bbe02b6fb332d1f13d38c6e1980b416cf89aDouglas Gregor } 893e942bbe02b6fb332d1f13d38c6e1980b416cf89aDouglas Gregor 894048f30a483ca352ee7f235a5be181b9dcc5f9d9cArgyrios Kyrtzidis ASTContext &getParentASTContext() const { 895048f30a483ca352ee7f235a5be181b9dcc5f9d9cArgyrios Kyrtzidis return cast<Decl>(this)->getASTContext(); 896048f30a483ca352ee7f235a5be181b9dcc5f9d9cArgyrios Kyrtzidis } 897048f30a483ca352ee7f235a5be181b9dcc5f9d9cArgyrios Kyrtzidis 898aab9e315184d344bbd733f13b68915d02db7b32bJohn McCall bool isClosure() const { 899aab9e315184d344bbd733f13b68915d02db7b32bJohn McCall return DeclKind == Decl::Block; 900aab9e315184d344bbd733f13b68915d02db7b32bJohn McCall } 901aab9e315184d344bbd733f13b68915d02db7b32bJohn McCall 902a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian bool isObjCContainer() const { 90380f775359357f90f34b6adb8104506f13a816a67Fariborz Jahanian switch (DeclKind) { 90480f775359357f90f34b6adb8104506f13a816a67Fariborz Jahanian case Decl::ObjCCategory: 90580f775359357f90f34b6adb8104506f13a816a67Fariborz Jahanian case Decl::ObjCCategoryImpl: 90680f775359357f90f34b6adb8104506f13a816a67Fariborz Jahanian case Decl::ObjCImplementation: 90780f775359357f90f34b6adb8104506f13a816a67Fariborz Jahanian case Decl::ObjCInterface: 90880f775359357f90f34b6adb8104506f13a816a67Fariborz Jahanian case Decl::ObjCProtocol: 90980f775359357f90f34b6adb8104506f13a816a67Fariborz Jahanian return true; 91080f775359357f90f34b6adb8104506f13a816a67Fariborz Jahanian } 91180f775359357f90f34b6adb8104506f13a816a67Fariborz Jahanian return false; 912a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian } 913a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian 9140ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner bool isFunctionOrMethod() const { 9150ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner switch (DeclKind) { 9160cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner case Decl::Block: 9170cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner case Decl::ObjCMethod: 9180cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner return true; 9190cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner default: 9209a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt return DeclKind >= Decl::firstFunction && DeclKind <= Decl::lastFunction; 9210ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 9220ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 9230ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 924ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis bool isFileContext() const { 925ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis return DeclKind == Decl::TranslationUnit || DeclKind == Decl::Namespace; 926ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis } 927ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis 9285f2bfd4811996abb783aa6c7254c56baa6930e8cDouglas Gregor bool isTranslationUnit() const { 9295f2bfd4811996abb783aa6c7254c56baa6930e8cDouglas Gregor return DeclKind == Decl::TranslationUnit; 9305f2bfd4811996abb783aa6c7254c56baa6930e8cDouglas Gregor } 9315f2bfd4811996abb783aa6c7254c56baa6930e8cDouglas Gregor 932bcbffc46f1ad3796c4582fa1e3a9113b5aa26061Douglas Gregor bool isRecord() const { 9339a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt return DeclKind >= Decl::firstRecord && DeclKind <= Decl::lastRecord; 934c7ed9c60b8ee04b119e23441cae2cfec74536ba9Argyrios Kyrtzidis } 935c7ed9c60b8ee04b119e23441cae2cfec74536ba9Argyrios Kyrtzidis 93644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor bool isNamespace() const { 93744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor return DeclKind == Decl::Namespace; 93844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor } 93944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 940410c4f2eb5e6a8c2318cacb9a6751f1b4fcff166Sebastian Redl bool isInlineNamespace() const; 941410c4f2eb5e6a8c2318cacb9a6751f1b4fcff166Sebastian Redl 942bc221637f5ed3538b8495dd13b831c11e821c712Douglas Gregor /// \brief Determines whether this context is dependent on a 943bc221637f5ed3538b8495dd13b831c11e821c712Douglas Gregor /// template parameter. 944bc221637f5ed3538b8495dd13b831c11e821c712Douglas Gregor bool isDependentContext() const; 945bc221637f5ed3538b8495dd13b831c11e821c712Douglas Gregor 946074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// isTransparentContext - Determines whether this context is a 947074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// "transparent" context, meaning that the members declared in this 948074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// context are semantically declared in the nearest enclosing 949074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// non-transparent (opaque) context but are lexically declared in 950074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// this context. For example, consider the enumerators of an 9511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// enumeration type: 952074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// @code 953074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// enum E { 9541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// Val1 955074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// }; 956074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// @endcode 957074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// Here, E is a transparent context, so its enumerator (Val1) will 958074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// appear (semantically) that it is in the same context of E. 959074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// Examples of transparent contexts include: enumerations (except for 960410c4f2eb5e6a8c2318cacb9a6751f1b4fcff166Sebastian Redl /// C++0x scoped enums), and C++ linkage specifications. 961074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor bool isTransparentContext() const; 962074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor 963ac65c6208d48b0f9b4661c30c28997a280ac5ba6John McCall /// \brief Determines whether this context is, or is nested within, 964ac65c6208d48b0f9b4661c30c28997a280ac5ba6John McCall /// a C++ extern "C" linkage spec. 965ac65c6208d48b0f9b4661c30c28997a280ac5ba6John McCall bool isExternCContext() const; 966ac65c6208d48b0f9b4661c30c28997a280ac5ba6John McCall 96761481dad22ebca3fba3fe4fb67a3b926d0895e9cDouglas Gregor /// \brief Determine whether this declaration context is equivalent 96861481dad22ebca3fba3fe4fb67a3b926d0895e9cDouglas Gregor /// to the declaration context DC. 9697a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl bool Equals(const DeclContext *DC) const { 970dbdf5e7d0b6f1f8d8c496c1a0ada6f706cddf100Douglas Gregor return DC && this->getPrimaryContext() == DC->getPrimaryContext(); 97161481dad22ebca3fba3fe4fb67a3b926d0895e9cDouglas Gregor } 9721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9736dd38daf1495367db8fe9e9a5cacb7420cf08e27Douglas Gregor /// \brief Determine whether this declaration context encloses the 9746dd38daf1495367db8fe9e9a5cacb7420cf08e27Douglas Gregor /// declaration context DC. 9757a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl bool Encloses(const DeclContext *DC) const; 976ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis 97744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// getPrimaryContext - There may be many different 97844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// declarations of the same entity (including forward declarations 97944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// of classes, multiple definitions of namespaces, etc.), each with 98044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// a different set of declarations. This routine returns the 98144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// "primary" DeclContext structure, which will contain the 98244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// information needed to perform name lookup into this context. 9830701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff DeclContext *getPrimaryContext(); 9840c01d18094100db92d38daa923c95661512db203John McCall const DeclContext *getPrimaryContext() const { 9850c01d18094100db92d38daa923c95661512db203John McCall return const_cast<DeclContext*>(this)->getPrimaryContext(); 9860c01d18094100db92d38daa923c95661512db203John McCall } 98744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 9887a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl /// getRedeclContext - Retrieve the context in which an entity conflicts with 9897a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl /// other entities of the same name, or where it is a redeclaration if the 990410c4f2eb5e6a8c2318cacb9a6751f1b4fcff166Sebastian Redl /// two entities are compatible. This skips through transparent contexts. 9917a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl DeclContext *getRedeclContext(); 9927a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl const DeclContext *getRedeclContext() const { 9937a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl return const_cast<DeclContext *>(this)->getRedeclContext(); 99417a9b9e3ee75f5dbb4819cc8ebf40eec8015f84aDouglas Gregor } 9951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 99688b7094185b9d4fe9820c731b6936d8d37f6143eDouglas Gregor /// \brief Retrieve the nearest enclosing namespace context. 99788b7094185b9d4fe9820c731b6936d8d37f6143eDouglas Gregor DeclContext *getEnclosingNamespaceContext(); 99888b7094185b9d4fe9820c731b6936d8d37f6143eDouglas Gregor const DeclContext *getEnclosingNamespaceContext() const { 99988b7094185b9d4fe9820c731b6936d8d37f6143eDouglas Gregor return const_cast<DeclContext *>(this)->getEnclosingNamespaceContext(); 100088b7094185b9d4fe9820c731b6936d8d37f6143eDouglas Gregor } 100188b7094185b9d4fe9820c731b6936d8d37f6143eDouglas Gregor 10027a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl /// \brief Test if this context is part of the enclosing namespace set of 10037a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl /// the context NS, as defined in C++0x [namespace.def]p9. If either context 10047a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl /// isn't a namespace, this is equivalent to Equals(). 10057a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl /// 10067a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl /// The enclosing namespace set of a namespace is the namespace and, if it is 10077a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl /// inline, its enclosing namespace, recursively. 10087a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl bool InEnclosingNamespaceSetOf(const DeclContext *NS) const; 10097a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl 101044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// getNextContext - If this is a DeclContext that may have other 101144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// DeclContexts that are semantically connected but syntactically 101244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// different, such as C++ namespaces, this routine retrieves the 101344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// next DeclContext in the link. Iteration through the chain of 101444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// DeclContexts should begin at the primary DeclContext and 101544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// continue until this function returns NULL. For example, given: 101644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// @code 101744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// namespace N { 101844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// int x; 101944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// } 102044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// namespace N { 102144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// int y; 102244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// } 102344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// @endcode 102444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// The first occurrence of namespace N will be the primary 102544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// DeclContext. Its getNextContext will return the second 102644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// occurrence of namespace N. 102744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor DeclContext *getNextContext(); 102844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 102944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// decl_iterator - Iterates through the declarations stored 103044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// within this context. 10316037fcba3431b47de1a994c9b286feac17894effDouglas Gregor class decl_iterator { 10326037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// Current - The current declaration. 10334afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor Decl *Current; 10346037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 10356037fcba3431b47de1a994c9b286feac17894effDouglas Gregor public: 10364afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor typedef Decl* value_type; 10374afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor typedef Decl* reference; 10384afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor typedef Decl* pointer; 10396037fcba3431b47de1a994c9b286feac17894effDouglas Gregor typedef std::forward_iterator_tag iterator_category; 10406037fcba3431b47de1a994c9b286feac17894effDouglas Gregor typedef std::ptrdiff_t difference_type; 10416037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 10426037fcba3431b47de1a994c9b286feac17894effDouglas Gregor decl_iterator() : Current(0) { } 10434afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor explicit decl_iterator(Decl *C) : Current(C) { } 10446037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 10456037fcba3431b47de1a994c9b286feac17894effDouglas Gregor reference operator*() const { return Current; } 10466037fcba3431b47de1a994c9b286feac17894effDouglas Gregor pointer operator->() const { return Current; } 10476037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 104896f4468b6b1bf69bb01c1207f716a3ffaeb4a8d3Chris Lattner decl_iterator& operator++() { 1049244a67d911d08c3757a18ad666e4a268cf3ee285Chris Lattner Current = Current->getNextDeclInContext(); 105096f4468b6b1bf69bb01c1207f716a3ffaeb4a8d3Chris Lattner return *this; 105196f4468b6b1bf69bb01c1207f716a3ffaeb4a8d3Chris Lattner } 10526037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 10536037fcba3431b47de1a994c9b286feac17894effDouglas Gregor decl_iterator operator++(int) { 10546037fcba3431b47de1a994c9b286feac17894effDouglas Gregor decl_iterator tmp(*this); 10556037fcba3431b47de1a994c9b286feac17894effDouglas Gregor ++(*this); 10566037fcba3431b47de1a994c9b286feac17894effDouglas Gregor return tmp; 10576037fcba3431b47de1a994c9b286feac17894effDouglas Gregor } 10586037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 10591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump friend bool operator==(decl_iterator x, decl_iterator y) { 10606037fcba3431b47de1a994c9b286feac17894effDouglas Gregor return x.Current == y.Current; 10616037fcba3431b47de1a994c9b286feac17894effDouglas Gregor } 10621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump friend bool operator!=(decl_iterator x, decl_iterator y) { 10636037fcba3431b47de1a994c9b286feac17894effDouglas Gregor return x.Current != y.Current; 10646037fcba3431b47de1a994c9b286feac17894effDouglas Gregor } 10656037fcba3431b47de1a994c9b286feac17894effDouglas Gregor }; 106644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 106744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// decls_begin/decls_end - Iterate over the declarations stored in 10681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// this context. 106917945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis decl_iterator decls_begin() const; 107017945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis decl_iterator decls_end() const; 107117945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis bool decls_empty() const; 107244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 1073681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl /// noload_decls_begin/end - Iterate over the declarations stored in this 1074681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl /// context that are currently loaded; don't attempt to retrieve anything 1075681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl /// from an external source. 1076681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl decl_iterator noload_decls_begin() const; 1077681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl decl_iterator noload_decls_end() const; 1078681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl 1079f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// specific_decl_iterator - Iterates over a subrange of 1080f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// declarations stored in a DeclContext, providing only those that 1081669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// are of type SpecificDecl (or a class derived from it). This 1082f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// iterator is used, for example, to provide iteration over just 1083669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// the fields within a RecordDecl (with SpecificDecl = FieldDecl). 1084f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor template<typename SpecificDecl> 1085f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor class specific_decl_iterator { 1086f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// Current - The current, underlying declaration iterator, which 1087d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// will either be NULL or will point to a declaration of 1088f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// type SpecificDecl. 1089f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor DeclContext::decl_iterator Current; 10901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1091f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// SkipToNextDecl - Advances the current position up to the next 1092f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// declaration of type SpecificDecl that also meets the criteria 1093f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// required by Acceptable. 1094f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor void SkipToNextDecl() { 1095669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor while (*Current && !isa<SpecificDecl>(*Current)) 1096f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor ++Current; 1097f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 1098f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 1099f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor public: 1100f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor typedef SpecificDecl* value_type; 1101f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor typedef SpecificDecl* reference; 1102f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor typedef SpecificDecl* pointer; 1103f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor typedef std::iterator_traits<DeclContext::decl_iterator>::difference_type 1104f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor difference_type; 1105f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor typedef std::forward_iterator_tag iterator_category; 1106f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 1107669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor specific_decl_iterator() : Current() { } 1108f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 1109f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// specific_decl_iterator - Construct a new iterator over a 1110d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// subset of the declarations the range [C, 1111d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// end-of-declarations). If A is non-NULL, it is a pointer to a 1112d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// member function of SpecificDecl that should return true for 1113d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// all of the SpecificDecl instances that will be in the subset 1114d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// of iterators. For example, if you want Objective-C instance 1115d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// methods, SpecificDecl will be ObjCMethodDecl and A will be 1116d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// &ObjCMethodDecl::isInstanceMethod. 1117669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor explicit specific_decl_iterator(DeclContext::decl_iterator C) : Current(C) { 1118f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor SkipToNextDecl(); 1119f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 1120f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 11216037fcba3431b47de1a994c9b286feac17894effDouglas Gregor reference operator*() const { return cast<SpecificDecl>(*Current); } 11226037fcba3431b47de1a994c9b286feac17894effDouglas Gregor pointer operator->() const { return cast<SpecificDecl>(*Current); } 1123f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 1124f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor specific_decl_iterator& operator++() { 1125f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor ++Current; 1126f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor SkipToNextDecl(); 1127f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor return *this; 1128f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 1129f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 1130f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor specific_decl_iterator operator++(int) { 1131f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor specific_decl_iterator tmp(*this); 1132f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor ++(*this); 1133f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor return tmp; 1134f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 11351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1136f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor friend bool 1137f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor operator==(const specific_decl_iterator& x, const specific_decl_iterator& y) { 1138f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor return x.Current == y.Current; 1139f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 11401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump friend bool 1142f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor operator!=(const specific_decl_iterator& x, const specific_decl_iterator& y) { 1143f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor return x.Current != y.Current; 1144f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 1145f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor }; 1146f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 1147669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// \brief Iterates over a filtered subrange of declarations stored 1148669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// in a DeclContext. 1149669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// 1150669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// This iterator visits only those declarations that are of type 1151669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// SpecificDecl (or a class derived from it) and that meet some 1152669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// additional run-time criteria. This iterator is used, for 1153669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// example, to provide access to the instance methods within an 1154669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// Objective-C interface (with SpecificDecl = ObjCMethodDecl and 1155669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// Acceptable = ObjCMethodDecl::isInstanceMethod). 1156669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor template<typename SpecificDecl, bool (SpecificDecl::*Acceptable)() const> 1157669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor class filtered_decl_iterator { 1158669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// Current - The current, underlying declaration iterator, which 1159669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// will either be NULL or will point to a declaration of 1160669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// type SpecificDecl. 1161669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor DeclContext::decl_iterator Current; 11621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1163669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// SkipToNextDecl - Advances the current position up to the next 1164669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// declaration of type SpecificDecl that also meets the criteria 1165669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// required by Acceptable. 1166669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor void SkipToNextDecl() { 1167669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor while (*Current && 1168669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor (!isa<SpecificDecl>(*Current) || 1169669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor (Acceptable && !(cast<SpecificDecl>(*Current)->*Acceptable)()))) 1170669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor ++Current; 1171669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor } 1172669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 1173669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor public: 1174669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor typedef SpecificDecl* value_type; 1175669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor typedef SpecificDecl* reference; 1176669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor typedef SpecificDecl* pointer; 1177669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor typedef std::iterator_traits<DeclContext::decl_iterator>::difference_type 1178669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor difference_type; 1179669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor typedef std::forward_iterator_tag iterator_category; 1180669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 1181669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor filtered_decl_iterator() : Current() { } 1182669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 1183669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// specific_decl_iterator - Construct a new iterator over a 1184669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// subset of the declarations the range [C, 1185669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// end-of-declarations). If A is non-NULL, it is a pointer to a 1186669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// member function of SpecificDecl that should return true for 1187669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// all of the SpecificDecl instances that will be in the subset 1188669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// of iterators. For example, if you want Objective-C instance 1189669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// methods, SpecificDecl will be ObjCMethodDecl and A will be 1190669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// &ObjCMethodDecl::isInstanceMethod. 1191669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor explicit filtered_decl_iterator(DeclContext::decl_iterator C) : Current(C) { 1192669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor SkipToNextDecl(); 1193669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor } 1194669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 1195669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor reference operator*() const { return cast<SpecificDecl>(*Current); } 1196669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor pointer operator->() const { return cast<SpecificDecl>(*Current); } 1197669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 1198669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor filtered_decl_iterator& operator++() { 1199669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor ++Current; 1200669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor SkipToNextDecl(); 1201669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor return *this; 1202669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor } 1203669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 1204669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor filtered_decl_iterator operator++(int) { 1205669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor filtered_decl_iterator tmp(*this); 1206669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor ++(*this); 1207669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor return tmp; 1208669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor } 12091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1210669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor friend bool 1211669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor operator==(const filtered_decl_iterator& x, const filtered_decl_iterator& y) { 1212669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor return x.Current == y.Current; 1213669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor } 12141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump friend bool 1216669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor operator!=(const filtered_decl_iterator& x, const filtered_decl_iterator& y) { 1217669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor return x.Current != y.Current; 1218669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor } 1219669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor }; 1220669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 122140f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// @brief Add the declaration D into this context. 122240f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// 122340f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// This routine should be invoked when the declaration D has first 122440f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// been declared, to place D into the context where it was 122540f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// (lexically) defined. Every declaration must be added to one 122640f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// (and only one!) context, where it can be visited via 122740f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// [decls_begin(), decls_end()). Once a declaration has been added 122840f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// to its lexical context, the corresponding DeclContext owns the 122940f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// declaration. 123040f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// 123140f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// If D is also a NamedDecl, it will be made visible within its 123240f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// semantic context via makeDeclVisibleInContext. 123317945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis void addDecl(Decl *D); 123444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 12353f9a8a60614b763785d54ad08821745d03a4af70John McCall /// @brief Add the declaration D to this context without modifying 12363f9a8a60614b763785d54ad08821745d03a4af70John McCall /// any lookup tables. 12373f9a8a60614b763785d54ad08821745d03a4af70John McCall /// 12383f9a8a60614b763785d54ad08821745d03a4af70John McCall /// This is useful for some operations in dependent contexts where 12393f9a8a60614b763785d54ad08821745d03a4af70John McCall /// the semantic context might not be dependent; this basically 12403f9a8a60614b763785d54ad08821745d03a4af70John McCall /// only happens with friends. 12413f9a8a60614b763785d54ad08821745d03a4af70John McCall void addHiddenDecl(Decl *D); 12423f9a8a60614b763785d54ad08821745d03a4af70John McCall 12439f54ad4381370c6b771424b53d219e661d6d6706John McCall /// @brief Removes a declaration from this context. 12449f54ad4381370c6b771424b53d219e661d6d6706John McCall void removeDecl(Decl *D); 12459f54ad4381370c6b771424b53d219e661d6d6706John McCall 124644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// lookup_iterator - An iterator that provides access to the results 124744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// of looking up a name within this context. 12484afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor typedef NamedDecl **lookup_iterator; 124944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 125044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// lookup_const_iterator - An iterator that provides non-mutable 125144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// access to the results of lookup up a name within this context. 12524afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor typedef NamedDecl * const * lookup_const_iterator; 125344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 1254ea318642072d3d94b5c3cff0fa6f4b33d2db0768John McCall typedef DeclContextLookupResult lookup_result; 1255ea318642072d3d94b5c3cff0fa6f4b33d2db0768John McCall typedef DeclContextLookupConstResult lookup_const_result; 125644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 125744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// lookup - Find the declarations (if any) with the given Name in 125844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// this context. Returns a range of iterators that contains all of 125940f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// the declarations with this name, with object, function, member, 126040f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// and enumerator names preceding any tag name. Note that this 126140f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// routine will not look into parent contexts. 126217945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis lookup_result lookup(DeclarationName Name); 126317945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis lookup_const_result lookup(DeclarationName Name) const; 126444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 1265b75a3451bcae1301875282e73a13934c90b6574cDouglas Gregor /// \brief A simplistic name lookup mechanism that performs name lookup 1266b75a3451bcae1301875282e73a13934c90b6574cDouglas Gregor /// into this declaration context without consulting the external source. 1267b75a3451bcae1301875282e73a13934c90b6574cDouglas Gregor /// 1268b75a3451bcae1301875282e73a13934c90b6574cDouglas Gregor /// This function should almost never be used, because it subverts the 1269b75a3451bcae1301875282e73a13934c90b6574cDouglas Gregor /// usual relationship between a DeclContext and the external source. 1270b75a3451bcae1301875282e73a13934c90b6574cDouglas Gregor /// See the ASTImporter for the (few, but important) use cases. 1271b75a3451bcae1301875282e73a13934c90b6574cDouglas Gregor void localUncachedLookup(DeclarationName Name, 1272b75a3451bcae1301875282e73a13934c90b6574cDouglas Gregor llvm::SmallVectorImpl<NamedDecl *> &Results); 1273b75a3451bcae1301875282e73a13934c90b6574cDouglas Gregor 127440f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// @brief Makes a declaration visible within this context. 127540f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// 127640f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// This routine makes the declaration D visible to name lookup 127740f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// within this context and, if this is a transparent context, 127840f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// within its parent contexts up to the first enclosing 127940f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// non-transparent context. Making a declaration visible within a 128040f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// context does not transfer ownership of a declaration, and a 128140f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// declaration can be visible in many contexts that aren't its 128240f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// lexical context. 128340f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// 128440f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// If D is a redeclaration of an existing declaration that is 128540f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// visible from this context, as determined by 128640f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// NamedDecl::declarationReplaces, the previous declaration will be 128740f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// replaced with D. 1288ab88d97734f1260402a0c6a8f6b77bed7ed4e295John McCall /// 1289ab88d97734f1260402a0c6a8f6b77bed7ed4e295John McCall /// @param Recoverable true if it's okay to not add this decl to 1290ab88d97734f1260402a0c6a8f6b77bed7ed4e295John McCall /// the lookup tables because it can be easily recovered by walking 1291ab88d97734f1260402a0c6a8f6b77bed7ed4e295John McCall /// the declaration chains. 1292ab88d97734f1260402a0c6a8f6b77bed7ed4e295John McCall void makeDeclVisibleInContext(NamedDecl *D, bool Recoverable = true); 12937643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidis 12942a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor /// udir_iterator - Iterates through the using-directives stored 12952a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor /// within this context. 12962a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor typedef UsingDirectiveDecl * const * udir_iterator; 12971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12982a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor typedef std::pair<udir_iterator, udir_iterator> udir_iterator_range; 12992a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor 130017945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis udir_iterator_range getUsingDirectives() const; 13012a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor 130217945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis udir_iterator using_directives_begin() const { 130317945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis return getUsingDirectives().first; 13042a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor } 13052a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor 130617945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis udir_iterator using_directives_end() const { 130717945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis return getUsingDirectives().second; 13082a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor } 13092a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor 13100c01d18094100db92d38daa923c95661512db203John McCall // These are all defined in DependentDiagnostic.h. 13110c01d18094100db92d38daa923c95661512db203John McCall class ddiag_iterator; 13120c01d18094100db92d38daa923c95661512db203John McCall inline ddiag_iterator ddiag_begin() const; 13130c01d18094100db92d38daa923c95661512db203John McCall inline ddiag_iterator ddiag_end() const; 13140c01d18094100db92d38daa923c95661512db203John McCall 1315c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor // Low-level accessors 1316c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor 1317c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor /// \brief Retrieve the internal representation of the lookup structure. 13180c01d18094100db92d38daa923c95661512db203John McCall StoredDeclsMap* getLookupPtr() const { return LookupPtr; } 1319c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor 13202cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// \brief Whether this DeclContext has external storage containing 13212cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// additional declarations that are lexically in this context. 13222cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor bool hasExternalLexicalStorage() const { return ExternalLexicalStorage; } 13232cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 13242cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// \brief State whether this DeclContext has external storage for 13252cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// declarations lexically in this context. 13261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setHasExternalLexicalStorage(bool ES = true) { 13271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ExternalLexicalStorage = ES; 13282cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor } 13292cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 13302cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// \brief Whether this DeclContext has external storage containing 13312cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// additional declarations that are visible in this context. 13322cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor bool hasExternalVisibleStorage() const { return ExternalVisibleStorage; } 13332cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 13342cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// \brief State whether this DeclContext has external storage for 13352cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// declarations visible in this context. 13361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setHasExternalVisibleStorage(bool ES = true) { 13371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ExternalVisibleStorage = ES; 13382cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor } 13392cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 13402ea054fbc59ed19b8e3304e7e7cbdd56a5a5120fDouglas Gregor /// \brief Determine whether the given declaration is stored in the list of 13412ea054fbc59ed19b8e3304e7e7cbdd56a5a5120fDouglas Gregor /// declarations lexically within this context. 13422ea054fbc59ed19b8e3304e7e7cbdd56a5a5120fDouglas Gregor bool isDeclInLexicalTraversal(const Decl *D) const { 13432ea054fbc59ed19b8e3304e7e7cbdd56a5a5120fDouglas Gregor return D && (D->NextDeclInContext || D == FirstDecl || D == LastDecl); 13442ea054fbc59ed19b8e3304e7e7cbdd56a5a5120fDouglas Gregor } 13452ea054fbc59ed19b8e3304e7e7cbdd56a5a5120fDouglas Gregor 13463d7641e090cf113dec64306a1597d3e4523e2a55Argyrios Kyrtzidis static bool classof(const Decl *D); 1347b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner static bool classof(const DeclContext *D) { return true; } 13489a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt#define DECL(NAME, BASE) 13499a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt#define DECL_CONTEXT(NAME) \ 13509a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt static bool classof(const NAME##Decl *D) { return true; } 13519a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt#include "clang/AST/DeclNodes.inc" 13527643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidis 135384834432289a810e713f82f1ed94a99ad8a5c2eaAnders Carlsson void dumpDeclContext() const; 13542b7d8ddc746a9096f8af4bd0d8b07eae523864b5Anders Carlsson 13557643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidisprivate: 135617945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis void LoadLexicalDeclsFromExternalStorage() const; 13572cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 13580c01d18094100db92d38daa923c95661512db203John McCall friend class DependentDiagnostic; 13590c01d18094100db92d38daa923c95661512db203John McCall StoredDeclsMap *CreateStoredDeclsMap(ASTContext &C) const; 13600c01d18094100db92d38daa923c95661512db203John McCall 136117945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis void buildLookup(DeclContext *DCtx); 136217945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis void makeDeclVisibleInContextImpl(NamedDecl *D); 13630ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner}; 13640ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 1365f57172b24f08a68d179675989813d5479dc87829Douglas Gregorinline bool Decl::isTemplateParameter() const { 136679c2278a66d8fc0943774d1b7c71a32f7764e1e2Douglas Gregor return getKind() == TemplateTypeParm || getKind() == NonTypeTemplateParm || 136779c2278a66d8fc0943774d1b7c71a32f7764e1e2Douglas Gregor getKind() == TemplateTemplateParm; 13684afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor} 13694afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 137080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall// Specialization selected when ToTy is not a known subclass of DeclContext. 137180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCalltemplate <class ToTy, 137280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall bool IsKnownSubtype = ::llvm::is_base_of< DeclContext, ToTy>::value> 137380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCallstruct cast_convert_decl_context { 137480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static const ToTy *doit(const DeclContext *Val) { 137580cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall return static_cast<const ToTy*>(Decl::castFromDeclContext(Val)); 137680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall } 137780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall 137880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static ToTy *doit(DeclContext *Val) { 137980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall return static_cast<ToTy*>(Decl::castFromDeclContext(Val)); 138080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall } 138180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall}; 138280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall 138380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall// Specialization selected when ToTy is a known subclass of DeclContext. 138480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCalltemplate <class ToTy> 138580cd64a8450d8e2c079dc134d9711cd45ba89d63John McCallstruct cast_convert_decl_context<ToTy, true> { 138680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static const ToTy *doit(const DeclContext *Val) { 138780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall return static_cast<const ToTy*>(Val); 138880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall } 138980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall 139080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static ToTy *doit(DeclContext *Val) { 139180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall return static_cast<ToTy*>(Val); 139280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall } 139380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall}; 139480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall 139580cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall 13960ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner} // end clang. 13970ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 13980ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnernamespace llvm { 13990ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 140080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall/// isa<T>(DeclContext*) 14014d509341bd5db06a517daa311379f52bb540bc34Eli Friedmantemplate <typename To> 14024d509341bd5db06a517daa311379f52bb540bc34Eli Friedmanstruct isa_impl<To, ::clang::DeclContext> { 140342220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis static bool doit(const ::clang::DeclContext &Val) { 14044d509341bd5db06a517daa311379f52bb540bc34Eli Friedman return To::classofKind(Val.getDeclKind()); 14050ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 14060ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner}; 14070ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 140880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall/// cast<T>(DeclContext*) 140980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCalltemplate<class ToTy> 141080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCallstruct cast_convert_val<ToTy, 141180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall const ::clang::DeclContext,const ::clang::DeclContext> { 141280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static const ToTy &doit(const ::clang::DeclContext &Val) { 141380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall return *::clang::cast_convert_decl_context<ToTy>::doit(&Val); 141480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall } 141580cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall}; 141680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCalltemplate<class ToTy> 141780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCallstruct cast_convert_val<ToTy, ::clang::DeclContext, ::clang::DeclContext> { 141880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static ToTy &doit(::clang::DeclContext &Val) { 141980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall return *::clang::cast_convert_decl_context<ToTy>::doit(&Val); 142080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall } 142180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall}; 142280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCalltemplate<class ToTy> 142380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCallstruct cast_convert_val<ToTy, 142480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall const ::clang::DeclContext*, const ::clang::DeclContext*> { 142580cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static const ToTy *doit(const ::clang::DeclContext *Val) { 142680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall return ::clang::cast_convert_decl_context<ToTy>::doit(Val); 142780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall } 142880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall}; 142980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCalltemplate<class ToTy> 143080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCallstruct cast_convert_val<ToTy, ::clang::DeclContext*, ::clang::DeclContext*> { 143180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static ToTy *doit(::clang::DeclContext *Val) { 143280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall return ::clang::cast_convert_decl_context<ToTy>::doit(Val); 143380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall } 143480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall}; 143580cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall 143642220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis/// Implement cast_convert_val for Decl -> DeclContext conversions. 14370ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnertemplate<class FromTy> 143842220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisstruct cast_convert_val< ::clang::DeclContext, FromTy, FromTy> { 1439b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner static ::clang::DeclContext &doit(const FromTy &Val) { 144042220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis return *FromTy::castToDeclContext(&Val); 14410ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 14420ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner}; 14430ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 14440ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnertemplate<class FromTy> 144542220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisstruct cast_convert_val< ::clang::DeclContext, FromTy*, FromTy*> { 1446b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner static ::clang::DeclContext *doit(const FromTy *Val) { 144742220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis return FromTy::castToDeclContext(Val); 14480ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 14490ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner}; 145042220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis 145144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregortemplate<class FromTy> 145244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregorstruct cast_convert_val< const ::clang::DeclContext, FromTy, FromTy> { 145344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor static const ::clang::DeclContext &doit(const FromTy &Val) { 145444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor return *FromTy::castToDeclContext(&Val); 145544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor } 145644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor}; 145744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 145844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregortemplate<class FromTy> 145944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregorstruct cast_convert_val< const ::clang::DeclContext, FromTy*, FromTy*> { 146044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor static const ::clang::DeclContext *doit(const FromTy *Val) { 146144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor return FromTy::castToDeclContext(Val); 146244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor } 146344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor}; 146444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 14650ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner} // end namespace llvm 14660ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 14670ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner#endif 1468