DeclBase.h revision 109f5fc8dff6f3bd707e0e4140dc99ef7d4f3e88
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 172fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/AST/AttrIterator.h" 18514d3b6b93c83c0841d2f9dd7af8ecc2877fe921Douglas Gregor#include "clang/AST/DeclarationName.h" 19ad2b804faf29042e6c4e331d0987f103f1e2fd31John McCall#include "clang/Basic/Specifiers.h" 20ee219fd5f2776d8dd39d857f87304297b5ed743aChris Lattner#include "llvm/ADT/PointerUnion.h" 21aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar#include "llvm/Support/Compiler.h" 22aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar#include "llvm/Support/PrettyStackTrace.h" 230ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 240ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnernamespace clang { 259852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramerclass ASTMutationListener; 269852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramerclass BlockDecl; 27d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidisclass CXXRecordDecl; 289852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramerclass CompoundStmt; 299852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramerclass DeclContext; 309852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramerclass DeclarationName; 319852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramerclass DependentDiagnostic; 32b048c9835969c4f7fe06264748be18ed4b442116Chris Lattnerclass EnumDecl; 339852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramerclass FunctionDecl; 349852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramerclass LinkageSpecDecl; 35ca2ab45341c448284cf93770018c717810575f86Douglas Gregorclass Module; 369852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramerclass NamedDecl; 379852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramerclass NamespaceDecl; 380701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroffclass ObjCCategoryDecl; 390701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroffclass ObjCCategoryImplDecl; 409852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramerclass ObjCContainerDecl; 41bfb498d0996ef049efe9476f2802976fd145cd60Argyrios Kyrtzidisclass ObjCImplDecl; 429852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramerclass ObjCImplementationDecl; 439852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramerclass ObjCInterfaceDecl; 449852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramerclass ObjCMethodDecl; 459852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramerclass ObjCProtocolDecl; 469852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramerstruct PrintingPolicy; 479852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramerclass Stmt; 480c01d18094100db92d38daa923c95661512db203John McCallclass StoredDeclsMap; 499852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramerclass TranslationUnitDecl; 509852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramerclass UsingDirectiveDecl; 510eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner} 520eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner 530eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattnernamespace llvm { 540eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner// DeclContext* is only 4-byte aligned on 32-bit systems. 550eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattnertemplate<> 560eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner class PointerLikeTypeTraits<clang::DeclContext*> { 570eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner typedef clang::DeclContext* PT; 580eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattnerpublic: 590eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner static inline void *getAsVoidPointer(PT P) { return P; } 600eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner static inline PT getFromVoidPointer(void *P) { 610eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner return static_cast<PT>(P); 620eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner } 630eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner enum { NumLowBitsAvailable = 2 }; 640eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner}; 650eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner} 660eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner 670eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattnernamespace clang { 680ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 690a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \brief Captures the result of checking the availability of a 700a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// declaration. 710a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor enum AvailabilityResult { 720a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor AR_Available = 0, 730a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor AR_NotYetIntroduced, 740a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor AR_Deprecated, 750a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor AR_Unavailable 760a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor }; 770a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor 781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Decl - This represents one declaration (or definition), e.g. a variable, 791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// typedef, function, struct, etc. 800ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner/// 810ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnerclass Decl { 820ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnerpublic: 8364650af7cc4352c6c67b9bd1bf8ef3ce7471b910Douglas Gregor /// \brief Lists the kind of concrete classes of Decl. 840ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner enum Kind { 859a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt#define DECL(DERIVED, BASE) DERIVED, 869a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt#define ABSTRACT_DECL(DECL) 879a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt#define DECL_RANGE(BASE, START, END) \ 889a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt first##BASE = START, last##BASE = END, 899a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt#define LAST_DECL_RANGE(BASE, START, END) \ 909a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt first##BASE = START, last##BASE = END 919a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt#include "clang/AST/DeclNodes.inc" 920ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner }; 930ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 946ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner /// \brief A placeholder type used to construct an empty shell of a 956ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner /// decl-derived type that will be filled in later (e.g., by some 966ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner /// deserialization method). 976ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner struct EmptyShell { }; 986ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner 990d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// IdentifierNamespace - The different namespaces in which 1000d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// declarations may appear. According to C99 6.2.3, there are 1010d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// four namespaces, labels, tags, members and ordinary 1020d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// identifiers. C++ describes lookup completely differently: 1030d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// certain lookups merely "ignore" certain kinds of declarations, 1040d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// usually based on whether the declaration is of a type, etc. 105ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// 1060d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// These are meant as bitmasks, so that searches in 1070d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// C++ can look into the "tag" namespace during ordinary lookup. 1080d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// 10907a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl /// Decl currently provides 15 bits of IDNS bits. 1100ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner enum IdentifierNamespace { 1110d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// Labels, declared with 'x:' and referenced with 'goto x'. 1120d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall IDNS_Label = 0x0001, 1130d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall 1140d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// Tags, declared with 'struct foo;' and referenced with 1150d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// 'struct foo'. All tags are also types. This is what 1160d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// elaborated-type-specifiers look for in C. 1170d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall IDNS_Tag = 0x0002, 1180d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall 1190d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// Types, declared with 'struct foo', typedefs, etc. 1200d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// This is what elaborated-type-specifiers look for in C++, 1210d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// but note that it's ill-formed to find a non-tag. 1220d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall IDNS_Type = 0x0004, 1230d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall 1240d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// Members, declared with object declarations within tag 1250d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// definitions. In C, these can only be found by "qualified" 1260d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// lookup in member expressions. In C++, they're found by 1270d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// normal lookup. 1280d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall IDNS_Member = 0x0008, 1290d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall 1300d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// Namespaces, declared with 'namespace foo {}'. 1310d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// Lookup for nested-name-specifiers find these. 1320d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall IDNS_Namespace = 0x0010, 1330d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall 1340d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// Ordinary names. In C, everything that's not a label, tag, 1350d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// or member ends up here. 1360d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall IDNS_Ordinary = 0x0020, 1370d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall 138d4582b8e6d056f5d991f1b8372e89a6aae58feaeJordan Rose /// Objective C \@protocol. 1390d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall IDNS_ObjCProtocol = 0x0040, 1400d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall 1410d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// This declaration is a friend function. A friend function 1420d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// declaration is always in this namespace but may also be in 1430d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// IDNS_Ordinary if it was previously declared. 1440d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall IDNS_OrdinaryFriend = 0x0080, 1450d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall 1460d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// This declaration is a friend class. A friend class 1470d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// declaration is always in this namespace but may also be in 1480d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// IDNS_Tag|IDNS_Type if it was previously declared. 1490d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall IDNS_TagFriend = 0x0100, 1500d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall 1510d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// This declaration is a using declaration. A using declaration 1520d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// *introduces* a number of other declarations into the current 1530d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// scope, and those declarations use the IDNS of their targets, 1540d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// but the actual using declarations go in this namespace. 15576d326448d7e4c10b2896edc2ee855d1e68d1b88John McCall IDNS_Using = 0x0200, 15676d326448d7e4c10b2896edc2ee855d1e68d1b88John McCall 15776d326448d7e4c10b2896edc2ee855d1e68d1b88John McCall /// This declaration is a C++ operator declared in a non-class 15876d326448d7e4c10b2896edc2ee855d1e68d1b88John McCall /// context. All such operators are also in IDNS_Ordinary. 15976d326448d7e4c10b2896edc2ee855d1e68d1b88John McCall /// C++ lexical operator lookup looks for these. 16076d326448d7e4c10b2896edc2ee855d1e68d1b88John McCall IDNS_NonMemberOperator = 0x0400 1610ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner }; 1621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16309e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// ObjCDeclQualifier - 'Qualifiers' written next to the return and 16409e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// parameter types in method declarations. Other than remembering 16509e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// them and mangling them into the method's signature string, these 16609e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// are ignored by the compiler; they are consumed by certain 16709e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// remote-messaging frameworks. 16809e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// 16909e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// in, inout, and out are mutually exclusive and apply only to 17009e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// method parameters. bycopy and byref are mutually exclusive and 17109e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// apply only to method parameters (?). oneway applies only to 17209e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// results. All of these expect their corresponding parameter to 17309e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// have a particular type. None of this is currently enforced by 17409e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// clang. 17509e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// 17609e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// This should be kept in sync with ObjCDeclSpec::ObjCDeclQualifier. 1770ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner enum ObjCDeclQualifier { 1780ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_None = 0x0, 1790ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_In = 0x1, 1800ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_Inout = 0x2, 1810ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_Out = 0x4, 1820ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_Bycopy = 0x8, 1830ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_Byref = 0x10, 1840ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_Oneway = 0x20 1850ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner }; 1861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18746cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregorprotected: 18846cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor // Enumeration values used in the bits stored in NextInContextAndBits. 18946cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor enum { 19046cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor /// \brief Whether this declaration is a top-level declaration (function, 19146cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor /// global variable, etc.) that is lexically inside an objc container 19246cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor /// definition. 19346cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor TopLevelDeclInObjCContainerFlag = 0x01, 19446cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor 19546cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor /// \brief Whether this declaration is private to the module in which it was 19646cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor /// defined. 19746cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor ModulePrivateFlag = 0x02 19846cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor }; 19946cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor 20046cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor /// \brief The next declaration within the same lexical 2014afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// DeclContext. These pointers form the linked list that is 2024afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// traversed via DeclContext's decls_begin()/decls_end(). 20346cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor /// 20446cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor /// The extra two bits are used for the TopLevelDeclInObjCContainer and 20546cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor /// ModulePrivate bits. 20646cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor llvm::PointerIntPair<Decl *, 2, unsigned> NextInContextAndBits; 2074afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 20846cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregorprivate: 2094afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor friend class DeclContext; 2104afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 211ee219fd5f2776d8dd39d857f87304297b5ed743aChris Lattner struct MultipleDC { 212ee219fd5f2776d8dd39d857f87304297b5ed743aChris Lattner DeclContext *SemanticDC; 213ee219fd5f2776d8dd39d857f87304297b5ed743aChris Lattner DeclContext *LexicalDC; 214ee219fd5f2776d8dd39d857f87304297b5ed743aChris Lattner }; 2151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2174afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// DeclCtx - Holds either a DeclContext* or a MultipleDC*. 2184afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// For declarations that don't contain C++ scope specifiers, it contains 2194afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// the DeclContext where the Decl was declared. 2204afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// For declarations with C++ scope specifiers, it contains a MultipleDC* 2214afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// with the context where it semantically belongs (SemanticDC) and the 2224afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// context where it was lexically declared (LexicalDC). 2234afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// e.g.: 2244afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// 2254afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// namespace A { 2264afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// void f(); // SemanticDC == LexicalDC == 'namespace A' 2274afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// } 2284afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// void A::f(); // SemanticDC == namespace 'A' 2294afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// // LexicalDC == global namespace 230ee219fd5f2776d8dd39d857f87304297b5ed743aChris Lattner llvm::PointerUnion<DeclContext*, MultipleDC*> DeclCtx; 2314afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 232ee219fd5f2776d8dd39d857f87304297b5ed743aChris Lattner inline bool isInSemaDC() const { return DeclCtx.is<DeclContext*>(); } 233ee219fd5f2776d8dd39d857f87304297b5ed743aChris Lattner inline bool isOutOfSemaDC() const { return DeclCtx.is<MultipleDC*>(); } 2344afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor inline MultipleDC *getMultipleDC() const { 235ee219fd5f2776d8dd39d857f87304297b5ed743aChris Lattner return DeclCtx.get<MultipleDC*>(); 2364afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 23710d8379676f32b493740a5509e2cd7f0d6433139Chris Lattner inline DeclContext *getSemanticDC() const { 238ee219fd5f2776d8dd39d857f87304297b5ed743aChris Lattner return DeclCtx.get<DeclContext*>(); 23910d8379676f32b493740a5509e2cd7f0d6433139Chris Lattner } 2401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 241381d34e0b205ca27bcc7e7c1652561941c437965Douglas Gregor /// Loc - The location of this decl. 24239d7650656fdd1be879ed7d0c722cfeae95e56d5Daniel Dunbar SourceLocation Loc; 2431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2440ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// DeclKind - This indicates which class this is. 245838dc597e25614c653a062a124b06a04d6b7f5ebRafael Espindola unsigned DeclKind : 8; 2461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2470ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// InvalidDecl - This indicates a semantic error occurred. 24835043e56150dc4eda882acd5ddfe0f8e3c0a8cb1John McCall unsigned InvalidDecl : 1; 2491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2500ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// HasAttrs - This indicates whether the decl has attributes or not. 25135043e56150dc4eda882acd5ddfe0f8e3c0a8cb1John McCall unsigned HasAttrs : 1; 252d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis 2536b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor /// Implicit - Whether this declaration was implicitly generated by 2546b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor /// the implementation rather than explicitly written by the user. 25535043e56150dc4eda882acd5ddfe0f8e3c0a8cb1John McCall unsigned Implicit : 1; 2566b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor 257e0762c92110dfdcdd207db461a4ea17afd168f1eDouglas Gregor /// \brief Whether this declaration was "used", meaning that a definition is 258e0762c92110dfdcdd207db461a4ea17afd168f1eDouglas Gregor /// required. 25935043e56150dc4eda882acd5ddfe0f8e3c0a8cb1John McCall unsigned Used : 1; 2609cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor 2616b6b42aed07726178f61954ac6e51f47da00275cArgyrios Kyrtzidis /// \brief Whether this declaration was "referenced". 2626b6b42aed07726178f61954ac6e51f47da00275cArgyrios Kyrtzidis /// The difference with 'Used' is whether the reference appears in a 2636b6b42aed07726178f61954ac6e51f47da00275cArgyrios Kyrtzidis /// evaluated context or not, e.g. functions used in uninstantiated templates 2646b6b42aed07726178f61954ac6e51f47da00275cArgyrios Kyrtzidis /// are regarded as "referenced" but not "used". 2656b6b42aed07726178f61954ac6e51f47da00275cArgyrios Kyrtzidis unsigned Referenced : 1; 266ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 26702892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar /// \brief Whether statistic collection is enabled. 26802892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar static bool StatisticsEnabled; 26902892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar 2709cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregorprotected: 2717d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor /// Access - Used by C++ decls for the access specifier. 2727d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor // NOTE: VC++ treats enums as signed, avoid using the AccessSpecifier enum 2737d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor unsigned Access : 2; 2747d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor friend class CXXClassMemberWrapper; 2750b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl 27608e0bc16b3312c27e87d33be7dcf3d4fe5bdd2e2Douglas Gregor /// \brief Whether this declaration was loaded from an AST file. 27708e0bc16b3312c27e87d33be7dcf3d4fe5bdd2e2Douglas Gregor unsigned FromASTFile : 1; 278ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 279f143ffc4a9af79ac1d822fea6995af4bf45d17dcDouglas Gregor /// \brief Whether this declaration is hidden from normal name lookup, e.g., 280f143ffc4a9af79ac1d822fea6995af4bf45d17dcDouglas Gregor /// because it is was loaded from an AST file is either module-private or 281f143ffc4a9af79ac1d822fea6995af4bf45d17dcDouglas Gregor /// because its submodule has not been made visible. 282f143ffc4a9af79ac1d822fea6995af4bf45d17dcDouglas Gregor unsigned Hidden : 1; 283f143ffc4a9af79ac1d822fea6995af4bf45d17dcDouglas Gregor 284769dbdf467681f6020ff248b969c2d41a4fdccd3Chris Lattner /// IdentifierNamespace - This specifies what IDNS_* namespace this lives in. 285381d34e0b205ca27bcc7e7c1652561941c437965Douglas Gregor unsigned IdentifierNamespace : 12; 2861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 287838dc597e25614c653a062a124b06a04d6b7f5ebRafael Espindola /// \brief Whether the \c CachedLinkage field is active. 288381d34e0b205ca27bcc7e7c1652561941c437965Douglas Gregor /// 289838dc597e25614c653a062a124b06a04d6b7f5ebRafael Espindola /// This field is only valid for NamedDecls subclasses. 290838dc597e25614c653a062a124b06a04d6b7f5ebRafael Espindola mutable unsigned HasCachedLinkage : 1; 291838dc597e25614c653a062a124b06a04d6b7f5ebRafael Espindola 292838dc597e25614c653a062a124b06a04d6b7f5ebRafael Espindola /// \brief If \c HasCachedLinkage, the linkage of this declaration. 293838dc597e25614c653a062a124b06a04d6b7f5ebRafael Espindola /// 294838dc597e25614c653a062a124b06a04d6b7f5ebRafael Espindola /// This field is only valid for NamedDecls subclasses. 295381d34e0b205ca27bcc7e7c1652561941c437965Douglas Gregor mutable unsigned CachedLinkage : 2; 296ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2978d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor friend class ASTDeclWriter; 2988d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor friend class ASTDeclReader; 299ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor friend class ASTReader; 3008d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor 3019cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregorprivate: 3021329c274628cc8c4e8ad472b41d1a78c8123f611Anders Carlsson void CheckAccessDeclContext() const; 3031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3044afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorprotected: 305d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis 3061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Decl(Kind DK, DeclContext *DC, SourceLocation L) 30746cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor : NextInContextAndBits(), DeclCtx(DC), 30839d7650656fdd1be879ed7d0c722cfeae95e56d5Daniel Dunbar Loc(L), DeclKind(DK), InvalidDecl(0), 3096b6b42aed07726178f61954ac6e51f47da00275cArgyrios Kyrtzidis HasAttrs(false), Implicit(false), Used(false), Referenced(false), 31046cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor Access(AS_none), FromASTFile(0), Hidden(0), 311381d34e0b205ca27bcc7e7c1652561941c437965Douglas Gregor IdentifierNamespace(getIdentifierNamespaceForKind(DK)), 312838dc597e25614c653a062a124b06a04d6b7f5ebRafael Espindola HasCachedLinkage(0) 313381d34e0b205ca27bcc7e7c1652561941c437965Douglas Gregor { 31402892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar if (StatisticsEnabled) add(DK); 3150ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 3161bb19638f2ec0d63ed131b51ca8d9542d1a9afeeSam Bishop 3176764334dfa73d67cbbb1b1fc8fe00440aad00f2aArgyrios Kyrtzidis Decl(Kind DK, EmptyShell Empty) 31846cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor : NextInContextAndBits(), DeclKind(DK), InvalidDecl(0), 3196b6b42aed07726178f61954ac6e51f47da00275cArgyrios Kyrtzidis HasAttrs(false), Implicit(false), Used(false), Referenced(false), 32046cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor Access(AS_none), FromASTFile(0), Hidden(0), 321381d34e0b205ca27bcc7e7c1652561941c437965Douglas Gregor IdentifierNamespace(getIdentifierNamespaceForKind(DK)), 322838dc597e25614c653a062a124b06a04d6b7f5ebRafael Espindola HasCachedLinkage(0) 323381d34e0b205ca27bcc7e7c1652561941c437965Douglas Gregor { 32402892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar if (StatisticsEnabled) add(DK); 3256764334dfa73d67cbbb1b1fc8fe00440aad00f2aArgyrios Kyrtzidis } 3266764334dfa73d67cbbb1b1fc8fe00440aad00f2aArgyrios Kyrtzidis 327da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor virtual ~Decl(); 328da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor 3291e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor /// \brief Allocate memory for a deserialized declaration. 3301e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor /// 3311e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor /// This routine must be used to allocate memory for any declaration that is 3321e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor /// deserialized from a module file. 3331e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor /// 3341e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor /// \param Context The context in which we will allocate memory. 3351e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor /// \param ID The global ID of the deserialized declaration. 3361e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor /// \param Size The size of the allocated object. 3371e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor static void *AllocateDeserializedDecl(const ASTContext &Context, 3381e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor unsigned ID, 3391e68ecc4fcce12f683c4fd38acfd1a004001b04fDouglas Gregor unsigned Size); 3406bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor 3416bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor /// \brief Update a potentially out-of-date declaration. 3426bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor void updateOutOfDate(IdentifierInfo &II) const; 3436bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor 3441bb19638f2ec0d63ed131b51ca8d9542d1a9afeeSam Bishoppublic: 34555d608cbadf1e9c05064f9287c057d50b7df65b4Argyrios Kyrtzidis 34655d608cbadf1e9c05064f9287c057d50b7df65b4Argyrios Kyrtzidis /// \brief Source range that this declaration covers. 347aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar virtual SourceRange getSourceRange() const LLVM_READONLY { 348da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor return SourceRange(getLocation(), getLocation()); 349da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor } 350aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceLocation getLocStart() const LLVM_READONLY { 351aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar return getSourceRange().getBegin(); 352aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar } 353aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceLocation getLocEnd() const LLVM_READONLY { 354aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar return getSourceRange().getEnd(); 355aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar } 35655d608cbadf1e9c05064f9287c057d50b7df65b4Argyrios Kyrtzidis 3570ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner SourceLocation getLocation() const { return Loc; } 3580ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner void setLocation(SourceLocation L) { Loc = L; } 3590ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 36035043e56150dc4eda882acd5ddfe0f8e3c0a8cb1John McCall Kind getKind() const { return static_cast<Kind>(DeclKind); } 3610ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner const char *getDeclKindName() const; 3621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36346cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor Decl *getNextDeclInContext() { return NextInContextAndBits.getPointer(); } 36446cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor const Decl *getNextDeclInContext() const {return NextInContextAndBits.getPointer();} 36596f4468b6b1bf69bb01c1207f716a3ffaeb4a8d3Chris Lattner 3664afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor DeclContext *getDeclContext() { 36710d8379676f32b493740a5509e2cd7f0d6433139Chris Lattner if (isInSemaDC()) 36810d8379676f32b493740a5509e2cd7f0d6433139Chris Lattner return getSemanticDC(); 36910d8379676f32b493740a5509e2cd7f0d6433139Chris Lattner return getMultipleDC()->SemanticDC; 3704afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 3710cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner const DeclContext *getDeclContext() const { 3720cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner return const_cast<Decl*>(this)->getDeclContext(); 3730cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner } 3743708b3df2e86998dca4c006939014ea1174da834Argyrios Kyrtzidis 375aab9e315184d344bbd733f13b68915d02db7b32bJohn McCall /// Finds the innermost non-closure context of this declaration. 376aab9e315184d344bbd733f13b68915d02db7b32bJohn McCall /// That is, walk out the DeclContext chain, skipping any blocks. 377aab9e315184d344bbd733f13b68915d02db7b32bJohn McCall DeclContext *getNonClosureContext(); 378aab9e315184d344bbd733f13b68915d02db7b32bJohn McCall const DeclContext *getNonClosureContext() const { 379aab9e315184d344bbd733f13b68915d02db7b32bJohn McCall return const_cast<Decl*>(this)->getNonClosureContext(); 380aab9e315184d344bbd733f13b68915d02db7b32bJohn McCall } 381aab9e315184d344bbd733f13b68915d02db7b32bJohn McCall 3823708b3df2e86998dca4c006939014ea1174da834Argyrios Kyrtzidis TranslationUnitDecl *getTranslationUnitDecl(); 3833708b3df2e86998dca4c006939014ea1174da834Argyrios Kyrtzidis const TranslationUnitDecl *getTranslationUnitDecl() const { 3843708b3df2e86998dca4c006939014ea1174da834Argyrios Kyrtzidis return const_cast<Decl*>(this)->getTranslationUnitDecl(); 3853708b3df2e86998dca4c006939014ea1174da834Argyrios Kyrtzidis } 3863708b3df2e86998dca4c006939014ea1174da834Argyrios Kyrtzidis 3879aeed32282fe8a775c24c01c923717ca86695685John McCall bool isInAnonymousNamespace() const; 3889aeed32282fe8a775c24c01c923717ca86695685John McCall 389aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar ASTContext &getASTContext() const LLVM_READONLY; 3901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3911329c274628cc8c4e8ad472b41d1a78c8123f611Anders Carlsson void setAccess(AccessSpecifier AS) { 3921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Access = AS; 3933a1c36c099df4dcc94d1d24516a8a2c809c764d4Douglas Gregor#ifndef NDEBUG 3941329c274628cc8c4e8ad472b41d1a78c8123f611Anders Carlsson CheckAccessDeclContext(); 3953a1c36c099df4dcc94d1d24516a8a2c809c764d4Douglas Gregor#endif 3961329c274628cc8c4e8ad472b41d1a78c8123f611Anders Carlsson } 3971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump AccessSpecifier getAccess() const { 3993a1c36c099df4dcc94d1d24516a8a2c809c764d4Douglas Gregor#ifndef NDEBUG 4001329c274628cc8c4e8ad472b41d1a78c8123f611Anders Carlsson CheckAccessDeclContext(); 4013a1c36c099df4dcc94d1d24516a8a2c809c764d4Douglas Gregor#endif 4021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return AccessSpecifier(Access); 403b8547e800f9553a72c2f3635ae2371692bd4411aAnders Carlsson } 4044afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 405109f5fc8dff6f3bd707e0e4140dc99ef7d4f3e88Douglas Gregor /// \brief Retrieve the access specifier for this declaration, even though 406109f5fc8dff6f3bd707e0e4140dc99ef7d4f3e88Douglas Gregor /// it may not yet have been properly set. 407109f5fc8dff6f3bd707e0e4140dc99ef7d4f3e88Douglas Gregor AccessSpecifier getAccessUnsafe() const { 408109f5fc8dff6f3bd707e0e4140dc99ef7d4f3e88Douglas Gregor return AccessSpecifier(Access); 409109f5fc8dff6f3bd707e0e4140dc99ef7d4f3e88Douglas Gregor } 410109f5fc8dff6f3bd707e0e4140dc99ef7d4f3e88Douglas Gregor 41176a642ff4fce7a0648c79a1f01324a8c3880e251Chris Lattner bool hasAttrs() const { return HasAttrs; } 4124bbb8501d9db2ae72b1e39afaafa5795d67ffe03Argyrios Kyrtzidis void setAttrs(const AttrVec& Attrs) { 4134bbb8501d9db2ae72b1e39afaafa5795d67ffe03Argyrios Kyrtzidis return setAttrsImpl(Attrs, getASTContext()); 4144bbb8501d9db2ae72b1e39afaafa5795d67ffe03Argyrios Kyrtzidis } 415ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner AttrVec &getAttrs() { 416cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt return const_cast<AttrVec&>(const_cast<const Decl*>(this)->getAttrs()); 41781abbdd848aa02c30242bd22dcc6ffe024ae2957Chris Lattner } 418cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt const AttrVec &getAttrs() const; 41940b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis void swapAttrs(Decl *D); 420cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt void dropAttrs(); 4210ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 422b5f35bae05f1ce3ae62ca52b266a086fd019e89bDouglas Gregor void addAttr(Attr *A) { 423b5f35bae05f1ce3ae62ca52b266a086fd019e89bDouglas Gregor if (hasAttrs()) 424b5f35bae05f1ce3ae62ca52b266a086fd019e89bDouglas Gregor getAttrs().push_back(A); 425b5f35bae05f1ce3ae62ca52b266a086fd019e89bDouglas Gregor else 426b5f35bae05f1ce3ae62ca52b266a086fd019e89bDouglas Gregor setAttrs(AttrVec(1, A)); 427b5f35bae05f1ce3ae62ca52b266a086fd019e89bDouglas Gregor } 4281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 429cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt typedef AttrVec::const_iterator attr_iterator; 430cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt 431cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt // FIXME: Do not rely on iterators having comparable singular values. 432cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt // Note that this should error out if they do not. 433cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt attr_iterator attr_begin() const { 434cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt return hasAttrs() ? getAttrs().begin() : 0; 435cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt } 436cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt attr_iterator attr_end() const { 437cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt return hasAttrs() ? getAttrs().end() : 0; 438cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt } 439ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 440c3ca14d13741889a9b924d0ca32e818f07a9834aFariborz Jahanian template <typename T> 4418cf0f52037e0c4bf656953ae63a07e8156aeb5fbFariborz Jahanian void dropAttr() { 4428cf0f52037e0c4bf656953ae63a07e8156aeb5fbFariborz Jahanian if (!HasAttrs) return; 443ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 44410be5bad483cfe66bb5eb5ff948c03c4628ce774Benjamin Kramer AttrVec &Vec = getAttrs(); 44510be5bad483cfe66bb5eb5ff948c03c4628ce774Benjamin Kramer Vec.erase(std::remove_if(Vec.begin(), Vec.end(), isa<T, Attr*>), Vec.end()); 44610be5bad483cfe66bb5eb5ff948c03c4628ce774Benjamin Kramer 44710be5bad483cfe66bb5eb5ff948c03c4628ce774Benjamin Kramer if (Vec.empty()) 4488cf0f52037e0c4bf656953ae63a07e8156aeb5fbFariborz Jahanian HasAttrs = false; 4498cf0f52037e0c4bf656953ae63a07e8156aeb5fbFariborz Jahanian } 450ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 451cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt template <typename T> 452cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt specific_attr_iterator<T> specific_attr_begin() const { 453cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt return specific_attr_iterator<T>(attr_begin()); 454cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt } 455cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt template <typename T> 456cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt specific_attr_iterator<T> specific_attr_end() const { 457cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt return specific_attr_iterator<T>(attr_end()); 458cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt } 459cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt 460cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt template<typename T> T *getAttr() const { 461cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt return hasAttrs() ? getSpecificAttr<T>(getAttrs()) : 0; 462cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt } 46340b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis template<typename T> bool hasAttr() const { 464cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt return hasAttrs() && hasSpecificAttr<T>(getAttrs()); 465cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt } 466cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt 467cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt /// getMaxAlignment - return the maximum alignment specified by attributes 468cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt /// on this decl, 0 if there are none. 4692fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer unsigned getMaxAlignment() const; 4701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4710ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// setInvalidDecl - Indicates the Decl had a semantic error. This 4720ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// allows for graceful error recovery. 47342738573253da1bd61f9c44f8d77f600d3b0cd1cDouglas Gregor void setInvalidDecl(bool Invalid = true); 4740ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner bool isInvalidDecl() const { return (bool) InvalidDecl; } 4756b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor 4766b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor /// isImplicit - Indicates whether the declaration was implicitly 4776b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor /// generated by the implementation. If false, this declaration 4786b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor /// was written explicitly in the source code. 4796b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor bool isImplicit() const { return Implicit; } 4806b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor void setImplicit(bool I = true) { Implicit = I; } 4811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 482e0762c92110dfdcdd207db461a4ea17afd168f1eDouglas Gregor /// \brief Whether this declaration was used, meaning that a definition 483e0762c92110dfdcdd207db461a4ea17afd168f1eDouglas Gregor /// is required. 484c070cc602d6eefea881f71a60de09e05b54c3fddDouglas Gregor /// 485c070cc602d6eefea881f71a60de09e05b54c3fddDouglas Gregor /// \param CheckUsedAttr When true, also consider the "used" attribute 486c070cc602d6eefea881f71a60de09e05b54c3fddDouglas Gregor /// (in addition to the "used" bit set by \c setUsed()) when determining 487c070cc602d6eefea881f71a60de09e05b54c3fddDouglas Gregor /// whether the function is used. 488c070cc602d6eefea881f71a60de09e05b54c3fddDouglas Gregor bool isUsed(bool CheckUsedAttr = true) const; 489cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt 490e0762c92110dfdcdd207db461a4ea17afd168f1eDouglas Gregor void setUsed(bool U = true) { Used = U; } 4911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4926b6b42aed07726178f61954ac6e51f47da00275cArgyrios Kyrtzidis /// \brief Whether this declaration was referenced. 4936b6b42aed07726178f61954ac6e51f47da00275cArgyrios Kyrtzidis bool isReferenced() const; 4946b6b42aed07726178f61954ac6e51f47da00275cArgyrios Kyrtzidis 4956b6b42aed07726178f61954ac6e51f47da00275cArgyrios Kyrtzidis void setReferenced(bool R = true) { Referenced = R; } 4966b6b42aed07726178f61954ac6e51f47da00275cArgyrios Kyrtzidis 497c14a03dffff69b5e1c55cc118fc52d8fd9f3a28dArgyrios Kyrtzidis /// \brief Whether this declaration is a top-level declaration (function, 498c14a03dffff69b5e1c55cc118fc52d8fd9f3a28dArgyrios Kyrtzidis /// global variable, etc.) that is lexically inside an objc container 499c14a03dffff69b5e1c55cc118fc52d8fd9f3a28dArgyrios Kyrtzidis /// definition. 500c14a03dffff69b5e1c55cc118fc52d8fd9f3a28dArgyrios Kyrtzidis bool isTopLevelDeclInObjCContainer() const { 50146cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor return NextInContextAndBits.getInt() & TopLevelDeclInObjCContainerFlag; 502c14a03dffff69b5e1c55cc118fc52d8fd9f3a28dArgyrios Kyrtzidis } 503c14a03dffff69b5e1c55cc118fc52d8fd9f3a28dArgyrios Kyrtzidis 504c14a03dffff69b5e1c55cc118fc52d8fd9f3a28dArgyrios Kyrtzidis void setTopLevelDeclInObjCContainer(bool V = true) { 50546cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor unsigned Bits = NextInContextAndBits.getInt(); 50646cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor if (V) 50746cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor Bits |= TopLevelDeclInObjCContainerFlag; 50846cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor else 50946cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor Bits &= ~TopLevelDeclInObjCContainerFlag; 51046cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor NextInContextAndBits.setInt(Bits); 51146cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor } 51246cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor 51346cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregorprotected: 51446cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor /// \brief Whether this declaration was marked as being private to the 51546cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor /// module in which it was defined. 51646cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor bool isModulePrivate() const { 51746cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor return NextInContextAndBits.getInt() & ModulePrivateFlag; 51846cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor } 51946cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor 52046cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor /// \brief Specify whether this declaration was marked as being private 52146cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor /// to the module in which it was defined. 52246cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor void setModulePrivate(bool MP = true) { 52346cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor unsigned Bits = NextInContextAndBits.getInt(); 52446cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor if (MP) 52546cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor Bits |= ModulePrivateFlag; 52646cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor else 52746cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor Bits &= ~ModulePrivateFlag; 52846cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor NextInContextAndBits.setInt(Bits); 529c14a03dffff69b5e1c55cc118fc52d8fd9f3a28dArgyrios Kyrtzidis } 530c14a03dffff69b5e1c55cc118fc52d8fd9f3a28dArgyrios Kyrtzidis 531c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor /// \brief Set the owning module ID. 532c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor void setOwningModuleID(unsigned ID) { 533c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor assert(isFromASTFile() && "Only works on a deserialized declaration"); 534c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor *((unsigned*)this - 2) = ID; 535c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor } 536c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor 53746cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregorpublic: 53846cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor 5390a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \brief Determine the availability of the given declaration. 5400a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// 5410a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// This routine will determine the most restrictive availability of 5420a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// the given declaration (e.g., preferring 'unavailable' to 5430a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// 'deprecated'). 5440a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// 5450a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \param Message If non-NULL and the result is not \c 5460a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// AR_Available, will be set to a (possibly empty) message 5470a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// describing why the declaration has not been introduced, is 5480a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// deprecated, or is unavailable. 5490a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor AvailabilityResult getAvailability(std::string *Message = 0) const; 5500a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor 5510a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \brief Determine whether this declaration is marked 'deprecated'. 5520a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// 5530a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \param Message If non-NULL and the declaration is deprecated, 5540a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// this will be set to the message describing why the declaration 5550a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// was deprecated (which may be empty). 5560a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor bool isDeprecated(std::string *Message = 0) const { 5570a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor return getAvailability(Message) == AR_Deprecated; 5580a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor } 5590a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor 5600a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \brief Determine whether this declaration is marked 'unavailable'. 5610a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// 5620a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \param Message If non-NULL and the declaration is unavailable, 5630a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// this will be set to the message describing why the declaration 5640a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// was made unavailable (which may be empty). 5650a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor bool isUnavailable(std::string *Message = 0) const { 5660a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor return getAvailability(Message) == AR_Unavailable; 5670a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor } 5680a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor 5690a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \brief Determine whether this is a weak-imported symbol. 5700a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// 5710a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// Weak-imported symbols are typically marked with the 5727f3ad231bed2184694e407772689e8903068bdcaEli Friedman /// 'weak_import' attribute, but may also be marked with an 5730a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// 'availability' attribute where we're targing a platform prior to 5740a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// the introduction of this feature. 5750a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor bool isWeakImported() const; 5760a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor 5770a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \brief Determines whether this symbol can be weak-imported, 5780a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// e.g., whether it would be well-formed to add the weak_import 5790a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// attribute. 5800a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// 5810a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \param IsDefinition Set to \c true to indicate that this 5820a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// declaration cannot be weak-imported because it has a definition. 5830a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor bool canBeWeakImported(bool &IsDefinition) const; 5840a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor 585919814def90acecd25a35445862f0c0ff72a9b05Douglas Gregor /// \brief Determine whether this declaration came from an AST file (such as 586919814def90acecd25a35445862f0c0ff72a9b05Douglas Gregor /// a precompiled header or module) rather than having been parsed. 58708e0bc16b3312c27e87d33be7dcf3d4fe5bdd2e2Douglas Gregor bool isFromASTFile() const { return FromASTFile; } 588ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 589b6b60c1521a2e65f60e93c5fd56c103cf027df63Douglas Gregor /// \brief Retrieve the global declaration ID associated with this 590b6b60c1521a2e65f60e93c5fd56c103cf027df63Douglas Gregor /// declaration, which specifies where in the 591b6b60c1521a2e65f60e93c5fd56c103cf027df63Douglas Gregor unsigned getGlobalID() const { 592b6b60c1521a2e65f60e93c5fd56c103cf027df63Douglas Gregor if (isFromASTFile()) 593b6b60c1521a2e65f60e93c5fd56c103cf027df63Douglas Gregor return *((const unsigned*)this - 1); 594b6b60c1521a2e65f60e93c5fd56c103cf027df63Douglas Gregor return 0; 595b6b60c1521a2e65f60e93c5fd56c103cf027df63Douglas Gregor } 596c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor 597c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor /// \brief Retrieve the global ID of the module that owns this particular 598c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor /// declaration. 599c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor unsigned getOwningModuleID() const { 600c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor if (isFromASTFile()) 601c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor return *((const unsigned*)this - 2); 602c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor 603c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor return 0; 604c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor } 605ca2ab45341c448284cf93770018c717810575f86Douglas Gregor 606ca2ab45341c448284cf93770018c717810575f86Douglas Gregorprivate: 607ca2ab45341c448284cf93770018c717810575f86Douglas Gregor Module *getOwningModuleSlow() const; 608ca2ab45341c448284cf93770018c717810575f86Douglas Gregor 609ca2ab45341c448284cf93770018c717810575f86Douglas Gregorpublic: 610ca2ab45341c448284cf93770018c717810575f86Douglas Gregor Module *getOwningModule() const { 611ca2ab45341c448284cf93770018c717810575f86Douglas Gregor if (!isFromASTFile()) 612ca2ab45341c448284cf93770018c717810575f86Douglas Gregor return 0; 613ca2ab45341c448284cf93770018c717810575f86Douglas Gregor 614ca2ab45341c448284cf93770018c717810575f86Douglas Gregor return getOwningModuleSlow(); 615ca2ab45341c448284cf93770018c717810575f86Douglas Gregor } 616ca2ab45341c448284cf93770018c717810575f86Douglas Gregor 617cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor unsigned getIdentifierNamespace() const { 618769dbdf467681f6020ff248b969c2d41a4fdccd3Chris Lattner return IdentifierNamespace; 6190ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 620d62fdc448b3ace606c8c9c9f13e43218fa204dbfChris Lattner bool isInIdentifierNamespace(unsigned NS) const { 621d62fdc448b3ace606c8c9c9f13e43218fa204dbfChris Lattner return getIdentifierNamespace() & NS; 622d62fdc448b3ace606c8c9c9f13e43218fa204dbfChris Lattner } 623769dbdf467681f6020ff248b969c2d41a4fdccd3Chris Lattner static unsigned getIdentifierNamespaceForKind(Kind DK); 624769dbdf467681f6020ff248b969c2d41a4fdccd3Chris Lattner 6250d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall bool hasTagIdentifierNamespace() const { 6260d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall return isTagIdentifierNamespace(getIdentifierNamespace()); 6270d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall } 6280d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall static bool isTagIdentifierNamespace(unsigned NS) { 6290d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall // TagDecls have Tag and Type set and may also have TagFriend. 6300d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall return (NS & ~IDNS_TagFriend) == (IDNS_Tag | IDNS_Type); 6310d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall } 6321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6334afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// getLexicalDeclContext - The declaration context where this Decl was 6344afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// lexically declared (LexicalDC). May be different from 6354afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// getDeclContext() (SemanticDC). 6364afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// e.g.: 6374afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// 6384afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// namespace A { 6394afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// void f(); // SemanticDC == LexicalDC == 'namespace A' 6404afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// } 6414afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// void A::f(); // SemanticDC == namespace 'A' 6424afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// // LexicalDC == global namespace 64310d8379676f32b493740a5509e2cd7f0d6433139Chris Lattner DeclContext *getLexicalDeclContext() { 6444afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor if (isInSemaDC()) 64510d8379676f32b493740a5509e2cd7f0d6433139Chris Lattner return getSemanticDC(); 6464afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return getMultipleDC()->LexicalDC; 6474afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 64810d8379676f32b493740a5509e2cd7f0d6433139Chris Lattner const DeclContext *getLexicalDeclContext() const { 64910d8379676f32b493740a5509e2cd7f0d6433139Chris Lattner return const_cast<Decl*>(this)->getLexicalDeclContext(); 6504afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 651f5cecfbdcd20be224861f9e67c5973a9a2b61512Argyrios Kyrtzidis 652da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor virtual bool isOutOfLine() const { 653da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor return getLexicalDeclContext() != getDeclContext(); 654da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor } 6551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6566ab3524f72a6e64aa04973fa9433b5559abb3525Douglas Gregor /// setDeclContext - Set both the semantic and lexical DeclContext 6576ab3524f72a6e64aa04973fa9433b5559abb3525Douglas Gregor /// to DC. 6586ab3524f72a6e64aa04973fa9433b5559abb3525Douglas Gregor void setDeclContext(DeclContext *DC); 6596ab3524f72a6e64aa04973fa9433b5559abb3525Douglas Gregor 6604afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor void setLexicalDeclContext(DeclContext *DC); 6614afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 6627a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl /// isDefinedOutsideFunctionOrMethod - This predicate returns true if this 6637a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl /// scoped decl is defined outside the current function or method. This is 6647a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl /// roughly global variables and functions, but also handles enums (which 6657a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl /// could be defined inside or outside a function etc). 666c8680f46970a5a53d07e05edd93657e64764da3cArgyrios Kyrtzidis bool isDefinedOutsideFunctionOrMethod() const { 667c8680f46970a5a53d07e05edd93657e64764da3cArgyrios Kyrtzidis return getParentFunctionOrMethod() == 0; 668c8680f46970a5a53d07e05edd93657e64764da3cArgyrios Kyrtzidis } 669c8680f46970a5a53d07e05edd93657e64764da3cArgyrios Kyrtzidis 670c8680f46970a5a53d07e05edd93657e64764da3cArgyrios Kyrtzidis /// \brief If this decl is defined inside a function/method/block it returns 671c8680f46970a5a53d07e05edd93657e64764da3cArgyrios Kyrtzidis /// the corresponding DeclContext, otherwise it returns null. 672c8680f46970a5a53d07e05edd93657e64764da3cArgyrios Kyrtzidis const DeclContext *getParentFunctionOrMethod() const; 673fcc1e50ebcb441c6c610ccd539f57c57549bd66cArgyrios Kyrtzidis DeclContext *getParentFunctionOrMethod() { 674fcc1e50ebcb441c6c610ccd539f57c57549bd66cArgyrios Kyrtzidis return const_cast<DeclContext*>( 675fcc1e50ebcb441c6c610ccd539f57c57549bd66cArgyrios Kyrtzidis const_cast<const Decl*>(this)->getParentFunctionOrMethod()); 676fcc1e50ebcb441c6c610ccd539f57c57549bd66cArgyrios Kyrtzidis } 6774afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 678b57a4fe73b8227c0dba651818b8495dfca61e530Argyrios Kyrtzidis /// \brief Retrieves the "canonical" declaration of the given declaration. 679da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor virtual Decl *getCanonicalDecl() { return this; } 680b57a4fe73b8227c0dba651818b8495dfca61e530Argyrios Kyrtzidis const Decl *getCanonicalDecl() const { 681b57a4fe73b8227c0dba651818b8495dfca61e530Argyrios Kyrtzidis return const_cast<Decl*>(this)->getCanonicalDecl(); 682b57a4fe73b8227c0dba651818b8495dfca61e530Argyrios Kyrtzidis } 683fc7e2a8fbb08f0f496ac6cea0721fe72db8ce240Argyrios Kyrtzidis 684ac4e3794c60fc194fb2bd9764aa81d4cae530eccArgyrios Kyrtzidis /// \brief Whether this particular Decl is a canonical one. 685b57a4fe73b8227c0dba651818b8495dfca61e530Argyrios Kyrtzidis bool isCanonicalDecl() const { return getCanonicalDecl() == this; } 686c896ad064fd6ee73a7e0536d94df77b2cc7313b6Douglas Gregor 6871e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidisprotected: 6881e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis /// \brief Returns the next redeclaration or itself if this is the only decl. 6891e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis /// 6901e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis /// Decl subclasses that can be redeclared should override this method so that 6911e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis /// Decl::redecl_iterator can iterate over them. 692da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor virtual Decl *getNextRedeclaration() { return this; } 6931e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis 694ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor /// \brief Implementation of getPreviousDecl(), to be overridden by any 695ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor /// subclass that has a redeclaration chain. 696ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor virtual Decl *getPreviousDeclImpl() { return 0; } 697ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor 698ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor /// \brief Implementation of getMostRecentDecl(), to be overridden by any 699ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor /// subclass that has a redeclaration chain. 700ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor virtual Decl *getMostRecentDeclImpl() { return this; } 701ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor 7021e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidispublic: 7031e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis /// \brief Iterates through all the redeclarations of the same decl. 7041e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis class redecl_iterator { 7051e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis /// Current - The current declaration. 7061e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis Decl *Current; 7071e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis Decl *Starter; 7081e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis 7091e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis public: 710581deb3da481053c4993c7600f97acf7768caac5David Blaikie typedef Decl *value_type; 711581deb3da481053c4993c7600f97acf7768caac5David Blaikie typedef const value_type &reference; 712581deb3da481053c4993c7600f97acf7768caac5David Blaikie typedef const value_type *pointer; 7131e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis typedef std::forward_iterator_tag iterator_category; 714581deb3da481053c4993c7600f97acf7768caac5David Blaikie typedef std::ptrdiff_t difference_type; 7151e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis 7161e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis redecl_iterator() : Current(0) { } 7171e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis explicit redecl_iterator(Decl *C) : Current(C), Starter(C) { } 7181e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis 719581deb3da481053c4993c7600f97acf7768caac5David Blaikie reference operator*() const { return Current; } 720581deb3da481053c4993c7600f97acf7768caac5David Blaikie value_type operator->() const { return Current; } 7211e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis 7221e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis redecl_iterator& operator++() { 7231e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis assert(Current && "Advancing while iterator has reached end"); 7241e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis // Get either previous decl or latest decl. 7251e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis Decl *Next = Current->getNextRedeclaration(); 72622cbd2b794676c3b29c2b401c26730ed7047809eArgyrios Kyrtzidis assert(Next && "Should return next redeclaration or itself, never null!"); 7271e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis Current = (Next != Starter ? Next : 0); 7281e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis return *this; 7291e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis } 7301e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis 7311e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis redecl_iterator operator++(int) { 7321e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis redecl_iterator tmp(*this); 7331e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis ++(*this); 7341e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis return tmp; 7351e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis } 7361e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis 7371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump friend bool operator==(redecl_iterator x, redecl_iterator y) { 7381e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis return x.Current == y.Current; 7391e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis } 7401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump friend bool operator!=(redecl_iterator x, redecl_iterator y) { 7411e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis return x.Current != y.Current; 7421e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis } 7431e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis }; 7441e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis 7451e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis /// \brief Returns iterator for all the redeclarations of the same decl. 7461e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis /// It will iterate at least once (when this decl is the only one). 7471e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis redecl_iterator redecls_begin() const { 7481e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis return redecl_iterator(const_cast<Decl*>(this)); 7491e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis } 7501e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis redecl_iterator redecls_end() const { return redecl_iterator(); } 751fc7e2a8fbb08f0f496ac6cea0721fe72db8ce240Argyrios Kyrtzidis 752f785a7d611404cf4747287a2bbc59b4d0e6a5a8cDouglas Gregor /// \brief Retrieve the previous declaration that declares the same entity 753f785a7d611404cf4747287a2bbc59b4d0e6a5a8cDouglas Gregor /// as this declaration, or NULL if there is no previous declaration. 754ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor Decl *getPreviousDecl() { return getPreviousDeclImpl(); } 755f785a7d611404cf4747287a2bbc59b4d0e6a5a8cDouglas Gregor 756f785a7d611404cf4747287a2bbc59b4d0e6a5a8cDouglas Gregor /// \brief Retrieve the most recent declaration that declares the same entity 757ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor /// as this declaration, or NULL if there is no previous declaration. 758ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor const Decl *getPreviousDecl() const { 759ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor return const_cast<Decl *>(this)->getPreviousDeclImpl(); 760ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor } 761f785a7d611404cf4747287a2bbc59b4d0e6a5a8cDouglas Gregor 762ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor /// \brief Retrieve the most recent declaration that declares the same entity 763ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor /// as this declaration (which may be this declaration). 764ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor Decl *getMostRecentDecl() { return getMostRecentDeclImpl(); } 765ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor 766ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor /// \brief Retrieve the most recent declaration that declares the same entity 767ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor /// as this declaration (which may be this declaration). 768ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor const Decl *getMostRecentDecl() const { 769ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor return const_cast<Decl *>(this)->getMostRecentDeclImpl(); 770ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor } 771ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor 772d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl /// getBody - If this Decl represents a declaration for a body of code, 773d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl /// such as a function or method definition, this method returns the 774d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl /// top-level Stmt* of that body. Otherwise this method returns null. 775da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor virtual Stmt* getBody() const { return 0; } 776d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl 77706a54a38be5054c910ffc92db60edab23f9ea105Argyrios Kyrtzidis /// \brief Returns true if this Decl represents a declaration for a body of 77806a54a38be5054c910ffc92db60edab23f9ea105Argyrios Kyrtzidis /// code, such as a function or method definition. 779da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor virtual bool hasBody() const { return getBody() != 0; } 78006a54a38be5054c910ffc92db60edab23f9ea105Argyrios Kyrtzidis 781d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl /// getBodyRBrace - Gets the right brace of the body, if a body exists. 782d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl /// This works whether the body is a CompoundStmt or a CXXTryStmt. 7836fb0aee4f9dc261bbec72e1283ad8dc0557a6d96Argyrios Kyrtzidis SourceLocation getBodyRBrace() const; 784d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl 7850ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner // global temp stats (until we have a per-module visitor) 7869a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt static void add(Kind k); 78702892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar static void EnableStatistics(); 7880ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner static void PrintStats(); 7891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 79067e332009c6e349dc34700f539747afcff990336Anders Carlsson /// isTemplateParameter - Determines whether this declaration is a 791f57172b24f08a68d179675989813d5479dc87829Douglas Gregor /// template parameter. 792f57172b24f08a68d179675989813d5479dc87829Douglas Gregor bool isTemplateParameter() const; 7931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 79467e332009c6e349dc34700f539747afcff990336Anders Carlsson /// isTemplateParameter - Determines whether this declaration is a 79567e332009c6e349dc34700f539747afcff990336Anders Carlsson /// template parameter pack. 79667e332009c6e349dc34700f539747afcff990336Anders Carlsson bool isTemplateParameterPack() const; 797f57172b24f08a68d179675989813d5479dc87829Douglas Gregor 7981fe85ea697fb5c85acded3ac0ddbc19f89c2e181Douglas Gregor /// \brief Whether this declaration is a parameter pack. 7991fe85ea697fb5c85acded3ac0ddbc19f89c2e181Douglas Gregor bool isParameterPack() const; 800ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 801ed9d84a2112e2bd56befb5f4fa8fc5bdf71fafa3Caitlin Sadowski /// \brief returns true if this declaration is a template 802ed9d84a2112e2bd56befb5f4fa8fc5bdf71fafa3Caitlin Sadowski bool isTemplateDecl() const; 803ed9d84a2112e2bd56befb5f4fa8fc5bdf71fafa3Caitlin Sadowski 804e53060fa78ad7e98352049f72787bdb7543e2a48Douglas Gregor /// \brief Whether this declaration is a function or function template. 805e53060fa78ad7e98352049f72787bdb7543e2a48Douglas Gregor bool isFunctionOrFunctionTemplate() const; 80602cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall 80702cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// \brief Changes the namespace of this declaration to reflect that it's 80802cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// the object of a friend declaration. 80902cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// 81002cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// These declarations appear in the lexical context of the friending 81102cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// class, but in the semantic context of the actual entity. This property 81202cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// applies only to a specific decl object; other redeclarations of the 81302cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// same entity may not (and probably don't) share this property. 81402cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall void setObjectOfFriendDecl(bool PreviouslyDeclared) { 81502cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall unsigned OldNS = IdentifierNamespace; 816b0cb022daec8671406ab25f4b5d5a6d48d823bc4John McCall assert((OldNS & (IDNS_Tag | IDNS_Ordinary | 817b0cb022daec8671406ab25f4b5d5a6d48d823bc4John McCall IDNS_TagFriend | IDNS_OrdinaryFriend)) && 818b0cb022daec8671406ab25f4b5d5a6d48d823bc4John McCall "namespace includes neither ordinary nor tag"); 8190d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall assert(!(OldNS & ~(IDNS_Tag | IDNS_Ordinary | IDNS_Type | 820b0cb022daec8671406ab25f4b5d5a6d48d823bc4John McCall IDNS_TagFriend | IDNS_OrdinaryFriend)) && 821b0cb022daec8671406ab25f4b5d5a6d48d823bc4John McCall "namespace includes other than ordinary or tag"); 822b0cb022daec8671406ab25f4b5d5a6d48d823bc4John McCall 823b0cb022daec8671406ab25f4b5d5a6d48d823bc4John McCall IdentifierNamespace = 0; 824b0cb022daec8671406ab25f4b5d5a6d48d823bc4John McCall if (OldNS & (IDNS_Tag | IDNS_TagFriend)) { 82502cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall IdentifierNamespace |= IDNS_TagFriend; 8260d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall if (PreviouslyDeclared) IdentifierNamespace |= IDNS_Tag | IDNS_Type; 827b0cb022daec8671406ab25f4b5d5a6d48d823bc4John McCall } 828b0cb022daec8671406ab25f4b5d5a6d48d823bc4John McCall 829b0cb022daec8671406ab25f4b5d5a6d48d823bc4John McCall if (OldNS & (IDNS_Ordinary | IDNS_OrdinaryFriend)) { 83002cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall IdentifierNamespace |= IDNS_OrdinaryFriend; 831b0cb022daec8671406ab25f4b5d5a6d48d823bc4John McCall if (PreviouslyDeclared) IdentifierNamespace |= IDNS_Ordinary; 832b0cb022daec8671406ab25f4b5d5a6d48d823bc4John McCall } 83302cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall } 83402cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall 83502cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall enum FriendObjectKind { 83602cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall FOK_None, // not a friend object 83702cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall FOK_Declared, // a friend of a previously-declared entity 83802cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall FOK_Undeclared // a friend of a previously-undeclared entity 83902cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall }; 84002cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall 84102cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// \brief Determines whether this declaration is the object of a 84202cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// friend declaration and, if so, what kind. 84302cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// 84402cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// There is currently no direct way to find the associated FriendDecl. 84502cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall FriendObjectKind getFriendObjectKind() const { 84602cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall unsigned mask 84702cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall = (IdentifierNamespace & (IDNS_TagFriend | IDNS_OrdinaryFriend)); 84802cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall if (!mask) return FOK_None; 849ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return (IdentifierNamespace & (IDNS_Tag | IDNS_Ordinary) ? 850255d6415a692e8384971755f91541497d54b3193Anders Carlsson FOK_Declared : FOK_Undeclared); 85102cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall } 8521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 85376d326448d7e4c10b2896edc2ee855d1e68d1b88John McCall /// Specifies that this declaration is a C++ overloaded non-member. 85476d326448d7e4c10b2896edc2ee855d1e68d1b88John McCall void setNonMemberOperator() { 85576d326448d7e4c10b2896edc2ee855d1e68d1b88John McCall assert(getKind() == Function || getKind() == FunctionTemplate); 85676d326448d7e4c10b2896edc2ee855d1e68d1b88John McCall assert((IdentifierNamespace & IDNS_Ordinary) && 85776d326448d7e4c10b2896edc2ee855d1e68d1b88John McCall "visible non-member operators should be in ordinary namespace"); 85876d326448d7e4c10b2896edc2ee855d1e68d1b88John McCall IdentifierNamespace |= IDNS_NonMemberOperator; 85976d326448d7e4c10b2896edc2ee855d1e68d1b88John McCall } 86076d326448d7e4c10b2896edc2ee855d1e68d1b88John McCall 86180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { return true; } 86242220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis static DeclContext *castToDeclContext(const Decl *); 86342220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis static Decl *castFromDeclContext(const DeclContext *); 8641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8655cb3d699f0e37de1767eb23d26d03953a46cf1ffRichard Trieu void print(raw_ostream &Out, unsigned Indentation = 0, 8665cb3d699f0e37de1767eb23d26d03953a46cf1ffRichard Trieu bool PrintInstantiation = false) const; 8678cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner void print(raw_ostream &Out, const PrintingPolicy &Policy, 8685cb3d699f0e37de1767eb23d26d03953a46cf1ffRichard Trieu unsigned Indentation = 0, bool PrintInstantiation = false) const; 86942f42c0dd5cf71fbfc6fa282d03079a902f6e342Eli Friedman static void printGroup(Decl** Begin, unsigned NumDecls, 8708cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner raw_ostream &Out, const PrintingPolicy &Policy, 87142f42c0dd5cf71fbfc6fa282d03079a902f6e342Eli Friedman unsigned Indentation = 0); 872559b928b05aeacc9c984a9d633ad586bbe858196Alexander Kornienko // Debuggers don't usually respect default arguments. 87342c72c258e08ca79c9267346b4badcddd8fcd001Benjamin Kramer LLVM_ATTRIBUTE_USED void dump() const; 8747ba443aa8cfb222737d3a964a19ad4fb1328c4b5Richard Trieu // Same as dump(), but forces color printing. 8757ba443aa8cfb222737d3a964a19ad4fb1328c4b5Richard Trieu LLVM_ATTRIBUTE_USED void dumpColor() const; 876559b928b05aeacc9c984a9d633ad586bbe858196Alexander Kornienko void dump(raw_ostream &Out) const; 877559b928b05aeacc9c984a9d633ad586bbe858196Alexander Kornienko // Debuggers don't usually respect default arguments. 87842c72c258e08ca79c9267346b4badcddd8fcd001Benjamin Kramer LLVM_ATTRIBUTE_USED void dumpXML() const; 879559b928b05aeacc9c984a9d633ad586bbe858196Alexander Kornienko void dumpXML(raw_ostream &OS) const; 8804fe0c8e9c76b96e7aff21696a40dacc09d0237bcDouglas Gregor 88181abbdd848aa02c30242bd22dcc6ffe024ae2957Chris Lattnerprivate: 8824bbb8501d9db2ae72b1e39afaafa5795d67ffe03Argyrios Kyrtzidis void setAttrsImpl(const AttrVec& Attrs, ASTContext &Ctx); 8834bbb8501d9db2ae72b1e39afaafa5795d67ffe03Argyrios Kyrtzidis void setDeclContextsImpl(DeclContext *SemaDC, DeclContext *LexicalDC, 8844bbb8501d9db2ae72b1e39afaafa5795d67ffe03Argyrios Kyrtzidis ASTContext &Ctx); 88581abbdd848aa02c30242bd22dcc6ffe024ae2957Chris Lattner 8867b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidisprotected: 8877b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis ASTMutationListener *getASTMutationListener() const; 8880ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner}; 8890ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 890eaa9511dd2bcb0c7f90f47a236a91c82048f484eDouglas Gregor/// \brief Determine whether two declarations declare the same entity. 891eaa9511dd2bcb0c7f90f47a236a91c82048f484eDouglas Gregorinline bool declaresSameEntity(const Decl *D1, const Decl *D2) { 892eaa9511dd2bcb0c7f90f47a236a91c82048f484eDouglas Gregor if (!D1 || !D2) 893eaa9511dd2bcb0c7f90f47a236a91c82048f484eDouglas Gregor return false; 894eaa9511dd2bcb0c7f90f47a236a91c82048f484eDouglas Gregor 895dec1cc4ec73e96f315ab7dee51459700c0ad821dDouglas Gregor if (D1 == D2) 896dec1cc4ec73e96f315ab7dee51459700c0ad821dDouglas Gregor return true; 897dec1cc4ec73e96f315ab7dee51459700c0ad821dDouglas Gregor 898eaa9511dd2bcb0c7f90f47a236a91c82048f484eDouglas Gregor return D1->getCanonicalDecl() == D2->getCanonicalDecl(); 899eaa9511dd2bcb0c7f90f47a236a91c82048f484eDouglas Gregor} 900eaa9511dd2bcb0c7f90f47a236a91c82048f484eDouglas Gregor 90149f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner/// PrettyStackTraceDecl - If a crash occurs, indicate that it happened when 90249f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner/// doing something to a specific decl. 90349f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattnerclass PrettyStackTraceDecl : public llvm::PrettyStackTraceEntry { 904c52365674b5b157a0486f75c12dd9f4cc41d8089Daniel Dunbar const Decl *TheDecl; 90549f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner SourceLocation Loc; 90649f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner SourceManager &SM; 90749f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner const char *Message; 90849f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattnerpublic: 909c52365674b5b157a0486f75c12dd9f4cc41d8089Daniel Dunbar PrettyStackTraceDecl(const Decl *theDecl, SourceLocation L, 91049f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner SourceManager &sm, const char *Msg) 91149f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner : TheDecl(theDecl), Loc(L), SM(sm), Message(Msg) {} 9121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9138cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner virtual void print(raw_ostream &OS) const; 9141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump}; 9151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9163bc93e3124ad5e7191c4a12dc981c8ee53578193David Blaikietypedef llvm::MutableArrayRef<NamedDecl*> DeclContextLookupResult; 917ea318642072d3d94b5c3cff0fa6f4b33d2db0768John McCall 918cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenkotypedef ArrayRef<NamedDecl *> DeclContextLookupConstResult; 91949f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner 920b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner/// DeclContext - This is used only as base class of specific decl types that 9211ad4dd78ec53c24ea9e752b216035d7aa666fe49Argyrios Kyrtzidis/// can act as declaration contexts. These decls are (only the top classes 9221ad4dd78ec53c24ea9e752b216035d7aa666fe49Argyrios Kyrtzidis/// that directly derive from DeclContext are mentioned, not their subclasses): 9230ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner/// 924ef177820100ab583b08fd3056e2a5a52ee4b1629Argyrios Kyrtzidis/// TranslationUnitDecl 9252d1c5d313cd0c229cc614e74baa4c5756a4b46f4Argyrios Kyrtzidis/// NamespaceDecl 9260ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner/// FunctionDecl 9271ad4dd78ec53c24ea9e752b216035d7aa666fe49Argyrios Kyrtzidis/// TagDecl 928d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis/// ObjCMethodDecl 9291ad4dd78ec53c24ea9e752b216035d7aa666fe49Argyrios Kyrtzidis/// ObjCContainerDecl 930074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor/// LinkageSpecDecl 93156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff/// BlockDecl 9321ad4dd78ec53c24ea9e752b216035d7aa666fe49Argyrios Kyrtzidis/// 933b048c9835969c4f7fe06264748be18ed4b442116Chris Lattnerclass DeclContext { 9340ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// DeclKind - This indicates which class this is. 93535043e56150dc4eda882acd5ddfe0f8e3c0a8cb1John McCall unsigned DeclKind : 8; 9360ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 9372cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// \brief Whether this declaration context also has some external 9382cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// storage that contains additional declarations that are lexically 9392cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// part of this context. 940bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith mutable bool ExternalLexicalStorage : 1; 9412cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 9422cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// \brief Whether this declaration context also has some external 9432cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// storage that contains additional declarations that are visible 9442cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// in this context. 945bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith mutable bool ExternalVisibleStorage : 1; 946bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith 947bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith /// \brief Whether this declaration context has had external visible 948bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith /// storage added since the last lookup. In this case, \c LookupPtr's 949bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith /// invariant may not hold and needs to be fixed before we perform 950bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith /// another lookup. 951bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith mutable bool NeedToReconcileExternalVisibleStorage : 1; 9522cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 953c36c540c5bfce941f3d892919394d092491211f2Douglas Gregor /// \brief Pointer to the data structure used to lookup declarations 9540c01d18094100db92d38daa923c95661512db203John McCall /// within this context (or a DependentStoredDeclsMap if this is a 955c5d3e80c64af9604ad798282cc6861f9cd2afc52Richard Smith /// dependent context), and a bool indicating whether we have lazily 956c5d3e80c64af9604ad798282cc6861f9cd2afc52Richard Smith /// omitted any declarations from the map. We maintain the invariant 957bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith /// that, if the map contains an entry for a DeclarationName (and we 958bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith /// haven't lazily omitted anything), then it contains all relevant 959bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith /// entries for that name. 960c5d3e80c64af9604ad798282cc6861f9cd2afc52Richard Smith mutable llvm::PointerIntPair<StoredDeclsMap*, 1, bool> LookupPtr; 96144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 962eb5e9986e577b1e2bff3cca5973a2494fb593fbbArgyrios Kyrtzidisprotected: 9636037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// FirstDecl - The first declaration stored within this declaration 9646037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// context. 9652cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor mutable Decl *FirstDecl; 9666037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 9676037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// LastDecl - The last declaration stored within this declaration 9686037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// context. FIXME: We could probably cache this value somewhere 9696037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// outside of the DeclContext, to reduce the size of DeclContext by 9706037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// another pointer. 9712cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor mutable Decl *LastDecl; 9727643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidis 97376bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall friend class ExternalASTSource; 974643586fe4fcd42b0978efd3566832ab4dce50367Argyrios Kyrtzidis friend class ASTWriter; 97576bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall 976eb5e9986e577b1e2bff3cca5973a2494fb593fbbArgyrios Kyrtzidis /// \brief Build up a chain of declarations. 977eb5e9986e577b1e2bff3cca5973a2494fb593fbbArgyrios Kyrtzidis /// 978eb5e9986e577b1e2bff3cca5973a2494fb593fbbArgyrios Kyrtzidis /// \returns the first/last pair of declarations. 979eb5e9986e577b1e2bff3cca5973a2494fb593fbbArgyrios Kyrtzidis static std::pair<Decl *, Decl *> 980341785ec52f87c0803ba52dc88faac4e136f8593Bill Wendling BuildDeclChain(ArrayRef<Decl*> Decls, bool FieldsAlreadyLoaded); 981eb5e9986e577b1e2bff3cca5973a2494fb593fbbArgyrios Kyrtzidis 982bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith DeclContext(Decl::Kind K) 983bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith : DeclKind(K), ExternalLexicalStorage(false), 984bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith ExternalVisibleStorage(false), 985bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith NeedToReconcileExternalVisibleStorage(false), LookupPtr(0, false), 986bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith FirstDecl(0), LastDecl(0) {} 98744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 9880ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnerpublic: 98944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor ~DeclContext(); 99044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 9919b9ca01ff3136a7539dc08a4c4e1a3dd8c8d3a7dArgyrios Kyrtzidis Decl::Kind getDeclKind() const { 99235043e56150dc4eda882acd5ddfe0f8e3c0a8cb1John McCall return static_cast<Decl::Kind>(DeclKind); 9939b9ca01ff3136a7539dc08a4c4e1a3dd8c8d3a7dArgyrios Kyrtzidis } 9940a4739305a984ef9b821cedad5f4fe235eb6ef7dSteve Naroff const char *getDeclKindName() const; 9959b9ca01ff3136a7539dc08a4c4e1a3dd8c8d3a7dArgyrios Kyrtzidis 996305ec42f971a2b3e114eb35256c23e955c497a1cArgyrios Kyrtzidis /// getParent - Returns the containing DeclContext. 9970cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner DeclContext *getParent() { 998305ec42f971a2b3e114eb35256c23e955c497a1cArgyrios Kyrtzidis return cast<Decl>(this)->getDeclContext(); 999305ec42f971a2b3e114eb35256c23e955c497a1cArgyrios Kyrtzidis } 10000cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner const DeclContext *getParent() const { 10010cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner return const_cast<DeclContext*>(this)->getParent(); 1002d2595ecce5f8350e485c83bfe767549a522b2802Argyrios Kyrtzidis } 10031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 100477407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis /// getLexicalParent - Returns the containing lexical DeclContext. May be 100544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// different from getParent, e.g.: 100644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// 100744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// namespace A { 100844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// struct S; 100944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// } 101044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// struct A::S {}; // getParent() == namespace 'A' 101177407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis /// // getLexicalParent() == translation unit 101277407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis /// 101377407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis DeclContext *getLexicalParent() { 10140cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner return cast<Decl>(this)->getLexicalDeclContext(); 101577407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis } 10160cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner const DeclContext *getLexicalParent() const { 10170cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner return const_cast<DeclContext*>(this)->getLexicalParent(); 10181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 1019048f30a483ca352ee7f235a5be181b9dcc5f9d9cArgyrios Kyrtzidis 1020e942bbe02b6fb332d1f13d38c6e1980b416cf89aDouglas Gregor DeclContext *getLookupParent(); 1021ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1022e942bbe02b6fb332d1f13d38c6e1980b416cf89aDouglas Gregor const DeclContext *getLookupParent() const { 1023e942bbe02b6fb332d1f13d38c6e1980b416cf89aDouglas Gregor return const_cast<DeclContext*>(this)->getLookupParent(); 1024e942bbe02b6fb332d1f13d38c6e1980b416cf89aDouglas Gregor } 1025ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1026048f30a483ca352ee7f235a5be181b9dcc5f9d9cArgyrios Kyrtzidis ASTContext &getParentASTContext() const { 1027048f30a483ca352ee7f235a5be181b9dcc5f9d9cArgyrios Kyrtzidis return cast<Decl>(this)->getASTContext(); 1028048f30a483ca352ee7f235a5be181b9dcc5f9d9cArgyrios Kyrtzidis } 1029048f30a483ca352ee7f235a5be181b9dcc5f9d9cArgyrios Kyrtzidis 1030aab9e315184d344bbd733f13b68915d02db7b32bJohn McCall bool isClosure() const { 1031aab9e315184d344bbd733f13b68915d02db7b32bJohn McCall return DeclKind == Decl::Block; 1032aab9e315184d344bbd733f13b68915d02db7b32bJohn McCall } 1033aab9e315184d344bbd733f13b68915d02db7b32bJohn McCall 1034a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian bool isObjCContainer() const { 103580f775359357f90f34b6adb8104506f13a816a67Fariborz Jahanian switch (DeclKind) { 103680f775359357f90f34b6adb8104506f13a816a67Fariborz Jahanian case Decl::ObjCCategory: 103780f775359357f90f34b6adb8104506f13a816a67Fariborz Jahanian case Decl::ObjCCategoryImpl: 103880f775359357f90f34b6adb8104506f13a816a67Fariborz Jahanian case Decl::ObjCImplementation: 103980f775359357f90f34b6adb8104506f13a816a67Fariborz Jahanian case Decl::ObjCInterface: 104080f775359357f90f34b6adb8104506f13a816a67Fariborz Jahanian case Decl::ObjCProtocol: 104180f775359357f90f34b6adb8104506f13a816a67Fariborz Jahanian return true; 104280f775359357f90f34b6adb8104506f13a816a67Fariborz Jahanian } 104380f775359357f90f34b6adb8104506f13a816a67Fariborz Jahanian return false; 1044a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian } 1045a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian 10460ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner bool isFunctionOrMethod() const { 10470ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner switch (DeclKind) { 10480cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner case Decl::Block: 10490cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner case Decl::ObjCMethod: 10500cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner return true; 10510cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner default: 10529a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt return DeclKind >= Decl::firstFunction && DeclKind <= Decl::lastFunction; 10530ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 10540ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 10550ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 1056ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis bool isFileContext() const { 1057ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis return DeclKind == Decl::TranslationUnit || DeclKind == Decl::Namespace; 1058ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis } 1059ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis 10605f2bfd4811996abb783aa6c7254c56baa6930e8cDouglas Gregor bool isTranslationUnit() const { 10615f2bfd4811996abb783aa6c7254c56baa6930e8cDouglas Gregor return DeclKind == Decl::TranslationUnit; 10625f2bfd4811996abb783aa6c7254c56baa6930e8cDouglas Gregor } 10635f2bfd4811996abb783aa6c7254c56baa6930e8cDouglas Gregor 1064bcbffc46f1ad3796c4582fa1e3a9113b5aa26061Douglas Gregor bool isRecord() const { 10659a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt return DeclKind >= Decl::firstRecord && DeclKind <= Decl::lastRecord; 1066c7ed9c60b8ee04b119e23441cae2cfec74536ba9Argyrios Kyrtzidis } 1067c7ed9c60b8ee04b119e23441cae2cfec74536ba9Argyrios Kyrtzidis 106844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor bool isNamespace() const { 106944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor return DeclKind == Decl::Namespace; 107044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor } 107144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 1072410c4f2eb5e6a8c2318cacb9a6751f1b4fcff166Sebastian Redl bool isInlineNamespace() const; 1073410c4f2eb5e6a8c2318cacb9a6751f1b4fcff166Sebastian Redl 1074bc221637f5ed3538b8495dd13b831c11e821c712Douglas Gregor /// \brief Determines whether this context is dependent on a 1075bc221637f5ed3538b8495dd13b831c11e821c712Douglas Gregor /// template parameter. 1076bc221637f5ed3538b8495dd13b831c11e821c712Douglas Gregor bool isDependentContext() const; 1077bc221637f5ed3538b8495dd13b831c11e821c712Douglas Gregor 1078074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// isTransparentContext - Determines whether this context is a 1079074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// "transparent" context, meaning that the members declared in this 1080074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// context are semantically declared in the nearest enclosing 1081074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// non-transparent (opaque) context but are lexically declared in 1082074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// this context. For example, consider the enumerators of an 10831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// enumeration type: 1084074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// @code 1085074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// enum E { 10861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// Val1 1087074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// }; 1088074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// @endcode 1089074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// Here, E is a transparent context, so its enumerator (Val1) will 1090074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// appear (semantically) that it is in the same context of E. 1091074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// Examples of transparent contexts include: enumerations (except for 1092410c4f2eb5e6a8c2318cacb9a6751f1b4fcff166Sebastian Redl /// C++0x scoped enums), and C++ linkage specifications. 1093074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor bool isTransparentContext() const; 1094074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor 1095ac65c6208d48b0f9b4661c30c28997a280ac5ba6John McCall /// \brief Determines whether this context is, or is nested within, 1096ac65c6208d48b0f9b4661c30c28997a280ac5ba6John McCall /// a C++ extern "C" linkage spec. 1097ac65c6208d48b0f9b4661c30c28997a280ac5ba6John McCall bool isExternCContext() const; 1098ac65c6208d48b0f9b4661c30c28997a280ac5ba6John McCall 1099950fee2555f7a6bd193e588d6b6a941fd182391aRafael Espindola /// \brief Determines whether this context is, or is nested within, 1100950fee2555f7a6bd193e588d6b6a941fd182391aRafael Espindola /// a C++ extern "C++" linkage spec. 1101950fee2555f7a6bd193e588d6b6a941fd182391aRafael Espindola bool isExternCXXContext() const; 1102950fee2555f7a6bd193e588d6b6a941fd182391aRafael Espindola 110361481dad22ebca3fba3fe4fb67a3b926d0895e9cDouglas Gregor /// \brief Determine whether this declaration context is equivalent 110461481dad22ebca3fba3fe4fb67a3b926d0895e9cDouglas Gregor /// to the declaration context DC. 11057a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl bool Equals(const DeclContext *DC) const { 1106dbdf5e7d0b6f1f8d8c496c1a0ada6f706cddf100Douglas Gregor return DC && this->getPrimaryContext() == DC->getPrimaryContext(); 110761481dad22ebca3fba3fe4fb67a3b926d0895e9cDouglas Gregor } 11081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11096dd38daf1495367db8fe9e9a5cacb7420cf08e27Douglas Gregor /// \brief Determine whether this declaration context encloses the 11106dd38daf1495367db8fe9e9a5cacb7420cf08e27Douglas Gregor /// declaration context DC. 11117a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl bool Encloses(const DeclContext *DC) const; 1112ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis 11134b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// \brief Find the nearest non-closure ancestor of this context, 11144b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// i.e. the innermost semantic parent of this context which is not 11154b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// a closure. A context may be its own non-closure ancestor. 11164b9c2d235fb9449e249d74f48ecfec601650de93John McCall DeclContext *getNonClosureAncestor(); 11174b9c2d235fb9449e249d74f48ecfec601650de93John McCall const DeclContext *getNonClosureAncestor() const { 11184b9c2d235fb9449e249d74f48ecfec601650de93John McCall return const_cast<DeclContext*>(this)->getNonClosureAncestor(); 11194b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 11204b9c2d235fb9449e249d74f48ecfec601650de93John McCall 112144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// getPrimaryContext - There may be many different 112244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// declarations of the same entity (including forward declarations 112344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// of classes, multiple definitions of namespaces, etc.), each with 112444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// a different set of declarations. This routine returns the 112544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// "primary" DeclContext structure, which will contain the 112644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// information needed to perform name lookup into this context. 11270701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff DeclContext *getPrimaryContext(); 11280c01d18094100db92d38daa923c95661512db203John McCall const DeclContext *getPrimaryContext() const { 11290c01d18094100db92d38daa923c95661512db203John McCall return const_cast<DeclContext*>(this)->getPrimaryContext(); 11300c01d18094100db92d38daa923c95661512db203John McCall } 113144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 11327a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl /// getRedeclContext - Retrieve the context in which an entity conflicts with 11337a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl /// other entities of the same name, or where it is a redeclaration if the 1134410c4f2eb5e6a8c2318cacb9a6751f1b4fcff166Sebastian Redl /// two entities are compatible. This skips through transparent contexts. 11357a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl DeclContext *getRedeclContext(); 11367a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl const DeclContext *getRedeclContext() const { 11377a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl return const_cast<DeclContext *>(this)->getRedeclContext(); 113817a9b9e3ee75f5dbb4819cc8ebf40eec8015f84aDouglas Gregor } 11391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 114088b7094185b9d4fe9820c731b6936d8d37f6143eDouglas Gregor /// \brief Retrieve the nearest enclosing namespace context. 114188b7094185b9d4fe9820c731b6936d8d37f6143eDouglas Gregor DeclContext *getEnclosingNamespaceContext(); 114288b7094185b9d4fe9820c731b6936d8d37f6143eDouglas Gregor const DeclContext *getEnclosingNamespaceContext() const { 114388b7094185b9d4fe9820c731b6936d8d37f6143eDouglas Gregor return const_cast<DeclContext *>(this)->getEnclosingNamespaceContext(); 114488b7094185b9d4fe9820c731b6936d8d37f6143eDouglas Gregor } 114588b7094185b9d4fe9820c731b6936d8d37f6143eDouglas Gregor 11467a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl /// \brief Test if this context is part of the enclosing namespace set of 11477a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl /// the context NS, as defined in C++0x [namespace.def]p9. If either context 11487a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl /// isn't a namespace, this is equivalent to Equals(). 11497a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl /// 11507a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl /// The enclosing namespace set of a namespace is the namespace and, if it is 11517a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl /// inline, its enclosing namespace, recursively. 11527a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl bool InEnclosingNamespaceSetOf(const DeclContext *NS) const; 11537a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl 115418483f583333f8d940393e64ce111c6979639665James Dennett /// \brief Collects all of the declaration contexts that are semantically 1155f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor /// connected to this declaration context. 1156f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor /// 1157f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor /// For declaration contexts that have multiple semantically connected but 1158f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor /// syntactically distinct contexts, such as C++ namespaces, this routine 1159f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor /// retrieves the complete set of such declaration contexts in source order. 1160f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor /// For example, given: 1161f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor /// 1162f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor /// \code 116344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// namespace N { 116444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// int x; 116544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// } 116644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// namespace N { 116744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// int y; 116844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// } 1169f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor /// \endcode 1170f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor /// 1171f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor /// The \c Contexts parameter will contain both definitions of N. 1172f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor /// 1173f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor /// \param Contexts Will be cleared and set to the set of declaration 1174f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor /// contexts that are semanticaly connected to this declaration context, 1175f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor /// in source order, including this context (which may be the only result, 1176f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor /// for non-namespace contexts). 1177cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko void collectAllContexts(SmallVectorImpl<DeclContext *> &Contexts); 117844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 117944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// decl_iterator - Iterates through the declarations stored 118044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// within this context. 11816037fcba3431b47de1a994c9b286feac17894effDouglas Gregor class decl_iterator { 11826037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// Current - The current declaration. 11834afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor Decl *Current; 11846037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 11856037fcba3431b47de1a994c9b286feac17894effDouglas Gregor public: 1186581deb3da481053c4993c7600f97acf7768caac5David Blaikie typedef Decl *value_type; 1187581deb3da481053c4993c7600f97acf7768caac5David Blaikie typedef const value_type &reference; 1188581deb3da481053c4993c7600f97acf7768caac5David Blaikie typedef const value_type *pointer; 11896037fcba3431b47de1a994c9b286feac17894effDouglas Gregor typedef std::forward_iterator_tag iterator_category; 11906037fcba3431b47de1a994c9b286feac17894effDouglas Gregor typedef std::ptrdiff_t difference_type; 11916037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 11926037fcba3431b47de1a994c9b286feac17894effDouglas Gregor decl_iterator() : Current(0) { } 11934afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor explicit decl_iterator(Decl *C) : Current(C) { } 11946037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 11956037fcba3431b47de1a994c9b286feac17894effDouglas Gregor reference operator*() const { return Current; } 1196581deb3da481053c4993c7600f97acf7768caac5David Blaikie // This doesn't meet the iterator requirements, but it's convenient 1197581deb3da481053c4993c7600f97acf7768caac5David Blaikie value_type operator->() const { return Current; } 11986037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 119996f4468b6b1bf69bb01c1207f716a3ffaeb4a8d3Chris Lattner decl_iterator& operator++() { 1200244a67d911d08c3757a18ad666e4a268cf3ee285Chris Lattner Current = Current->getNextDeclInContext(); 120196f4468b6b1bf69bb01c1207f716a3ffaeb4a8d3Chris Lattner return *this; 120296f4468b6b1bf69bb01c1207f716a3ffaeb4a8d3Chris Lattner } 12036037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 12046037fcba3431b47de1a994c9b286feac17894effDouglas Gregor decl_iterator operator++(int) { 12056037fcba3431b47de1a994c9b286feac17894effDouglas Gregor decl_iterator tmp(*this); 12066037fcba3431b47de1a994c9b286feac17894effDouglas Gregor ++(*this); 12076037fcba3431b47de1a994c9b286feac17894effDouglas Gregor return tmp; 12086037fcba3431b47de1a994c9b286feac17894effDouglas Gregor } 12096037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 12101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump friend bool operator==(decl_iterator x, decl_iterator y) { 12116037fcba3431b47de1a994c9b286feac17894effDouglas Gregor return x.Current == y.Current; 12126037fcba3431b47de1a994c9b286feac17894effDouglas Gregor } 12131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump friend bool operator!=(decl_iterator x, decl_iterator y) { 12146037fcba3431b47de1a994c9b286feac17894effDouglas Gregor return x.Current != y.Current; 12156037fcba3431b47de1a994c9b286feac17894effDouglas Gregor } 12166037fcba3431b47de1a994c9b286feac17894effDouglas Gregor }; 121744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 121844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// decls_begin/decls_end - Iterate over the declarations stored in 12191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// this context. 122017945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis decl_iterator decls_begin() const; 1221581deb3da481053c4993c7600f97acf7768caac5David Blaikie decl_iterator decls_end() const { return decl_iterator(); } 122217945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis bool decls_empty() const; 122344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 1224681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl /// noload_decls_begin/end - Iterate over the declarations stored in this 1225681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl /// context that are currently loaded; don't attempt to retrieve anything 1226681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl /// from an external source. 1227681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl decl_iterator noload_decls_begin() const; 1228581deb3da481053c4993c7600f97acf7768caac5David Blaikie decl_iterator noload_decls_end() const { return decl_iterator(); } 1229681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl 1230f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// specific_decl_iterator - Iterates over a subrange of 1231f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// declarations stored in a DeclContext, providing only those that 1232669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// are of type SpecificDecl (or a class derived from it). This 1233f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// iterator is used, for example, to provide iteration over just 1234669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// the fields within a RecordDecl (with SpecificDecl = FieldDecl). 1235f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor template<typename SpecificDecl> 1236f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor class specific_decl_iterator { 1237f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// Current - The current, underlying declaration iterator, which 1238d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// will either be NULL or will point to a declaration of 1239f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// type SpecificDecl. 1240f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor DeclContext::decl_iterator Current; 12411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1242f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// SkipToNextDecl - Advances the current position up to the next 1243f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// declaration of type SpecificDecl that also meets the criteria 1244f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// required by Acceptable. 1245f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor void SkipToNextDecl() { 1246669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor while (*Current && !isa<SpecificDecl>(*Current)) 1247f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor ++Current; 1248f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 1249f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 1250f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor public: 1251581deb3da481053c4993c7600f97acf7768caac5David Blaikie typedef SpecificDecl *value_type; 1252581deb3da481053c4993c7600f97acf7768caac5David Blaikie // TODO: Add reference and pointer typedefs (with some appropriate proxy 1253581deb3da481053c4993c7600f97acf7768caac5David Blaikie // type) if we ever have a need for them. 1254581deb3da481053c4993c7600f97acf7768caac5David Blaikie typedef void reference; 1255581deb3da481053c4993c7600f97acf7768caac5David Blaikie typedef void pointer; 1256f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor typedef std::iterator_traits<DeclContext::decl_iterator>::difference_type 1257f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor difference_type; 1258f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor typedef std::forward_iterator_tag iterator_category; 1259f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 1260669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor specific_decl_iterator() : Current() { } 1261f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 1262f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// specific_decl_iterator - Construct a new iterator over a 1263d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// subset of the declarations the range [C, 1264d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// end-of-declarations). If A is non-NULL, it is a pointer to a 1265d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// member function of SpecificDecl that should return true for 1266d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// all of the SpecificDecl instances that will be in the subset 1267d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// of iterators. For example, if you want Objective-C instance 1268d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// methods, SpecificDecl will be ObjCMethodDecl and A will be 1269d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// &ObjCMethodDecl::isInstanceMethod. 1270669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor explicit specific_decl_iterator(DeclContext::decl_iterator C) : Current(C) { 1271f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor SkipToNextDecl(); 1272f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 1273f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 1274581deb3da481053c4993c7600f97acf7768caac5David Blaikie value_type operator*() const { return cast<SpecificDecl>(*Current); } 1275581deb3da481053c4993c7600f97acf7768caac5David Blaikie // This doesn't meet the iterator requirements, but it's convenient 1276581deb3da481053c4993c7600f97acf7768caac5David Blaikie value_type operator->() const { return **this; } 1277f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 1278f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor specific_decl_iterator& operator++() { 1279f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor ++Current; 1280f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor SkipToNextDecl(); 1281f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor return *this; 1282f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 1283f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 1284f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor specific_decl_iterator operator++(int) { 1285f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor specific_decl_iterator tmp(*this); 1286f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor ++(*this); 1287f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor return tmp; 1288f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 12891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1290ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie friend bool operator==(const specific_decl_iterator& x, 1291ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie const specific_decl_iterator& y) { 1292f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor return x.Current == y.Current; 1293f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 12941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1295ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie friend bool operator!=(const specific_decl_iterator& x, 1296ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie const specific_decl_iterator& y) { 1297f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor return x.Current != y.Current; 1298f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 1299f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor }; 1300f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 1301669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// \brief Iterates over a filtered subrange of declarations stored 1302669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// in a DeclContext. 1303669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// 1304669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// This iterator visits only those declarations that are of type 1305669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// SpecificDecl (or a class derived from it) and that meet some 1306669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// additional run-time criteria. This iterator is used, for 1307669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// example, to provide access to the instance methods within an 1308669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// Objective-C interface (with SpecificDecl = ObjCMethodDecl and 1309669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// Acceptable = ObjCMethodDecl::isInstanceMethod). 1310669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor template<typename SpecificDecl, bool (SpecificDecl::*Acceptable)() const> 1311669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor class filtered_decl_iterator { 1312669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// Current - The current, underlying declaration iterator, which 1313669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// will either be NULL or will point to a declaration of 1314669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// type SpecificDecl. 1315669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor DeclContext::decl_iterator Current; 13161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1317669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// SkipToNextDecl - Advances the current position up to the next 1318669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// declaration of type SpecificDecl that also meets the criteria 1319669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// required by Acceptable. 1320669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor void SkipToNextDecl() { 1321669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor while (*Current && 1322669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor (!isa<SpecificDecl>(*Current) || 1323669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor (Acceptable && !(cast<SpecificDecl>(*Current)->*Acceptable)()))) 1324669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor ++Current; 1325669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor } 1326669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 1327669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor public: 1328581deb3da481053c4993c7600f97acf7768caac5David Blaikie typedef SpecificDecl *value_type; 1329581deb3da481053c4993c7600f97acf7768caac5David Blaikie // TODO: Add reference and pointer typedefs (with some appropriate proxy 1330581deb3da481053c4993c7600f97acf7768caac5David Blaikie // type) if we ever have a need for them. 1331581deb3da481053c4993c7600f97acf7768caac5David Blaikie typedef void reference; 1332581deb3da481053c4993c7600f97acf7768caac5David Blaikie typedef void pointer; 1333669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor typedef std::iterator_traits<DeclContext::decl_iterator>::difference_type 1334669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor difference_type; 1335669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor typedef std::forward_iterator_tag iterator_category; 1336669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 1337669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor filtered_decl_iterator() : Current() { } 1338669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 1339bd4fa45e7cf6a2f0adcb0ab66d5b3d338ec56c3cDavid Blaikie /// filtered_decl_iterator - Construct a new iterator over a 1340669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// subset of the declarations the range [C, 1341669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// end-of-declarations). If A is non-NULL, it is a pointer to a 1342669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// member function of SpecificDecl that should return true for 1343669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// all of the SpecificDecl instances that will be in the subset 1344669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// of iterators. For example, if you want Objective-C instance 1345669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// methods, SpecificDecl will be ObjCMethodDecl and A will be 1346669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// &ObjCMethodDecl::isInstanceMethod. 1347669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor explicit filtered_decl_iterator(DeclContext::decl_iterator C) : Current(C) { 1348669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor SkipToNextDecl(); 1349669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor } 1350669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 1351581deb3da481053c4993c7600f97acf7768caac5David Blaikie value_type operator*() const { return cast<SpecificDecl>(*Current); } 1352581deb3da481053c4993c7600f97acf7768caac5David Blaikie value_type operator->() const { return cast<SpecificDecl>(*Current); } 1353669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 1354669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor filtered_decl_iterator& operator++() { 1355669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor ++Current; 1356669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor SkipToNextDecl(); 1357669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor return *this; 1358669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor } 1359669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 1360669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor filtered_decl_iterator operator++(int) { 1361669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor filtered_decl_iterator tmp(*this); 1362669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor ++(*this); 1363669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor return tmp; 1364669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor } 13651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1366ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie friend bool operator==(const filtered_decl_iterator& x, 1367ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie const filtered_decl_iterator& y) { 1368669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor return x.Current == y.Current; 1369669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor } 13701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1371ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie friend bool operator!=(const filtered_decl_iterator& x, 1372ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie const filtered_decl_iterator& y) { 1373669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor return x.Current != y.Current; 1374669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor } 1375669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor }; 1376669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 137740f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// @brief Add the declaration D into this context. 137840f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// 137940f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// This routine should be invoked when the declaration D has first 138040f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// been declared, to place D into the context where it was 138140f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// (lexically) defined. Every declaration must be added to one 138240f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// (and only one!) context, where it can be visited via 138340f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// [decls_begin(), decls_end()). Once a declaration has been added 138440f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// to its lexical context, the corresponding DeclContext owns the 138540f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// declaration. 138640f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// 138740f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// If D is also a NamedDecl, it will be made visible within its 138840f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// semantic context via makeDeclVisibleInContext. 138917945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis void addDecl(Decl *D); 1390381509ea9965ab6bde9b36b4131ad08bf851d9b4Sean Callanan 1391381509ea9965ab6bde9b36b4131ad08bf851d9b4Sean Callanan /// @brief Add the declaration D into this context, but suppress 1392381509ea9965ab6bde9b36b4131ad08bf851d9b4Sean Callanan /// searches for external declarations with the same name. 1393381509ea9965ab6bde9b36b4131ad08bf851d9b4Sean Callanan /// 1394381509ea9965ab6bde9b36b4131ad08bf851d9b4Sean Callanan /// Although analogous in function to addDecl, this removes an 1395381509ea9965ab6bde9b36b4131ad08bf851d9b4Sean Callanan /// important check. This is only useful if the Decl is being 1396381509ea9965ab6bde9b36b4131ad08bf851d9b4Sean Callanan /// added in response to an external search; in all other cases, 1397381509ea9965ab6bde9b36b4131ad08bf851d9b4Sean Callanan /// addDecl() is the right function to use. 1398381509ea9965ab6bde9b36b4131ad08bf851d9b4Sean Callanan /// See the ASTImporter for use cases. 13999faf810f08132aabb34a478297dfeea89c3bbe17Sean Callanan void addDeclInternal(Decl *D); 140044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 14013f9a8a60614b763785d54ad08821745d03a4af70John McCall /// @brief Add the declaration D to this context without modifying 14023f9a8a60614b763785d54ad08821745d03a4af70John McCall /// any lookup tables. 14033f9a8a60614b763785d54ad08821745d03a4af70John McCall /// 14043f9a8a60614b763785d54ad08821745d03a4af70John McCall /// This is useful for some operations in dependent contexts where 14053f9a8a60614b763785d54ad08821745d03a4af70John McCall /// the semantic context might not be dependent; this basically 14063f9a8a60614b763785d54ad08821745d03a4af70John McCall /// only happens with friends. 14073f9a8a60614b763785d54ad08821745d03a4af70John McCall void addHiddenDecl(Decl *D); 14083f9a8a60614b763785d54ad08821745d03a4af70John McCall 14099f54ad4381370c6b771424b53d219e661d6d6706John McCall /// @brief Removes a declaration from this context. 14109f54ad4381370c6b771424b53d219e661d6d6706John McCall void removeDecl(Decl *D); 14119f54ad4381370c6b771424b53d219e661d6d6706John McCall 141244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// lookup_iterator - An iterator that provides access to the results 141344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// of looking up a name within this context. 14144afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor typedef NamedDecl **lookup_iterator; 141544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 141644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// lookup_const_iterator - An iterator that provides non-mutable 141744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// access to the results of lookup up a name within this context. 14184afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor typedef NamedDecl * const * lookup_const_iterator; 141944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 1420ea318642072d3d94b5c3cff0fa6f4b33d2db0768John McCall typedef DeclContextLookupResult lookup_result; 1421ea318642072d3d94b5c3cff0fa6f4b33d2db0768John McCall typedef DeclContextLookupConstResult lookup_const_result; 142244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 142344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// lookup - Find the declarations (if any) with the given Name in 142444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// this context. Returns a range of iterators that contains all of 142540f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// the declarations with this name, with object, function, member, 142640f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// and enumerator names preceding any tag name. Note that this 142740f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// routine will not look into parent contexts. 142817945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis lookup_result lookup(DeclarationName Name); 1429514d3b6b93c83c0841d2f9dd7af8ecc2877fe921Douglas Gregor lookup_const_result lookup(DeclarationName Name) const { 1430514d3b6b93c83c0841d2f9dd7af8ecc2877fe921Douglas Gregor return const_cast<DeclContext*>(this)->lookup(Name); 1431514d3b6b93c83c0841d2f9dd7af8ecc2877fe921Douglas Gregor } 143244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 1433b75a3451bcae1301875282e73a13934c90b6574cDouglas Gregor /// \brief A simplistic name lookup mechanism that performs name lookup 1434b75a3451bcae1301875282e73a13934c90b6574cDouglas Gregor /// into this declaration context without consulting the external source. 1435b75a3451bcae1301875282e73a13934c90b6574cDouglas Gregor /// 1436ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// This function should almost never be used, because it subverts the 1437b75a3451bcae1301875282e73a13934c90b6574cDouglas Gregor /// usual relationship between a DeclContext and the external source. 1438b75a3451bcae1301875282e73a13934c90b6574cDouglas Gregor /// See the ASTImporter for the (few, but important) use cases. 1439ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie void localUncachedLookup(DeclarationName Name, 1440cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko SmallVectorImpl<NamedDecl *> &Results); 1441ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 144240f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// @brief Makes a declaration visible within this context. 144340f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// 144440f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// This routine makes the declaration D visible to name lookup 144540f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// within this context and, if this is a transparent context, 144640f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// within its parent contexts up to the first enclosing 144740f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// non-transparent context. Making a declaration visible within a 144840f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// context does not transfer ownership of a declaration, and a 144940f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// declaration can be visible in many contexts that aren't its 145040f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// lexical context. 145140f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// 145240f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// If D is a redeclaration of an existing declaration that is 145340f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// visible from this context, as determined by 145440f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// NamedDecl::declarationReplaces, the previous declaration will be 145540f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// replaced with D. 14561b7f9cbed1b96b58a6e5f7808ebc9345a76a0936Richard Smith void makeDeclVisibleInContext(NamedDecl *D); 14577643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidis 1458173a37a57b79bd8f94b85c2273039e760b159922Nick Lewycky /// all_lookups_iterator - An iterator that provides a view over the results 1459173a37a57b79bd8f94b85c2273039e760b159922Nick Lewycky /// of looking up every possible name. 1460173a37a57b79bd8f94b85c2273039e760b159922Nick Lewycky class all_lookups_iterator; 1461173a37a57b79bd8f94b85c2273039e760b159922Nick Lewycky 1462173a37a57b79bd8f94b85c2273039e760b159922Nick Lewycky all_lookups_iterator lookups_begin() const; 1463173a37a57b79bd8f94b85c2273039e760b159922Nick Lewycky 1464173a37a57b79bd8f94b85c2273039e760b159922Nick Lewycky all_lookups_iterator lookups_end() const; 1465173a37a57b79bd8f94b85c2273039e760b159922Nick Lewycky 14662a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor /// udir_iterator - Iterates through the using-directives stored 14672a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor /// within this context. 14682a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor typedef UsingDirectiveDecl * const * udir_iterator; 14691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14702a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor typedef std::pair<udir_iterator, udir_iterator> udir_iterator_range; 14712a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor 147217945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis udir_iterator_range getUsingDirectives() const; 14732a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor 147417945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis udir_iterator using_directives_begin() const { 147517945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis return getUsingDirectives().first; 14762a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor } 14772a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor 147817945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis udir_iterator using_directives_end() const { 147917945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis return getUsingDirectives().second; 14802a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor } 14812a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor 14820c01d18094100db92d38daa923c95661512db203John McCall // These are all defined in DependentDiagnostic.h. 14830c01d18094100db92d38daa923c95661512db203John McCall class ddiag_iterator; 14840c01d18094100db92d38daa923c95661512db203John McCall inline ddiag_iterator ddiag_begin() const; 14850c01d18094100db92d38daa923c95661512db203John McCall inline ddiag_iterator ddiag_end() const; 14860c01d18094100db92d38daa923c95661512db203John McCall 1487c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor // Low-level accessors 14885b8d0af4234252b38229a5bae1d615ac9769f73fRichard Smith 1489d5a20c19416d7143771b4d503fa808ae01c4e7adSean Callanan /// \brief Mark the lookup table as needing to be built. This should be 149063a9514a2330b144575a136e38875193760126f7Richard Smith /// used only if setHasExternalLexicalStorage() has been called on any 149163a9514a2330b144575a136e38875193760126f7Richard Smith /// decl context for which this is the primary context. 1492d5a20c19416d7143771b4d503fa808ae01c4e7adSean Callanan void setMustBuildLookupTable() { 1493d5a20c19416d7143771b4d503fa808ae01c4e7adSean Callanan LookupPtr.setInt(true); 1494d5a20c19416d7143771b4d503fa808ae01c4e7adSean Callanan } 1495c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor 1496c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor /// \brief Retrieve the internal representation of the lookup structure. 1497c5d3e80c64af9604ad798282cc6861f9cd2afc52Richard Smith /// This may omit some names if we are lazily building the structure. 1498c5d3e80c64af9604ad798282cc6861f9cd2afc52Richard Smith StoredDeclsMap *getLookupPtr() const { return LookupPtr.getPointer(); } 1499c5d3e80c64af9604ad798282cc6861f9cd2afc52Richard Smith 1500c5d3e80c64af9604ad798282cc6861f9cd2afc52Richard Smith /// \brief Ensure the lookup structure is fully-built and return it. 1501c5d3e80c64af9604ad798282cc6861f9cd2afc52Richard Smith StoredDeclsMap *buildLookup(); 1502c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor 15032cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// \brief Whether this DeclContext has external storage containing 15042cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// additional declarations that are lexically in this context. 15052cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor bool hasExternalLexicalStorage() const { return ExternalLexicalStorage; } 15062cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 15072cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// \brief State whether this DeclContext has external storage for 15082cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// declarations lexically in this context. 15091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setHasExternalLexicalStorage(bool ES = true) { 15101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ExternalLexicalStorage = ES; 15112cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor } 15122cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 15132cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// \brief Whether this DeclContext has external storage containing 15142cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// additional declarations that are visible in this context. 15152cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor bool hasExternalVisibleStorage() const { return ExternalVisibleStorage; } 15162cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 15172cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// \brief State whether this DeclContext has external storage for 15182cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// declarations visible in this context. 15191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setHasExternalVisibleStorage(bool ES = true) { 15201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ExternalVisibleStorage = ES; 15218896339a3c654dc44877d52a926eb89ab3ef30b5Richard Smith if (ES && LookupPtr.getPointer()) 1522bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith NeedToReconcileExternalVisibleStorage = true; 15232cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor } 15242cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 15252ea054fbc59ed19b8e3304e7e7cbdd56a5a5120fDouglas Gregor /// \brief Determine whether the given declaration is stored in the list of 15262ea054fbc59ed19b8e3304e7e7cbdd56a5a5120fDouglas Gregor /// declarations lexically within this context. 15272ea054fbc59ed19b8e3304e7e7cbdd56a5a5120fDouglas Gregor bool isDeclInLexicalTraversal(const Decl *D) const { 152846cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor return D && (D->NextInContextAndBits.getPointer() || D == FirstDecl || 152946cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor D == LastDecl); 15302ea054fbc59ed19b8e3304e7e7cbdd56a5a5120fDouglas Gregor } 1531ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 15323d7641e090cf113dec64306a1597d3e4523e2a55Argyrios Kyrtzidis static bool classof(const Decl *D); 1533b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner static bool classof(const DeclContext *D) { return true; } 15347643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidis 15350ee7d94ece918f22e67d0f09fcbc631c91091adcArgyrios Kyrtzidis LLVM_ATTRIBUTE_USED void dumpDeclContext() const; 15362b7d8ddc746a9096f8af4bd0d8b07eae523864b5Anders Carlsson 15377643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidisprivate: 1538bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith void reconcileExternalVisibleStorage(); 153917945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis void LoadLexicalDeclsFromExternalStorage() const; 1540ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1541ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// @brief Makes a declaration visible within this context, but 1542381509ea9965ab6bde9b36b4131ad08bf851d9b4Sean Callanan /// suppresses searches for external declarations with the same 1543381509ea9965ab6bde9b36b4131ad08bf851d9b4Sean Callanan /// name. 1544381509ea9965ab6bde9b36b4131ad08bf851d9b4Sean Callanan /// 1545381509ea9965ab6bde9b36b4131ad08bf851d9b4Sean Callanan /// Analogous to makeDeclVisibleInContext, but for the exclusive 1546381509ea9965ab6bde9b36b4131ad08bf851d9b4Sean Callanan /// use of addDeclInternal(). 15471b7f9cbed1b96b58a6e5f7808ebc9345a76a0936Richard Smith void makeDeclVisibleInContextInternal(NamedDecl *D); 15482cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 15490c01d18094100db92d38daa923c95661512db203John McCall friend class DependentDiagnostic; 15500c01d18094100db92d38daa923c95661512db203John McCall StoredDeclsMap *CreateStoredDeclsMap(ASTContext &C) const; 15510c01d18094100db92d38daa923c95661512db203John McCall 1552c5d3e80c64af9604ad798282cc6861f9cd2afc52Richard Smith void buildLookupImpl(DeclContext *DCtx); 1553c5d3e80c64af9604ad798282cc6861f9cd2afc52Richard Smith void makeDeclVisibleInContextWithFlags(NamedDecl *D, bool Internal, 1554c5d3e80c64af9604ad798282cc6861f9cd2afc52Richard Smith bool Rediscoverable); 15559faf810f08132aabb34a478297dfeea89c3bbe17Sean Callanan void makeDeclVisibleInContextImpl(NamedDecl *D, bool Internal); 15560ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner}; 15570ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 1558f57172b24f08a68d179675989813d5479dc87829Douglas Gregorinline bool Decl::isTemplateParameter() const { 155979c2278a66d8fc0943774d1b7c71a32f7764e1e2Douglas Gregor return getKind() == TemplateTypeParm || getKind() == NonTypeTemplateParm || 156079c2278a66d8fc0943774d1b7c71a32f7764e1e2Douglas Gregor getKind() == TemplateTemplateParm; 15614afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor} 15624afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 156380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall// Specialization selected when ToTy is not a known subclass of DeclContext. 156480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCalltemplate <class ToTy, 156580cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall bool IsKnownSubtype = ::llvm::is_base_of< DeclContext, ToTy>::value> 156680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCallstruct cast_convert_decl_context { 156780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static const ToTy *doit(const DeclContext *Val) { 156880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall return static_cast<const ToTy*>(Decl::castFromDeclContext(Val)); 156980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall } 157080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall 157180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static ToTy *doit(DeclContext *Val) { 157280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall return static_cast<ToTy*>(Decl::castFromDeclContext(Val)); 157380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall } 157480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall}; 157580cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall 157680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall// Specialization selected when ToTy is a known subclass of DeclContext. 157780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCalltemplate <class ToTy> 157880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCallstruct cast_convert_decl_context<ToTy, true> { 157980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static const ToTy *doit(const DeclContext *Val) { 158080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall return static_cast<const ToTy*>(Val); 158180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall } 158280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall 158380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static ToTy *doit(DeclContext *Val) { 158480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall return static_cast<ToTy*>(Val); 158580cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall } 158680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall}; 158780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall 158880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall 15890ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner} // end clang. 15900ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 15910ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnernamespace llvm { 15920ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 159380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall/// isa<T>(DeclContext*) 15944d509341bd5db06a517daa311379f52bb540bc34Eli Friedmantemplate <typename To> 15954d509341bd5db06a517daa311379f52bb540bc34Eli Friedmanstruct isa_impl<To, ::clang::DeclContext> { 159642220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis static bool doit(const ::clang::DeclContext &Val) { 15974d509341bd5db06a517daa311379f52bb540bc34Eli Friedman return To::classofKind(Val.getDeclKind()); 15980ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 15990ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner}; 16000ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 160180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall/// cast<T>(DeclContext*) 160280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCalltemplate<class ToTy> 160380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCallstruct cast_convert_val<ToTy, 160480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall const ::clang::DeclContext,const ::clang::DeclContext> { 160580cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static const ToTy &doit(const ::clang::DeclContext &Val) { 160680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall return *::clang::cast_convert_decl_context<ToTy>::doit(&Val); 160780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall } 160880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall}; 160980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCalltemplate<class ToTy> 161080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCallstruct cast_convert_val<ToTy, ::clang::DeclContext, ::clang::DeclContext> { 161180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static ToTy &doit(::clang::DeclContext &Val) { 161280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall return *::clang::cast_convert_decl_context<ToTy>::doit(&Val); 161380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall } 161480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall}; 161580cd64a8450d8e2c079dc134d9711cd45ba89d63John McCalltemplate<class ToTy> 161680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCallstruct cast_convert_val<ToTy, 161780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall const ::clang::DeclContext*, const ::clang::DeclContext*> { 161880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static const ToTy *doit(const ::clang::DeclContext *Val) { 161980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall return ::clang::cast_convert_decl_context<ToTy>::doit(Val); 162080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall } 162180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall}; 162280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCalltemplate<class ToTy> 162380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCallstruct cast_convert_val<ToTy, ::clang::DeclContext*, ::clang::DeclContext*> { 162480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static ToTy *doit(::clang::DeclContext *Val) { 162580cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall return ::clang::cast_convert_decl_context<ToTy>::doit(Val); 162680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall } 162780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall}; 162880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall 162942220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis/// Implement cast_convert_val for Decl -> DeclContext conversions. 16300ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnertemplate<class FromTy> 163142220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisstruct cast_convert_val< ::clang::DeclContext, FromTy, FromTy> { 1632b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner static ::clang::DeclContext &doit(const FromTy &Val) { 163342220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis return *FromTy::castToDeclContext(&Val); 16340ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 16350ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner}; 16360ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 16370ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnertemplate<class FromTy> 163842220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisstruct cast_convert_val< ::clang::DeclContext, FromTy*, FromTy*> { 1639b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner static ::clang::DeclContext *doit(const FromTy *Val) { 164042220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis return FromTy::castToDeclContext(Val); 16410ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 16420ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner}; 164342220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis 164444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregortemplate<class FromTy> 164544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregorstruct cast_convert_val< const ::clang::DeclContext, FromTy, FromTy> { 164644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor static const ::clang::DeclContext &doit(const FromTy &Val) { 164744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor return *FromTy::castToDeclContext(&Val); 164844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor } 164944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor}; 165044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 165144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregortemplate<class FromTy> 165244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregorstruct cast_convert_val< const ::clang::DeclContext, FromTy*, FromTy*> { 165344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor static const ::clang::DeclContext *doit(const FromTy *Val) { 165444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor return FromTy::castToDeclContext(Val); 165544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor } 165644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor}; 165744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 16580ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner} // end namespace llvm 16590ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 16600ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner#endif 1661